Skip to content

Commit ca97b5d

Browse files
author
julian
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 832a024 + 22f6e8d commit ca97b5d

5 files changed

Lines changed: 38 additions & 25 deletions

File tree

src/main/resources/static/js/pages/editor/Editor.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import accordions from "../../shared/modules/accordions.js";
2-
import { identifierValid, widgetsValid } from "./utils/editorValidations.js";
2+
import {
3+
identifierValid,
4+
widgetsValid,
5+
sourcesValid,
6+
} from "./utils/editorValidations.js";
37
import state from "./utils/editorState.js";
48
import {
59
createSource,
610
createWidget,
711
loadSources,
8-
saveSources,
912
} from "./utils/editorActions.js";
1013
import { debounce } from "../../shared/modules/utils.js";
1114
import {
@@ -30,7 +33,7 @@ export default class Editor {
3033
this.initGrid();
3134

3235
// Load existing data
33-
loadSources(config.sources || []);
36+
loadSources(config.sources || [], config.generators || []);
3437
state.grid.load(config.widgets || []);
3538

3639
// Replace whitespaces in the id with dashes
@@ -133,11 +136,13 @@ export default class Editor {
133136
const pipelines = await getPipelines();
134137
const config = {
135138
id: id,
136-
sources: saveSources(),
139+
sources: state.sources,
140+
generators: state.generators,
137141
widgets: state.grid.save(false),
138142
};
139143

140-
const ok = identifierValid(config) && widgetsValid(config);
144+
const ok =
145+
identifierValid(config) && widgetsValid(config) && sourcesValid(config);
141146

142147
if (ok && pipelines.includes(config.id)) {
143148
state.modal.confirm(

src/main/resources/static/js/pages/editor/configs/Source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getAnnotations } from "../../../api/annotations.api.js";
33
export default class Source {
44
static defaultConfig = {
55
uri: "",
6-
createsGenerators: [],
6+
settings: {},
77
};
88
static formConfig = {
99
uri: {

src/main/resources/static/js/pages/editor/controller/SourceController.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class SourceController {
1414
this.item = item;
1515
}
1616

17-
init() {
17+
init(generators = []) {
1818
const buttons = this.root.querySelectorAll("button");
1919
const options = this.root.querySelector(".dv-dropdown-menu");
2020
const body = this.root.querySelector(".dv-source-card-body");
@@ -26,10 +26,13 @@ export default class SourceController {
2626
);
2727

2828
// Load existing generators
29-
for (const config of this.item.createsGenerators) {
29+
for (const config of [
30+
...(this.item.createsGenerators || []),
31+
...generators,
32+
]) {
3033
this.appendGenerator(body, config);
3134
}
32-
this.item.createsGenerators = [];
35+
delete this.item.createsGenerators;
3336

3437
// Append available generator options
3538
Object.values(configs).forEach((Generator) => {

src/main/resources/static/js/pages/editor/utils/editorActions.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,17 @@ import WidgetController from "../controller/WidgetController.js";
44
import SourceController from "../controller/SourceController.js";
55
import GeneratorController from "../controller/GeneratorController.js";
66

7-
export function loadSources(configs) {
7+
export function loadSources(sources, generators) {
88
const container = document.querySelector(".dv-sources-container");
99

10-
for (const config of configs) {
10+
for (const config of sources) {
1111
const controller = createSource(config);
1212

1313
container.prepend(controller.root);
14-
controller.init();
14+
controller.init(generators);
1515
}
1616
}
1717

18-
export function saveSources() {
19-
const sources = structuredClone(state.sources);
20-
21-
for (const generator of state.generators) {
22-
const { source: id, ...rest } = generator;
23-
const source = sources.find((item) => item.id === id);
24-
25-
source.createsGenerators.push(rest);
26-
}
27-
28-
return sources;
29-
}
30-
3118
export function createSource(config) {
3219
const source = deepClone(config);
3320
source.id = source.id || randomId("Source");

src/main/resources/static/js/pages/editor/utils/editorValidations.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ export function widgetsValid(config) {
4242
return false;
4343
}
4444
}
45+
46+
export function sourcesValid(config) {
47+
const empty = config.sources.filter((source) => source.uri === "");
48+
49+
if (empty.length === 1) {
50+
state.modal.alert(
51+
"Empty Sources",
52+
`There is one source with no annotation type selected.`,
53+
);
54+
} else if (empty.length > 1) {
55+
state.modal.alert(
56+
"Empty Sources",
57+
`There are ${empty.length} sources with no annotation type selected.`,
58+
);
59+
}
60+
61+
return empty.length === 0;
62+
}

0 commit comments

Comments
 (0)