other-parameters.component.ts 18.9 KB
Newer Older
1
2
3
4
import { Component, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { HttpClient } from '@angular/common/http';
import { KeyValue } from '@angular/common';
5
import { FormControl, Validators } from '@angular/forms';
6
import { catchError, debounceTime, filter, map, tap } from 'rxjs/operators';
7
import { ColorEvent } from 'ngx-color';
8
import { FunctionsService } from '@service/functions.service';
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import {
    amber,
    blue,
    blueGrey,
    brown,
    cyan,
    deepOrange,
    deepPurple,
    green,
    indigo,
    lightBlue,
    lightGreen,
    lime,
    orange,
    pink,
    purple,
    red,
    teal,
    yellow,
} from 'material-colors';
29
30
31
32
import { ConfirmComponent } from '@plugins/modal/confirm.component';
import { of } from 'rxjs';
import { NotificationService } from '@service/notification/notification.service';
import { MatDialog } from '@angular/material/dialog';
33
34
35
36
37
38
39
40
41
42

@Component({
    selector: 'app-other-parameters',
    templateUrl: './other-parameters.component.html',
    styleUrls: ['./other-parameters.component.scss'],
})
export class OtherParametersComponent implements OnInit {

    editorsConf: any = {
        java: {},
43
44
        onlyoffice: {
            ssl: new FormControl(false),
45
46
            uri: new FormControl('192.168.0.11', [Validators.required]),
            port: new FormControl(8765, [Validators.required]),
47
48
            token: new FormControl(''),
            authorizationHeader: new FormControl('Authorization')
49
        },
50
51
        collaboraonline: {
            ssl: new FormControl(false),
52
53
            uri: new FormControl('192.168.0.11', [Validators.required]),
            port: new FormControl(9980, [Validators.required]),
54
55
56
57
58
59
        },
        office365sharepoint: {
            tenantId: new FormControl('abc-123456789-efd', [Validators.required]),
            clientId: new FormControl('abc-123456789-efd', [Validators.required]),
            clientSecret: new FormControl('abc-123456789-efd'),
            siteUrl: new FormControl('https://exemple.sharepoint.com/sites/example', [Validators.required]),
60
61
62
        }
    };

63
    addinOutlookConf = {
64
65
66
        indexingModelId: new FormControl(null, [Validators.required]),
        typeId: new FormControl(null, [Validators.required]),
        statusId: new FormControl(null, [Validators.required]),
67
        attachmentTypeId: new FormControl(null, [Validators.required]),
68
    };
69

70
71
72
73
74
75
76
77
78
79
80
81
    watermark = {
        enabled: new FormControl(true),
        text: new FormControl('Copie conforme de [alt_identifier] le [date_now] [hour_now]'),
        posX: new FormControl(30),
        posY: new FormControl(35),
        angle: new FormControl(0),
        opacity: new FormControl(0.5),
        font: new FormControl('helvetica'),
        size: new FormControl(10),
        color: new FormControl([20, 192, 30]),
    };

82
    editorsEnabled = [];
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
    fonts = [
        {
            id: 'courier',
            label: 'courier'
        },
        {
            id: 'courierB',
            label: 'courierB'
        },
        {
            id: 'courierI',
            label: 'courierI'
        },
        {
            id: 'courierBI',
            label: 'courierBI'
        },
        {
            id: 'helvetica',
            label: 'helvetica'
        },
        {
            id: 'helveticaB',
            label: 'helveticaB'
        },
        {
            id: 'helveticaI',
            label: 'helveticaI'
        },
        {
            id: 'helveticaBI',
            label: 'helveticaBI'
        },
        {
            id: 'times',
            label: 'times'
        },
        {
            id: 'timesB',
            label: 'timesB'
        },
        {
            id: 'timesI',
            label: 'timesI'
        },
        {
            id: 'timesBI',
            label: 'timesBI'
        },
        {
            id: 'symbol',
            label: 'symbol'
        },
        {
            id: 'zapfdingbats',
            label: 'zapfdingbats'
        }
    ];

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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
    colors: string[] = [
        red['900'],
        red['700'],
        red['500'],
        red['300'],
        red['100'],
        pink['900'],
        pink['700'],
        pink['500'],
        pink['300'],
        pink['100'],
        purple['900'],
        purple['700'],
        purple['500'],
        purple['300'],
        purple['100'],
        deepPurple['900'],
        deepPurple['700'],
        deepPurple['500'],
        deepPurple['300'],
        deepPurple['100'],
        indigo['900'],
        indigo['700'],
        indigo['500'],
        indigo['300'],
        indigo['100'],
        blue['900'],
        blue['700'],
        blue['500'],
        blue['300'],
        blue['100'],
        lightBlue['900'],
        lightBlue['700'],
        lightBlue['500'],
        lightBlue['300'],
        lightBlue['100'],
        cyan['900'],
        cyan['700'],
        cyan['500'],
        cyan['300'],
        cyan['100'],
        teal['900'],
        teal['700'],
        teal['500'],
        teal['300'],
        teal['100'],
        '#194D33',
        green['700'],
        green['500'],
        green['300'],
        green['100'],
        lightGreen['900'],
        lightGreen['700'],
        lightGreen['500'],
        lightGreen['300'],
        lightGreen['100'],
        lime['900'],
        lime['700'],
        lime['500'],
        lime['300'],
        lime['100'],
        yellow['900'],
        yellow['700'],
        yellow['500'],
        yellow['300'],
        yellow['100'],
        amber['900'],
        amber['700'],
        amber['500'],
        amber['300'],
        amber['100'],
        orange['900'],
        orange['700'],
        orange['500'],
        orange['300'],
        orange['100'],
        deepOrange['900'],
        deepOrange['700'],
        deepOrange['500'],
        deepOrange['300'],
        deepOrange['100'],
        brown['900'],
        brown['700'],
        brown['500'],
        brown['300'],
        brown['100'],
        blueGrey['900'],
        blueGrey['700'],
        blueGrey['500'],
        blueGrey['300'],
        blueGrey['100'],
    ];

236
237
    indexingModels: any = [];
    doctypes: any = [];
238
    statuses: any = [];
239
    attachmentsTypes: any = [];
240

241
242
243
    constructor(
        public translate: TranslateService,
        public http: HttpClient,
244
245
        private dialog: MatDialog,
        private notify: NotificationService,
246
        public functions: FunctionsService,
247
248
    ) { }

249
    async ngOnInit() {
250
        this.getStatuses();
251
252
        this.getDoctypes();
        this.getIndexingModels();
253
        this.getAttachmentTypes();
254
        await this.getWatermarkConfiguration();
255
        await this.getEditorsConfiguration();
256
        await this.getAddinOutlookConfConfiguration();
257
258
259
260
        Object.keys(this.editorsConf).forEach(editorId => {
            Object.keys(this.editorsConf[editorId]).forEach((elementId: any) => {
                this.editorsConf[editorId][elementId].valueChanges
                    .pipe(
261
                        debounceTime(1000),
262
263
                        filter(() => this.editorsConf[editorId][elementId].valid),
                        tap(() => {
264
265
266
267
268
                            this.saveConfEditor();
                        }),
                    ).subscribe();
            });
        });
269
270
271
        Object.keys(this.watermark).forEach(elemId => {
            this.watermark[elemId].valueChanges
                .pipe(
272
                    debounceTime(1000),
273
274
275
276
277
                    tap((value: any) => {
                        this.saveWatermarkConf();
                    }),
                ).subscribe();
        });
278
279
280
281
282
283
284
285
286
287

        Object.keys(this.addinOutlookConf).forEach(elemId => {
            this.addinOutlookConf[elemId].valueChanges
                .pipe(
                    debounceTime(1000),
                    tap((value: any) => {
                        this.saveAddinOutlookConf();
                    }),
                ).subscribe();
        });
288
289
    }

290
291
    getWatermarkConfiguration() {
        return new Promise((resolve, reject) => {
292
            this.http.get('../rest/watermark/configuration').pipe(
293
                tap((data: any) => {
294
295
296
297
298
299
300
301
302
303
304
305
306
                    if (!this.functions.empty(data.configuration)) {
                        this.watermark = {
                            enabled: new FormControl(data.configuration.enabled),
                            text: new FormControl(data.configuration.text),
                            posX: new FormControl(data.configuration.posX),
                            posY: new FormControl(data.configuration.posY),
                            angle: new FormControl(data.configuration.angle),
                            opacity: new FormControl(data.configuration.opacity),
                            font: new FormControl(data.configuration.font),
                            size: new FormControl(data.configuration.size),
                            color: new FormControl(data.configuration.color),
                        };
                    }
307
308
309
310
311
312
                    resolve(true);
                })
            ).subscribe();
        });
    }

313
314
    getAddinOutlookConfConfiguration() {
        return new Promise((resolve, reject) => {
315
            this.http.get('../rest/plugins/outlook/configuration').pipe(
316
                tap(async (data: any) => {
Alex ORLUC's avatar
Alex ORLUC committed
317
                    if (!this.functions.empty(data.configuration) && Object.keys(data.configuration).length > 1) {
318
                        this.addinOutlookConf = {
319
320
                            indexingModelId: new FormControl(data.configuration.indexingModelId),
                            typeId: new FormControl(data.configuration.typeId),
321
                            statusId: new FormControl(data.configuration.statusId),
322
                            attachmentTypeId: new FormControl(data.configuration.attachmentTypeId),
323
                        };
324
325
326
                    } else {
                        await this.setDefaultValues();
                        this.saveAddinOutlookConf();
327
328
329
330
331
332
333
                    }
                    resolve(true);
                })
            ).subscribe();
        });
    }

334
335
    getEditorsConfiguration() {
        return new Promise((resolve, reject) => {
336
            this.http.get('../rest/configurations/admin_document_editors').pipe(
337
338
339
                map((data: any) => data.configuration.value),
                tap((data: any) => {
                    Object.keys(data).forEach(confId => {
340
                        this.editorsEnabled.push(confId);
341
                        Object.keys(data[confId]).forEach(itemId => {
342
343
                            console.log(confId, itemId);

344
345
346
                            if (!this.functions.empty(this.editorsConf[confId][itemId])) {
                                this.editorsConf[confId][itemId].setValue(data[confId][itemId]);
                            }
347
348
349
350
351
352
353
354
                        });
                    });
                    resolve(true);
                })
            ).subscribe();
        });
    }

355
356
357
358
    getInputType(value: any) {
        return typeof value;
    }

359
    originalOrder = (a: KeyValue<string, any>, b: KeyValue<string, any>): number => 0;
360
361
362

    addEditor(id: string) {
        this.editorsEnabled.push(id);
363
        this.saveConfEditor();
364
365
366
    }

    removeEditor(index: number) {
367
368
369
370
371
372
373
374
375
376
377
378
379
        const dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.delete'), msg: this.translate.instant('lang.confirmAction') } });

        dialogRef.afterClosed().pipe(
            filter((data: string) => data === 'ok'),
            tap(() => {
                this.editorsEnabled.splice(index, 1);
                this.saveConfEditor();
            }),
            catchError((err: any) => {
                this.notify.handleSoftErrors(err);
                return of(false);
            })
        ).subscribe();
380
381
382
383
384
385
386
387
388
389
390
391
    }

    getAvailableEditors() {
        const allEditors = Object.keys(this.editorsConf);
        const availableEditors = allEditors.filter(editor => this.editorsEnabled.indexOf(editor) === -1);
        return availableEditors;
    }

    allEditorsEnabled() {
        return Object.keys(this.editorsConf).length === this.editorsEnabled.length;
    }

392
    saveWatermarkConf() {
393
        this.http.put('../rest/watermark/configuration', this.formatWatermarkConfig()).pipe(
394
395
396
            tap(() => {
                this.notify.success(this.translate.instant('lang.dataUpdated'));
            }),
397
398
399
            catchError((err: any) => {
                this.notify.handleErrors(err);
                return of(false);
400
401
            })
        ).subscribe();
402
403
    }

404
    saveAddinOutlookConf() {
405
        this.http.put('../rest/plugins/outlook/configuration', this.formatAddinOutlookConfig()).pipe(
406
407
408
409
410
411
412
413
414
415
            tap(() => {
                this.notify.success(this.translate.instant('lang.dataUpdated'));
            }),
            catchError((err: any) => {
                this.notify.handleErrors(err);
                return of(false);
            })
        ).subscribe();
    }

416
    saveConfEditor() {
417
        this.http.put('../rest/configurations/admin_document_editors', this.formatEditorsConfig()).pipe(
418
419
420
            tap(() => {
                this.notify.success(this.translate.instant('lang.dataUpdated'));
            }),
421
422
423
            catchError((err: any) => {
                this.notify.handleErrors(err);
                return of(false);
424
425
            })
        ).subscribe();
426
427
    }

428
429
430
431
432
433
434
435
436
    formatAddinOutlookConfig() {
        const obj: any = {};
        Object.keys(this.addinOutlookConf).forEach(elemId => {
            obj[elemId] = this.addinOutlookConf[elemId].value;

        });
        return obj;
    }

437
438
439
440
441
442
443
444
445
    formatWatermarkConfig() {
        const obj: any = {};
        Object.keys(this.watermark).forEach(elemId => {
            obj[elemId] = this.watermark[elemId].value;

        });
        return obj;
    }

446
447
    formatEditorsConfig() {
        const obj: any = {};
448
        this.editorsEnabled.forEach(id => {
449
450
451
452
453
454
455
456
457
            if (this.editorsEnabled.indexOf(id) > -1) {
                obj[id] = {};
                Object.keys(this.editorsConf[id]).forEach(elemId => {
                    obj[id][elemId] = this.editorsConf[id][elemId].value;
                });
            }
        });
        return obj;
    }
458
459
460
461

    handleChange($event: ColorEvent) {
        this.watermark.color.setValue([$event.color.rgb.r, $event.color.rgb.g, $event.color.rgb.b]);
    }
462
463
464

    getDoctypes() {
        return new Promise((resolve, reject) => {
465
            this.http.get('../rest/doctypes').pipe(
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
                tap((data: any) => {
                    let arrValues: any[] = [];
                    data.structure.forEach((doctype: any) => {
                        if (doctype['doctypes_second_level_id'] === undefined) {
                            arrValues.push({
                                id: doctype.doctypes_first_level_id,
                                label: doctype.doctypes_first_level_label,
                                title: doctype.doctypes_first_level_label,
                                disabled: true,
                                isTitle: true,
                                color: doctype.css_style
                            });
                            data.structure.filter((info: any) => info.doctypes_first_level_id === doctype.doctypes_first_level_id && info.doctypes_second_level_id !== undefined && info.description === undefined).forEach((secondDoctype: any) => {
                                arrValues.push({
                                    id: secondDoctype.doctypes_second_level_id,
                                    label: '&nbsp;&nbsp;&nbsp;&nbsp;' + secondDoctype.doctypes_second_level_label,
                                    title: secondDoctype.doctypes_second_level_label,
                                    disabled: true,
                                    isTitle: true,
                                    color: secondDoctype.css_style
                                });
487
488
489
490
491
492
493
                                arrValues = arrValues.concat(data.structure.filter((infoDoctype: any) => infoDoctype.doctypes_second_level_id === secondDoctype.doctypes_second_level_id && infoDoctype.description !== undefined).map((infoType: any) => ({
                                    id: infoType.type_id,
                                    label: '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + infoType.description,
                                    title: infoType.description,
                                    disabled: false,
                                    isTitle: false,
                                })));
494
495
496
497
                            });
                        }
                    });
                    this.doctypes = arrValues;
498
                    const defaultDoctype = arrValues.filter((struct: any) => !struct.disabled)[0].id;
499
                    resolve(defaultDoctype);
500
501
502
503
504
505
506
                })
            ).subscribe();
        });
    }

    getIndexingModels() {
        return new Promise((resolve, reject) => {
507
            this.http.get('../rest/indexingModels').pipe(
508
509
                tap((data: any) => {
                    this.indexingModels = data.indexingModels.filter((info: any) => info.private === false);
510
511
                    const defaultIndexingModel = data.indexingModels[0].id;
                    resolve(defaultIndexingModel);
512
513
514
515
                })
            ).subscribe();
        });
    }
516
517
518

    getStatuses() {
        return new Promise((resolve, reject) => {
519
            this.http.get('../rest/statuses').pipe(
520
                tap((data: any) => {
521
522
523
524
                    this.statuses = data.statuses.map((status: any) => ({
                        id: status.identifier,
                        label: status.label_status
                    }));
525
526
                    const defaultStatus = data.statuses[0].identifier;
                    resolve(defaultStatus);
527
528
529
530
                })
            ).subscribe();
        });
    }
531

532
533
534
535
536
537
538
539
540
541
    getAttachmentTypes() {
        return new Promise((resolve, reject) => {
            this.http.get('../rest/attachmentsTypes').pipe(
                tap((data: any) => {
                    Object.keys(data.attachmentsTypes).forEach(templateType => {
                        this.attachmentsTypes.push({
                            id: data.attachmentsTypes[templateType].id,
                            label: data.attachmentsTypes[templateType].label
                        });
                    });
542
543
                    const defAttachment: any = Object.values(data.attachmentsTypes)[0];
                    resolve(defAttachment.id);
544
545
                })
            ).subscribe();
546
547
548
549
550
551
552
553
554
555
556
557
558
        });
    }

    setDefaultValues() {
        return new Promise((resolve, reject) => {
            Promise.all([this.getIndexingModels(), this.getDoctypes(), this.getStatuses(), this.getAttachmentTypes()]).then((data: any) => {
                this.addinOutlookConf.indexingModelId.setValue(data[0]);
                this.addinOutlookConf.typeId.setValue(data[1]);
                this.addinOutlookConf.statusId.setValue(data[2]);
                this.addinOutlookConf.attachmentTypeId.setValue(data[3]);
                resolve(true);
            });
        });
559
    }
560
}