@valtimo/form-management 4.15.2-next-main.8

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.
Files changed (29) hide show
  1. package/README.md +24 -0
  2. package/bundles/valtimo-form-management.umd.js +954 -0
  3. package/bundles/valtimo-form-management.umd.js.map +1 -0
  4. package/bundles/valtimo-form-management.umd.min.js +2 -0
  5. package/bundles/valtimo-form-management.umd.min.js.map +1 -0
  6. package/esm2015/lib/form-management-create/form-management-create.component.js +82 -0
  7. package/esm2015/lib/form-management-edit/form-management-edit.component.js +147 -0
  8. package/esm2015/lib/form-management-list/form-management-list.component.js +73 -0
  9. package/esm2015/lib/form-management-routing.module.js +58 -0
  10. package/esm2015/lib/form-management-upload/form-management-upload.component.js +150 -0
  11. package/esm2015/lib/form-management.component.js +31 -0
  12. package/esm2015/lib/form-management.module.js +55 -0
  13. package/esm2015/lib/form-management.service.js +54 -0
  14. package/esm2015/public-api.js +22 -0
  15. package/esm2015/valtimo-form-management.js +10 -0
  16. package/fesm2015/valtimo-form-management.js +638 -0
  17. package/fesm2015/valtimo-form-management.js.map +1 -0
  18. package/lib/form-management-create/form-management-create.component.d.ts +20 -0
  19. package/lib/form-management-edit/form-management-edit.component.d.ts +31 -0
  20. package/lib/form-management-list/form-management-list.component.d.ts +24 -0
  21. package/lib/form-management-routing.module.d.ts +2 -0
  22. package/lib/form-management-upload/form-management-upload.component.d.ts +37 -0
  23. package/lib/form-management.component.d.ts +5 -0
  24. package/lib/form-management.module.d.ts +2 -0
  25. package/lib/form-management.service.d.ts +15 -0
  26. package/package.json +19 -0
  27. package/public-api.d.ts +3 -0
  28. package/valtimo-form-management.d.ts +9 -0
  29. package/valtimo-form-management.metadata.json +1 -0
