From f5d5959f3df696666b51bf6e7f98d51662d3af59 Mon Sep 17 00:00:00 2001 From: Tina Shi Date: Sun, 8 Mar 2020 15:46:12 -0700 Subject: [PATCH 1/3] ts - added UI for filter on tag page --- .../resources/templates/fragments/tag_search_form.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/resources/templates/fragments/tag_search_form.html b/src/main/resources/templates/fragments/tag_search_form.html index 7bd469a..1d78233 100644 --- a/src/main/resources/templates/fragments/tag_search_form.html +++ b/src/main/resources/templates/fragments/tag_search_form.html @@ -10,6 +10,16 @@ + +
+
Filter by:
+ + Alphabetical + + Number of articles + + Keyword +
From 588ee660072bcd53a2cdd7415acde5a5b666ab3b Mon Sep 17 00:00:00 2001 From: Tina Shi Date: Sun, 8 Mar 2020 16:13:44 -0700 Subject: [PATCH 2/3] ts - added tagSort function in tagController --- .../mapache_search/controllers/TagController.java | 11 +++++++++++ .../templates/fragments/tag_search_form.html | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/ucsb/cs56/mapache_search/controllers/TagController.java b/src/main/java/edu/ucsb/cs56/mapache_search/controllers/TagController.java index f5f3948..6d12aa5 100644 --- a/src/main/java/edu/ucsb/cs56/mapache_search/controllers/TagController.java +++ b/src/main/java/edu/ucsb/cs56/mapache_search/controllers/TagController.java @@ -64,4 +64,15 @@ public String tagSearch(@ModelAttribute Tag tag, Model model, OAuth2Authenticati return "tags"; } + @GetMapping("/tags/search") + public String tagSort(@ModelAttribute Tag tag, Model model, OAuth2AuthenticationToken token, String filter) { + List allTags = tagRepository.findAll(); + if (filter == "alphabetical") { + Collections.sort(allTags, (t1, t2)->{ + return t1.getName().compareTo(t2.getName()); + }); + model.addAttribute("alphabeticalTags", allTags); + } + } + } \ No newline at end of file diff --git a/src/main/resources/templates/fragments/tag_search_form.html b/src/main/resources/templates/fragments/tag_search_form.html index 1d78233..a44d7f9 100644 --- a/src/main/resources/templates/fragments/tag_search_form.html +++ b/src/main/resources/templates/fragments/tag_search_form.html @@ -13,7 +13,7 @@
Filter by:
- + Alphabetical Number of articles From 7f8998a4001b2e9b02b47d809fe70d8deca87f5b Mon Sep 17 00:00:00 2001 From: Jared Flores Date: Sun, 8 Mar 2020 16:48:22 -0700 Subject: [PATCH 3/3] jf/ts - added alphabetical filtering for tags --- .../controllers/TagController.java | 19 ++++++++++++------ src/main/resources/static/js/tags.js | 20 +++++++++++++++++++ .../templates/fragments/tag_search_form.html | 8 +++----- src/main/resources/templates/tags.html | 1 + 4 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 src/main/resources/static/js/tags.js diff --git a/src/main/java/edu/ucsb/cs56/mapache_search/controllers/TagController.java b/src/main/java/edu/ucsb/cs56/mapache_search/controllers/TagController.java index 6d12aa5..4b4cb89 100644 --- a/src/main/java/edu/ucsb/cs56/mapache_search/controllers/TagController.java +++ b/src/main/java/edu/ucsb/cs56/mapache_search/controllers/TagController.java @@ -1,6 +1,8 @@ package edu.ucsb.cs56.mapache_search.controllers; import java.util.List; +import java.util.ArrayList; +import java.util.Collections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; @@ -64,15 +66,20 @@ public String tagSearch(@ModelAttribute Tag tag, Model model, OAuth2Authenticati return "tags"; } - @GetMapping("/tags/search") + @GetMapping("/tags/filter") public String tagSort(@ModelAttribute Tag tag, Model model, OAuth2AuthenticationToken token, String filter) { - List allTags = tagRepository.findAll(); - if (filter == "alphabetical") { + Iterable tags = tagRepository.findAll(); + List allTags = new ArrayList(); + for (Tag t : tags) { + allTags.add(t); + } + if (filter.equals("alphabetical")) { Collections.sort(allTags, (t1, t2)->{ - return t1.getName().compareTo(t2.getName()); + return t1.getName().toLowerCase().compareTo(t2.getName().toLowerCase()); }); - model.addAttribute("alphabeticalTags", allTags); + model.addAttribute("alphabetical", true); } + model.addAttribute("tags", allTags); + return "tags"; } - } \ No newline at end of file diff --git a/src/main/resources/static/js/tags.js b/src/main/resources/static/js/tags.js new file mode 100644 index 0000000..60f7a7d --- /dev/null +++ b/src/main/resources/static/js/tags.js @@ -0,0 +1,20 @@ +// tags.js +var $document = $(document); + +function tag_page_ready() { + $filterBoxes = $(".filter-checkbox"); + + function filterBy(e) { + $this = $(this); + if(this.checked) { + var newURL = window.location.protocol + "//"; + newURL += window.location.host; + newURL += "/tags/filter?filter=" + $this.val(); + window.location.href = newURL; + } + } + + $filterBoxes.on("change", filterBy); +} + +$document.ready(tag_page_ready); \ No newline at end of file diff --git a/src/main/resources/templates/fragments/tag_search_form.html b/src/main/resources/templates/fragments/tag_search_form.html index a44d7f9..185b345 100644 --- a/src/main/resources/templates/fragments/tag_search_form.html +++ b/src/main/resources/templates/fragments/tag_search_form.html @@ -13,12 +13,10 @@
Filter by:
- + Alphabetical - - Number of articles - - Keyword +
diff --git a/src/main/resources/templates/tags.html b/src/main/resources/templates/tags.html index 7d2a3a7..c8c333e 100644 --- a/src/main/resources/templates/tags.html +++ b/src/main/resources/templates/tags.html @@ -24,6 +24,7 @@
+ \ No newline at end of file