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 f5f3948c..4b4cb899 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,4 +66,20 @@ public String tagSearch(@ModelAttribute Tag tag, Model model, OAuth2Authenticati return "tags"; } + @GetMapping("/tags/filter") + public String tagSort(@ModelAttribute Tag tag, Model model, OAuth2AuthenticationToken token, String filter) { + 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().toLowerCase().compareTo(t2.getName().toLowerCase()); + }); + 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 00000000..60f7a7db --- /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 7bd469a7..185b3459 100644 --- a/src/main/resources/templates/fragments/tag_search_form.html +++ b/src/main/resources/templates/fragments/tag_search_form.html @@ -10,6 +10,14 @@ + +
+
Filter by:
+ + Alphabetical + +
diff --git a/src/main/resources/templates/tags.html b/src/main/resources/templates/tags.html index 7d2a3a73..c8c333e1 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