Resource addition: fix searching and creation

This commit is contained in:
Drew DeVault 2020-04-02 13:38:28 -04:00
parent af43379a80
commit e3cae053b9
6 changed files with 292 additions and 284 deletions

View File

@ -67,13 +67,13 @@ def new_POST(owner, project_name):
break
if not list_name:
search = valid.optional("search")
mls = lists.get_list(owner)
mls = lists.get_lists(owner)
# TODO: Search properly
mls = filter(lambda r: search.lower() in r["name"].lower(), mls)
mls = sorted(mls, key=lambda r: r["updated"], reverse=True)
return render_template("mailing-list-new.html",
view="new-resource", owner=owner, project=project,
lists=mls)
lists=mls, search=search)
mailing_list = lists.get_list(owner, list_name)
ml = MailingList()

View File

@ -59,9 +59,10 @@ def new_POST(owner, project_name):
if not tracker_name:
search = valid.optional("search")
trackers = todo.get_trackers(owner)
# TODO: Search properly
tracker = filter(lambda r: search.lower() in r["name"].lower(), trackers)
tracker = sorted(trackers, key=lambda r: r["updated"], reverse=True)
trackers = filter(lambda r:
search.lower() in r["name"].lower()
or search.lower() in r["description"].lower(), trackers)
trackers = sorted(trackers, key=lambda r: r["updated"], reverse=True)
return render_template("tracker-new.html", view="new-resource",
owner=owner, project=project, trackers=trackers,
search=search)

View File

