@datagrok/hit-triage 1.10.8 → 1.11.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/.grokignore +2 -0
- package/.turbo/turbo-build.log +24 -6
- package/.vscode/settings.json +16 -0
- package/CHANGELOG.md +80 -1
- package/CLAUDE.md +87 -10
- package/README_HD.md +14 -14
- package/README_HT.md +6 -6
- package/README_PH.md +110 -0
- package/bdd/bdd.config.json +3 -0
- package/bdd/bindings/campaign.ts +626 -0
- package/bdd/bindings/hit-design.ts +93 -0
- package/bdd/bindings/landing.ts +839 -0
- package/bdd/bindings/pepti-hit.ts +35 -0
- package/bdd/features/campaign/crumbs.feature +22 -0
- package/bdd/features/campaign/grid.feature +56 -0
- package/bdd/features/campaign/merge.feature +105 -0
- package/bdd/features/campaign/molecule-vid.feature +40 -0
- package/bdd/features/campaign/permissions.feature +46 -0
- package/bdd/features/campaign/progress-tracker.feature +89 -0
- package/bdd/features/campaign/refresh-hint.feature +33 -0
- package/bdd/features/campaign/ribbon.feature +49 -0
- package/bdd/features/campaign/stage-choices.feature +39 -0
- package/bdd/features/campaign/submit.feature +135 -0
- package/bdd/features/campaign/tracker-cards.feature +46 -0
- package/bdd/features/campaign/view-only.feature +37 -0
- package/bdd/features/hit-design/campaign-column-metadata.feature +61 -0
- package/bdd/features/landing/campaign-deep-links.feature +61 -0
- package/bdd/features/landing/hit-design-campaigns-fixes.feature +116 -0
- package/bdd/features/landing/hit-design-campaigns.feature +153 -0
- package/bdd/features/landing/hit-triage-campaigns.feature +99 -0
- package/bdd/features/landing/new-campaign.feature +69 -0
- package/bdd/features/landing/pep-triage-campaigns.feature +41 -0
- package/bdd/features/landing/pepti-hit-landing.feature +132 -0
- package/bdd/features/pepti-hit/helm-edit.feature +47 -0
- package/bdd/features/templates/template-editor.feature +130 -0
- package/bdd/features/templates/template-picker.feature +112 -0
- package/bdd/features/templates/triage-forms.feature +59 -0
- package/bdd/fixtures/bar-chart.layout +1 -0
- package/bdd/fixtures/merge-local.csv +2 -0
- package/bdd/generated/campaign/crumbs.test.ts +33 -0
- package/bdd/generated/campaign/grid.test.ts +79 -0
- package/bdd/generated/campaign/merge.test.ts +134 -0
- package/bdd/generated/campaign/molecule-vid.test.ts +52 -0
- package/bdd/generated/campaign/permissions.test.ts +58 -0
- package/bdd/generated/campaign/progress-tracker.test.ts +129 -0
- package/bdd/generated/campaign/refresh-hint.test.ts +44 -0
- package/bdd/generated/campaign/ribbon.test.ts +65 -0
- package/bdd/generated/campaign/stage-choices.test.ts +55 -0
- package/bdd/generated/campaign/submit.test.ts +167 -0
- package/bdd/generated/campaign/tracker-cards.test.ts +49 -0
- package/bdd/generated/campaign/view-only.test.ts +51 -0
- package/bdd/generated/hit-design/campaign-column-metadata.test.ts +76 -0
- package/bdd/generated/landing/campaign-deep-links.test.ts +68 -0
- package/bdd/generated/landing/hit-design-campaigns-fixes.test.ts +99 -0
- package/bdd/generated/landing/hit-design-campaigns.test.ts +160 -0
- package/bdd/generated/landing/hit-triage-campaigns.test.ts +107 -0
- package/bdd/generated/landing/new-campaign.test.ts +78 -0
- package/bdd/generated/landing/pep-triage-campaigns.test.ts +52 -0
- package/bdd/generated/landing/pepti-hit-landing.test.ts +130 -0
- package/bdd/generated/pepti-hit/helm-edit.test.ts +64 -0
- package/bdd/generated/templates/template-editor.test.ts +137 -0
- package/bdd/generated/templates/template-picker.test.ts +119 -0
- package/bdd/generated/templates/triage-forms.test.ts +68 -0
- package/bdd/package.json +1 -0
- package/bdd/tsconfig.json +13 -0
- package/css/hit-triage.css +27 -23
- package/dist/package-test.js +690 -4
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +318 -73
- package/dist/package.js.map +1 -1
- package/package.json +15 -8
- package/queries/locks.sql +37 -0
- package/src/app/accordeons/layout-input.ts +52 -44
- package/src/app/accordeons/new-campaign-accordeon.ts +91 -54
- package/src/app/accordeons/new-hit-design-campaign-accordeon.ts +3 -67
- package/src/app/accordeons/new-pep-triage-template-accordeon.ts +39 -41
- package/src/app/accordeons/new-template-accordeon.ts +41 -24
- package/src/app/ai/view-functions.ts +22 -19
- package/src/app/base-view.ts +99 -8
- package/src/app/consts.ts +8 -5
- package/src/app/dialogs/functions-dialog.ts +14 -9
- package/src/app/dialogs/merge-table-dialog.ts +181 -325
- package/src/app/hit-app-base.ts +61 -90
- package/src/app/hit-design-app.ts +492 -882
- package/src/app/hit-design-views/info-view.ts +57 -407
- package/src/app/hit-design-views/submit-view.ts +216 -111
- package/src/app/hit-design-views/tiles-view.ts +168 -123
- package/src/app/hit-design-views/utils.css +0 -8
- package/src/app/hit-triage-app.ts +69 -38
- package/src/app/hit-triage-views/info-view.ts +70 -371
- package/src/app/pep-triage-app.ts +2 -2
- package/src/app/pep-triage-views/info-view.ts +42 -83
- package/src/app/pepti-hit-app.ts +32 -183
- package/src/app/pepti-hits-views/info-view.ts +15 -37
- package/src/app/shared/campaign-catalog.ts +408 -0
- package/src/app/shared/campaign-session.ts +557 -0
- package/src/app/shared/compute-editor.ts +274 -0
- package/src/app/shared/hit-home.ts +45 -0
- package/src/app/shared/new-campaign-form.ts +90 -0
- package/src/app/shared/permissions-editor.ts +93 -0
- package/src/app/shared/template-editor.ts +331 -0
- package/src/app/shared/template-picker.ts +154 -0
- package/src/app/types.ts +2 -0
- package/src/app/utils/merge-table.ts +183 -78
- package/src/app/utils.ts +34 -325
- package/src/package-api.ts +29 -8
- package/src/package-test.ts +17 -2
- package/src/package.g.ts +12 -8
- package/src/package.ts +19 -7
- package/src/tests/ai.ts +244 -0
- package/src/tests/campaign-layout.ts +82 -0
- package/src/tests/campaign-session.ts +168 -0
- package/src/tests/campaigns.ts +23 -0
- package/src/tests/catalog.ts +156 -0
- package/src/tests/compat.ts +482 -0
- package/src/tests/compute.ts +165 -0
- package/src/tests/fixtures.ts +359 -0
- package/src/tests/merge.ts +149 -0
- package/src/tests/owners.ts +11 -0
- package/src/tests/save-lock.ts +932 -0
- package/src/tests/storage.ts +106 -0
- package/src/tests/template-editor.ts +538 -0
- package/src/tests/templates.ts +143 -0
- package/src/tests/triage-start.ts +81 -0
- package/src/tests/u2-guards.ts +384 -0
- package/src/tests/vid.ts +77 -0
- package/tsconfig.json +3 -0
- package/src/app/accordeons/new-hit-design-template-accordeon.ts +0 -238
- package/src/app/dialogs/permissions-dialog.ts +0 -66
|
@@ -1,438 +1,88 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
2
|
import * as grok from 'datagrok-api/grok';
|
|
3
|
-
import
|
|
4
|
-
import * as DG from 'datagrok-api/dg';
|
|
5
|
-
import {u2} from '@datagrok-libraries/utils/src/u2';
|
|
3
|
+
import type {AppHeaderOptions} from '@datagrok-libraries/u2';
|
|
6
4
|
import {HitDesignApp} from '../hit-design-app';
|
|
7
5
|
import {_package} from '../../package';
|
|
8
|
-
import
|
|
9
|
-
import {CampaignGrouping, CampaignGroupingType, CampaignJsonName, CampaignTableColumns, DefaultCampaignTableInfoGetters, HitDesignCampaignIdKey, i18n} from '../consts';
|
|
6
|
+
import {CampaignJsonName, CampaignTableName, HitDesignCampaignIdKey} from '../consts';
|
|
10
7
|
import {HitDesignCampaign, HitDesignTemplate} from '../types';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
setSavedCampaignsSorting,
|
|
17
|
-
setSavedCampaignTableColumns,
|
|
18
|
-
sortCampaigns} from '../utils';
|
|
19
|
-
import {newHitDesignCampaignAccordeon} from '../accordeons/new-hit-design-campaign-accordeon';
|
|
20
|
-
import {newHitDesignTemplateAccordeon} from '../accordeons/new-hit-design-template-accordeon';
|
|
21
|
-
import {HitBaseView} from '../base-view';
|
|
22
|
-
import {defaultPermissions, PermissionsDialog} from '../dialogs/permissions-dialog';
|
|
8
|
+
import {checkViewPermissions, loadTemplate, modifyUrl} from '../utils';
|
|
9
|
+
import {CampaignUnavailableError, HitLandingView} from '../base-view';
|
|
10
|
+
import {HitHomeOptions} from '../shared/hit-home';
|
|
11
|
+
import {newCampaignForm} from '../shared/new-campaign-form';
|
|
12
|
+
import {openTemplateEditor} from '../shared/template-editor';
|
|
23
13
|
import {hitInfoAiDescription} from '../ai/view-functions';
|
|
24
14
|
|
|
25
15
|
export class HitDesignInfoView
|
|
26
16
|
<T extends HitDesignTemplate = HitDesignTemplate, K extends HitDesignApp = HitDesignApp>
|
|
27
|
-
extends
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
protected _contentRoot: HTMLElement = ui.div([], {classes: 'hit-triage-info-view-container'});
|
|
31
|
-
constructor(app: K) {
|
|
32
|
-
super(app);
|
|
17
|
+
extends HitLandingView<T, K> {
|
|
18
|
+
constructor(app: K, readme = 'README_HD.md') {
|
|
19
|
+
super(app, readme);
|
|
33
20
|
this.name = 'Hit Design';
|
|
34
21
|
// TODO: Remove before api release
|
|
35
22
|
(this as any).aiDescription = hitInfoAiDescription(app.appName);
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
38
|
-
this.root.appendChild(this._contentRoot);
|
|
39
|
-
grok.shell.windows.showHelp = true;
|
|
40
|
-
grok.shell.windows.help.showHelp(_package.webRoot + 'README_HD.md'); // TODO: Separate readme for Hit Design
|
|
41
|
-
this.checkCampaign().then((c) => {this.app.campaign = c; this.init();});
|
|
23
|
+
this.onActivated();
|
|
24
|
+
void this.init().then(() => this.openLinked());
|
|
42
25
|
}
|
|
43
26
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
'- Calculate different molecular properties\n' +
|
|
58
|
-
'- Save campaigns and continue from where you left off\n' +
|
|
59
|
-
'- Submit final selection to the function of your choice',
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
protected campaignsTableRoot: HTMLElement | null = null;
|
|
64
|
-
|
|
65
|
-
protected async refreshCampaignsTable() {
|
|
66
|
-
if (this.campaignsTableRoot == null)
|
|
67
|
-
return;
|
|
68
|
-
ui.setUpdateIndicator(this.campaignsTableRoot, true);
|
|
69
|
-
try {
|
|
70
|
-
const t = await this.getCampaignsTable();
|
|
71
|
-
ui.setUpdateIndicator(this.campaignsTableRoot, false);
|
|
72
|
-
ui.empty(this.campaignsTableRoot);
|
|
73
|
-
this.campaignsTableRoot.appendChild(t);
|
|
74
|
-
} catch (e) {
|
|
75
|
-
grok.shell.error('Failed to update campaigns table');
|
|
76
|
-
console.error(e);
|
|
77
|
-
} finally {
|
|
78
|
-
ui.setUpdateIndicator(this.campaignsTableRoot, false);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
async init(presetTemplate?: T) {
|
|
82
|
-
ui.setUpdateIndicator(this.root, true);
|
|
83
|
-
try {
|
|
84
|
-
const continueCampaignsHeader = ui.h1(i18n.continueCampaigns);
|
|
85
|
-
|
|
86
|
-
const createNewCampaignHeader = ui.h1(i18n.createNewCampaignHeader, {style: {marginLeft: '10px'}});
|
|
87
|
-
|
|
88
|
-
const campaignAccordionDiv = ui.div();
|
|
89
|
-
const templatesDiv = ui.divH([]);
|
|
90
|
-
const contentDiv = ui.div([templatesDiv, campaignAccordionDiv], 'ui-form');
|
|
91
|
-
|
|
92
|
-
const campaignsTable = await this.getCampaignsTable();
|
|
93
|
-
this.campaignsTableRoot = ui.div([campaignsTable], {style: {position: 'relative'}});
|
|
94
|
-
|
|
95
|
-
// grouping via different campaign properties
|
|
96
|
-
const groupIcon = ui.iconFA('layer-group', async () => {
|
|
97
|
-
const menu = DG.Menu.popup();
|
|
98
|
-
Object.values(CampaignGrouping).forEach((i) => {
|
|
99
|
-
menu.item(i, async () => {
|
|
100
|
-
setSavedCampaignsGrouping(i as CampaignGroupingType);
|
|
101
|
-
await this.refreshCampaignsTable();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
const campaignFieldsGroup = menu.group('Campaign Fields');
|
|
105
|
-
const campaignNamesMap = await _package.loadCampaigns(this.app.appName, this.deletedCampaigns);
|
|
106
|
-
const customFields = new Set<string>();
|
|
107
|
-
Object.values(campaignNamesMap).forEach((c) => {
|
|
108
|
-
if (c.campaignFields)
|
|
109
|
-
Object.keys(c.campaignFields).forEach((field) => customFields.add(field));
|
|
110
|
-
});
|
|
111
|
-
Array.from(customFields).forEach((field) => {
|
|
112
|
-
campaignFieldsGroup.item(field, async () => {
|
|
113
|
-
setSavedCampaignsGrouping(`campaignFields.${field}`);
|
|
114
|
-
await this.refreshCampaignsTable();
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
menu.show({element: sortingHeader, x: 120, y: sortingHeader.offsetTop + 30});
|
|
119
|
-
}, 'Group by');
|
|
120
|
-
groupIcon.style.marginBottom = '9px';
|
|
121
|
-
groupIcon.style.marginLeft = '8px';
|
|
122
|
-
groupIcon.style.fontSize = '15px';
|
|
123
|
-
groupIcon.style.color = 'var(--blue-1)';
|
|
124
|
-
ui.tooltip.bind(groupIcon, () => `Group Campaigns. Current: ${this.currentGroupping}`);
|
|
125
|
-
|
|
126
|
-
const editColumnsIcon = ui.iconFA('eye', async () => {
|
|
127
|
-
const menu = DG.Menu.popup();
|
|
128
|
-
const campaignNamesMap = await _package.loadCampaigns(this.app.appName, this.deletedCampaigns);
|
|
129
|
-
const getters: {[key in CampaignTableColumns]: (a: HitDesignCampaign) => string} = {...DefaultCampaignTableInfoGetters};
|
|
130
|
-
// remove Name as it is always present
|
|
131
|
-
// @ts-ignore
|
|
132
|
-
delete getters['Name'];
|
|
133
|
-
Object.values(campaignNamesMap).forEach((c) => {
|
|
134
|
-
if (c.campaignFields) {
|
|
135
|
-
Object.keys(c.campaignFields).forEach((field) => {
|
|
136
|
-
getters[`campaignFields.${field}`] = (a) => a.campaignFields?.[field] ?? '';
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
const savedColumns = getSavedCampaignTableColumns().reduce((acc: {[code in CampaignTableColumns]: boolean}, col) => {acc[col] = true; return acc;}, {} as any);
|
|
141
|
-
// first add the main columns
|
|
142
|
-
Object.keys(getters).filter((g) => !g.startsWith('campaignFields.')).forEach((col) => {
|
|
143
|
-
menu.item(col, () => {
|
|
144
|
-
savedColumns[col as CampaignTableColumns] = !savedColumns[col as CampaignTableColumns];
|
|
145
|
-
setSavedCampaignTableColumns(Object.keys(savedColumns).filter((c) => savedColumns[c as CampaignTableColumns]) as CampaignTableColumns[]);
|
|
146
|
-
this.refreshCampaignsTable();
|
|
147
|
-
}, null, {check: savedColumns[col as CampaignTableColumns] ?? false});
|
|
148
|
-
});
|
|
149
|
-
// then add a new group
|
|
150
|
-
const campaignsPropsGroup = menu.group('Campaign Fields');
|
|
151
|
-
|
|
152
|
-
Object.keys(getters).filter((g) => g.startsWith('campaignFields.')).forEach((col) => {
|
|
153
|
-
campaignsPropsGroup.item(col.replace('campaignFields.', ''), () => {
|
|
154
|
-
savedColumns[col as CampaignTableColumns] = !savedColumns[col as CampaignTableColumns];
|
|
155
|
-
setSavedCampaignTableColumns(Object.keys(savedColumns).filter((c) => savedColumns[c as CampaignTableColumns]) as CampaignTableColumns[]);
|
|
156
|
-
this.refreshCampaignsTable();
|
|
157
|
-
}, null, {check: savedColumns[col as CampaignTableColumns] ?? false});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// then add the custom fields
|
|
161
|
-
menu.show({element: sortingHeader, x: 100, y: sortingHeader.offsetTop + 30});
|
|
162
|
-
}, 'View');
|
|
163
|
-
ui.tooltip.bind(editColumnsIcon, 'Edit visible columns in campaigns table');
|
|
164
|
-
editColumnsIcon.style.marginBottom = '9px';
|
|
165
|
-
editColumnsIcon.style.marginLeft = '8px';
|
|
166
|
-
editColumnsIcon.style.fontSize = '15px';
|
|
167
|
-
editColumnsIcon.style.color = 'var(--blue-1)';
|
|
168
|
-
|
|
169
|
-
const refreshIcon = ui.iconFA('sync', async () => {
|
|
170
|
-
await this.refreshCampaignsTable();
|
|
171
|
-
}, 'Refresh');
|
|
172
|
-
refreshIcon.style.marginBottom = '9px';
|
|
173
|
-
refreshIcon.style.marginLeft = '8px';
|
|
174
|
-
refreshIcon.style.color = 'var(--blue-1)';
|
|
175
|
-
ui.tooltip.bind(refreshIcon, () => 'Refresh campaigns table');
|
|
176
|
-
const sortingHeader = ui.divH([continueCampaignsHeader, editColumnsIcon, groupIcon, refreshIcon], {style: {alignItems: 'center'}});
|
|
177
|
-
$(this._contentRoot).empty();
|
|
178
|
-
this._contentRoot.appendChild(ui.divV([sortingHeader], {style: {marginLeft: '10px'}}));
|
|
179
|
-
this._contentRoot.appendChild(this.campaignsTableRoot);
|
|
180
|
-
this._contentRoot.appendChild(createNewCampaignHeader);
|
|
181
|
-
this._contentRoot.appendChild(contentDiv);
|
|
182
|
-
await this.startNewCampaign(campaignAccordionDiv, templatesDiv, presetTemplate);
|
|
183
|
-
} finally {
|
|
184
|
-
ui.setUpdateIndicator(this.root, false);
|
|
185
|
-
}
|
|
27
|
+
protected header(): AppHeaderOptions {
|
|
28
|
+
return {
|
|
29
|
+
icon: _package.webRoot + '/images/icons/hit-design-icon.png',
|
|
30
|
+
learnMore: 'https://github.com/datagrok-ai/public/blob/master/packages/HitTriage/README_HD.md',
|
|
31
|
+
items: [
|
|
32
|
+
'Configure your own workflow using the template editor',
|
|
33
|
+
'Sketch molecules in the molecular spreadsheet',
|
|
34
|
+
'Annotate and share ideas with the team',
|
|
35
|
+
'Calculate different molecular properties',
|
|
36
|
+
'Save campaigns and continue from where you left off',
|
|
37
|
+
'Submit final selection to the function of your choice',
|
|
38
|
+
],
|
|
39
|
+
};
|
|
186
40
|
}
|
|
187
41
|
|
|
188
|
-
protected
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
let selectedTemplate: T | null = null;
|
|
199
|
-
let templateChangeFlag = true;
|
|
200
|
-
const onTemmplateChange = async () => {
|
|
201
|
-
if (!templateChangeFlag)
|
|
202
|
-
return;
|
|
203
|
-
const templateName = templatesInput.value;
|
|
204
|
-
const template: T = presetTemplate && presetTemplate.name === templateName ? presetTemplate :
|
|
205
|
-
await loadTemplate<T>(`${this.app.appName}/templates/${templateName}.json`);
|
|
206
|
-
selectedTemplate = template;
|
|
207
|
-
const newCampaignAccordeon = await this.getNewCampaignAccordeon(template);
|
|
208
|
-
$(containerDiv).empty();
|
|
209
|
-
containerDiv.appendChild(newCampaignAccordeon);
|
|
42
|
+
protected homeOptions(preset?: T): HitHomeOptions<T> {
|
|
43
|
+
return {
|
|
44
|
+
header: this.header(),
|
|
45
|
+
catalog: this.catalogOptions('HD', (c) => c.name, (campaigns) =>
|
|
46
|
+
this.app.existingStatuses = Array.from(new Set(campaigns.map((c) => c.status).filter((s) => !!s)))),
|
|
47
|
+
picker: {app: this.app.appName, preset,
|
|
48
|
+
edit: (template) => void openTemplateEditor({app: this.app, preset: template, onCreated: (t) => this.init(t)}),
|
|
49
|
+
form: (template, {column}) => newCampaignForm({template, column,
|
|
50
|
+
nextCode: () => this.app.getNewCampaignName(`${this.app.appName}/campaigns`, template.key),
|
|
51
|
+
start: ({fields, name}) => this.app.startNewCampaign(template, fields, name)})},
|
|
210
52
|
};
|
|
211
|
-
|
|
212
|
-
const templatesInput = ui.input.choice('Template', {value: presetTemplate?.name ?? templates[0], items: templates,
|
|
213
|
-
onValueChanged: async () => {
|
|
214
|
-
await onTemmplateChange();
|
|
215
|
-
}});
|
|
216
|
-
templatesInput.root.style.width = '100%';
|
|
217
|
-
const createNewtemplateButton = ui.icons.add(() => {
|
|
218
|
-
this.createNewTemplate();
|
|
219
|
-
}, i18n.createNewTemplate);
|
|
220
|
-
|
|
221
|
-
const cloneTemplateButton = ui.icons.copy(() => {
|
|
222
|
-
if (selectedTemplate)
|
|
223
|
-
this.createNewTemplate(selectedTemplate);
|
|
224
|
-
}, 'Clone template');
|
|
225
|
-
|
|
226
|
-
const deleteTempleteButton = ui.icons.delete(() => {
|
|
227
|
-
if (!templatesInput.value || templatesInput.items.length < 2)
|
|
228
|
-
return;
|
|
229
|
-
ui.dialog('Delete template')
|
|
230
|
-
.add(ui.divText(`Are you sure you want to delete template ${templatesInput.value}?`))
|
|
231
|
-
.onOK(async () => {
|
|
232
|
-
try {
|
|
233
|
-
const prevValue = templatesInput.value;
|
|
234
|
-
await _package.files.delete(`${this.app.appName}/templates/${prevValue}.json`);
|
|
235
|
-
templateChangeFlag = false;
|
|
236
|
-
templatesInput.items = templatesInput.items.filter((item) => item !== prevValue);
|
|
237
|
-
templatesInput.value = templatesInput.items[0];
|
|
238
|
-
templateChangeFlag = true;
|
|
239
|
-
await onTemmplateChange();
|
|
240
|
-
grok.shell.info('Template ' + prevValue + ' was deleted successfully');
|
|
241
|
-
} catch (e) {
|
|
242
|
-
templateChangeFlag = true;
|
|
243
|
-
grok.shell.error('Failed to delete template ' + templatesInput.value);
|
|
244
|
-
console.error(e);
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
.show();
|
|
248
|
-
}, 'Delete template');
|
|
249
|
-
deleteTempleteButton.style.color = 'var(--blue-1)';
|
|
250
|
-
createNewtemplateButton.style.color = '#2083d5';
|
|
251
|
-
templatesInput.addOptions(createNewtemplateButton);
|
|
252
|
-
templatesInput.addOptions(cloneTemplateButton);
|
|
253
|
-
templatesInput.addOptions(deleteTempleteButton);
|
|
254
|
-
await onTemmplateChange();
|
|
255
|
-
$(templateInputDiv).empty();
|
|
256
|
-
templateInputDiv.appendChild(templatesInput.root);
|
|
257
53
|
}
|
|
258
54
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
const urlParams = new URLSearchParams(url);
|
|
263
|
-
if (!urlParams.has(HitDesignCampaignIdKey) && !campId)
|
|
264
|
-
return;
|
|
265
|
-
const campaignId = campId ?? urlParams.get(HitDesignCampaignIdKey);
|
|
55
|
+
protected async checkCampaign(campaignId: string) {
|
|
56
|
+
// taken before the reads: a campaign asked for later wins, however long this one reads
|
|
57
|
+
const ticket = this.app.openTicket();
|
|
266
58
|
// check if such campaign exists
|
|
267
59
|
if (!await _package.files.exists(`${this.app.appName}/campaigns/${campaignId}/${CampaignJsonName}`))
|
|
268
60
|
return;
|
|
269
61
|
const campaign: HitDesignCampaign =
|
|
270
62
|
JSON.parse(await _package.files.readAsText(`${this.app.appName}/campaigns/${campaignId}/${CampaignJsonName}`));
|
|
271
|
-
if
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
this.app.campaign = campaign;
|
|
63
|
+
// in case if the link was opened and user has no permissions to view the campaign
|
|
64
|
+
if (campaign.authorUserId && campaign.permissions &&
|
|
65
|
+
!await checkViewPermissions(campaign.authorUserId, campaign.permissions)
|
|
66
|
+
) {
|
|
67
|
+
this.app.setBaseUrl();
|
|
68
|
+
return;
|
|
280
69
|
}
|
|
281
|
-
//
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
70
|
+
// what the open reads is checked before the app takes the campaign: a failed open leaves the open one in place
|
|
71
|
+
const templatePath = `${this.app.appName}/templates/${campaign.templateName}.json`;
|
|
72
|
+
if (!campaign.template && !await _package.files.exists(templatePath))
|
|
73
|
+
throw new CampaignUnavailableError('its template is missing');
|
|
74
|
+
const tablePath = campaign.savePath ??
|
|
75
|
+
`System.AppData/HitTriage/${this.app.appName}/campaigns/${campaignId}/${CampaignTableName}`;
|
|
76
|
+
if (!await grok.dapi.files.exists(tablePath))
|
|
77
|
+
throw new CampaignUnavailableError(`its table ${tablePath} is missing`);
|
|
78
|
+
const template: T = (campaign.template as T) ?? await loadTemplate<T>(templatePath);
|
|
79
|
+
// a campaign opened after this one was asked for is the one shown, its address the address
|
|
80
|
+
if (!await this.app.setTemplate(template, campaignId, campaign, ticket))
|
|
81
|
+
return;
|
|
287
82
|
|
|
288
|
-
|
|
289
|
-
modifyUrl(HitDesignCampaignIdKey, campId);
|
|
83
|
+
modifyUrl(HitDesignCampaignIdKey, campaignId);
|
|
290
84
|
|
|
291
85
|
campaign.template = template;
|
|
292
86
|
return campaign;
|
|
293
87
|
}
|
|
294
|
-
|
|
295
|
-
private async getCampaignsTable() {
|
|
296
|
-
const campaignNamesMap = await _package.loadCampaigns(this.app.appName, this.deletedCampaigns);
|
|
297
|
-
const grouppingMode = getSavedCampaignsGrouping();
|
|
298
|
-
const campaignSorting = getSavedCampaignsSorting();
|
|
299
|
-
const allCampaigns = Object.values(campaignNamesMap);
|
|
300
|
-
// sort all campaigns
|
|
301
|
-
if (campaignSorting)
|
|
302
|
-
sortCampaigns(allCampaigns, campaignSorting);
|
|
303
|
-
const grouppedCampaigns = getGroupedCampaigns<HitDesignCampaign>(allCampaigns, grouppingMode);
|
|
304
|
-
const shownColumns = getSavedCampaignTableColumns();
|
|
305
|
-
|
|
306
|
-
this.currentGroupping = grouppingMode;
|
|
307
|
-
this.app.existingStatuses = Array.from(new Set(allCampaigns.map((c) => c.status).filter((s) => !!s)));
|
|
308
|
-
const deleteAndShareCampaignIcons = (info: HitDesignCampaign) => {
|
|
309
|
-
const deleteIcon = ui.icons.delete(async () => {
|
|
310
|
-
ui.dialog('Delete campaign')
|
|
311
|
-
.add(ui.divText(`Are you sure you want to delete campaign ${info.name}?`))
|
|
312
|
-
.onOK(async () => {
|
|
313
|
-
await this.deleteCampaignAndRefresh(this.app.appName, info.name);
|
|
314
|
-
})
|
|
315
|
-
.show();
|
|
316
|
-
}, 'Delete campaign');
|
|
317
|
-
const shareIcon = ui.iconFA('share', async () => {
|
|
318
|
-
await (new PermissionsDialog(info.permissions)).show(async (res) => {
|
|
319
|
-
try {
|
|
320
|
-
info.permissions = res;
|
|
321
|
-
info.authorUserId ??= grok.shell.user.id;
|
|
322
|
-
await _package.saveCampaignJson(this.app.appName, info);
|
|
323
|
-
grok.shell.info('Permissions updated for campaign ' + info.name);
|
|
324
|
-
} catch (e) {
|
|
325
|
-
grok.shell.error('Failed to update permissions for campaign ' + info.name);
|
|
326
|
-
console.error(e);
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
}, 'Manage campaign permissions');
|
|
330
|
-
deleteIcon.style.display = 'none';
|
|
331
|
-
shareIcon.style.display = 'none';
|
|
332
|
-
const authorId = info.authorUserId ?? DG.User.current().id;
|
|
333
|
-
const perms = info.permissions ?? defaultPermissions;
|
|
334
|
-
checkEditPermissions(authorId, perms).then((canEdit) => {
|
|
335
|
-
if (canEdit) {
|
|
336
|
-
deleteIcon.style.display = 'inline-block';
|
|
337
|
-
shareIcon.style.display = 'inline-block';
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
deleteIcon.style.color = 'var(--blue-1)';
|
|
341
|
-
shareIcon.style.color = 'var(--blue-1)';
|
|
342
|
-
return [shareIcon, deleteIcon];
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
const table = ui.table(Object.values(grouppedCampaigns).flat(), (info) =>
|
|
346
|
-
([ui.link(info.friendlyName ?? info.name, () => this.setCampaign(info.name), 'Continue Campaign', ''),
|
|
347
|
-
...(shownColumns.map((col) => col.startsWith('campaignFields.') ?
|
|
348
|
-
info.campaignFields?.[col.replace('campaignFields.', '')] ?? '' :
|
|
349
|
-
DefaultCampaignTableInfoGetters[col as unknown as keyof typeof DefaultCampaignTableInfoGetters](info) ?? '')),
|
|
350
|
-
...(deleteAndShareCampaignIcons(info)),
|
|
351
|
-
]),
|
|
352
|
-
['Name', ...(shownColumns.map((a) => a.replace('campaignFields.', ''))), '', '']);
|
|
353
|
-
table.style.color = 'var(--grey-5)';
|
|
354
|
-
table.style.marginLeft = '24px';
|
|
355
|
-
// add sorting support
|
|
356
|
-
table.querySelectorAll('tr.header > td').forEach((el, i) => {
|
|
357
|
-
if (!el.textContent)
|
|
358
|
-
return;
|
|
359
|
-
const field = i === 0 ? 'Name' : shownColumns[i - 1];
|
|
360
|
-
if (campaignSorting && field === campaignSorting.columnName) {
|
|
361
|
-
// add icon
|
|
362
|
-
const sortIcon = campaignSorting.ascending ? '↑' : '↓';
|
|
363
|
-
el.appendChild(ui.span([sortIcon], {style: {fontSize: '12px', marginLeft: '2px'}}));
|
|
364
|
-
}
|
|
365
|
-
(el as HTMLElement).addEventListener('dblclick', () => {
|
|
366
|
-
let nextSorting: SavedCampaignsTableSorting | null = {columnName: field, ascending: true};
|
|
367
|
-
if (campaignSorting && field === campaignSorting.columnName)
|
|
368
|
-
nextSorting = campaignSorting.ascending ? {columnName: field, ascending: false} : null;
|
|
369
|
-
setSavedCampaignsSorting(nextSorting);
|
|
370
|
-
this.refreshCampaignsTable();
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
processGroupingTable(table, grouppedCampaigns);
|
|
376
|
-
return table;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
public async setCampaign(campaignName: string) {
|
|
380
|
-
const campaign = await this.checkCampaign(campaignName);
|
|
381
|
-
this.app.campaign = campaign;
|
|
382
|
-
}
|
|
383
|
-
async getNewCampaignAccordeon(template: T) {
|
|
384
|
-
const {root, promise, cancelPromise} = newHitDesignCampaignAccordeon(template);
|
|
385
|
-
promise.then(async (camp) => {
|
|
386
|
-
this.app.clearCampaign();// make sure the previous campaign is cleared
|
|
387
|
-
this.app.dataFrame = camp.df;
|
|
388
|
-
await this.app.setTemplate(template);
|
|
389
|
-
this.app.campaignProps = camp.campaignProps;
|
|
390
|
-
const campaignName = !!camp.name?.trim() ? camp.name?.trim() : undefined;
|
|
391
|
-
await this.app.saveCampaign(false, true, {friendlyName: campaignName});
|
|
392
|
-
if (template.layoutViewState && this.app.campaign)
|
|
393
|
-
this.app.campaign.layout = template.layoutViewState;
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
cancelPromise.then(() => {
|
|
397
|
-
this.init();
|
|
398
|
-
});
|
|
399
|
-
return root;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
private async createNewTemplate(preset?: T) {
|
|
403
|
-
ui.setUpdateIndicator(this.root, true);
|
|
404
|
-
try {
|
|
405
|
-
const newTemplateAccordeon = await newHitDesignTemplateAccordeon(this.app, preset);
|
|
406
|
-
// hideComponents(toRemove);
|
|
407
|
-
// $(containerDiv).empty();
|
|
408
|
-
// $(templateInputDiv).empty();
|
|
409
|
-
|
|
410
|
-
const newView = new DG.ViewBase();
|
|
411
|
-
const curView = grok.shell.v;
|
|
412
|
-
newView.name = 'New Template';
|
|
413
|
-
newView.root.appendChild(newTemplateAccordeon.root);
|
|
414
|
-
newView.parentCall = this.app.parentCall;
|
|
415
|
-
grok.shell.addView(newView);
|
|
416
|
-
newView.path = new URL(this.app.baseUrl).pathname + '/new-template';
|
|
417
|
-
const {sub} = addBreadCrumbsToRibbons(newView, this.app.appName, i18n.createNewTemplate, async () => {
|
|
418
|
-
grok.shell.v = curView;
|
|
419
|
-
newView.close();
|
|
420
|
-
});
|
|
421
|
-
//containerDiv.appendChild(newTemplateAccordeon.root);
|
|
422
|
-
newTemplateAccordeon.template.then(async (t) => {
|
|
423
|
-
await this.init(t as any);
|
|
424
|
-
newView.close();
|
|
425
|
-
popRibbonPannels(newView);
|
|
426
|
-
grok.shell.v = curView;
|
|
427
|
-
sub.unsubscribe();
|
|
428
|
-
});
|
|
429
|
-
newTemplateAccordeon.cancelPromise.then(async () => {
|
|
430
|
-
sub.unsubscribe();
|
|
431
|
-
newView.close();
|
|
432
|
-
grok.shell.v = curView;
|
|
433
|
-
});
|
|
434
|
-
} finally {
|
|
435
|
-
ui.setUpdateIndicator(this.root, false);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
88
|
}
|