From 8261bbb3e283c9b8001e45dd200bc2cec0a67b65 Mon Sep 17 00:00:00 2001 From: yelinz Date: Fri, 29 Dec 2023 14:11:01 +0100 Subject: [PATCH] refactor: tag and mark filter with no request --- addon/components/document-grid.hbs | 2 +- addon/components/document-view.hbs | 22 +++++----- addon/components/document-view.js | 29 +++++++++---- addon/components/tag-filter.hbs | 36 +++++++++------- addon/components/tag-filter.js | 43 ++++++++++++------- addon/services/tags.js | 18 -------- tests/acceptance/documents-test.js | 10 ++++- .../components/document-view-test.js | 4 +- .../integration/components/tag-filter-test.js | 23 ++++++---- tests/unit/services/tags-test.js | 3 -- 10 files changed, 105 insertions(+), 85 deletions(-) diff --git a/addon/components/document-grid.hbs b/addon/components/document-grid.hbs index 0169f12f..4f94ae11 100644 --- a/addon/components/document-grid.hbs +++ b/addon/components/document-grid.hbs @@ -4,7 +4,7 @@ ...attributes {{did-insert this.setupGridAnimations}} > - {{#if this.fetchDocuments.isRunning}} + {{#if @loading}} {{#each (range 0 10) as |index|}}
diff --git a/addon/components/document-view.hbs b/addon/components/document-view.hbs index a652caf7..7c7d0c02 100644 --- a/addon/components/document-view.hbs +++ b/addon/components/document-view.hbs @@ -8,12 +8,13 @@
{{! List & Grid View }} {{#if this.listView}} {{else}} diff --git a/addon/components/document-view.js b/addon/components/document-view.js index 8ef0d3d7..28110d46 100644 --- a/addon/components/document-view.js +++ b/addon/components/document-view.js @@ -2,7 +2,8 @@ import { action } from "@ember/object"; import { inject as service } from "@ember/service"; import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; -import { dropTask, lastValue, task } from "ember-concurrency"; +import { dropTask, task } from "ember-concurrency"; +import { task as trackedTask } from "ember-resources/util/ember-concurrency"; import { ErrorHandler } from "ember-alexandria/helpers/error-handler"; @@ -19,6 +20,8 @@ export default class DocumentViewComponent extends Component { @tracked listView = true; @tracked sort = "title"; @tracked sortDirection = ""; + // Needed for ember-resource + @tracked uploadedDocuments = 0; constructor(parent, args) { super(parent, args); @@ -47,10 +50,15 @@ export default class DocumentViewComponent extends Component { this.router.transitionTo(this.router.currentRouteName, { queryParams: { sort: this.sortDirection + this.sort }, }); - this.fetchDocuments.perform(); } - @lastValue("fetchDocuments") fetchedDocuments; + fetchedDocuments = trackedTask(this, this.fetchDocuments, () => [ + this.sort, + this.sortDirection, + this.args.filters, + this.uploadedDocuments, + ]); + @task *fetchDocuments() { const documents = yield this.store.query("document", { @@ -114,8 +122,7 @@ export default class DocumentViewComponent extends Component { count: files.length, }), ); - - await this.fetchDocuments.perform(); + this.afterUpload(); } catch (error) { new ErrorHandler(this, error).notify( "alexandria.errors.upload-document", @@ -135,7 +142,7 @@ export default class DocumentViewComponent extends Component { } if (event.key === "a" && event.ctrlKey) { event.preventDefault(); - this.fetchedDocuments.forEach((doc) => { + this.fetchedDocuments.value.forEach((doc) => { this.documents.selectDocument(doc); }); } @@ -163,8 +170,9 @@ export default class DocumentViewComponent extends Component { // SHIFT SELECTION if (event.shiftKey) { - const selectedDocIndex = this.fetchedDocuments.indexOf(selectedDocument); - const firstSelectedDocIndex = this.fetchedDocuments.indexOf( + const selectedDocIndex = + this.fetchedDocuments.value.indexOf(selectedDocument); + const firstSelectedDocIndex = this.fetchedDocuments.value.indexOf( this.documents.selectedDocuments[0], ); @@ -195,4 +203,9 @@ export default class DocumentViewComponent extends Component { ); open(file.downloadUrl); } + + @action + afterUpload() { + this.uploadedDocuments++; + } } diff --git a/addon/components/tag-filter.hbs b/addon/components/tag-filter.hbs index 3e600554..c953d958 100644 --- a/addon/components/tag-filter.hbs +++ b/addon/components/tag-filter.hbs @@ -2,23 +2,27 @@ class="uk-border uk-padding-small uk-width-expand uk-flex uk-flex-wrap uk-flex-middle" ...attributes > - {{#each this.activeMarks.value as |mark|}} - - {{/each}} - {{#if (and this.searchTags.isFinished (not this.searchTags.value))}} - {{t "alexandria.tag-filter.empty"}} + {{#if this.marks.marks.hasRan}} + {{#each this.availableMarks.value as |mark|}} + + {{/each}} + {{/if}} + {{#if (and this.availableTags.isFinished (not this.availableTags.value))}} + {{t + "alexandria.tag-filter.empty" + }} {{else}} - {{#each this.tags.fetchSearchTags.lastSuccessful.value as |tag|}} + {{#each this.availableTags.value as |tag|}}