@ -1,151 +1,154 @@
{% extends "resource-new.html" %}
{% block content %}
<form method="POST">
{{csrf_token()}}
<div class="row">
{# TODO: Hide this option for any projects which already have lists #}
<div class="col-lg-8">
<h3>Use a common template</h3>
<fieldset class="form-group">
<div class="form-check">
<label
class="form-check-label"
title="Only visible to you and your collaborators"
>
<input
class="form-check-input"
type="radio"
name="template"
value="public-inbox"
checked> public-inbox
<small id="visibility-unlisted-help" class="form-text text-muted">
Direct users to send patches &amp; questions to a single "public
inbox" shared with several other projects.
</small>
</label>
</div>
<div class="form-check">
<label
class="form-check-label"
title="Visible to anyone with the link, but not shown on your profile"
>
<input
class="form-check-input"
type="radio"
name="template"
value="announce-devel">
{{project.name}}-announce and
{{project.name}}-devel
<small id="visibility-unlisted-help" class="form-text text-muted">
Separate mailing lists for low-frequency project announcements,
and for patches &amp; development.
</small>
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input
class="form-check-input"
type="radio"
name="template"
value="announce-devel-discuss">
{{project.name}}-announce,
{{project.name}}-devel, and
{{project.name}}-discuss
<small id="visibility-public-help" class="form-text text-muted">
One list for announcements, one for patches &amp; development,
and another for user support and discussion.
</small>
</label>
</div>
</fieldset>
<div class="flex-grow-1 d-flex flex-row justify-content-end">
<button
type="submit"
class="btn btn-primary align-self-end"
name="from-template"
>Create these mailing lists {{icon("caret-right")}}</button>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Or create a new mailing list
</h3>
<div class="form-group">
<label for="{{ typename }}">Name</label>
<input
type="text"
name="name"
id="name"
class="form-control {{ valid.cls("name") }}"
value="{{ name or project.name }}" />
{{ valid.summary("name") }}
<div class="form-group">
<label for="description">Description</label>
<textarea
type="text"
name="description"
id="description"
class="form-control {{valid.cls("description")}}"
rows="5"
aria-describedby="description-help-text"
placeholder="Introduce this mailing list to users and explain the posting rules."
>{{ description or "" }}</textarea>
<small id="description-help-text" class="form-text text-muted pull-left">
Markdown supported
<div class="row">
{# TODO: Hide this option for any projects which already have lists #}
<form method="POST" class="col-lg-8">
{{csrf_token()}}
<h3>Use a common template</h3>
<fieldset class="form-group">
<div class="form-check">
<label
class="form-check-label"
title="Only visible to you and your collaborators"
>
<input
class="form-check-input"
type="radio"
name="template"
value="public-inbox"
checked> public-inbox
<small id="visibility-unlisted-help" class="form-text text-muted">
Direct users to send patches &amp; questions to a single "public
inbox" shared with several other projects.
</small>
{{valid.summary("description")}}
</div>
</label>
</div>
<div class="flex-grow-1 d-flex flex-row justify-content-end">
<button
type="submit"
class="btn btn-primary align-self-end"
name="create"
>Create new mailing list {{icon("caret-right")}}</button>
<div class="form-check">
<label
class="form-check-label"
title="Visible to anyone with the link, but not shown on your profile"
>
<input
class="form-check-input"
type="radio"
name="template"
value="announce-devel">
{{project.name}}-announce and
{{project.name}}-devel
<small id="visibility-unlisted-help" class="form-text text-muted">
Separate mailing lists for low-frequency project announcements,
and for patches &amp; development.
</small>
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input
class="form-check-input"
type="radio"
name="template"
value="announce-devel-discuss">
{{project.name}}-announce,
{{project.name}}-devel, and
{{project.name}}-discuss
<small id="visibility-public-help" class="form-text text-muted">
One list for announcements, one for patches &amp; development,
and another for user support and discussion.
</small>
</label>
</div>
</fieldset>
<div class="flex-grow-1 d-flex flex-row justify-content-end">
<button
type="submit"
class="btn btn-primary align-self-end"
name="from-template"
>Create these mailing lists {{icon("caret-right")}}</button>
</div>
</div>
{% if any(lists) %}
<div class="row">
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Or add an existing mailing list
</h3>
{# TODO: Pagination #}
</form>
</div>
<form method="POST" class="row">
{{csrf_token()}}
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Or create a new mailing list
</h3>
<div class="form-group">
<label for="{{ typename }}">Name</label>
<input
type="text"
name="name"
id="name"
class="form-control {{ valid.cls("name") }}"
value="{{ name or project.name }}" />
{{ valid.summary("name") }}
<div class="form-group">
{# TODO: How exactly should this work #}
<input
name="search"
<label for="description">Description</label>
<textarea
type="text"
placeholder="Search your mailing lists"
class="form-control"
value="{{ search if search else "" }}" />
</div>
<div class="event-list select-resource">
{% for list in lists %}
<div class="event">
<h3>
<button
type="submit"
name="existing-{{ list["name"] }}"
class="pull-right btn btn-primary btn-lg"
>Select list&nbsp;{{ icon("caret-right") }}</button>
<a
href="{{get_origin("lists.sr.ht",
external=True)}}/{{ list["owner"]["canonical_name"] }}/{{list["name"]}}"
target="_blank"
rel="noopener"
>{{ list["name"] }}</a>
</h3>
</div>
{% endfor %}
name="description"
id="description"
class="form-control {{valid.cls("description")}}"
rows="5"
aria-describedby="description-help-text"
placeholder="Introduce this mailing list to users and explain the posting rules."
>{{ description or "" }}</textarea>
<small id="description-help-text" class="form-text text-muted pull-left">
Markdown supported
</small>
{{valid.summary("description")}}
</div>
</div>
<div class="flex-grow-1 d-flex flex-row justify-content-end">
<button
type="submit"
class="btn btn-primary align-self-end"
name="create"
>Create new mailing list {{icon("caret-right")}}</button>
</div>
</div>
{% endif %}
</form>
{% if any(lists) or search %}
<div class="row">
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Or add an existing mailing list
</h3>
{# TODO: Pagination #}
<form class="form-group" method="POST">
{{csrf_token()}}
<input
name="search"
type="text"
placeholder="Search mailing lists"
class="form-control{% if search_error %} is-invalid{% endif %}"
value="{{ search if search else "" }}" />
{% if search_error %}
<div class="invalid-feedback">{{ search_error }}</div>
{% endif %}
</form>
<form method="POST" class="event-list select-resource">
{{csrf_token()}}
{% for list in lists %}
<div class="event">
<h3>
<button
type="submit"
name="existing-{{ list["name"] }}"
class="pull-right btn btn-primary btn-lg"
>Select list&nbsp;{{ icon("caret-right") }}</button>
<a
href="{{get_origin("lists.sr.ht",
external=True)}}/{{ list["owner"]["canonical_name"] }}/{{list["name"]}}"
target="_blank"
rel="noopener"
>{{ list["name"] }}</a>
</h3>
</div>
{% endfor %}
</form>
</div>
</div>
{% endif %}
{% endblock %}

