FEATURE: Replace combo-box with search filter (#28)
* FEATURE: Replace combo-box with search filter * Delete unused listname property and css fixes * Use ES6 syntax and `@computed` decorator
This commit is contained in:
parent
9f95a23b83
commit
344f6e357d
|
@ -2,6 +2,7 @@ import showModal from "discourse/lib/show-modal";
|
||||||
import Query from "discourse/plugins/discourse-data-explorer/discourse/models/query";
|
import Query from "discourse/plugins/discourse-data-explorer/discourse/models/query";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import { default as computed } from "ember-addons/ember-computed-decorators";
|
||||||
|
|
||||||
const NoQuery = Query.create({ name: "No queries", fake: true });
|
const NoQuery = Query.create({ name: "No queries", fake: true });
|
||||||
|
|
||||||
|
@ -26,6 +27,17 @@ export default Ember.Controller.extend({
|
||||||
sortBy: ["last_run_at:desc"],
|
sortBy: ["last_run_at:desc"],
|
||||||
sortedQueries: Em.computed.sort("model", "sortBy"),
|
sortedQueries: Em.computed.sort("model", "sortBy"),
|
||||||
|
|
||||||
|
@computed("search")
|
||||||
|
filteredContent(search) {
|
||||||
|
const regexp = new RegExp(this.get("search"));
|
||||||
|
return this.get("sortedQueries").filter(function(result) {
|
||||||
|
return (
|
||||||
|
regexp.test(result.get("name")) ||
|
||||||
|
regexp.test(result.get("description"))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
createDisabled: function() {
|
createDisabled: function() {
|
||||||
return (this.get("newQueryName") || "").trim().length === 0;
|
return (this.get("newQueryName") || "").trim().length === 0;
|
||||||
}.property("newQueryName"),
|
}.property("newQueryName"),
|
||||||
|
|
|
@ -54,17 +54,6 @@ const Query = RestModel.extend({
|
||||||
);
|
);
|
||||||
}.property("id"),
|
}.property("id"),
|
||||||
|
|
||||||
listName: function() {
|
|
||||||
let name = this.get("name");
|
|
||||||
if (this.get("dirty")) {
|
|
||||||
name += " (*)";
|
|
||||||
}
|
|
||||||
if (this.get("destroyed")) {
|
|
||||||
name += " (deleted)";
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}.property("name", "dirty", "destroyed"),
|
|
||||||
|
|
||||||
createProperties() {
|
createProperties() {
|
||||||
if (this.get("sql")) {
|
if (this.get("sql")) {
|
||||||
// Importing
|
// Importing
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#unless selectedQueryId}}
|
{{#unless selectedQueryId}}
|
||||||
<div class="query-list">
|
<div class="query-list">
|
||||||
{{combo-box valueAttribute="id" class="btn-left" value=selectedQueryId nameProperty="listName" none="explorer.menu_none" content=content castInteger="true" nameChanges="true"}}
|
{{text-field value=search placeholderKey="explorer.search_placeholder"}}
|
||||||
{{d-button action="showCreate" icon="plus" class="no-text btn-right"}}
|
{{d-button action="showCreate" icon="plus" class="no-text btn-right"}}
|
||||||
{{d-button action="importQuery" label="explorer.import.label" icon="upload btn-right"}}
|
{{d-button action="importQuery" label="explorer.import.label" icon="upload btn-right"}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -164,7 +164,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tr></tr>
|
<tr></tr>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#each sortedQueries as |query|}}
|
{{#each filteredContent as |query|}}
|
||||||
<tr class="query-row">
|
<tr class="query-row">
|
||||||
<td>
|
<td>
|
||||||
<a {{action "scrollTop"}} href="/admin/plugins/explorer/?id={{query.id}}">
|
<a {{action "scrollTop"}} href="/admin/plugins/explorer/?id={{query.id}}">
|
||||||
|
@ -191,6 +191,9 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{{else}}
|
||||||
|
<br>
|
||||||
|
<em class="no-search-results"> {{i18n "explorer.no_search_results"}}</em>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -236,6 +236,7 @@
|
||||||
|
|
||||||
.query-list {
|
.query-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
max-height: 30px;
|
||||||
.btn-left {
|
.btn-left {
|
||||||
margin-right: 0.5em;
|
margin-right: 0.5em;
|
||||||
}
|
}
|
||||||
|
@ -296,6 +297,9 @@
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
.no-search-results {
|
||||||
|
color: $primary-medium;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.result-info {
|
.result-info {
|
||||||
|
|
|
@ -66,4 +66,5 @@ en:
|
||||||
explain_label: "Include query plan?"
|
explain_label: "Include query plan?"
|
||||||
save_params: "Set Defaults"
|
save_params: "Set Defaults"
|
||||||
reset_params: "Reset"
|
reset_params: "Reset"
|
||||||
menu_none: "Select a query"
|
search_placeholder: "Search..."
|
||||||
|
no_search_results: "Sorry, we couldn't find any results matching your text."
|
||||||
|
|
Loading…
Reference in New Issue