DEV: minor full page search refactoring (#15242)
- drops jquery usage - shows clear all/ select all only when appropriate - removes ~ char apparently un-needed
This commit is contained in:
parent
f889ec2fcd
commit
adb23636e6
|
@ -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() {
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in New Issue