~netlandish/links

a050631d2e09f2c05899272c49fda12930a14e31 — Yader Velasquez 9 months ago d0f1260
Add slugify support for advanced search form js

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

M core/routes.go
M static/js/advancedsearch.js
M core/routes.go => core/routes.go +4 -2
@@ 1171,6 1171,7 @@ func (s *Service) PopularLinkList(c echo.Context) error {
		"links":     links,
		"isPopular": true,
		"navFlag":   "popular",
		"tagFilter": "",
	}
	if search != "" {
		gmap["search"] = search


@@ 1241,7 1242,7 @@ func (s *Service) OrgLinksList(c echo.Context) error {
			}
		}`)

	var isOrgLink bool
	var isOrgLink, advancedSearch bool
	var navFlag string
	org := &models.Organization{}
	if c.Path() != c.Echo().Reverse(s.RouteName("recent_link_list")) {


@@ 1266,6 1267,7 @@ func (s *Service) OrgLinksList(c echo.Context) error {
		org = orgs[0]
		isOrgLink = true
		navFlag = "bookmarks"
		advancedSearch = true
	} else {
		navFlag = "recent"
	}


@@ 1368,7 1370,7 @@ func (s *Service) OrgLinksList(c echo.Context) error {
		"tagFilter":        strings.Replace(tag, ",", ", ", -1),
		"excludeTagFilter": strings.Replace(excludeTag, ",", ", ", -1),
		"navFlag":          navFlag,
		"advancedSearch":   true,
		"advancedSearch":   advancedSearch,
		"hasUnreadFilter":  hasUnreadFilter,
		"hasStarredFilter": hasStarredFilter,
		"hasAllFilter":     hasAllFilter,

M static/js/advancedsearch.js => static/js/advancedsearch.js +11 -1
@@ 5,6 5,16 @@ var form = document.getElementById("advanced-search");
var btn = document.getElementById("advanced-search-btn")
var tagInputDiv = document.getElementById("advanced-search-tags")

function slugify(s) {
    if (s === ", ") {
        return ""
    }
    var re = /[^a-z0-9]+/g;
    s = s.toLowerCase().trim();
    s = s.replace(re, "-");
    return s.replace(/^-+|-+$/g, "");
}

function autocomplete() {
    tags = this.value.split(",")
    tag = tags[tags.length -1].trim()


@@ 72,7 82,7 @@ form.addEventListener("submit", function(e) {
    if (tagValue === "") {
        form.elements.tag.disabled = true;
    } else {
        tagValue = tagValue.split(", ").join(",");
        tagValue = tagValue.split(", ").map(slugify).join(",");
        if (tagValue.endsWith(",")) {
            tagValue = tagValue.slice(0, -1);
        }