From 77f1280f6ad0ebdac96daf22dd549a70ba5b5347 Mon Sep 17 00:00:00 2001 From: Stephan Hug Date: Thu, 26 Aug 2021 16:50:44 +0200 Subject: [PATCH] fix: fixed the document sorting and removed some comments in the tag service --- addon/components/document-view.js | 14 ++++++++++++-- addon/controllers/application.js | 4 ++-- addon/services/tags.js | 4 +--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/addon/components/document-view.js b/addon/components/document-view.js index 7ba2ed79..13dc35f8 100644 --- a/addon/components/document-view.js +++ b/addon/components/document-view.js @@ -20,10 +20,20 @@ export default class DocumentViewComponent extends Component { constructor(parent, args) { super(parent, args); - // Adds a key down event listener to enable Ctrl+A document selection of all docs + /* Adds a key down event listener to enable Ctrl+A document selection of all docs + as well as ESC key press for deselection of all docs */ window.addEventListener("keydown", (event) => { this.handleKeyDown(event); }); + + // Initiliase the sorting param of the route + if (this.router?.currentRoute?.queryParams?.sort) { + this.sort = decodeURIComponent(this.router.currentRoute.queryParams.sort); + if (this.sort[0] === "-") { + // reverse sorting + this.sortDirection = "-"; + } + } } get canDrop() { @@ -42,7 +52,7 @@ export default class DocumentViewComponent extends Component { this.sortDirection = ""; } this.router.transitionTo({ - queryParams: { sort: this.sort, sortDirection: this.sortDirection }, + queryParams: { sort: this.sortDirection + this.sort }, }); this.fetchDocuments.perform(); } diff --git a/addon/controllers/application.js b/addon/controllers/application.js index 49a9c4a0..e4b2dc22 100644 --- a/addon/controllers/application.js +++ b/addon/controllers/application.js @@ -28,8 +28,8 @@ export default class ApplicationController extends Controller { tags: this.tags, search: this.search, activeGroup: this.activeGroup, - sort: this.sort, - sortDirection: this.sortDirection, + // sort: this.sort, + // sortDirection: this.sortDirection, }; if (this.config && this.config.modelMetaFilters.document) { diff --git a/addon/services/tags.js b/addon/services/tags.js index 2cd20eaa..b9b63e9f 100644 --- a/addon/services/tags.js +++ b/addon/services/tags.js @@ -47,10 +47,8 @@ export default class TagsService extends Service { * @returns {Object} addedTag The added tag */ @action async add(document, tag) { - // debugger; if (typeof tag === "string") { tag = tag.trim(); - // const existing = this.allTags.findBy("name", tag); const existing = this.allTags.findBy("id", dasherize(tag)); if (existing) { tag = existing; @@ -92,6 +90,6 @@ export default class TagsService extends Service { document.tags.removeObject(tag); await document.save(); - this.fetchSearchTags.perform(); // TODO: Is this required? + this.fetchSearchTags.perform(); } }