@@ -0,0 +1,638 @@
1
+ import { ɵɵdefineInjectable, ɵɵinject, Injectable, Component, ViewEncapsulation, NgModule, EventEmitter, ViewChild, Input, Output } from '@angular/core';
2
+ import { HttpClient } from '@angular/common/http';
3
+ import { ConfigService } from '@valtimo/config';
4
+ import { Router, ActivatedRoute, RouterModule } from '@angular/router';
5
+ import { AuthGuardService } from '@valtimo/security';
6
+ import { FormControl, Validators, FormBuilder, ReactiveFormsModule, FormsModule } from '@angular/forms';
7
+ import { AlertService, FormIoModule, WidgetModule, ListModule, DropzoneModule, ModalModule } from '@valtimo/components';
8
+ import { combineLatest, BehaviorSubject, Subscription, Subject } from 'rxjs';
9
+ import { take, first } from 'rxjs/operators';
10
+ import { ROLE_ADMIN } from '@valtimo/contract';
11
+ import { CommonModule } from '@angular/common';
12
+ import { TranslateService, TranslateModule } from '@ngx-translate/core';
13
+ import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
14
+ import { DocumentService } from '@valtimo/document';
15
+
16
+ /*
17
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
18
+ *
19
+ * Licensed under EUPL, Version 1.2 (the "License");
20
+ * you may not use this file except in compliance with the License.
21
+ * You may obtain a copy of the License at
22
+ *
23
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" basis,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ class FormManagementService {
32
+ constructor(http, configService) {
33
+ this.http = http;
34
+ this.configService = configService;
35
+ this.valtimoApiConfig = configService.config.valtimoApi;
36
+ }
37
+ getFormDefinition(formDefinitionId) {
38
+ return this.http.get(`${this.valtimoApiConfig.endpointUri}form-management/${formDefinitionId}`);
39
+ }
40
+ queryFormDefinitions(params) {
41
+ return this.http.get(`${this.valtimoApiConfig.endpointUri}form-management`, { observe: 'response', params: params });
42
+ }
43
+ createFormDefinition(request) {
44
+ return this.http.post(`${this.valtimoApiConfig.endpointUri}form-management`, request);
45
+ }
46
+ modifyFormDefinition(request) {
47
+ return this.http.put(`${this.valtimoApiConfig.endpointUri}form-management`, request);
48
+ }
49
+ deleteFormDefinition(formDefinitionId) {
50
+ return this.http.delete(`${this.valtimoApiConfig.endpointUri}form-management/${formDefinitionId}`);
51
+ }
52
+ }
53
+ FormManagementService.ɵprov = ɵɵdefineInjectable({ factory: function FormManagementService_Factory() { return new FormManagementService(ɵɵinject(HttpClient), ɵɵinject(ConfigService)); }, token: FormManagementService, providedIn: "root" });
54
+ FormManagementService.decorators = [
55
+ { type: Injectable, args: [{
56
+ providedIn: 'root'
57
+ },] }
58
+ ];
59
+ FormManagementService.ctorParameters = () => [
60
+ { type: HttpClient },
61
+ { type: ConfigService }
62
+ ];
63
+
64
+ /*
65
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
66
+ *
67
+ * Licensed under EUPL, Version 1.2 (the "License");
68
+ * you may not use this file except in compliance with the License.
69
+ * You may obtain a copy of the License at
70
+ *
71
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
72
+ *
73
+ * Unless required by applicable law or agreed to in writing, software
74
+ * distributed under the License is distributed on an "AS IS" basis,
75
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76
+ * See the License for the specific language governing permissions and
77
+ * limitations under the License.
78
+ */
79
+ class FormManagementComponent {
80
+ constructor() {
81
+ }
82
+ ngOnInit() {
83
+ }
84
+ }
85
+ FormManagementComponent.decorators = [
86
+ { type: Component, args: [{
87
+ selector: 'valtimo-form-management',
88
+ template: "<!--\n ~ Copyright 2015-2020 Ritense BV, the Netherlands.\n ~\n ~ Licensed under EUPL, Version 1.2 (the \"License\");\n ~ you may not use this file except in compliance with the License.\n ~ You may obtain a copy of the License at\n ~\n ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n ~\n ~ Unless required by applicable law or agreed to in writing, software\n ~ distributed under the License is distributed on an \"AS IS\" basis,\n ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n ~ See the License for the specific language governing permissions and\n ~ limitations under the License.\n -->\n\n<div class=\"main-content pt-0\">\n <div class=\"container-fluid\">\n <div class=\"text-right\">\n <div class=\"btn-group mt-m3px mb-3\">\n <button [routerLink]=\"'create'\" [queryParams]=\"{'upload': 'true'}\" class=\"btn btn-secondary btn-space\">\n <i class=\"icon mdi mdi-upload\"></i>&nbsp;\n {{ 'Upload' | translate }}\n </button>\n <button [routerLink]=\"'create'\" class=\"btn btn-primary btn-space mr-0\">\n <i class=\"icon mdi mdi-plus\"></i> &nbsp;\n <span>{{ 'Create new Form' | translate }}</span>\n </button>\n </div>\n </div>\n <valtimo-widget>\n <valtimo-form-management-list></valtimo-form-management-list>\n </valtimo-widget>\n </div>\n</div>\n",
89
+ styles: ["/*!\n * Copyright 2015-2020 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */"]
90
+ },] }
91
+ ];
92
+ FormManagementComponent.ctorParameters = () => [];
93
+
94
+ /*
95
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
96
+ *
97
+ * Licensed under EUPL, Version 1.2 (the "License");
98
+ * you may not use this file except in compliance with the License.
99
+ * You may obtain a copy of the License at
100
+ *
101
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
102
+ *
103
+ * Unless required by applicable law or agreed to in writing, software
104
+ * distributed under the License is distributed on an "AS IS" basis,
105
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
106
+ * See the License for the specific language governing permissions and
107
+ * limitations under the License.
108
+ */
109
+ class FormManagementCreateComponent {
110
+ constructor(formManagementService, formBuilder, router, alertService, route) {
111
+ this.formManagementService = formManagementService;
112
+ this.formBuilder = formBuilder;
113
+ this.router = router;
114
+ this.alertService = alertService;
115
+ this.route = route;
116
+ }
117
+ get formControls() {
118
+ return this.form.controls;
119
+ }
120
+ ngOnInit() {
121
+ this.form = this.formBuilder.group({
122
+ name: new FormControl('', Validators.required)
123
+ });
124
+ }
125
+ reset() {
126
+ this.form.setValue({
127
+ name: ''
128
+ });
129
+ }
130
+ createFormDefinition() {
131
+ const emptyForm = {
132
+ display: 'form',
133
+ components: []
134
+ };
135
+ const request = {
136
+ name: this.form.value.name,
137
+ formDefinition: JSON.stringify(emptyForm)
138
+ };
139
+ combineLatest([this.formManagementService.createFormDefinition(request), this.route.queryParams])
140
+ .pipe(take(1))
141
+ .subscribe(([formDefinition, params]) => {
142
+ this.alertService.success('Created new Form');
143
+ if ((params === null || params === void 0 ? void 0 : params.upload) === 'true') {
144
+ this.router.navigate(['/form-management/edit', formDefinition.id], { queryParams: { upload: 'true' } });
145
+ }
146
+ else {
147
+ this.router.navigate(['/form-management/edit', formDefinition.id]);
148
+ }
149
+ }, err => {
150
+ this.alertService.error('Error creating new Form');
151
+ });
152
+ }
153
+ }
154
+ FormManagementCreateComponent.decorators = [
155
+ { type: Component, args: [{
156
+ selector: 'valtimo-form-management-create',
157
+ template: "<!--\n ~ Copyright 2015-2020 Ritense BV, the Netherlands.\n ~\n ~ Licensed under EUPL, Version 1.2 (the \"License\");\n ~ you may not use this file except in compliance with the License.\n ~ You may obtain a copy of the License at\n ~\n ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n ~\n ~ Unless required by applicable law or agreed to in writing, software\n ~ distributed under the License is distributed on an \"AS IS\" basis,\n ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n ~ See the License for the specific language governing permissions and\n ~ limitations under the License.\n -->\n\n<div class=\"main-content\">\n <div class=\"container-fluid\">\n <div class=\"col-12 px-0 mb-5\">\n <valtimo-widget>\n <div class=\"bg-white p-5\">\n <form [formGroup]=\"form\" (ngSubmit)=\"createFormDefinition()\">\n <div class=\"form-group row\">\n <label class=\"col-12 col-sm-3 col-form-label text-sm-right\" for=\"name\">Name</label>\n <div class=\"col-12 col-sm-8 col-lg-6\">\n <input type=\"text\" id=\"name\" formControlName=\"name\"\n class=\"form-control\" placeholder=\"Form definition name\"\n [ngClass]=\"{'is-valid': formControls.name.touched && formControls.name.valid, 'is-invalid': formControls.name.touched && formControls.name.errors}\"\n required/>\n <div *ngIf=\"formControls.name.touched && formControls.name.errors\"\n class=\"invalid-feedback\">\n <div *ngIf=\"formControls.name.errors.required\">Name is required</div>\n </div>\n </div>\n </div>\n <div class=\"row pt-3 mt-1\">\n <div class=\"col-12 col-sm-6 text-left\">\n <a [routerLink]=\"'/forms'\" class=\"btn btn-space btn-default\">Back</a>\n </div>\n <div class=\"col-12 col-sm-6 text-right\">\n <button class=\"btn btn-space btn-secondary\" type=\"button\" (click)=\"reset()\">Reset\n </button>\n <button class=\"btn btn-space btn-primary\" type=\"submit\" [disabled]=\"form.invalid\">\n Submit\n </button>\n </div>\n </div>\n </form>\n </div>\n </valtimo-widget>\n </div>\n </div>\n</div>\n",
158
+ styles: ["/*!\n * Copyright 2015-2020 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */"]
159
+ },] }
160
+ ];
161
+ FormManagementCreateComponent.ctorParameters = () => [
162
+ { type: FormManagementService },
163
+ { type: FormBuilder },
164
+ { type: Router },
165
+ { type: AlertService },
166
+ { type: ActivatedRoute }
167
+ ];
168
+
169
+ /*
170
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
171
+ *
172
+ * Licensed under EUPL, Version 1.2 (the "License");
173
+ * you may not use this file except in compliance with the License.
174
+ * You may obtain a copy of the License at
175
+ *
176
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
177
+ *
178
+ * Unless required by applicable law or agreed to in writing, software
179
+ * distributed under the License is distributed on an "AS IS" basis,
180
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
181
+ * See the License for the specific language governing permissions and
182
+ * limitations under the License.
183
+ */
184
+ class FormManagementEditComponent {
185
+ constructor(formManagementService, alertService, route, router) {
186
+ this.formManagementService = formManagementService;
187
+ this.alertService = alertService;
188
+ this.route = route;
189
+ this.router = router;
190
+ this.showModal$ = new BehaviorSubject(false);
191
+ this.reloading$ = new BehaviorSubject(false);
192
+ this.modifiedFormDefinition = null;
193
+ this.formDefinition = null;
194
+ this.alertSub = Subscription.EMPTY;
195
+ this.formDefinitionId = null;
196
+ }
197
+ ngOnInit() {
198
+ this.loadFormDefinition();
199
+ this.checkToOpenUploadModal();
200
+ }
201
+ ngOnDestroy() {
202
+ this.alertSub.unsubscribe();
203
+ }
204
+ loadFormDefinition() {
205
+ this.formDefinitionId = this.route.snapshot.paramMap.get('id');
206
+ this.formManagementService.getFormDefinition(this.formDefinitionId).subscribe(formDefinition => {
207
+ this.formDefinition = formDefinition;
208
+ }, () => {
209
+ this.alertService.error('Error retrieving Form Definition');
210
+ });
211
+ }
212
+ modifyFormDefinition() {
213
+ const form = JSON.stringify(this.modifiedFormDefinition != null ? this.modifiedFormDefinition : this.formDefinition.formDefinition);
214
+ const request = {
215
+ id: this.formDefinition.id,
216
+ name: this.formDefinition.name,
217
+ formDefinition: form
218
+ };
219
+ this.formManagementService.modifyFormDefinition(request).subscribe(() => {
220
+ this.router.navigate(['/form-management']);
221
+ this.alertService.success('Form deployed');
222
+ }, err => {
223
+ this.alertService.error('Error deploying Form');
224
+ });
225
+ }
226
+ formBuilderChanged(event) {
227
+ this.modifiedFormDefinition = event.form;
228
+ }
229
+ delete() {
230
+ if (!this.alertSub.closed) {
231
+ return;
232
+ }
233
+ const mssg = 'Delete Form?';
234
+ const confirmations = [
235
+ {
236
+ label: 'Cancel',
237
+ class: 'btn btn-default',
238
+ value: false
239
+ },
240
+ {
241
+ label: 'Delete',
242
+ class: 'btn btn-primary',
243
+ value: true
244
+ }
245
+ ];
246
+ this.alertService.notification(mssg, confirmations);
247
+ this.alertSub = this.alertService.getAlertConfirmChangeEmitter()
248
+ .pipe(first())
249
+ .subscribe(alert => {
250
+ if (alert.confirm === true) {
251
+ this.deleteFormDefinition();
252
+ }
253
+ });
254
+ }
255
+ deleteFormDefinition() {
256
+ this.formManagementService.deleteFormDefinition(this.formDefinition.id).subscribe(() => {
257
+ this.router.navigate(['/form-management']);
258
+ this.alertService.success('Form deleted');
259
+ }, err => {
260
+ this.alertService.error('Error deleting Form');
261
+ });
262
+ }
263
+ downloadFormDefinition() {
264
+ const file = new Blob([JSON.stringify(this.formDefinition)], { type: 'text/json' });
265
+ const link = document.createElement('a');
266
+ link.download = `form_${this.formDefinition.name}.json`;
267
+ link.href = window.URL.createObjectURL(file);
268
+ link.click();
269
+ window.URL.revokeObjectURL(link.href);
270
+ link.remove();
271
+ }
272
+ showModal() {
273
+ this.showModal$.next(true);
274
+ }
275
+ setFormDefinition(formDefinition) {
276
+ var _a;
277
+ this.reloading$.next(true);
278
+ const definition = JSON.parse(formDefinition);
279
+ const components = (_a = definition === null || definition === void 0 ? void 0 : definition.formDefinition) === null || _a === void 0 ? void 0 : _a.components;
280
+ const currentDefinition = this.modifiedFormDefinition || this.formDefinition.formDefinition;
281
+ const newDefinition = Object.assign(Object.assign({}, currentDefinition), (components && { components }));
282
+ this.modifiedFormDefinition = newDefinition;
283
+ this.formDefinition.formDefinition = newDefinition;
284
+ this.reloading$.next(false);
285
+ }
286
+ checkToOpenUploadModal() {
287
+ this.route.queryParams.pipe(take(1))
288
+ .subscribe((params) => {
289
+ if ((params === null || params === void 0 ? void 0 : params.upload) === 'true') {
290
+ this.showModal();
291
+ }
292
+ });
293
+ }
294
+ }
295
+ FormManagementEditComponent.decorators = [
296
+ { type: Component, args: [{
297
+ selector: 'valtimo-form-management-edit',
298
+ template: "<!--\n ~ Copyright 2015-2020 Ritense BV, the Netherlands.\n ~\n ~ Licensed under EUPL, Version 1.2 (the \"License\");\n ~ you may not use this file except in compliance with the License.\n ~ You may obtain a copy of the License at\n ~\n ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n ~\n ~ Unless required by applicable law or agreed to in writing, software\n ~ distributed under the License is distributed on an \"AS IS\" basis,\n ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n ~ See the License for the specific language governing permissions and\n ~ limitations under the License.\n -->\n\n<div class=\"main-content pt-0\">\n <div class=\"container-fluid\" *ngIf=\"formDefinition\">\n <div class=\"btn-group mt-m3px mb-3 float-right\">\n <button class='btn btn-primary btn-space' (click)=\"downloadFormDefinition()\">\n <i class=\"fa fa-save\"></i>\n {{ 'Download' | translate }}\n </button>\n <button class=\"btn btn-secondary btn-space\" (click)=\"showModal()\" [disabled]=\"formDefinition.readOnly\">\n <i class=\"icon mdi mdi-upload\"></i>&nbsp;\n {{ 'Upload' | translate }}\n </button>\n <button class='btn btn-danger btn-space' (click)=\"delete()\" [disabled]=\"formDefinition.readOnly\">\n <i class=\"fa fa-trash\"></i>&nbsp;Delete\n </button>\n <button class='btn btn-success btn-space' (click)=\"modifyFormDefinition()\" [disabled]=\"formDefinition.readOnly\">\n <i class=\"fa fa-upload\"></i>&nbsp;Deploy\n </button>\n </div>\n <div class=\"clearfix\"></div>\n <div class=\"bg-light formbuilder-header overflow-auto\">\n <h3 class=\"formbuilder-title\">{{formDefinition.name}}\n <div *ngIf=\"formDefinition.readOnly\" class=\"pull-right\">\n <span class=\"badge badge-pill badge-info increase-size\">Read-only</span>\n </div>\n </h3>\n </div>\n <ng-container *ngIf=\"!(reloading$ | async)\">\n <valtimo-form-io-builder [form]=\"formDefinition.formDefinition\" (change)=\"formBuilderChanged($event)\"></valtimo-form-io-builder>\n </ng-container>\n </div>\n</div>\n\n<valtimo-form-management-upload\n [show$]=\"showModal$\"\n (definitionUploaded)=\"setFormDefinition($event)\"\n></valtimo-form-management-upload>\n",
299
+ encapsulation: ViewEncapsulation.None,
300
+ styles: ["/*!\n * Copyright 2015-2020 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */.btn.formcomponent.gu-mirror,.formbuilder .btn.formcomponent.drag-copy{background-color:silver;border-color:silver;color:#fff;font-weight:400}.btn.formcomponent.gu-mirror:active,.btn.formcomponent.gu-mirror:hover,.formbuilder .btn.formcomponent.drag-copy:active,.formbuilder .btn.formcomponent.drag-copy:hover{box-shadow:none}.btn.formcomponent.gu-mirror:active,.formbuilder .btn.formcomponent.drag-copy:active{background-color:silver;border-color:silver}.formbuilder-header{border:1px solid #dee2e6;border-bottom:0;font-size:18px;height:80px;padding-left:18px;padding-right:18px}.formbuilder-header .formbuilder-title{margin-bottom:7px;margin-top:21px}.formbuilder-header .formbuilder-subtitle{margin-bottom:12px;margin-top:0}.formbuilder{background:#fff;border:1px solid #dee2e6;margin-left:0!important;margin-right:0!important;padding:1rem}.formbuilder .form-builder-panel .builder-group-button[aria-expanded=\"\"],.formbuilder .form-builder-panel .builder-group-button[aria-expanded=false]{color:#a9a9a9}.formbuilder .form-builder-panel .builder-group-button[aria-expanded=true]{color:#000}.formbuilder .drag-and-drop-alert{display:none}.formbuilder .formarea{background-color:#fff;border:1px solid silver;padding:10px}.increase-size{font-size:1rem}"]
301
+ },] }
302
+ ];
303
+ FormManagementEditComponent.ctorParameters = () => [
304
+ { type: FormManagementService },
305
+ { type: AlertService },
306
+ { type: ActivatedRoute },
307
+ { type: Router }
308
+ ];
309
+
310
+ /*
311
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
312
+ *
313
+ * Licensed under EUPL, Version 1.2 (the "License");
314
+ * you may not use this file except in compliance with the License.
315
+ * You may obtain a copy of the License at
316
+ *
317
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
318
+ *
319
+ * Unless required by applicable law or agreed to in writing, software
320
+ * distributed under the License is distributed on an "AS IS" basis,
321
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
322
+ * See the License for the specific language governing permissions and
323
+ * limitations under the License.
324
+ */
325
+ const ɵ0 = { title: 'Form management', roles: [ROLE_ADMIN] }, ɵ1 = { title: 'Create new Form', roles: [ROLE_ADMIN] }, ɵ2 = { title: 'Form Builder', roles: [ROLE_ADMIN] };
326
+ const routes = [
327
+ {
328
+ path: 'form-management',
329
+ component: FormManagementComponent,
330
+ canActivate: [AuthGuardService],
331
+ data: ɵ0
332
+ },
333
+ {
334
+ path: 'form-management/create',
335
+ component: FormManagementCreateComponent,
336
+ canActivate: [AuthGuardService],
337
+ data: ɵ1
338
+ },
339
+ {
340
+ path: 'form-management/edit/:id',
341
+ component: FormManagementEditComponent,
342
+ canActivate: [AuthGuardService],
343
+ data: ɵ2
344
+ }
345
+ ];
346
+ class FormManagementRoutingModule {
347
+ }
348
+ FormManagementRoutingModule.decorators = [
349
+ { type: NgModule, args: [{
350
+ imports: [
351
+ RouterModule.forChild(routes)
352
+ ],
353
+ exports: [
354
+ RouterModule
355
+ ],
356
+ declarations: []
357
+ },] }
358
+ ];
359
+
360
+ /*
361
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
362
+ *
363
+ * Licensed under EUPL, Version 1.2 (the "License");
364
+ * you may not use this file except in compliance with the License.
365
+ * You may obtain a copy of the License at
366
+ *
367
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
368
+ *
369
+ * Unless required by applicable law or agreed to in writing, software
370
+ * distributed under the License is distributed on an "AS IS" basis,
371
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
372
+ * See the License for the specific language governing permissions and
373
+ * limitations under the License.
374
+ */
375
+ class FormManagementListComponent {
376
+ constructor(formManagementService, router) {
377
+ this.formManagementService = formManagementService;
378
+ this.router = router;
379
+ this.formDefinitions = [];
380
+ this.formDefinitionFields = [
381
+ { key: 'name', label: 'Name' },
382
+ { key: 'readOnly', label: 'Read-only' }
383
+ ];
384
+ this.pagination = {
385
+ collectionSize: 0,
386
+ page: 1,
387
+ size: 10,
388
+ maxPaginationItemSize: 5
389
+ };
390
+ this.pageParam = 0;
391
+ }
392
+ paginationClicked(page) {
393
+ this.pageParam = page - 1;
394
+ this.loadFormDefinitions();
395
+ }
396
+ ngOnInit() {
397
+ }
398
+ paginationSet() {
399
+ this.loadFormDefinitions();
400
+ }
401
+ loadFormDefinitions(searchTerm) {
402
+ const params = { page: this.pageParam, size: this.pagination.size };
403
+ if (searchTerm) {
404
+ params['searchTerm'] = searchTerm;
405
+ }
406
+ this.formManagementService.queryFormDefinitions(params).subscribe((results) => {
407
+ this.pagination.collectionSize = results.body.totalElements;
408
+ this.formDefinitions = results.body.content;
409
+ });
410
+ }
411
+ editFormDefinition(formDefinition) {
412
+ this.router.navigate(['/form-management/edit', formDefinition.id]);
413
+ }
414
+ searchTermEntered(searchTerm) {
415
+ this.loadFormDefinitions(searchTerm);
416
+ }
417
+ }
418
+ FormManagementListComponent.decorators = [
419
+ { type: Component, args: [{
420
+ selector: 'valtimo-form-management-list',
421
+ template: "<!--\n ~ Copyright 2015-2020 Ritense BV, the Netherlands.\n ~\n ~ Licensed under EUPL, Version 1.2 (the \"License\");\n ~ you may not use this file except in compliance with the License.\n ~ You may obtain a copy of the License at\n ~\n ~ https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n ~\n ~ Unless required by applicable law or agreed to in writing, software\n ~ distributed under the License is distributed on an \"AS IS\" basis,\n ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n ~ See the License for the specific language governing permissions and\n ~ limitations under the License.\n -->\n\n<valtimo-list [items]=\"formDefinitions\"\n [fields]=\"formDefinitionFields\"\n [viewMode]=\"true\"\n [isSearchable]=\"true\"\n [pagination]=\"pagination\"\n paginationIdentifier=\"formManagementList\"\n (paginationClicked)=\"paginationClicked($event)\"\n (paginationSet)=\"paginationSet()\"\n (rowClicked)=\"editFormDefinition($event)\"\n [header]=\"true\"\n (search)=\"searchTermEntered($event)\"\n>\n <div header>\n <h3 class=\"list-header-title\">{{ 'Forms' | translate }}</h3>\n <h5 class=\"list-header-description\">{{ 'Overview of all Forms' | translate }}</h5>\n </div>\n</valtimo-list>\n",
422
+ styles: ["/*!\n * Copyright 2015-2020 Ritense BV, the Netherlands.\n *\n * Licensed under EUPL, Version 1.2 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" basis,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */"]
423
+ },] }
424
+ ];
425
+ FormManagementListComponent.ctorParameters = () => [
426
+ { type: FormManagementService },
427
+ { type: Router }
428
+ ];
429
+
430
+ /*
431
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
432
+ *
433
+ * Licensed under EUPL, Version 1.2 (the "License");
434
+ * you may not use this file except in compliance with the License.
435
+ * You may obtain a copy of the License at
436
+ *
437
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
438
+ *
439
+ * Unless required by applicable law or agreed to in writing, software
440
+ * distributed under the License is distributed on an "AS IS" basis,
441
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
442
+ * See the License for the specific language governing permissions and
443
+ * limitations under the License.
444
+ */
445
+ class FormManagementUploadComponent {
446
+ constructor(documentService, translateService) {
447
+ this.documentService = documentService;
448
+ this.translateService = translateService;
449
+ this.definitionUploaded = new EventEmitter();
450
+ this.clear$ = new Subject();
451
+ this.jsonString$ = new BehaviorSubject('');
452
+ this.error$ = new BehaviorSubject('');
453
+ this.disabled$ = new BehaviorSubject(false);
454
+ this.file$ = new BehaviorSubject(undefined);
455
+ }
456
+ ngAfterViewInit() {
457
+ this.openShowSubscription();
458
+ this.openFileSubscription();
459
+ }
460
+ ngOnDestroy() {
461
+ this.showSubscription.unsubscribe();
462
+ this.fileSubscription.unsubscribe();
463
+ this.closeErrorSubscription();
464
+ }
465
+ setFile(file) {
466
+ this.clearError();
467
+ this.file$.next(file);
468
+ }
469
+ uploadDefinition() {
470
+ this.disable();
471
+ this.jsonString$
472
+ .pipe(take(1))
473
+ .subscribe((definition) => {
474
+ this.closeErrorSubscription();
475
+ this.clearError();
476
+ this.enable();
477
+ this.hideModal();
478
+ this.definitionUploaded.emit(definition);
479
+ });
480
+ }
481
+ openErrorSubscription(errorCode) {
482
+ this.closeErrorSubscription();
483
+ this.errorSubscription = this.translateService.stream(errorCode).subscribe(error => {
484
+ this.error$.next(error);
485
+ });
486
+ }
487
+ closeErrorSubscription() {
488
+ if (this.errorSubscription) {
489
+ this.errorSubscription.unsubscribe();
490
+ }
491
+ }
492
+ clearError() {
493
+ this.error$.next('');
494
+ }
495
+ openFileSubscription() {
496
+ this.fileSubscription = this.file$.subscribe(file => {
497
+ if (file) {
498
+ const reader = new FileReader();
499
+ reader.onloadend = () => {
500
+ const result = reader.result.toString();
501
+ if (this.stringIsValidJson(result)) {
502
+ this.jsonString$.next(result);
503
+ }
504
+ };
505
+ reader.readAsText(file);
506
+ }
507
+ else {
508
+ this.clearJsonString();
509
+ }
510
+ });
511
+ }
512
+ openShowSubscription() {
513
+ this.showSubscription = this.show$.subscribe(show => {
514
+ if (show) {
515
+ this.showModal();
516
+ }
517
+ else {
518
+ this.hideModal();
519
+ }
520
+ this.clearJsonString();
521
+ this.clearError();
522
+ this.clearDropzone();
523
+ });
524
+ }
525
+ clearJsonString() {
526
+ this.jsonString$.next('');
527
+ }
528
+ clearDropzone() {
529
+ this.clear$.next();
530
+ }
531
+ showModal() {
532
+ this.modal.show();
533
+ }
534
+ hideModal() {
535
+ this.modal.hide();
536
+ }
537
+ stringIsValidJson(string) {
538
+ var _a, _b;
539
+ try {
540
+ // tslint:disable-next-line
541
+ (_b = (_a = JSON.parse(string)) === null || _a === void 0 ? void 0 : _a.formDefinition) === null || _b === void 0 ? void 0 : _b.components;
542
+ }
543
+ catch (e) {
544
+ this.clearDropzone();
545
+ this.openErrorSubscription('dropzone.error.invalidFormDef');
546
+ return false;
547
+ }
548
+ return true;
549
+ }
550
+ disable() {
551
+ this.disabled$.next(true);
552
+ }
553
+ enable() {
554
+ this.disabled$.next(false);
555
+ }
556
+ }
557
+ FormManagementUploadComponent.decorators = [
558
+ { type: Component, args: [{
559
+ selector: 'valtimo-form-management-upload',
560
+ template: "<valtimo-modal #uploadFormDefinitionModal [title]=\"'uploadFormDefinition' | translate\" showFooter=\"true\">\n <div class=\"mt-2\" body>\n <valtimo-dropzone\n [clear$]=\"clear$\"\n (fileSelected)=\"setFile($event)\"\n [disabled]=\"disabled$ | async\"\n [subtitle]=\"'dropzone.formJsonDocDef' | translate\"\n [externalError$]=\"error$\"\n ></valtimo-dropzone>\n </div>\n <div footer>\n <ng-container *ngIf=\"(jsonString$ | async) && !(error$ | async); else pleaseSelect\">\n <button [disabled]=\"disabled$ | async\" class=\"btn btn-primary\" (click)=\"uploadDefinition()\">\n {{ 'Upload' | translate }}\n </button>\n </ng-container>\n </div>\n</valtimo-modal>\n\n<ng-template #pleaseSelect>\n <button class=\"btn btn-primary\" [disabled]=\"true\">\n {{ 'Select a document definition' | translate }}\n </button>\n</ng-template>\n",
561
+ styles: [""]
562
+ },] }
563
+ ];
564
+ FormManagementUploadComponent.ctorParameters = () => [
565
+ { type: DocumentService },
566
+ { type: TranslateService }
567
+ ];
568
+ FormManagementUploadComponent.propDecorators = {
569
+ modal: [{ type: ViewChild, args: ['uploadFormDefinitionModal',] }],
570
+ show$: [{ type: Input }],
571
+ definitionUploaded: [{ type: Output }]
572
+ };
573
+
574
+ /*
575
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
576
+ *
577
+ * Licensed under EUPL, Version 1.2 (the "License");
578
+ * you may not use this file except in compliance with the License.
579
+ * You may obtain a copy of the License at
580
+ *
581
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
582
+ *
583
+ * Unless required by applicable law or agreed to in writing, software
584
+ * distributed under the License is distributed on an "AS IS" basis,
585
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
586
+ * See the License for the specific language governing permissions and
587
+ * limitations under the License.
588
+ */
589
+ class FormManagementModule {
590
+ }
591
+ FormManagementModule.decorators = [
592
+ { type: NgModule, args: [{
593
+ declarations: [
594
+ FormManagementComponent,
595
+ FormManagementCreateComponent,
596
+ FormManagementListComponent,
597
+ FormManagementEditComponent,
598
+ FormManagementUploadComponent
599
+ ],
600
+ imports: [
601
+ FormManagementRoutingModule,
602
+ FormIoModule,
603
+ CommonModule,
604
+ ReactiveFormsModule,
605
+ FormsModule,
606
+ WidgetModule,
607
+ ListModule,
608
+ TranslateModule,
609
+ NgbTooltipModule,
610
+ DropzoneModule,
611
+ ModalModule
612
+ ],
613
+ exports: [FormManagementComponent]
614
+ },] }
615
+ ];
616
+
617
+ /*
618
+ * Copyright 2015-2020 Ritense BV, the Netherlands.
619
+ *
620
+ * Licensed under EUPL, Version 1.2 (the "License");
621
+ * you may not use this file except in compliance with the License.
622
+ * You may obtain a copy of the License at
623
+ *
624
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
625
+ *
626
+ * Unless required by applicable law or agreed to in writing, software
627
+ * distributed under the License is distributed on an "AS IS" basis,
628
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
629
+ * See the License for the specific language governing permissions and
630
+ * limitations under the License.
631
+ */
632
+
633
+ /**
634
+ * Generated bundle index. Do not edit.
635
+ */
636
+
637
+ export { FormManagementComponent, FormManagementModule, FormManagementService, FormManagementCreateComponent as ɵa, FormManagementListComponent as ɵb, FormManagementEditComponent as ɵc, FormManagementUploadComponent as ɵd, FormManagementRoutingModule as ɵe };
638
+ //# sourceMappingURL=valtimo-form-management.js.map