View File

@ -5,7 +5,7 @@
<h4>
<a
href="{{mailing_list.url()}}"
>{{tracker.owner.canonical_name}}/{{mailing_list.name}}</a>
>{{mailing_list.owner.canonical_name}}/{{mailing_list.name}}</a>
</h4>
{% if mailing_list.description %}
{{ mailing_list.description | md }}

View File

@ -1,76 +1,78 @@
{% extends "resource-new.html" %}
{% block content %}
<form method="POST">
<div class="row">
<div class="col-lg-8">
<h3>Create a new {{vcs}} repository</h3>
</div>
</div>
<form method="POST" class="row">
{{csrf_token()}}
<div class="row">
<div class="col-lg-8">
<h3>Create a new {{vcs}} repository</h3>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="col-lg-6">
<div class="form-group">
<label for="{{ typename }}">Name</label>
<input
type="text"
name="name"
id="name"
class="form-control {{ valid.cls("name") }}"
value="{{ name or project.name }}" />
{{ valid.summary("name") }}
<div class="form-group">
<label for="{{ typename }}">Name</label>
<label for="description">Description</label>
<input
type="text"
name="name"
id="name"
class="form-control {{ valid.cls("name") }}"
value="{{ name or project.name }}" />
{{ valid.summary("name") }}
<div class="form-group">
<label for="description">Description</label>
<input
type="text"
name="description"
id="description"
class="form-control {{valid.cls("description")}}"
value="{{ description or project.description }}" />
{{valid.summary("description")}}
</div>
</div>
<button type="submit" class="btn btn-primary" name="create">
Create new {{vcs}} repository {{ icon("caret-right") }}
</button>
</div>
</div>
{% if any(repos) %}
<div class="row">
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Or add an existing {{vcs}} repository
</h3>
{# TODO: Pagination #}
<div class="form-group">
{# TODO: How exactly should this work #}
<input
name="search"
type="text"
placeholder="Search your {{vcs}} repositories"
class="form-control"
value="{{ search if search else "" }}" />
</div>
<div class="event-list select-resource">
{% for repo in repos %}
<div class="event">
<h3>
<button
type="submit"
name="existing-{{ repo["name"] }}"
class="pull-right btn btn-primary btn-lg"
>Select repo&nbsp;{{ icon("caret-right") }}</button>
<a
href="{{get_origin("git.sr.ht",
external=True)}}/{{ repo["owner"]["canonical_name"] }}/{{repo["name"]}}"
target="_blank"
rel="noopener"
>{{ repo["name"] }}</a>
</h3>
</div>
{% endfor %}
name="description"
id="description"
class="form-control {{valid.cls("description")}}"
value="{{ description or project.description }}" />
{{valid.summary("description")}}
</div>
</div>
<button type="submit" class="btn btn-primary" name="create">
Create new {{vcs}} repository {{ icon("caret-right") }}
</button>
</div>
{% endif %}
</form>
{% if any(repos) or search %}
<div class="row">
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Or add an existing {{vcs}} repository
</h3>
{# TODO: Pagination #}
<form class="form-group" method="POST">
{{csrf_token()}}
<input
name="search"
type="text"
placeholder="Search repositories"
class="form-control{% if search_error %} is-invalid{% endif %}"
value="{{ search if search else "" }}" />
{% if search_error %}
<div class="invalid-feedback">{{ search_error }}</div>
{% endif %}
</form>
<form method="POST" class="event-list select-resource">
{{csrf_token()}}
{% for repo in repos %}
<div class="event">
<h3>
<button
type="submit"
name="existing-{{ repo["name"] }}"
class="pull-right btn btn-primary btn-lg"
>Select repo&nbsp;{{ icon("caret-right") }}</button>
<a
href="{{get_origin("git.sr.ht",
external=True)}}/{{ repo["owner"]["canonical_name"] }}/{{repo["name"]}}"
target="_blank"
rel="noopener"
>{{ repo["name"] }}</a>
</h3>
</div>
{% endfor %}
</form>
</div>
</div>
{% endif %}
{% endblock %}

View File

