~netlandish/links

4db18631a12a1e971bb2ac8cfdc5836075bd5792 — Yader Velasquez 9 months ago 45dc131
Fix broken advanced form and add new functions to shorts

References: https://todo.code.netlandish.com/~netlandish/links/47
2 files changed, 16 insertions(+), 11 deletions(-)

M short/routes.go
M templates/link_short_list.html
M short/routes.go => short/routes.go +7 -2
@@ 9,6 9,7 @@ import (
	"links/internal/localizer"
	"links/models"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"time"


@@ 118,14 119,17 @@ func (s *Service) LinkShortList(c echo.Context) error {
	op.Var("slug", slug)

	var tag, excludeTag string
	queries := make(url.Values)
	if c.QueryParam("tag") != "" {
		tag = c.QueryParam("tag")
		op.Var("tag", tag)
		queries.Add("tag", tag)
	}

	if c.QueryParam("exclude") != "" {
		excludeTag = c.QueryParam("exclude")
		op.Var("excludeTag", excludeTag)
		queries.Add("exclude", excludeTag)
	}

	if c.QueryParam("next") != "" {


@@ 168,9 172,10 @@ func (s *Service) LinkShortList(c echo.Context) error {
		"links":            linkShorts,
		"org":              org,
		"navFlag":          "short",
		"tagFilter":        tag,
		"excludeTagFilter": excludeTag,
		"tagFilter":        strings.Replace(tag, ",", ", ", -1),
		"excludeTagFilter": strings.Replace(excludeTag, ",", ", ", -1),
		"advancedSearch":   true,
		"queries":          queries,
	}

	if result.LinkShorts.PageInfo.HasPrevPage {

M templates/link_short_list.html => templates/link_short_list.html +9 -9
@@ 3,12 3,10 @@
  <h1 class="app-header__title">{{ .org.Name }} {{.pd.Title}}</h1>
  <a class="button primary is-small" href="{{reverse "short:link_short_create" .org.Slug}}">{{.pd.Data.add}}</a>
</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}}">
{{ if not .hideNav }}<p class="text-right"><a href="#" id="advanced-search-btn">{{.pd.Data.advanced_search}}</a></p>{{ end }}
{{if and (not .hideNav) (.advancedSearch)}}
    <section id="advanced-search-div" {{if and (not .tagFilter) (not .excludeTagFilter)}}class="d-none"{{end}}>
        <form method="GET" id="advanced-search-form" action="{{reverse "short:link_short_list" .org.Slug}}">
            <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>


@@ 29,8 27,10 @@
                </div>
            </div>
        </form>
    </div>
  {{end}}
    </section>
{{end}}

<section class="card shadow-card">
  <table class="striped">
    <thead>
      <tr>


@@ 58,7 58,7 @@
                                <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>
                                   href="{{if $.queries}}?{{addQueryElement $.queries "tag" .Slug}}{{else}}?tag={{.Slug}}{{end}}">#{{.Name}}</a>
                            {{end}}
                        {{end}}
                    </div>