@lblod/ember-rdfa-editor-lblod-plugins 39.1.1 → 39.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/addon/components/common/tags/collapsible-tag-list.gts +149 -0
- package/addon/components/common/tags/tag-selector.gts +117 -0
- package/addon/components/snippet-plugin/snippet-insert-placeholder.gts +10 -8
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.gts +278 -0
- package/addon/components/snippet-plugin/snippet-list/snippet-list-view.gts +130 -0
- package/addon/components/snippet-plugin/snippet-list-select.gts +10 -9
- package/addon/helpers/in-array.ts +3 -9
- package/addon/plugins/common/tags/queries.ts +64 -0
- package/addon/plugins/common/tags/types.ts +12 -0
- package/addon/plugins/location-plugin/_private/utils/location-helpers.ts +5 -1
- package/addon/plugins/snippet-plugin/index.ts +11 -1
- package/addon/plugins/snippet-plugin/utils/fetch-data.ts +48 -17
- package/addon/utils/get-ranked-pnodes.ts +26 -7
- package/app/components/common/tags/collapsible-tag-list.js +1 -0
- package/app/components/common/tags/tag-selector.js +1 -0
- package/app/styles/common/tags.scss +61 -0
- package/app/styles/snippet-plugin.scss +44 -1
- package/declarations/addon/components/common/tags/collapsible-tag-list.d.ts +26 -0
- package/declarations/addon/components/common/tags/tag-selector.d.ts +31 -0
- package/declarations/addon/components/snippet-plugin/snippet-list/snippet-list-modal.d.ts +6 -0
- package/declarations/addon/components/snippet-plugin/snippet-list/snippet-list-view.d.ts +12 -8
- package/declarations/addon/helpers/in-array.d.ts +1 -4
- package/declarations/addon/plugins/common/tags/queries.d.ts +12 -0
- package/declarations/addon/plugins/common/tags/types.d.ts +9 -0
- package/declarations/addon/plugins/snippet-plugin/index.d.ts +4 -1
- package/declarations/addon/plugins/snippet-plugin/utils/fetch-data.d.ts +7 -1
- package/declarations/addon/utils/get-ranked-pnodes.d.ts +10 -2
- package/package.json +1 -1
- package/translations/en-US.yaml +16 -4
- package/translations/nl-BE.yaml +16 -4
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.hbs +0 -63
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.ts +0 -111
- package/addon/components/snippet-plugin/snippet-list/snippet-list-view.hbs +0 -66
- package/addon/components/snippet-plugin/snippet-list/snippet-list-view.ts +0 -57
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @lblod/ember-rdfa-editor-lblod-plugins
|
|
2
2
|
|
|
3
|
+
## 39.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#686](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/686) [`25cb100`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/25cb10062fc4dc92e211bd4921171c73222152ee) Thanks [@elpoelma](https://github.com/elpoelma)! - snippet-list plugin: introduce tag filtering
|
|
8
|
+
|
|
9
|
+
- [#686](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/686) [`25cb100`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/25cb10062fc4dc92e211bd4921171c73222152ee) Thanks [@elpoelma](https://github.com/elpoelma)! - snippet-list plugin: move filtering options to separate sidebar
|
|
10
|
+
|
|
11
|
+
## 39.1.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#687](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/687) [`e843838`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/e843838e191b369d8f6d0e5815456a30d530ac07) Thanks [@abeforgit](https://github.com/abeforgit)! - Fix location suggestions when a location placeholder is present in the doc
|
|
16
|
+
|
|
3
17
|
## 39.1.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import AuPill from '@appuniversum/ember-appuniversum/components/au-pill';
|
|
3
|
+
import { modifier } from 'ember-modifier';
|
|
4
|
+
import { tracked } from '@glimmer/tracking';
|
|
5
|
+
import { on } from '@ember/modifier';
|
|
6
|
+
import t from 'ember-intl/helpers/t';
|
|
7
|
+
import { Tag } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/common/tags/types';
|
|
8
|
+
|
|
9
|
+
type Args = {
|
|
10
|
+
tags: Tag[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default class CollapsibleTagList extends Component<Args> {
|
|
14
|
+
@tracked visibleCount = this.tags.length;
|
|
15
|
+
@tracked isExpanded = false;
|
|
16
|
+
|
|
17
|
+
containerElement: HTMLElement | null = null;
|
|
18
|
+
resizeObserver: ResizeObserver | null = null;
|
|
19
|
+
|
|
20
|
+
get tags() {
|
|
21
|
+
return this.args.tags;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get visibleTags() {
|
|
25
|
+
return this.isExpanded ? this.tags : this.tags.slice(0, this.visibleCount);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get hiddenCount() {
|
|
29
|
+
return this.tags.length - this.visibleCount;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get showMorePill() {
|
|
33
|
+
return !this.isExpanded && this.hiddenCount > 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
containerModifier = modifier((element: HTMLElement) => {
|
|
37
|
+
this.containerElement = element;
|
|
38
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
39
|
+
if (!this.isExpanded) this.recalculate();
|
|
40
|
+
});
|
|
41
|
+
this.resizeObserver.observe(element);
|
|
42
|
+
this.recalculate();
|
|
43
|
+
return () => {
|
|
44
|
+
this.resizeObserver?.disconnect();
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expand = () => {
|
|
49
|
+
this.isExpanded = true;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
collapse = () => {
|
|
53
|
+
this.isExpanded = false;
|
|
54
|
+
this.recalculate();
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
recalculate = () => {
|
|
58
|
+
const container = this.containerElement;
|
|
59
|
+
if (!container) return;
|
|
60
|
+
|
|
61
|
+
const measureRow = container.querySelector('[data-measure-row]');
|
|
62
|
+
if (!measureRow) return;
|
|
63
|
+
|
|
64
|
+
const availableWidth = container.clientWidth;
|
|
65
|
+
const tagEls = Array.from(
|
|
66
|
+
measureRow.querySelectorAll('[data-measure-tag]'),
|
|
67
|
+
);
|
|
68
|
+
const moreEl = measureRow.querySelector('[data-measure-more]');
|
|
69
|
+
if (!moreEl) return;
|
|
70
|
+
|
|
71
|
+
const gap = Number.parseFloat(getComputedStyle(measureRow).columnGap) || 0;
|
|
72
|
+
|
|
73
|
+
let total = 0;
|
|
74
|
+
let fitCount = tagEls.length;
|
|
75
|
+
|
|
76
|
+
for (let i = 0; i < tagEls.length; i++) {
|
|
77
|
+
const tagWidth = (tagEls[i] as HTMLElement).getBoundingClientRect().width;
|
|
78
|
+
const nextTotal = total + (i > 0 ? gap : 0) + tagWidth;
|
|
79
|
+
|
|
80
|
+
const remainingAfterThis = tagEls.length - (i + 1);
|
|
81
|
+
const moreWidth =
|
|
82
|
+
remainingAfterThis > 0 ? gap + moreEl.getBoundingClientRect().width : 0;
|
|
83
|
+
|
|
84
|
+
if (nextTotal + moreWidth > availableWidth) {
|
|
85
|
+
fitCount = i;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
total = nextTotal;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
this.visibleCount = fitCount;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
<template>
|
|
96
|
+
<div
|
|
97
|
+
class='say-collapsible-tag-list
|
|
98
|
+
{{if this.isExpanded "say-collapsible-tag-list--expanded"}}'
|
|
99
|
+
{{this.containerModifier}}
|
|
100
|
+
>
|
|
101
|
+
{{! hidden row used only to measure natural widths }}
|
|
102
|
+
<div
|
|
103
|
+
class='say-collapsible-tag-list__measure'
|
|
104
|
+
data-measure-row
|
|
105
|
+
aria-hidden='true'
|
|
106
|
+
>
|
|
107
|
+
{{#each this.tags as |tag|}}
|
|
108
|
+
<span data-measure-tag>
|
|
109
|
+
<AuPill class='say-collapsible-tag-list__pill'>
|
|
110
|
+
{{tag.value}}
|
|
111
|
+
</AuPill>
|
|
112
|
+
</span>
|
|
113
|
+
{{/each}}
|
|
114
|
+
<span data-measure-more>
|
|
115
|
+
<AuPill class='say-collapsible-tag-list__pill'>
|
|
116
|
+
+{{this.tags.length}}
|
|
117
|
+
</AuPill>
|
|
118
|
+
</span>
|
|
119
|
+
</div>
|
|
120
|
+
<div class='say-collapsible-tag-list__visible'>
|
|
121
|
+
{{#each this.visibleTags as |tag|}}
|
|
122
|
+
<AuPill class='say-collapsible-tag-list__pill' title={{tag.value}}>
|
|
123
|
+
{{tag.value}}
|
|
124
|
+
</AuPill>
|
|
125
|
+
{{/each}}
|
|
126
|
+
|
|
127
|
+
{{#if this.showMorePill}}
|
|
128
|
+
<AuPill
|
|
129
|
+
type='button'
|
|
130
|
+
class='say-collapsible-tag-list__pill say-collapsible-tag-list__more'
|
|
131
|
+
{{on 'click' this.expand}}
|
|
132
|
+
>
|
|
133
|
+
+{{this.hiddenCount}}
|
|
134
|
+
</AuPill>
|
|
135
|
+
{{/if}}
|
|
136
|
+
|
|
137
|
+
{{#if this.isExpanded}}
|
|
138
|
+
<button
|
|
139
|
+
type='button'
|
|
140
|
+
class='au-u-muted au-u-italic say-collapsible-tag-list__less'
|
|
141
|
+
{{on 'click' this.collapse}}
|
|
142
|
+
>
|
|
143
|
+
{{t 'common.tags.collapsible-tag-list.show-less'}}
|
|
144
|
+
</button>
|
|
145
|
+
{{/if}}
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
</template>
|
|
149
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import PowerSelectMultiple from 'ember-power-select/components/power-select-multiple';
|
|
3
|
+
import t from 'ember-intl/helpers/t';
|
|
4
|
+
import { Tag } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/common/tags/types';
|
|
5
|
+
import { service } from '@ember/service';
|
|
6
|
+
import IntlService from 'ember-intl/services/intl';
|
|
7
|
+
import { tracked } from '@glimmer/tracking';
|
|
8
|
+
|
|
9
|
+
type Signature<T extends Tag> = {
|
|
10
|
+
Args: {
|
|
11
|
+
tags: T[];
|
|
12
|
+
selectedTags?: T[];
|
|
13
|
+
onChange: (tags: T[]) => void;
|
|
14
|
+
} & (
|
|
15
|
+
| {
|
|
16
|
+
allowTagCreation?: false;
|
|
17
|
+
tagConstructor?: never;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
allowTagCreation: true;
|
|
21
|
+
tagConstructor: (newTag: NewTag) => T;
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
Element: HTMLElement;
|
|
25
|
+
};
|
|
26
|
+
export type NewTag = {
|
|
27
|
+
value: string;
|
|
28
|
+
// this works better than a boolean "isNew" for runtime type-checking
|
|
29
|
+
optionType: 'new';
|
|
30
|
+
searchTerm?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type SelectorOption<T extends Tag> = T | NewTag;
|
|
34
|
+
|
|
35
|
+
export default class TagSelector<T extends Tag> extends Component<
|
|
36
|
+
Signature<T>
|
|
37
|
+
> {
|
|
38
|
+
@service declare intl: IntlService;
|
|
39
|
+
|
|
40
|
+
@tracked searchTerm: string | null = null;
|
|
41
|
+
|
|
42
|
+
changeSelection = (selectedTags: SelectorOption<T>[]) => {
|
|
43
|
+
// split up the selected options into existing and new tags
|
|
44
|
+
// this is a bit verbose but it's the most type-safe way to do this
|
|
45
|
+
const existingTags: T[] = [];
|
|
46
|
+
const newTags: NewTag[] = [];
|
|
47
|
+
for (const tagOrNew of selectedTags) {
|
|
48
|
+
if ('optionType' in tagOrNew) {
|
|
49
|
+
newTags.push(tagOrNew);
|
|
50
|
+
} else {
|
|
51
|
+
existingTags.push(tagOrNew);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.searchTerm = null;
|
|
56
|
+
// power-select doesn't allow you to make more than 1 new option at at time
|
|
57
|
+
// but just in case
|
|
58
|
+
if (newTags.length > 1) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
'unexpected state, only one new tag should be created at a time',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const addOption = newTags[0];
|
|
64
|
+
let newSelectedTags;
|
|
65
|
+
if (addOption && this.args.allowTagCreation) {
|
|
66
|
+
const newOption = this.args.tagConstructor(addOption);
|
|
67
|
+
newSelectedTags = [...existingTags, newOption];
|
|
68
|
+
} else {
|
|
69
|
+
newSelectedTags = existingTags;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.args.onChange(newSelectedTags);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
get options() {
|
|
76
|
+
const options: SelectorOption<T>[] = this.args.tags.slice();
|
|
77
|
+
|
|
78
|
+
if (
|
|
79
|
+
this.args.allowTagCreation &&
|
|
80
|
+
this.searchTerm &&
|
|
81
|
+
!options.find((tag) => tag.value === this.searchTerm)
|
|
82
|
+
) {
|
|
83
|
+
options.push({
|
|
84
|
+
optionType: 'new',
|
|
85
|
+
value: this.intl.t('common.tags.tag-selector.create-new-tag', {
|
|
86
|
+
tagName: this.searchTerm,
|
|
87
|
+
}),
|
|
88
|
+
searchTerm: this.searchTerm,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return options;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setSearchTerm = (term: string) => {
|
|
95
|
+
this.searchTerm = term;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
<template>
|
|
99
|
+
<PowerSelectMultiple
|
|
100
|
+
@onChange={{this.changeSelection}}
|
|
101
|
+
@onInput={{this.setSearchTerm}}
|
|
102
|
+
@options={{this.options}}
|
|
103
|
+
@searchEnabled={{true}}
|
|
104
|
+
@selected={{@selectedTags}}
|
|
105
|
+
@searchField='value'
|
|
106
|
+
@placeholder={{t 'common.tags.tag-selector.placeholder'}}
|
|
107
|
+
@noMatchesMessage={{t 'common.tags.tag-selector.no-results-message'}}
|
|
108
|
+
class='say-tag-selector'
|
|
109
|
+
...attributes
|
|
110
|
+
as |tag|
|
|
111
|
+
>
|
|
112
|
+
<span class='say-tag-selector__item' title={{tag.value}}>
|
|
113
|
+
{{tag.value}}
|
|
114
|
+
</span>
|
|
115
|
+
</PowerSelectMultiple>
|
|
116
|
+
</template>
|
|
117
|
+
}
|
|
@@ -70,13 +70,15 @@ export default class SnippetPluginSnippetInsertPlaceholder extends Component<Sig
|
|
|
70
70
|
{{t 'snippet-plugin.insert.placeholder'}}
|
|
71
71
|
</AuButton>
|
|
72
72
|
</li>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
{{#if this.isModalOpen}}
|
|
74
|
+
<SnippetListModal
|
|
75
|
+
@config={{@config}}
|
|
76
|
+
@snippetListUris={{empty}}
|
|
77
|
+
@allowMultipleSnippets={{false}}
|
|
78
|
+
@onSaveSnippetLists={{this.insertPlaceholder}}
|
|
79
|
+
@open={{true}}
|
|
80
|
+
@closeModal={{this.closeModal}}
|
|
81
|
+
/>
|
|
82
|
+
{{/if}}
|
|
81
83
|
</template>
|
|
82
84
|
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
import { restartableTask, timeout } from 'ember-concurrency';
|
|
4
|
+
import { task as trackedTask } from 'reactiveweb/ember-concurrency';
|
|
5
|
+
|
|
6
|
+
import { tracked } from '@glimmer/tracking';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
fetchSnippetLists,
|
|
10
|
+
OrderBy,
|
|
11
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/utils/fetch-data';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
SnippetPluginConfig,
|
|
15
|
+
SnippetList,
|
|
16
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
17
|
+
import { localCopy, trackedReset } from 'tracked-toolbox';
|
|
18
|
+
import AuModal from '@appuniversum/ember-appuniversum/components/au-modal';
|
|
19
|
+
import t from 'ember-intl/helpers/t';
|
|
20
|
+
import AuMainContainer from '@appuniversum/ember-appuniversum/components/au-main-container';
|
|
21
|
+
import AlertLoadError from '@lblod/ember-rdfa-editor-lblod-plugins/components/common/search/alert-load-error';
|
|
22
|
+
import SnippetListView from './snippet-list-view';
|
|
23
|
+
import AuToolbar from '@appuniversum/ember-appuniversum/components/au-toolbar';
|
|
24
|
+
import AuCheckbox from '@appuniversum/ember-appuniversum/components/au-checkbox';
|
|
25
|
+
import AuButtonGroup from '@appuniversum/ember-appuniversum/components/au-button-group';
|
|
26
|
+
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
|
|
27
|
+
import { on } from '@ember/modifier';
|
|
28
|
+
import AuHeading from '@appuniversum/ember-appuniversum/components/au-heading';
|
|
29
|
+
import AuLabel from '@appuniversum/ember-appuniversum/components/au-label';
|
|
30
|
+
import AuNativeInput from '../../au-native-input';
|
|
31
|
+
import { SAY } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
32
|
+
import { uniqueId } from '@ember/helper';
|
|
33
|
+
import AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row';
|
|
34
|
+
import { CrossIcon } from '@appuniversum/ember-appuniversum/components/icons/cross';
|
|
35
|
+
import { TagWithUri } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/common/tags/types';
|
|
36
|
+
import TagSelector from '../../common/tags/tag-selector';
|
|
37
|
+
import { trackedFunction } from 'reactiveweb/function';
|
|
38
|
+
import { fetchTags } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/common/tags/queries';
|
|
39
|
+
interface Signature {
|
|
40
|
+
Args: {
|
|
41
|
+
config: SnippetPluginConfig;
|
|
42
|
+
onSaveSnippetLists: (
|
|
43
|
+
lists: SnippetList[],
|
|
44
|
+
allowMultipleSnippets: boolean,
|
|
45
|
+
) => void;
|
|
46
|
+
snippetListUris: string[] | undefined;
|
|
47
|
+
closeModal: () => void;
|
|
48
|
+
open: boolean;
|
|
49
|
+
allowMultipleSnippets?: boolean;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default class SnippetListModalComponent extends Component<Signature> {
|
|
54
|
+
// Filtering
|
|
55
|
+
@tracked nameFilterText: string | null = null;
|
|
56
|
+
@tracked selectedTags: TagWithUri[] = [];
|
|
57
|
+
|
|
58
|
+
// Sorting
|
|
59
|
+
@tracked sort: OrderBy = null;
|
|
60
|
+
|
|
61
|
+
// Display
|
|
62
|
+
@tracked error: unknown;
|
|
63
|
+
|
|
64
|
+
@trackedReset('args.snippetListUris')
|
|
65
|
+
snippetListUris: string[] = [...(this.args.snippetListUris ?? [])];
|
|
66
|
+
|
|
67
|
+
@localCopy('args.allowMultipleSnippets') allowMultipleSnippets = false;
|
|
68
|
+
|
|
69
|
+
@action
|
|
70
|
+
handleMultipleSnippetsCheckbox(checked: boolean) {
|
|
71
|
+
this.allowMultipleSnippets = checked;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setNameFilterText = (event: Event) => {
|
|
75
|
+
this.nameFilterText = (event.target as HTMLInputElement).value;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
setSelectedTags = (tags: TagWithUri[]) => {
|
|
79
|
+
this.selectedTags = tags
|
|
80
|
+
.slice()
|
|
81
|
+
.sort((tagA, tagB) => tagA.value.localeCompare(tagB.value));
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
resetFilters = () => {
|
|
85
|
+
this.nameFilterText = null;
|
|
86
|
+
this.selectedTags = [];
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
get config() {
|
|
90
|
+
return this.args.config;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@action
|
|
94
|
+
closeModal() {
|
|
95
|
+
this.allowMultipleSnippets = this.args.allowMultipleSnippets ?? false;
|
|
96
|
+
this.args.closeModal();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@action
|
|
100
|
+
saveAndClose() {
|
|
101
|
+
const snippetLists = this.snippetListResource.value?.filter((snippetList) =>
|
|
102
|
+
this.snippetListUris.includes(snippetList.uri),
|
|
103
|
+
);
|
|
104
|
+
this.args.onSaveSnippetLists(
|
|
105
|
+
snippetLists || [],
|
|
106
|
+
this.allowMultipleSnippets,
|
|
107
|
+
);
|
|
108
|
+
this.args.closeModal();
|
|
109
|
+
// Clear selection for next time
|
|
110
|
+
this.snippetListUris = [];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
snippetListSearch = restartableTask(async () => {
|
|
114
|
+
await timeout(500);
|
|
115
|
+
|
|
116
|
+
const abortController = new AbortController();
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const queryResult = await fetchSnippetLists({
|
|
120
|
+
endpoint: this.args.config.endpoint,
|
|
121
|
+
abortSignal: abortController.signal,
|
|
122
|
+
filter: {
|
|
123
|
+
name: this.nameFilterText ?? undefined,
|
|
124
|
+
tags: this.selectedTags,
|
|
125
|
+
},
|
|
126
|
+
orderBy: this.sort,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return queryResult.results;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
this.error = error;
|
|
132
|
+
return [];
|
|
133
|
+
} finally {
|
|
134
|
+
abortController.abort();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
snippetListResource = trackedTask<SnippetList[]>(
|
|
139
|
+
this,
|
|
140
|
+
this.snippetListSearch,
|
|
141
|
+
() => [this.nameFilterText, this.selectedTags, this.sort],
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
tags = trackedFunction(this, async () => {
|
|
145
|
+
return fetchTags({
|
|
146
|
+
endpoint: this.args.config.endpoint,
|
|
147
|
+
filter: {
|
|
148
|
+
taggableTypes: [SAY('SnippetList').full],
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
@action
|
|
154
|
+
onChange(snippetListUris: string[]) {
|
|
155
|
+
this.snippetListUris = snippetListUris;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
<template>
|
|
159
|
+
<AuModal
|
|
160
|
+
@modalOpen={{@open}}
|
|
161
|
+
@closeModal={{this.closeModal}}
|
|
162
|
+
@title={{t 'snippet-plugin.snippet-list.modal.title'}}
|
|
163
|
+
@size='large'
|
|
164
|
+
@padding='none'
|
|
165
|
+
as |modal|
|
|
166
|
+
>
|
|
167
|
+
<modal.Body>
|
|
168
|
+
<AuMainContainer class='say-snippet-list-overview' as |mc|>
|
|
169
|
+
<mc.sidebar class='say-snippet-list-overview__sidebar'>
|
|
170
|
+
<AuHeading @level='2' @skin='3'>
|
|
171
|
+
{{t 'snippet-plugin.snippet-list.modal.filter.title'}}
|
|
172
|
+
</AuHeading>
|
|
173
|
+
<form class='say-snippet-list-overview__form'>
|
|
174
|
+
<AuFormRow>
|
|
175
|
+
{{#let (uniqueId) as |id|}}
|
|
176
|
+
<AuLabel
|
|
177
|
+
for={{id}}
|
|
178
|
+
@inline={{false}}
|
|
179
|
+
@required={{false}}
|
|
180
|
+
@error={{false}}
|
|
181
|
+
@warning={{false}}
|
|
182
|
+
>{{t
|
|
183
|
+
'snippet-plugin.snippet-list.modal.filter.name-filter.label'
|
|
184
|
+
}}</AuLabel>
|
|
185
|
+
<AuNativeInput
|
|
186
|
+
id={{id}}
|
|
187
|
+
@type='text'
|
|
188
|
+
@width='block'
|
|
189
|
+
@iconAlignment='right'
|
|
190
|
+
value={{this.nameFilterText}}
|
|
191
|
+
placeholder={{t
|
|
192
|
+
'snippet-plugin.snippet-list.modal.filter.name-filter.placeholder'
|
|
193
|
+
}}
|
|
194
|
+
{{on 'input' this.setNameFilterText}}
|
|
195
|
+
/>
|
|
196
|
+
{{/let}}
|
|
197
|
+
</AuFormRow>
|
|
198
|
+
{{#if this.tags.value}}
|
|
199
|
+
<AuFormRow>
|
|
200
|
+
{{#let (uniqueId) as |id|}}
|
|
201
|
+
<AuLabel
|
|
202
|
+
for={{id}}
|
|
203
|
+
@inline={{false}}
|
|
204
|
+
@required={{false}}
|
|
205
|
+
@error={{false}}
|
|
206
|
+
@warning={{false}}
|
|
207
|
+
>{{t
|
|
208
|
+
'snippet-plugin.snippet-list.modal.filter.tag-filter.label'
|
|
209
|
+
}}</AuLabel>
|
|
210
|
+
<TagSelector
|
|
211
|
+
id={{id}}
|
|
212
|
+
class='say-snippet-list-overview__tag-selector'
|
|
213
|
+
@tags={{this.tags.value}}
|
|
214
|
+
@onChange={{this.setSelectedTags}}
|
|
215
|
+
@selectedTags={{this.selectedTags}}
|
|
216
|
+
/>
|
|
217
|
+
{{/let}}
|
|
218
|
+
</AuFormRow>
|
|
219
|
+
{{/if}}
|
|
220
|
+
<AuButton
|
|
221
|
+
class='say-snippet-list-overview__reset-filters-button'
|
|
222
|
+
@skin='naked'
|
|
223
|
+
@size='large'
|
|
224
|
+
@icon={{CrossIcon}}
|
|
225
|
+
{{on 'click' this.resetFilters}}
|
|
226
|
+
>{{t 'snippet-plugin.snippet-list.modal.filter.reset'}}</AuButton>
|
|
227
|
+
</form>
|
|
228
|
+
</mc.sidebar>
|
|
229
|
+
<mc.content class='say-snippet-list-overview__content'>
|
|
230
|
+
<div class='say-snippet-list-overview__table'>
|
|
231
|
+
{{#if this.error}}
|
|
232
|
+
<AlertLoadError
|
|
233
|
+
@error={{this.error}}
|
|
234
|
+
class='au-u-margin-top-none'
|
|
235
|
+
/>
|
|
236
|
+
{{else}}
|
|
237
|
+
<SnippetListView
|
|
238
|
+
@snippetLists={{this.snippetListResource.value}}
|
|
239
|
+
@snippetListUris={{this.snippetListUris}}
|
|
240
|
+
@listNameFilter={{this.nameFilterText}}
|
|
241
|
+
@sort={{this.sort}}
|
|
242
|
+
@onChange={{this.onChange}}
|
|
243
|
+
@isLoading={{this.snippetListResource.isRunning}}
|
|
244
|
+
/>
|
|
245
|
+
{{/if}}
|
|
246
|
+
</div>
|
|
247
|
+
<AuToolbar
|
|
248
|
+
@border='top'
|
|
249
|
+
@size='large'
|
|
250
|
+
@nowrap={{true}}
|
|
251
|
+
class='say-snippet-list-overview__footer au-u-flex--vertical-center'
|
|
252
|
+
as |Group|
|
|
253
|
+
>
|
|
254
|
+
<Group>
|
|
255
|
+
<AuCheckbox
|
|
256
|
+
@checked={{this.allowMultipleSnippets}}
|
|
257
|
+
@onChange={{this.handleMultipleSnippetsCheckbox}}
|
|
258
|
+
>
|
|
259
|
+
{{t 'snippet-plugin.snippet-list.modal.multi-snippet-toggle'}}
|
|
260
|
+
</AuCheckbox>
|
|
261
|
+
</Group>
|
|
262
|
+
<Group>
|
|
263
|
+
<AuButtonGroup>
|
|
264
|
+
<AuButton @skin='secondary' {{on 'click' this.closeModal}}>
|
|
265
|
+
{{t 'snippet-plugin.snippet-list.modal.button.cancel'}}
|
|
266
|
+
</AuButton>
|
|
267
|
+
<AuButton @skin='primary' {{on 'click' this.saveAndClose}}>
|
|
268
|
+
{{t 'snippet-plugin.snippet-list.modal.button.update'}}
|
|
269
|
+
</AuButton>
|
|
270
|
+
</AuButtonGroup>
|
|
271
|
+
</Group>
|
|
272
|
+
</AuToolbar>
|
|
273
|
+
</mc.content>
|
|
274
|
+
</AuMainContainer>
|
|
275
|
+
</modal.Body>
|
|
276
|
+
</AuModal>
|
|
277
|
+
</template>
|
|
278
|
+
}
|