Skip to content

A platform for community discussion. Free, open, simple.

DEV: minor full page search refactoring (#15242)

Joffrey JAFFEUXadb23636e68d
diff --git a/app/assets/javascripts/discourse/app/controllers/full-page-search.js b/app/assets/javascripts/discourse/app/controllers/full-page-search.js
index d75bc34c9b3..bec3624eb4c 100644
--- a/app/assets/javascripts/discourse/app/controllers/full-page-search.js
+++ b/app/assets/javascripts/discourse/app/controllers/full-page-search.js
@@ -13,7 +13,7 @@ import I18n from "I18n";
import { ajax } from "discourse/lib/ajax";
import { escapeExpression } from "discourse/lib/utilities";
import { isEmpty } from "@ember/utils";
-import { or } from "@ember/object/computed";
+import { gt, or } from "@ember/object/computed";
import { scrollTop } from "discourse/mixins/scroll-top";
import { setTransient } from "discourse/lib/page-tracker";
import { Promise } from "rsvp";
@@ -248,6 +248,13 @@ export default Controller.extend({
return this.currentUser && this.currentUser.staff && hasResults;
},
+ hasSelection: gt("selected.length", 0),
+
+ @discourseComputed("selected.length", "model.posts.length")
+ hasUnselectedResults(selectionCount, postsCount) {
+ return selectionCount < postsCount;
+ },
+
@discourseComputed("model.grouped_search_result.can_create_topic")
canCreateTopic(userCanCreateTopic) {
return this.currentUser && userCanCreateTopic;
@@ -399,18 +406,28 @@ export default Controller.extend({
},
selectAll() {
- this.selected.addObjects(this.get("model.posts").map((r) => r.topic));
+ this.selected.addObjects(this.get("model.posts")).mapBy("topic");
+
// Doing this the proper way is a HUGE pain,
// we can hack this to work by observing each on the array
// in the component, however, when we select ANYTHING, we would force
// 50 traversals of the list
// This hack is cheap and easy
- $(".fps-result input[type=checkbox]").prop("checked", true);
+ document
+ .querySelectorAll(".fps-result input[type=checkbox]")
+ .forEach((checkbox) => {
+ checkbox.checked = true;
+ });
},
clearAll() {
this.selected.clear();
- $(".fps-result input[type=checkbox]").prop("checked", false);
+
+ document
+ .querySelectorAll(".fps-result input[type=checkbox]")
+ .forEach((checkbox) => {
+ checkbox.checked = false;
+ });
},
toggleBulkSelect() {
diff --git a/app/assets/javascripts/discourse/app/templates/full-page-search.hbs b/app/assets/javascripts/discourse/app/templates/full-page-search.hbs
index 795d559a1a9..2f7004702ac 100644
--- a/app/assets/javascripts/discourse/app/templates/full-page-search.hbs
+++ b/app/assets/javascripts/discourse/app/templates/full-page-search.hbs
@@ -81,8 +81,23 @@
{{/if}}
{{#if bulkSelectEnabled}}
- {{d-button icon="check-square" class="btn-default" action=(action "selectAll") label="search.select_all"~}}
- {{d-button icon="far-square" class="btn-default" action=(action "clearAll") label="search.clear_all"}}
+ {{#if hasUnselectedResults}}
+ {{d-button
+ icon="check-square"
+ class="btn-default"
+ action=(action "selectAll")
+ label="search.select_all"
+ }}
+ {{/if}}
+
+ {{#if hasSelection}}
+ {{d-button
+ icon="far-square"
+ class="btn-default"
+ action=(action "clearAll")
+ label="search.clear_all"
+ }}
+ {{/if}}
{{/if}}
<div class="sort-by inline-form">