@ -1,84 +1,86 @@
{% extends "resource-new.html" %}
{% block content %}
<form method="POST">
{{csrf_token()}}
<div class="row">
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Create a new ticket tracker
</h3>
<div class="row">
<form class="col-lg-8" method="POST">
{{csrf_token()}}
<h3 style="margin-top: 1rem">
Create a new ticket tracker
</h3>
<div class="form-group">
<label for="{{ typename }}">Name</label>
<input
type="text"
name="name"
id="name"
class="form-control {{ valid.cls("name") }}"
value="{{ name or project.name }}" />
{{ valid.summary("name") }}
<div class="form-group">
<label for="{{ typename }}">Name</label>
<input
<label for="description">Description</label>
<textarea
type="text"
name="name"
id="name"
class="form-control {{ valid.cls("name") }}"
value="{{ name or project.name }}" />
{{ valid.summary("name") }}
<div class="form-group">
<label for="description">Description</label>
<textarea
type="text"
name="description"
id="description"
class="form-control {{valid.cls("description")}}"
rows="5"
aria-describedby="description-help-text"
placeholder="Give users an idea of how to submit a good ticket for this tracker."
>{{ description or "" }}</textarea>
<small id="description-help-text" class="form-text text-muted pull-left">
Markdown supported
</small>
{{valid.summary("description")}}
</div>
</div>
<div class="flex-grow-1 d-flex flex-row justify-content-end">
<button
type="submit"
class="btn btn-primary align-self-end"
name="create"
>Create new tracker {{icon("caret-right")}}</button>
name="description"
id="description"
class="form-control {{valid.cls("description")}}"
rows="5"
aria-describedby="description-help-text"
placeholder="Give users an idea of how to submit a good ticket for this tracker."
>{{ description or "" }}</textarea>
<small id="description-help-text" class="form-text text-muted pull-left">
Markdown supported
</small>
{{valid.summary("description")}}
</div>
</div>
</div>
{% if any(trackers) %}
<div class="row">
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Or add an existing tracker
</h3>
{# TODO: Pagination #}
<div class="form-group">
{# TODO: How exactly should this work #}
<input
name="search"
type="text"
placeholder="Search your ticket trackers"
class="form-control"
value="{{ search if search else "" }}" />
</div>
<div class="event-list select-resource">
{% for tracker in trackers %}
<div class="event">
<h3>
<button
type="submit"
name="existing-{{ tracker["name"] }}"
class="pull-right btn btn-primary btn-lg"
>Select tracker&nbsp;{{ icon("caret-right") }}</button>
<a
href="{{get_origin("todo.sr.ht",
external=True)}}/{{ tracker["owner"]["canonical_name"] }}/{{tracker["name"]}}"
target="_blank"
rel="noopener"
>{{ tracker["name"] }}</a>
</h3>
</div>
{% endfor %}
</div>
<div class="flex-grow-1 d-flex flex-row justify-content-end">
<button
type="submit"
class="btn btn-primary align-self-end"
name="create"
>Create new tracker {{icon("caret-right")}}</button>
</div>
</form>
</div>
{% if any(trackers) or search %}
<div class="row">
<div class="col-lg-8">
<h3 style="margin-top: 1rem">
Or add an existing tracker
</h3>
{# TODO: Pagination #}
<form class="form-group" method="POST">
{{csrf_token()}}
<input
name="search"
type="text"
placeholder="Search ticket trackers"
class="form-control{% if search_error %} is-invalid{% endif %}"
value="{{ search if search else "" }}" />
{% if search_error %}
<div class="invalid-feedback">{{ search_error }}</div>
{% endif %}
</form>
<form class="event-list select-resource" method="POSt">
{{csrf_token()}}
{% for tracker in trackers %}
<div class="event">
<h3>
<button
type="submit"
name="existing-{{ tracker["name"] }}"
class="pull-right btn btn-primary btn-lg"
>Select tracker&nbsp;{{ icon("caret-right") }}</button>
<a
href="{{get_origin("todo.sr.ht",
external=True)}}/{{ tracker["owner"]["canonical_name"] }}/{{tracker["name"]}}"
target="_blank"
rel="noopener"
>{{ tracker["name"] }}</a>
</h3>
</div>
{% endfor %}
</form>
</div>
{% endif %}
</form>
</div>
{% endif %}
{% endblock %}