~netlandish/links

aa7aaa338a700bbe14366b19bdeebfc77fb7ea49 — Yader Velasquez 9 months ago 47f92b0
Move form to the top of the page
Urlencode values for tags links

References: https://todo.code.netlandish.com/~netlandish/links/47
3 files changed, 52 insertions(+), 39 deletions(-)

M static/js/advancedsearch.js
M templates/link_list.html
M templates/link_short_list.html
M static/js/advancedsearch.js => static/js/advancedsearch.js +5 -0
@@ 73,6 73,7 @@ form.addEventListener("submit", function(e) {
    e.preventDefault();
    var tagValue = form.elements.tag.value;
    var excludeValue = form.elements.exclude.value;
    var qValue = form.elements.q.value

    if (tagValue === "") {
        form.elements.tag.disabled = true;


@@ 95,6 96,10 @@ form.addEventListener("submit", function(e) {
        }
        form.elements.exclude.value = excludeValue;
    }

    if (qValue === "") {
        form.elements.q.disabled = true;
    }
    this.submit();
})


M templates/link_list.html => templates/link_list.html +41 -38
@@ 1,43 1,46 @@
{{template "base" .}}
<section class="app-header">
  <h1 class="app-header__title">{{ if .isOrgLink }}{{ .org.Name }} {{.pd.Title}}{{else if not .isPopular}}{{.pd.Data.recent}}{{else}}{{.pd.Data.popular}}{{end}}</h1>
  <form class="app-header__search app-header__search--inline" method="GET"
    action="{{if .isPopular}}{{reverse "core:popular_link_list"}}{{else if .isOrgLink}}{{reverse "core:home_link_list"}}{{else}}{{reverse "core:recent_link_list"}}{{end}}">
      <input type="search" name="q" value="{{.search}}"/>
      <button type="submit" class="button dark icon-only">
          <svg class="search-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" style="width:20px">
              <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" />
          </svg>
      </button>
  </form>
</section>
<section class="card shadow-card">
  {{if .advancedSearch}}
    <p><a href="#" id="advanced-search-btn">{{.pd.Data.advanced_search}}</a></p>
    <div id="advanced-search-div" {{if and (not .tagFilter) (not .excludeTagFilter)}}class="d-none"{{end}}>
        <form method="GET" id="advanced-search-form" action="{{.currURL}}">
            <div class="row">
                <div class="col-5"><label>{{.pd.Data.include_tags}}</label></div>
                <div class="col-5"><label>{{.pd.Data.exclude_tags}}</label></div>
                <div class="col-2"></div>
<form method="GET"
    action="{{if .isPopular}}{{reverse "core:popular_link_list"}}{{else if .isOrgLink}}{{reverse "core:home_link_list"}}{{else}}{{reverse "core:recent_link_list"}}{{end}}"
    id="advanced-search-form">
    <section class="app-header app-header-advanced-search">
        <h1 class="app-header__title">{{ if .isOrgLink }}{{ .org.Name }} {{.pd.Title}}{{else if not .isPopular}}{{.pd.Data.recent}}{{else}}{{.pd.Data.popular}}{{end}}</h1>
        <div class="app-header__search app-header__search--stack">
            <div class="app-header__search app-header__search--inline">
                <input type="search" name="q" value="{{.search}}"/>
                <button type="submit" class="button dark icon-only">
                    <svg class="search-icon" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" style="width:20px">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" />
                    </svg>
                </button>
            </div>
            <div class="row">
                <div class="col-5">
                    <input type="text" name="tag" value="{{.tagFilter}}" class="tag-selector" autocomplete="off"/>
                    <div class="d-none autocomplete-tags"></div>
                </div>
                <div class="col-5">
                    <input type="text" name="exclude" value="{{.excludeTagFilter}}" class="tag-selector" autocomplete="off"/>
                    <div class="d-none autocomplete-tags"></div>
                </div>
                <div class="col-2 is-right">
                    <button type="submit" class="button primary is-small">{{.pd.Data.apply}}</button>
                    <a href="{{.currURL}}" class="button primary is-small">{{.pd.Data.clear}}</a>
                </div>
            <p class="text-right"><a href="#" id="advanced-search-btn">{{.pd.Data.advanced_search}}</a></p>
        </div>
    </section>
    {{if .advancedSearch}}
    <section id="advanced-search-div" {{if and (not .tagFilter) (not .excludeTagFilter)}}class="d-none"{{end}}>
        <div class="row">
            <div class="col-5"><label>{{.pd.Data.include_tags}}</label></div>
            <div class="col-5"><label>{{.pd.Data.exclude_tags}}</label></div>
            <div class="col-2"></div>
        </div>
        <div class="row">
            <div class="col-5">
                <input type="text" name="tag" value="{{.tagFilter}}" class="tag-selector" autocomplete="off"/>
                <div class="d-none autocomplete-tags"></div>
            </div>
        </form>
    </div>
  {{end}}
            <div class="col-5">
                <input type="text" name="exclude" value="{{.excludeTagFilter}}" class="tag-selector" autocomplete="off"/>
                <div class="d-none autocomplete-tags"></div>
            </div>
            <div class="col-2 is-right">
                <button type="submit" class="button primary is-small">{{.pd.Data.apply}}</button>
                <a href="{{.currURL}}" class="button primary is-small">{{.pd.Data.clear}}</a>
            </div>
        </div>
    </section>
    {{end}}
</form>
<section class="card shadow-card">
  {{if .isOrgLink}}
    <p>
        <a class="filter-btn{{if .hasAllFilter}} active{{end}}" href="{{.currURL}}">{{.pd.Data.all}}</a>


@@ 149,7 152,7 @@
                <small class="link-tag__item link-tag__item--simple">#{{.Name}}</small>
            {{else}}
                <a class="link-tag__item link-tag__item--simple"
                   href="{{if $.tagFilter}}?tag={{$.tagFilter}}, {{.Slug}}{{if $.excludeTagFilter}}&exclude={{$.excludeTagFilter}}{{end}}{{else}}?tag={{.Slug}}{{if $.excludeTagFilter}}&exclude={{$.excludeTagFilter}}{{end}}{{end}}">#{{.Name}}</a>
                   href="{{if $.tagFilter}}?tag={{$.tagFilter}}{{urlquery (printf ", %s" .Slug)}}{{if $.excludeTagFilter}}&exclude={{$.excludeTagFilter}}{{end}}{{else}}?tag={{.Slug}}{{if $.excludeTagFilter}}&exclude={{$.excludeTagFilter}}{{end}}{{end}}">#{{.Name}}</a>
            {{end}}
          {{end}}
        </div>

M templates/link_short_list.html => templates/link_short_list.html +6 -1
@@ 54,7 54,12 @@
                    {{if .Tags}}
                    <div class="link-tag">
                        {{range .Tags}}
                        <a class="link-tag__item" href="?tag={{.Slug}}">{{.Name}}</a>
                            {{if isTagUsedInFilter .Slug $.tagFilter}}
                                <small class="link-tag__item">#{{.Name}}</small>
                            {{else}}
                                <a class="link-tag__item"
                                   href="{{if $.tagFilter}}?tag={{$.tagFilter}}, {{.Slug}}{{if $.excludeTagFilter}}&exclude={{$.excludeTagFilter}}{{end}}{{else}}?tag={{.Slug}}{{if $.excludeTagFilter}}&exclude={{$.excludeTagFilter}}{{end}}{{end}}">#{{.Name}}</a>
                            {{end}}
                        {{end}}
                    </div>
                    {{end}}