@mintplayer/ng-spark 22.23.0 → 22.25.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/README.md +196 -0
- package/fesm2022/mintplayer-ng-spark-attribute-description.mjs +100 -47
- package/fesm2022/mintplayer-ng-spark-attribute-description.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-client-operations.mjs +310 -329
- package/fesm2022/mintplayer-ng-spark-client-operations.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-column-filter.mjs +175 -135
- package/fesm2022/mintplayer-ng-spark-column-filter.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-contributions.mjs +721 -0
- package/fesm2022/mintplayer-ng-spark-contributions.mjs.map +1 -0
- package/fesm2022/mintplayer-ng-spark-grid.mjs +2385 -1118
- package/fesm2022/mintplayer-ng-spark-grid.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-history.mjs +598 -0
- package/fesm2022/mintplayer-ng-spark-history.mjs.map +1 -0
- package/fesm2022/mintplayer-ng-spark-icon.mjs +64 -27
- package/fesm2022/mintplayer-ng-spark-icon.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-models.mjs +405 -762
- package/fesm2022/mintplayer-ng-spark-models.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-moderation.mjs +1212 -0
- package/fesm2022/mintplayer-ng-spark-moderation.mjs.map +1 -0
- package/fesm2022/mintplayer-ng-spark-panels.mjs +60 -0
- package/fesm2022/mintplayer-ng-spark-panels.mjs.map +1 -0
- package/fesm2022/mintplayer-ng-spark-pipes.mjs +1158 -765
- package/fesm2022/mintplayer-ng-spark-pipes.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-po-create.mjs +273 -169
- package/fesm2022/mintplayer-ng-spark-po-create.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-po-detail.mjs +795 -410
- package/fesm2022/mintplayer-ng-spark-po-detail.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-po-edit.mjs +1196 -280
- package/fesm2022/mintplayer-ng-spark-po-edit.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-po-form.mjs +2244 -1224
- package/fesm2022/mintplayer-ng-spark-po-form.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-query-list.mjs +571 -303
- package/fesm2022/mintplayer-ng-spark-query-list.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-renderers.mjs +44 -55
- package/fesm2022/mintplayer-ng-spark-renderers.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-retry-action-modal.mjs +216 -177
- package/fesm2022/mintplayer-ng-spark-retry-action-modal.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-routes.mjs +24 -28
- package/fesm2022/mintplayer-ng-spark-routes.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-services.mjs +625 -640
- package/fesm2022/mintplayer-ng-spark-services.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-shell.mjs +1031 -397
- package/fesm2022/mintplayer-ng-spark-shell.mjs.map +1 -1
- package/fesm2022/mintplayer-ng-spark-soft-delete.mjs +294 -0
- package/fesm2022/mintplayer-ng-spark-soft-delete.mjs.map +1 -0
- package/fesm2022/mintplayer-ng-spark.mjs +14 -48
- package/fesm2022/mintplayer-ng-spark.mjs.map +1 -1
- package/package.json +23 -2
- package/types/mintplayer-ng-spark-attribute-description.d.ts +25 -18
- package/types/mintplayer-ng-spark-client-operations.d.ts +139 -160
- package/types/mintplayer-ng-spark-column-filter.d.ts +73 -55
- package/types/mintplayer-ng-spark-contributions.d.ts +231 -0
- package/types/mintplayer-ng-spark-grid.d.ts +917 -448
- package/types/mintplayer-ng-spark-history.d.ts +216 -0
- package/types/mintplayer-ng-spark-icon.d.ts +15 -13
- package/types/mintplayer-ng-spark-models.d.ts +681 -573
- package/types/mintplayer-ng-spark-moderation.d.ts +402 -0
- package/types/mintplayer-ng-spark-panels.d.ts +143 -0
- package/types/mintplayer-ng-spark-pipes.d.ts +131 -149
- package/types/mintplayer-ng-spark-po-create.d.ts +46 -37
- package/types/mintplayer-ng-spark-po-detail.d.ts +180 -117
- package/types/mintplayer-ng-spark-po-edit.d.ts +367 -64
- package/types/mintplayer-ng-spark-po-form.d.ts +558 -373
- package/types/mintplayer-ng-spark-query-list.d.ts +143 -82
- package/types/mintplayer-ng-spark-renderers.d.ts +121 -85
- package/types/mintplayer-ng-spark-retry-action-modal.d.ts +31 -34
- package/types/mintplayer-ng-spark-routes.d.ts +7 -11
- package/types/mintplayer-ng-spark-services.d.ts +377 -261
- package/types/mintplayer-ng-spark-shell.d.ts +228 -132
- package/types/mintplayer-ng-spark-soft-delete.d.ts +90 -0
- package/types/mintplayer-ng-spark.d.ts +19 -12
|
@@ -1,170 +1,274 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import { takeUntilDestroyed } from
|
|
4
|
-
import { CommonModule } from
|
|
5
|
-
import { ActivatedRoute, Router } from
|
|
6
|
-
import { Color } from
|
|
7
|
-
import { BsAlertComponent } from
|
|
8
|
-
import { BsContainerComponent } from
|
|
9
|
-
import { BsSpinnerComponent } from
|
|
10
|
-
import { SparkService } from
|
|
11
|
-
import { SparkPoFormComponent } from
|
|
12
|
-
import { ResolveTranslationPipe, TranslateKeyPipe } from
|
|
13
|
-
import { applyOverlay,
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, computed, inject, output, signal } from "@angular/core";
|
|
3
|
+
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
|
4
|
+
import { CommonModule } from "@angular/common";
|
|
5
|
+
import { ActivatedRoute, Router } from "@angular/router";
|
|
6
|
+
import { Color } from "@mintplayer/ng-bootstrap";
|
|
7
|
+
import { BsAlertComponent } from "@mintplayer/ng-bootstrap/alert";
|
|
8
|
+
import { BsContainerComponent } from "@mintplayer/ng-bootstrap/container";
|
|
9
|
+
import { BsSpinnerComponent } from "@mintplayer/ng-bootstrap/spinner";
|
|
10
|
+
import { SparkService } from "@mintplayer/ng-spark/services";
|
|
11
|
+
import { SparkPoFormComponent } from "@mintplayer/ng-spark/po-form";
|
|
12
|
+
import { ResolveTranslationPipe, TranslateKeyPipe } from "@mintplayer/ng-spark/pipes";
|
|
13
|
+
import { ShowedOn, applyOverlay, dictToNestedPo, fromDateInputValue, hasShowedOnFlag, isDateDataType, toDateInputValue } from "@mintplayer/ng-spark/models";
|
|
14
|
+
var SparkPoCreateComponent = class SparkPoCreateComponent {
|
|
15
|
+
route = inject(ActivatedRoute);
|
|
16
|
+
router = inject(Router);
|
|
17
|
+
sparkService = inject(SparkService);
|
|
18
|
+
saved = output();
|
|
19
|
+
cancelled = output();
|
|
20
|
+
colors = Color;
|
|
21
|
+
entityType = signal(null, ...ngDevMode ? [{ debugName: "entityType" }] : /* istanbul ignore next */ []);
|
|
22
|
+
type = signal("", ...ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []);
|
|
23
|
+
formData = signal({}, ...ngDevMode ? [{ debugName: "formData" }] : /* istanbul ignore next */ []);
|
|
24
|
+
refreshOverlay = signal({}, ...ngDevMode ? [{ debugName: "refreshOverlay" }] : /* istanbul ignore next */ []);
|
|
25
|
+
validationErrors = signal([], ...ngDevMode ? [{ debugName: "validationErrors" }] : /* istanbul ignore next */ []);
|
|
26
|
+
isSaving = signal(false, ...ngDevMode ? [{ debugName: "isSaving" }] : /* istanbul ignore next */ []);
|
|
27
|
+
allEntityTypes = signal([], ...ngDevMode ? [{ debugName: "allEntityTypes" }] : /* istanbul ignore next */ []);
|
|
28
|
+
generalErrors = computed(() => this.validationErrors().filter((e) => !e.attributeName), ...ngDevMode ? [{ debugName: "generalErrors" }] : /* istanbul ignore next */ []);
|
|
29
|
+
constructor() {
|
|
30
|
+
this.route.paramMap.pipe(takeUntilDestroyed()).subscribe((params) => this.onParamsChange(params));
|
|
31
|
+
}
|
|
32
|
+
async onParamsChange(params) {
|
|
33
|
+
this.type.set(params.get("type") || "");
|
|
34
|
+
const types = await this.sparkService.getEntityTypes();
|
|
35
|
+
const entityType = types.find((t) => t.id === this.type() || t.alias === this.type()) || null;
|
|
36
|
+
this.allEntityTypes.set(types);
|
|
37
|
+
this.initFormData(entityType);
|
|
38
|
+
if (entityType) await this.applyServerDefaults(entityType);
|
|
39
|
+
this.entityType.set(entityType);
|
|
40
|
+
}
|
|
41
|
+
async applyServerDefaults(entityType) {
|
|
42
|
+
const query = this.route.snapshot.queryParamMap;
|
|
43
|
+
const parentId = query.get("parentId") ?? void 0;
|
|
44
|
+
const parentType = query.get("parentType") ?? void 0;
|
|
45
|
+
const queryId = query.get("queryId") ?? void 0;
|
|
46
|
+
const fromSubQuery = !!(parentId && parentType && queryId);
|
|
47
|
+
try {
|
|
48
|
+
const po = await this.sparkService.newObject(this.type(), fromSubQuery ? {
|
|
49
|
+
parentId,
|
|
50
|
+
parentType,
|
|
51
|
+
queryId
|
|
52
|
+
} : void 0);
|
|
53
|
+
const editable = new Map(this.getEditableAttributes(entityType).map((a) => [a.name, a]));
|
|
54
|
+
const data = { ...this.formData() };
|
|
55
|
+
for (const attr of po?.attributes ?? []) {
|
|
56
|
+
const definition = editable.get(attr.name);
|
|
57
|
+
if (!definition || attr.value === null || attr.value === void 0 || definition.dataType === "AsDetail") continue;
|
|
58
|
+
data[attr.name] = isDateDataType(definition.dataType) ? toDateInputValue(definition.dataType, attr.value) : attr.value;
|
|
59
|
+
}
|
|
60
|
+
this.formData.set(data);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
const error = e;
|
|
63
|
+
const errors = error.error?.result?.errors ?? error.error?.errors;
|
|
64
|
+
this.validationErrors.set(errors ?? [{
|
|
65
|
+
attributeName: "",
|
|
66
|
+
errorMessage: { en: error.message || "The new item could not be prepared." },
|
|
67
|
+
ruleType: "error"
|
|
68
|
+
}]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
initFormData(entityType = this.entityType()) {
|
|
72
|
+
const data = {};
|
|
73
|
+
this.getEditableAttributes(entityType).forEach((attr) => {
|
|
74
|
+
if (attr.dataType === "Reference") data[attr.name] = null;
|
|
75
|
+
else if (attr.dataType === "AsDetail") data[attr.name] = attr.isArray ? [] : {};
|
|
76
|
+
else if (attr.dataType === "boolean" && !attr.lookupReferenceType) data[attr.name] = false;
|
|
77
|
+
else data[attr.name] = "";
|
|
78
|
+
});
|
|
79
|
+
this.formData.set(data);
|
|
80
|
+
}
|
|
81
|
+
getEditableAttributes(entityType = this.entityType()) {
|
|
82
|
+
const overlay = this.refreshOverlay();
|
|
83
|
+
return entityType?.attributes.map((a) => applyOverlay(a, overlay[a.name])).filter((a) => a.isVisible && !a.isReadOnly && hasShowedOnFlag(a.showedOn, ShowedOn.PersistentObject)).sort((a, b) => a.order - b.order) || [];
|
|
84
|
+
}
|
|
85
|
+
async onSave() {
|
|
86
|
+
if (!this.entityType()) return;
|
|
87
|
+
this.validationErrors.set([]);
|
|
88
|
+
this.isSaving.set(true);
|
|
89
|
+
const resolver = (clrName) => this.allEntityTypes().find((t) => t.clrType === clrName);
|
|
90
|
+
const attributes = this.getEditableAttributes().map((attr) => {
|
|
91
|
+
const base = {
|
|
92
|
+
id: attr.id,
|
|
93
|
+
name: attr.name,
|
|
94
|
+
value: isDateDataType(attr.dataType) ? fromDateInputValue(attr.dataType, this.formData()[attr.name]) : this.formData()[attr.name],
|
|
95
|
+
dataType: attr.dataType,
|
|
96
|
+
isArray: attr.isArray,
|
|
97
|
+
isRequired: attr.isRequired,
|
|
98
|
+
isVisible: attr.isVisible,
|
|
99
|
+
isReadOnly: attr.isReadOnly,
|
|
100
|
+
isValueChanged: true,
|
|
101
|
+
order: attr.order,
|
|
102
|
+
rules: attr.rules
|
|
103
|
+
};
|
|
104
|
+
if (attr.dataType === "AsDetail" && attr.asDetailType) {
|
|
105
|
+
const nestedType = resolver(attr.asDetailType);
|
|
106
|
+
if (nestedType) {
|
|
107
|
+
const raw = this.formData()[attr.name];
|
|
108
|
+
base.value = null;
|
|
109
|
+
base.asDetailType = attr.asDetailType;
|
|
110
|
+
if (attr.isArray) {
|
|
111
|
+
base.objects = (Array.isArray(raw) ? raw : []).map((item) => dictToNestedPo(item ?? {}, nestedType, resolver));
|
|
112
|
+
base.object = null;
|
|
113
|
+
} else {
|
|
114
|
+
base.object = raw ? dictToNestedPo(raw, nestedType, resolver) : null;
|
|
115
|
+
base.objects = null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return base;
|
|
120
|
+
});
|
|
121
|
+
const po = {
|
|
122
|
+
name: this.formData()["Name"] || "New Item",
|
|
123
|
+
objectTypeId: this.entityType().id,
|
|
124
|
+
attributes
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
const result = await this.sparkService.create(this.type(), po);
|
|
128
|
+
this.isSaving.set(false);
|
|
129
|
+
this.saved.emit(result);
|
|
130
|
+
this.router.navigate([
|
|
131
|
+
"/po",
|
|
132
|
+
this.type(),
|
|
133
|
+
result.id
|
|
134
|
+
]);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
this.isSaving.set(false);
|
|
137
|
+
const error = e;
|
|
138
|
+
const errors = error.error?.result?.errors ?? error.error?.errors;
|
|
139
|
+
if (error.status === 400 && errors) this.validationErrors.set(errors);
|
|
140
|
+
else this.validationErrors.set([{
|
|
141
|
+
attributeName: "",
|
|
142
|
+
errorMessage: { en: error.message || "An unexpected error occurred" },
|
|
143
|
+
ruleType: "error"
|
|
144
|
+
}]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
onCancel() {
|
|
148
|
+
this.cancelled.emit();
|
|
149
|
+
window.history.back();
|
|
150
|
+
}
|
|
151
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
152
|
+
minVersion: "12.0.0",
|
|
153
|
+
version: "22.2.0",
|
|
154
|
+
ngImport: i0,
|
|
155
|
+
type: SparkPoCreateComponent,
|
|
156
|
+
deps: [],
|
|
157
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
158
|
+
});
|
|
159
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
160
|
+
minVersion: "17.0.0",
|
|
161
|
+
version: "22.2.0",
|
|
162
|
+
type: SparkPoCreateComponent,
|
|
163
|
+
isStandalone: true,
|
|
164
|
+
selector: "spark-po-create",
|
|
165
|
+
outputs: {
|
|
166
|
+
saved: "saved",
|
|
167
|
+
cancelled: "cancelled"
|
|
168
|
+
},
|
|
169
|
+
ngImport: i0,
|
|
170
|
+
template: "<bs-container>\n<div class=\"container\">\n @if (entityType(); as et) {\n <h2 class=\"mb-4\">{{ 'common.create' | t }} {{ (et.description | resolveTranslation) || et.name }}</h2>\n\n @for (error of generalErrors(); track error.errorMessage) {\n <bs-alert [type]=\"colors.danger\" class=\"mb-3\">\n {{ error.errorMessage | resolveTranslation }}\n </bs-alert>\n }\n\n <spark-po-form\n [entityType]=\"et\"\n [(formData)]=\"formData\"\n [(refreshOverlay)]=\"refreshOverlay\"\n [objectTypeId]=\"type()\"\n [parentType]=\"type()\"\n [validationErrors]=\"validationErrors()\"\n [showButtons]=\"true\"\n [isSaving]=\"isSaving()\"\n (save)=\"onSave()\"\n (cancel)=\"onCancel()\">\n </spark-po-form>\n } @else {\n <div class=\"text-center p-5\">\n <bs-spinner />\n </div>\n }\n</div>\n</bs-container>\n",
|
|
171
|
+
dependencies: [
|
|
172
|
+
{
|
|
173
|
+
kind: "ngmodule",
|
|
174
|
+
type: CommonModule
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
kind: "component",
|
|
178
|
+
type: BsAlertComponent,
|
|
179
|
+
selector: "bs-alert",
|
|
180
|
+
inputs: [
|
|
181
|
+
"type",
|
|
182
|
+
"announce",
|
|
183
|
+
"isVisible"
|
|
184
|
+
],
|
|
185
|
+
outputs: ["isVisibleChange", "afterOpenedOrClosed"]
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
kind: "component",
|
|
189
|
+
type: BsContainerComponent,
|
|
190
|
+
selector: "bs-container"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
kind: "component",
|
|
194
|
+
type: BsSpinnerComponent,
|
|
195
|
+
selector: "bs-spinner",
|
|
196
|
+
inputs: ["type", "color"]
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
kind: "component",
|
|
200
|
+
type: SparkPoFormComponent,
|
|
201
|
+
selector: "spark-po-form",
|
|
202
|
+
inputs: [
|
|
203
|
+
"entityType",
|
|
204
|
+
"formData",
|
|
205
|
+
"validationErrors",
|
|
206
|
+
"showButtons",
|
|
207
|
+
"isSaving",
|
|
208
|
+
"parentId",
|
|
209
|
+
"parentType",
|
|
210
|
+
"objectTypeId",
|
|
211
|
+
"objectId",
|
|
212
|
+
"triggerPathPrefix",
|
|
213
|
+
"refreshOverlay"
|
|
214
|
+
],
|
|
215
|
+
outputs: [
|
|
216
|
+
"formDataChange",
|
|
217
|
+
"save",
|
|
218
|
+
"cancel",
|
|
219
|
+
"nestedTriggerRequested",
|
|
220
|
+
"nestedTriggerBlurred",
|
|
221
|
+
"refreshOverlayChange"
|
|
222
|
+
]
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
kind: "pipe",
|
|
226
|
+
type: ResolveTranslationPipe,
|
|
227
|
+
name: "resolveTranslation"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
kind: "pipe",
|
|
231
|
+
type: TranslateKeyPipe,
|
|
232
|
+
name: "t"
|
|
233
|
+
}
|
|
234
|
+
],
|
|
235
|
+
changeDetection: i0.ChangeDetectionStrategy.OnPush
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
239
|
+
minVersion: "12.0.0",
|
|
240
|
+
version: "22.2.0",
|
|
241
|
+
ngImport: i0,
|
|
242
|
+
type: SparkPoCreateComponent,
|
|
243
|
+
decorators: [{
|
|
244
|
+
type: Component,
|
|
245
|
+
args: [{
|
|
246
|
+
selector: "spark-po-create",
|
|
247
|
+
imports: [
|
|
248
|
+
CommonModule,
|
|
249
|
+
BsAlertComponent,
|
|
250
|
+
BsContainerComponent,
|
|
251
|
+
BsSpinnerComponent,
|
|
252
|
+
SparkPoFormComponent,
|
|
253
|
+
ResolveTranslationPipe,
|
|
254
|
+
TranslateKeyPipe
|
|
255
|
+
],
|
|
256
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
257
|
+
template: "<bs-container>\n<div class=\"container\">\n @if (entityType(); as et) {\n <h2 class=\"mb-4\">{{ 'common.create' | t }} {{ (et.description | resolveTranslation) || et.name }}</h2>\n\n @for (error of generalErrors(); track error.errorMessage) {\n <bs-alert [type]=\"colors.danger\" class=\"mb-3\">\n {{ error.errorMessage | resolveTranslation }}\n </bs-alert>\n }\n\n <spark-po-form\n [entityType]=\"et\"\n [(formData)]=\"formData\"\n [(refreshOverlay)]=\"refreshOverlay\"\n [objectTypeId]=\"type()\"\n [parentType]=\"type()\"\n [validationErrors]=\"validationErrors()\"\n [showButtons]=\"true\"\n [isSaving]=\"isSaving()\"\n (save)=\"onSave()\"\n (cancel)=\"onCancel()\">\n </spark-po-form>\n } @else {\n <div class=\"text-center p-5\">\n <bs-spinner />\n </div>\n }\n</div>\n</bs-container>\n"
|
|
258
|
+
}]
|
|
259
|
+
}],
|
|
260
|
+
ctorParameters: () => [],
|
|
261
|
+
propDecorators: {
|
|
262
|
+
saved: [{
|
|
263
|
+
type: i0.Output,
|
|
264
|
+
args: ["saved"]
|
|
265
|
+
}],
|
|
266
|
+
cancelled: [{
|
|
267
|
+
type: i0.Output,
|
|
268
|
+
args: ["cancelled"]
|
|
269
|
+
}]
|
|
270
|
+
}
|
|
271
|
+
});
|
|
169
272
|
export { SparkPoCreateComponent };
|
|
170
|
-
|
|
273
|
+
|
|
274
|
+
//# sourceMappingURL=mintplayer-ng-spark-po-create.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mintplayer-ng-spark-po-create.mjs","sources":["../../po-create/src/spark-po-create.component.ts","../../po-create/src/spark-po-create.component.html","../../po-create/mintplayer-ng-spark-po-create.ts"],"sourcesContent":["import { ChangeDetectionStrategy, Component, computed, inject, output, signal } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { CommonModule } from '@angular/common';\nimport { ActivatedRoute, Router } from '@angular/router';\nimport { HttpErrorResponse } from '@angular/common/http';\nimport { Color } from '@mintplayer/ng-bootstrap';\nimport { BsAlertComponent } from '@mintplayer/ng-bootstrap/alert';\nimport { BsContainerComponent } from '@mintplayer/ng-bootstrap/container';\nimport { BsSpinnerComponent } from '@mintplayer/ng-bootstrap/spinner';\nimport { SparkService } from '@mintplayer/ng-spark/services';\nimport { SparkPoFormComponent } from '@mintplayer/ng-spark/po-form';\nimport { TranslateKeyPipe, ResolveTranslationPipe } from '@mintplayer/ng-spark/pipes';\nimport {\n EntityType,\n PersistentObject,\n PersistentObjectAttribute,\n ValidationError,\n ShowedOn,\n hasShowedOnFlag,\n dictToNestedPo,\n EntityTypeResolver,\n isDateDataType,\n fromDateInputValue,\n RefreshOverlay,\n applyOverlay,\n} from '@mintplayer/ng-spark/models';\n\n@Component({\n selector: 'spark-po-create',\n imports: [CommonModule, BsAlertComponent, BsContainerComponent, BsSpinnerComponent, SparkPoFormComponent, ResolveTranslationPipe, TranslateKeyPipe],\n templateUrl: './spark-po-create.component.html',\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class SparkPoCreateComponent {\n private readonly route = inject(ActivatedRoute);\n private readonly router = inject(Router);\n private readonly sparkService = inject(SparkService);\n\n saved = output<PersistentObject>();\n cancelled = output<void>();\n\n colors = Color;\n entityType = signal<EntityType | null>(null);\n type = signal('');\n formData = signal<Record<string, any>>({});\n /** Bound two-way to the form. See {@link getEditableAttributes}. */\n refreshOverlay = signal<RefreshOverlay>({});\n validationErrors = signal<ValidationError[]>([]);\n isSaving = signal(false);\n private allEntityTypes = signal<EntityType[]>([]);\n generalErrors = computed(() => this.validationErrors().filter(e => !e.attributeName));\n\n constructor() {\n this.route.paramMap.pipe(takeUntilDestroyed()).subscribe(params => this.onParamsChange(params));\n }\n\n private async onParamsChange(params: any): Promise<void> {\n this.type.set(params.get('type') || '');\n const types = await this.sparkService.getEntityTypes();\n const entityType = types.find(t => t.id === this.type() || t.alias === this.type()) || null;\n this.entityType.set(entityType);\n this.allEntityTypes.set(types);\n this.initFormData();\n }\n\n initFormData(): void {\n const data: Record<string, any> = {};\n this.getEditableAttributes().forEach(attr => {\n if (attr.dataType === 'Reference') {\n data[attr.name] = null;\n } else if (attr.dataType === 'AsDetail') {\n data[attr.name] = attr.isArray ? [] : {};\n } else if (attr.dataType === 'boolean' && !attr.lookupReferenceType) {\n // Same reason as spark-po-edit: a lookup-backed boolean's third state is the absence of a\n // value, and seeding `false` here would make every new object explicitly opted out.\n data[attr.name] = false;\n } else {\n data[attr.name] = '';\n }\n });\n this.formData.set(data);\n }\n\n /**\n * ⚠️ Overlaid before filtering — same reason as <c>spark-po-edit</c>, and worse here: this list is\n * the <em>only</em> source of the create payload, so an attribute a refresh hook revealed was not\n * merely sent stale, it was absent from the new object entirely.\n */\n getEditableAttributes() {\n const overlay = this.refreshOverlay();\n return this.entityType()?.attributes\n .map(a => applyOverlay(a, overlay[a.name]))\n .filter(a => a.isVisible && !a.isReadOnly && hasShowedOnFlag(a.showedOn, ShowedOn.PersistentObject))\n .sort((a, b) => a.order - b.order) || [];\n }\n\n async onSave(): Promise<void> {\n if (!this.entityType()) return;\n\n this.validationErrors.set([]);\n this.isSaving.set(true);\n\n const resolver: EntityTypeResolver = (clrName) => this.allEntityTypes().find(t => t.clrType === clrName);\n const attributes: PersistentObjectAttribute[] = this.getEditableAttributes().map(attr => {\n const base: PersistentObjectAttribute = {\n id: attr.id,\n name: attr.name,\n // A date control hands back a bare local wall clock; the wire needs a complete ISO-8601\n // instant carrying the viewer's offset for the entered date.\n value: isDateDataType(attr.dataType)\n ? fromDateInputValue(attr.dataType, this.formData()[attr.name])\n : this.formData()[attr.name],\n dataType: attr.dataType,\n isArray: attr.isArray,\n isRequired: attr.isRequired,\n isVisible: attr.isVisible,\n isReadOnly: attr.isReadOnly,\n isValueChanged: true,\n order: attr.order,\n rules: attr.rules,\n };\n\n // AsDetail: pack the flat form dict into nested PO wire shape. Server's polymorphic\n // converter ignores attr.value for AsDetail and reads attr.object / attr.objects.\n if (attr.dataType === 'AsDetail' && attr.asDetailType) {\n const nestedType = resolver(attr.asDetailType);\n if (nestedType) {\n const raw = this.formData()[attr.name];\n base.value = null;\n base.asDetailType = attr.asDetailType;\n if (attr.isArray) {\n const items: any[] = Array.isArray(raw) ? raw : [];\n base.objects = items.map(item => dictToNestedPo((item ?? {}) as Record<string, any>, nestedType, resolver));\n base.object = null;\n } else {\n base.object = raw ? dictToNestedPo(raw as Record<string, any>, nestedType, resolver) : null;\n base.objects = null;\n }\n }\n }\n return base;\n });\n\n const po: Partial<PersistentObject> = {\n name: this.formData()['Name'] || 'New Item',\n objectTypeId: this.entityType()!.id,\n attributes\n };\n\n try {\n const result = await this.sparkService.create(this.type(), po);\n this.isSaving.set(false);\n this.saved.emit(result);\n this.router.navigate(['/po', this.type(), result.id]);\n } catch (e) {\n this.isSaving.set(false);\n const error = e as HttpErrorResponse;\n if (error.status === 400 && error.error?.errors) {\n this.validationErrors.set(error.error.errors);\n } else {\n this.validationErrors.set([{\n attributeName: '',\n errorMessage: { en: error.message || 'An unexpected error occurred' },\n ruleType: 'error'\n }]);\n }\n }\n }\n\n onCancel(): void {\n this.cancelled.emit();\n window.history.back();\n }\n}\n","<bs-container>\n<div class=\"container\">\n @if (entityType(); as et) {\n <h2 class=\"mb-4\">{{ 'common.create' | t }} {{ (et.description | resolveTranslation) || et.name }}</h2>\n\n @for (error of generalErrors(); track error.errorMessage) {\n <bs-alert [type]=\"colors.danger\" class=\"mb-3\">\n {{ error.errorMessage | resolveTranslation }}\n </bs-alert>\n }\n\n <spark-po-form\n [entityType]=\"et\"\n [(formData)]=\"formData\"\n [(refreshOverlay)]=\"refreshOverlay\"\n [objectTypeId]=\"type()\"\n [parentType]=\"type()\"\n [validationErrors]=\"validationErrors()\"\n [showButtons]=\"true\"\n [isSaving]=\"isSaving()\"\n (save)=\"onSave()\"\n (cancel)=\"onCancel()\">\n </spark-po-form>\n } @else {\n <div class=\"text-center p-5\">\n <bs-spinner />\n </div>\n }\n</div>\n</bs-container>\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;;MAiCa,sBAAsB,CAAA;AAChB,IAAA,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC;AAC9B,IAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AACvB,IAAA,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;IAEpD,KAAK,GAAG,MAAM,EAAoB;IAClC,SAAS,GAAG,MAAM,EAAQ;IAE1B,MAAM,GAAG,KAAK;IACd,UAAU,GAAG,MAAM,CAAo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BAAA,CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAE,oBAAoB,EAAA,QAAA,EAAA,cAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAE,kBAAkB,EAAA,QAAA,EAAA,YAAA,EAAA,MAAA,EAAA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAE,oBAAoB,EAAA,QAAA,EAAA,eAAA,EAAA,MAAA,EAAA,CAAA,YAAA,EAAA,UAAA,EAAA,kBAAA,EAAA,aAAA,EAAA,UAAA,EAAA,UAAA,EAAA,YAAA,EAAA,cAAA,EAAA,UAAA,EAAA,mBAAA,EAAA,gBAAA,CAAA,EAAA,OAAA,EAAA,CAAA,gBAAA,EAAA,MAAA,EAAA,QAAA,EAAA,wBAAA,EAAA,sBAAA,EAAA,sBAAA,CAAA,EAAA,EAAA,EAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAAE,sBAAsB,sDAAE,gBAAgB,EAAA,IAAA,EAAA,GAAA,EAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,CAAA;;2FAIvI,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBANlC,SAAS;AACE,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,iBAAiB,WAClB,CAAC,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,gBAAgB,CAAC,EAAA,eAAA,EAElI,uBAAuB,CAAC,MAAM,EAAA,QAAA,EAAA,03BAAA,EAAA;;;AE/BjD;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"mintplayer-ng-spark-po-create.mjs","names":[],"sources":["../../po-create/src/spark-po-create.component.ts","../../po-create/src/spark-po-create.component.html"],"sourcesContent":["import { ChangeDetectionStrategy, Component, computed, inject, output, signal } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { CommonModule } from '@angular/common';\nimport { ActivatedRoute, Router } from '@angular/router';\nimport { HttpErrorResponse } from '@angular/common/http';\nimport { Color } from '@mintplayer/ng-bootstrap';\nimport { BsAlertComponent } from '@mintplayer/ng-bootstrap/alert';\nimport { BsContainerComponent } from '@mintplayer/ng-bootstrap/container';\nimport { BsSpinnerComponent } from '@mintplayer/ng-bootstrap/spinner';\nimport { SparkService } from '@mintplayer/ng-spark/services';\nimport { SparkPoFormComponent } from '@mintplayer/ng-spark/po-form';\nimport { TranslateKeyPipe, ResolveTranslationPipe } from '@mintplayer/ng-spark/pipes';\nimport {\n EntityType,\n PersistentObject,\n PersistentObjectAttribute,\n ValidationError,\n ShowedOn,\n hasShowedOnFlag,\n dictToNestedPo,\n EntityTypeResolver,\n isDateDataType,\n fromDateInputValue,\n toDateInputValue,\n RefreshOverlay,\n applyOverlay,\n} from '@mintplayer/ng-spark/models';\n\n@Component({\n selector: 'spark-po-create',\n imports: [CommonModule, BsAlertComponent, BsContainerComponent, BsSpinnerComponent, SparkPoFormComponent, ResolveTranslationPipe, TranslateKeyPipe],\n templateUrl: './spark-po-create.component.html',\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class SparkPoCreateComponent {\n private readonly route = inject(ActivatedRoute);\n private readonly router = inject(Router);\n private readonly sparkService = inject(SparkService);\n\n saved = output<PersistentObject>();\n cancelled = output<void>();\n\n colors = Color;\n entityType = signal<EntityType | null>(null);\n type = signal('');\n formData = signal<Record<string, any>>({});\n /** Bound two-way to the form. See {@link getEditableAttributes}. */\n refreshOverlay = signal<RefreshOverlay>({});\n validationErrors = signal<ValidationError[]>([]);\n isSaving = signal(false);\n private allEntityTypes = signal<EntityType[]>([]);\n generalErrors = computed(() => this.validationErrors().filter(e => !e.attributeName));\n\n constructor() {\n this.route.paramMap.pipe(takeUntilDestroyed()).subscribe(params => this.onParamsChange(params));\n }\n\n private async onParamsChange(params: any): Promise<void> {\n this.type.set(params.get('type') || '');\n const types = await this.sparkService.getEntityTypes();\n const entityType = types.find(t => t.id === this.type() || t.alias === this.type()) || null;\n this.allEntityTypes.set(types);\n this.initFormData(entityType);\n if (entityType) await this.applyServerDefaults(entityType);\n this.entityType.set(entityType);\n }\n\n /**\n * The blank object comes from the server (#460, D19): `/po/new` runs the type's `OnNewAsync`, so a\n * default a hook sets — and, for a New started from a sub-query, the reference to the parent the\n * base hook fills — reaches the form. The sub-query card passes the parent as query parameters\n * (`parentId`, `parentType`, `queryId`), so it survives the navigation and a reload of this page.\n *\n * A refusal (the parent is gone, or not the caller's to see) is shown and the client-side blank\n * form stays usable, exactly as it was before the round-trip existed.\n */\n private async applyServerDefaults(entityType: EntityType): Promise<void> {\n const query = this.route.snapshot.queryParamMap;\n const parentId = query.get('parentId') ?? undefined;\n const parentType = query.get('parentType') ?? undefined;\n const queryId = query.get('queryId') ?? undefined;\n const fromSubQuery = !!(parentId && parentType && queryId);\n\n try {\n const po = await this.sparkService.newObject(this.type(), fromSubQuery ? { parentId, parentType, queryId } : undefined);\n const editable = new Map(this.getEditableAttributes(entityType).map(a => [a.name, a] as const));\n const data = { ...this.formData() };\n for (const attr of po?.attributes ?? []) {\n const definition = editable.get(attr.name);\n if (!definition || attr.value === null || attr.value === undefined || definition.dataType === 'AsDetail') continue;\n data[attr.name] = isDateDataType(definition.dataType)\n ? toDateInputValue(definition.dataType, attr.value)\n : attr.value;\n }\n this.formData.set(data);\n } catch (e) {\n const error = e as HttpErrorResponse;\n const errors = error.error?.result?.errors ?? error.error?.errors;\n this.validationErrors.set(errors ?? [{\n attributeName: '',\n errorMessage: { en: error.message || 'The new item could not be prepared.' },\n ruleType: 'error'\n }]);\n }\n }\n\n initFormData(entityType: EntityType | null = this.entityType()): void {\n const data: Record<string, any> = {};\n this.getEditableAttributes(entityType).forEach(attr => {\n if (attr.dataType === 'Reference') {\n data[attr.name] = null;\n } else if (attr.dataType === 'AsDetail') {\n data[attr.name] = attr.isArray ? [] : {};\n } else if (attr.dataType === 'boolean' && !attr.lookupReferenceType) {\n // Same reason as spark-po-edit: a lookup-backed boolean's third state is the absence of a\n // value, and seeding `false` here would make every new object explicitly opted out.\n data[attr.name] = false;\n } else {\n data[attr.name] = '';\n }\n });\n this.formData.set(data);\n }\n\n /**\n * ⚠️ Overlaid before filtering — same reason as <c>spark-po-edit</c>, and worse here: this list is\n * the <em>only</em> source of the create payload, so an attribute a refresh hook revealed was not\n * merely sent stale, it was absent from the new object entirely.\n */\n getEditableAttributes(entityType: EntityType | null = this.entityType()) {\n const overlay = this.refreshOverlay();\n return entityType?.attributes\n .map(a => applyOverlay(a, overlay[a.name]))\n .filter(a => a.isVisible && !a.isReadOnly && hasShowedOnFlag(a.showedOn, ShowedOn.PersistentObject))\n .sort((a, b) => a.order - b.order) || [];\n }\n\n async onSave(): Promise<void> {\n if (!this.entityType()) return;\n\n this.validationErrors.set([]);\n this.isSaving.set(true);\n\n const resolver: EntityTypeResolver = (clrName) => this.allEntityTypes().find(t => t.clrType === clrName);\n const attributes: PersistentObjectAttribute[] = this.getEditableAttributes().map(attr => {\n const base: PersistentObjectAttribute = {\n id: attr.id,\n name: attr.name,\n // A date control hands back a bare local wall clock; the wire needs a complete ISO-8601\n // instant carrying the viewer's offset for the entered date.\n value: isDateDataType(attr.dataType)\n ? fromDateInputValue(attr.dataType, this.formData()[attr.name])\n : this.formData()[attr.name],\n dataType: attr.dataType,\n isArray: attr.isArray,\n isRequired: attr.isRequired,\n isVisible: attr.isVisible,\n isReadOnly: attr.isReadOnly,\n isValueChanged: true,\n order: attr.order,\n rules: attr.rules,\n };\n\n // AsDetail: pack the flat form dict into nested PO wire shape. Server's polymorphic\n // converter ignores attr.value for AsDetail and reads attr.object / attr.objects.\n if (attr.dataType === 'AsDetail' && attr.asDetailType) {\n const nestedType = resolver(attr.asDetailType);\n if (nestedType) {\n const raw = this.formData()[attr.name];\n base.value = null;\n base.asDetailType = attr.asDetailType;\n if (attr.isArray) {\n const items: any[] = Array.isArray(raw) ? raw : [];\n base.objects = items.map(item => dictToNestedPo((item ?? {}) as Record<string, any>, nestedType, resolver));\n base.object = null;\n } else {\n base.object = raw ? dictToNestedPo(raw as Record<string, any>, nestedType, resolver) : null;\n base.objects = null;\n }\n }\n }\n return base;\n });\n\n const po: Partial<PersistentObject> = {\n name: this.formData()['Name'] || 'New Item',\n objectTypeId: this.entityType()!.id,\n attributes\n };\n\n try {\n const result = await this.sparkService.create(this.type(), po);\n this.isSaving.set(false);\n this.saved.emit(result);\n this.router.navigate(['/po', this.type(), result.id]);\n } catch (e) {\n this.isSaving.set(false);\n const error = e as HttpErrorResponse;\n // The errors live under `result` (every endpoint wraps its body in a ClientOperationEnvelope:\n // `{ result: { errors: [...] }, operations: [] }`), as in po-edit. Reading only\n // `error.error.errors` showed every create-time refusal as the raw Angular HTTP string.\n const errors = error.error?.result?.errors ?? error.error?.errors;\n if (error.status === 400 && errors) {\n this.validationErrors.set(errors);\n } else {\n this.validationErrors.set([{\n attributeName: '',\n errorMessage: { en: error.message || 'An unexpected error occurred' },\n ruleType: 'error'\n }]);\n }\n }\n }\n\n onCancel(): void {\n this.cancelled.emit();\n window.history.back();\n }\n}\n","<bs-container>\n<div class=\"container\">\n @if (entityType(); as et) {\n <h2 class=\"mb-4\">{{ 'common.create' | t }} {{ (et.description | resolveTranslation) || et.name }}</h2>\n\n @for (error of generalErrors(); track error.errorMessage) {\n <bs-alert [type]=\"colors.danger\" class=\"mb-3\">\n {{ error.errorMessage | resolveTranslation }}\n </bs-alert>\n }\n\n <spark-po-form\n [entityType]=\"et\"\n [(formData)]=\"formData\"\n [(refreshOverlay)]=\"refreshOverlay\"\n [objectTypeId]=\"type()\"\n [parentType]=\"type()\"\n [validationErrors]=\"validationErrors()\"\n [showButtons]=\"true\"\n [isSaving]=\"isSaving()\"\n (save)=\"onSave()\"\n (cancel)=\"onCancel()\">\n </spark-po-form>\n } @else {\n <div class=\"text-center p-5\">\n <bs-spinner />\n </div>\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