-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmulti-document-details.js
58 lines (48 loc) · 1.48 KB
/
multi-document-details.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
export default class MultiDocumentDetailsComponent extends Component {
@service("alexandria-side-panel") sidePanel;
@service("alexandria-documents") documents;
@tracked deleteDialog = null;
constructor(parent, args) {
super(parent, args);
this.boundHandleKeyDown = this.handleKeyDown.bind(this);
window.addEventListener("keydown", this.boundHandleKeyDown);
}
@action
registerDeleteDialog(showDialog) {
this.deleteDialog = showDialog;
}
willDestroy() {
super.willDestroy();
window.removeEventListener("keydown", this.boundHandleKeyDown);
}
handleKeyDown(event) {
if (this.documents.shortcutsDisabled) {
return;
}
if (event.key === "Delete" && this.deleteDialog) {
this.deleteDialog();
}
}
get mergedTags() {
const tags = [];
const nrOfDocs = this.args.selectedDocuments.length;
const allTags = this.args.selectedDocuments
.map((d) => d.tags) // all the tags for a document
.flat()
.map((t) => t.name); // produces one large array of all tags
this.args.selectedDocuments.forEach((doc) => {
doc.tags.forEach((tag) => {
tags.push({
name: tag.name,
selectedByAll:
allTags.filter((t) => t.name === tag.name) === nrOfDocs,
});
});
});
return tags;
}
}