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 { ajax } from "discourse/lib/ajax";
|
||||||
import { escapeExpression } from "discourse/lib/utilities";
|
import { escapeExpression } from "discourse/lib/utilities";
|
||||||
import { isEmpty } from "@ember/utils";
|
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 { scrollTop } from "discourse/mixins/scroll-top";
|
||||||
import { setTransient } from "discourse/lib/page-tracker";
|
import { setTransient } from "discourse/lib/page-tracker";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
|
@ -248,6 +248,13 @@ export default Controller.extend({
|
||||||
return this.currentUser && this.currentUser.staff && hasResults;
|
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")
|
@discourseComputed("model.grouped_search_result.can_create_topic")
|
||||||
canCreateTopic(userCanCreateTopic) {
|
canCreateTopic(userCanCreateTopic) {
|
||||||
return this.currentUser && userCanCreateTopic;
|
return this.currentUser && userCanCreateTopic;
|
||||||
|
@ -399,18 +406,28 @@ export default Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
selectAll() {
|
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,
|
// Doing this the proper way is a HUGE pain,
|
||||||
// we can hack this to work by observing each on the array
|
// we can hack this to work by observing each on the array
|
||||||
// in the component, however, when we select ANYTHING, we would force
|
// in the component, however, when we select ANYTHING, we would force
|
||||||
// 50 traversals of the list
|
// 50 traversals of the list
|
||||||
// This hack is cheap and easy
|
// 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() {
|
clearAll() {
|
||||||
this.selected.clear();
|
this.selected.clear();
|
||||||
$(".fps-result input[type=checkbox]").prop("checked", false);
|
|
||||||
|
document
|
||||||
|
.querySelectorAll(".fps-result input[type=checkbox]")
|
||||||
|
.forEach((checkbox) => {
|
||||||
|
checkbox.checked = false;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleBulkSelect() {
|
toggleBulkSelect() {
|
||||||
|
|
|
@ -81,8 +81,23 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if bulkSelectEnabled}}
|
{{#if bulkSelectEnabled}}
|
||||||
{{d-button icon="check-square" class="btn-default" action=(action "selectAll") label="search.select_all"~}}
|
{{#if hasUnselectedResults}}
|
||||||
{{d-button icon="far-square" class="btn-default" action=(action "clearAll") label="search.clear_all"}}
|
{{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}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="sort-by inline-form">
|
<div class="sort-by inline-form">
|
||||||
|
|
Loading…
Reference in New Issue