FIX: groups filtering input was causing a full page reload (#9282)
This commit is contained in:
parent
7952cbb9a2
commit
ef3d6d6580
|
@ -1,6 +1,8 @@
|
||||||
import Controller, { inject as controller } from "@ember/controller";
|
import Controller, { inject as controller } from "@ember/controller";
|
||||||
import discourseDebounce from "discourse/lib/debounce";
|
import { debounce } from "@ember/runloop";
|
||||||
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
import { action } from "@ember/object";
|
||||||
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
||||||
|
|
||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
application: controller(),
|
application: controller(),
|
||||||
|
@ -9,37 +11,53 @@ export default Controller.extend({
|
||||||
asc: null,
|
asc: null,
|
||||||
filter: "",
|
filter: "",
|
||||||
type: null,
|
type: null,
|
||||||
|
groups: null,
|
||||||
|
isLoading: false,
|
||||||
|
|
||||||
@discourseComputed("model.extras.type_filters")
|
@discourseComputed("groups.extras.type_filters")
|
||||||
types(typeFilters) {
|
types(typeFilters) {
|
||||||
const types = [];
|
const types = [];
|
||||||
|
|
||||||
if (typeFilters) {
|
if (typeFilters) {
|
||||||
typeFilters.forEach(type => {
|
typeFilters.forEach(type =>
|
||||||
types.push({ id: type, name: I18n.t(`groups.index.${type}_groups`) });
|
types.push({ id: type, name: I18n.t(`groups.index.${type}_groups`) })
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return types;
|
return types;
|
||||||
},
|
},
|
||||||
|
|
||||||
@observes("filterInput")
|
loadGroups(params) {
|
||||||
_setFilter: discourseDebounce(function() {
|
this.set("isLoading", true);
|
||||||
this.set("filter", this.filterInput);
|
|
||||||
}, 500),
|
|
||||||
|
|
||||||
@observes("model.canLoadMore")
|
this.store
|
||||||
_showFooter() {
|
.findAll("group", params)
|
||||||
this.set("application.showFooter", !this.get("model.canLoadMore"));
|
.then(groups => {
|
||||||
|
this.set("groups", groups);
|
||||||
|
|
||||||
|
if (groups.canLoadMore) {
|
||||||
|
this.set("application.showFooter", !groups.canLoadMore);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => this.set("isLoading", false));
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
|
onFilterChanged(filter) {
|
||||||
|
debounce(this, this._debouncedFilter, filter, INPUT_DELAY);
|
||||||
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
loadMore() {
|
loadMore() {
|
||||||
this.model.loadMore();
|
this.groups && this.groups.loadMore();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
new() {
|
new() {
|
||||||
this.transitionToRoute("groups.new");
|
this.transitionToRoute("groups.new");
|
||||||
}
|
},
|
||||||
|
|
||||||
|
_debouncedFilter(filter) {
|
||||||
|
this.set("filter", filter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,14 +14,10 @@ export default DiscourseRoute.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
model(params) {
|
model(params) {
|
||||||
this._params = params;
|
return params;
|
||||||
return this.store.findAll("group", params);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, params) {
|
||||||
controller.setProperties({
|
controller.loadGroups(params);
|
||||||
model,
|
|
||||||
filterInput: this._params.filter
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
{{#d-section pageClass="groups"}}
|
{{#d-section pageClass="groups"}}
|
||||||
<div class="groups-header">
|
<div class="groups-header">
|
||||||
{{#if currentUser.admin}}
|
{{#if currentUser.admin}}
|
||||||
{{d-button action=(action "new")
|
{{d-button
|
||||||
|
action=(action "new")
|
||||||
class="btn-default groups-header-new pull-right"
|
class="btn-default groups-header-new pull-right"
|
||||||
icon="plus"
|
icon="plus"
|
||||||
label="admin.groups.new.title"}}
|
label="admin.groups.new.title"
|
||||||
|
}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="groups-header-filters">
|
<div class="groups-header-filters">
|
||||||
{{text-field value=filterInput
|
{{input
|
||||||
|
value=(readonly filter)
|
||||||
placeholderKey="groups.index.all"
|
placeholderKey="groups.index.all"
|
||||||
class="groups-header-filters-name no-blur"}}
|
class="groups-header-filters-name no-blur"
|
||||||
|
input=(action "onFilterChanged" value="target.value")
|
||||||
|
}}
|
||||||
|
|
||||||
{{combo-box
|
{{combo-box
|
||||||
value=type
|
value=type
|
||||||
|
@ -25,12 +30,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#if model}}
|
{{#if groups}}
|
||||||
{{#conditional-loading-spinner condition=model.loading}}
|
{{#conditional-loading-spinner condition=isLoading}}
|
||||||
{{#load-more selector=".groups-boxes .group-box" action=(action "loadMore")}}
|
{{#load-more selector=".groups-boxes .group-box" action=(action "loadMore")}}
|
||||||
<div class='container'>
|
<div class='container'>
|
||||||
<div class="groups-boxes">
|
<div class="groups-boxes">
|
||||||
{{#each model as |group|}}
|
{{#each groups as |group|}}
|
||||||
{{#link-to "group.members" group.name class="group-box"}}
|
{{#link-to "group.members" group.name class="group-box"}}
|
||||||
<div class="group-box-inner">
|
<div class="group-box-inner">
|
||||||
<div class="group-info-wrapper">
|
<div class="group-info-wrapper">
|
||||||
|
@ -87,7 +92,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{/load-more}}
|
{{/load-more}}
|
||||||
|
|
||||||
{{conditional-loading-spinner condition=model.loadingMore}}
|
{{conditional-loading-spinner condition=groups.loadingMore}}
|
||||||
{{/conditional-loading-spinner}}
|
{{/conditional-loading-spinner}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<p>{{i18n "groups.index.empty"}}</p>
|
<p>{{i18n "groups.index.empty"}}</p>
|
||||||
|
|
Loading…
Reference in New Issue