Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
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
/*
* Copyright French Prime minister Office/SGMAP/DINSIC/Vitam Program (2019-2020)
* and the signatories of the "VITAM - Accord du Contributeur" agreement.
*
* contact@programmevitam.fr
*
* This software is a computer program whose purpose is to implement
* implement a digital archiving front-office system for the secure and
* efficient high volumetry VITAM solution.
*
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import {HttpHeaders, HttpParams} from '@angular/common/http';
import {Component, Inject, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {AccessContract, FileFormat, FilingPlanMode, IngestContract} from 'projects/vitamui-library/src/public-api';
import {Subscription} from 'rxjs';
import {ConfirmDialogService, Option} from 'ui-frontend-common';
import {AccessContractService} from '../../access-contract/access-contract.service';
import {ArchiveProfileApiService} from '../../core/api/archive-profile-api.service';
import {ManagementContractApiService} from '../../core/api/management-contract-api.service';
import {FileFormatService} from '../../file-format/file-format.service';
import {IngestContractService} from '../ingest-contract.service';
import {IngestContractCreateValidators} from './ingest-contract-create.validators';
const PROGRESS_BAR_MULTIPLICATOR = 100;
@Component({
selector: 'app-ingest-contract-create',
templateUrl: './ingest-contract-create.component.html',
styleUrls: ['./ingest-contract-create.component.scss']
})
export class IngestContractCreateComponent implements OnInit, OnDestroy {
form: FormGroup;
stepIndex = 0;
hasCustomGraphicIdentity = false;
hasError = true;
message: string;
@Input() tenantIdentifier: number;
FILLING_PLAN_MODE = FilingPlanMode;
// stepCount is the total number of steps and is used to calculate the advancement of the progress bar.
// We could get the number of steps using ViewChildren(StepComponent) but this triggers a
// "Expression has changed after it was checked" error so we instead manually define the value.
// Make sure to update this value whenever you add or remove a step from the template.
private stepCount = 4;
private keyPressSubscription: Subscription;
@ViewChild('fileSearch', {static: false}) fileSearch: any;
constructor(
public dialogRef: MatDialogRef<IngestContractCreateComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
private formBuilder: FormBuilder,
private ingestContractService: IngestContractService,
private ingestContractCreateValidators: IngestContractCreateValidators,
private confirmDialogService: ConfirmDialogService,
private fileFormatService: FileFormatService,
private managementContractService: ManagementContractApiService,
private archiveProfileService: ArchiveProfileApiService,
private accessContractService: AccessContractService
) {
}
statusControl = new FormControl(false);
linkParentIdControl = new FormControl();
checkParentIdControl = new FormControl();
accessContractSelect = new FormControl(null);
formatTypeList: FileFormat[];
managementContracts: any[];
archiveProfiles: any[];
accessContracts: AccessContract[];
usages: Option[] = [
{ key: 'BinaryMaster', label: 'Original numérique', info: '' },
{ key: 'Dissemination', label: 'Diffusion', info: '' },
{ key: 'Thumbnail', label: 'Vignette', info: '' },
{ key: 'TextContent', label: 'Contenu brut', info: '' },
{ key: 'PhysicalMaster', label: 'Original papier', info: '' }
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
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
236
237
238
239
240
241
242
];
ngOnInit() {
this.form = this.formBuilder.group({
identifier: [null, Validators.required],
status: ['INACTIVE'],
name: [null, [Validators.required], this.ingestContractCreateValidators.uniqueName()],
description: [null, Validators.required],
/* <- step 2 -> */
archiveProfiles: [new Array<string>(), /* Validators.required */],
managementContractId: [null],
/* <- step 3 -> */
everyFormatType: [true, Validators.required],
formatType: [new Array<string>(), Validators.required],
formatUnidentifiedAuthorized: [false, Validators.required],
/* <- step 4 -> */
binaryObjectMandatory: [true],
everyDataObjectVersion: [true],
dataObjectVersion: [new Array<string>(), Validators.required],
/* <- step 5 -> */
checkParentLink: ['AUTHORIZED', Validators.required],
linkParentId: [null, Validators.required],
checkParentId: [new Array<string>(), Validators.required],
/* default */
masterMandatory: [true, Validators.required],
computedInheritedRulesAtIngest: [false, Validators.required]
});
this.fileFormatService.getAllForTenant('' + this.tenantIdentifier).subscribe(files => {
this.formatTypeList = files;
});
this.accessContractService.getAll().subscribe((value) => {
this.accessContracts = value;
});
const params = new HttpParams().set('embedded', 'ALL');
const headers = new HttpHeaders().append('X-Tenant-Id', '' + this.tenantIdentifier);
this.managementContractService.getAllByParams(params, headers).subscribe(managmentContracts => {
this.managementContracts = managmentContracts;
});
this.archiveProfileService.getAllByParams(params, headers).subscribe(archiveProfiles => {
this.archiveProfiles = archiveProfiles;
});
this.statusControl.valueChanges.subscribe((value) => {
this.form.controls.status.setValue(value = (value === false) ? 'INACTIVE' : 'ACTIVE');
});
this.form.controls.name.valueChanges.subscribe((value) => {
this.form.controls.identifier.setValue(value);
});
this.linkParentIdControl.valueChanges.subscribe((value: { included: string[], excluded: string[] }) => {
if (value.included.length === 1) {
this.form.controls.linkParentId.setValue(value.included[0]);
} else {
this.form.controls.linkParentId.setValue(null);
}
});
this.checkParentIdControl.valueChanges.subscribe((value: { included: string[], excluded: string[] }) => {
if (value.included.length > 0) {
this.form.controls.checkParentId.setValue(value.included);
} else {
this.form.controls.checkParentId.setValue([]);
}
});
this.linkParentIdControl.setValue({included: [], excluded: []});
this.checkParentIdControl.setValue({included: [], excluded: []});
this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel());
}
ngOnDestroy() {
this.keyPressSubscription.unsubscribe();
}
onCancel() {
if (this.form.dirty) {
this.confirmDialogService.confirmBeforeClosing(this.dialogRef);
} else {
this.dialogRef.close();
}
}
onSubmit() {
/*if (this.form.invalid) { return; }*/
const ingestContract = this.form.value as IngestContract;
this.ingestContractService.create(ingestContract).subscribe(
() => {
this.dialogRef.close(true);
},
(error) => {
this.dialogRef.close(false);
console.error(error);
});
}
firstStepInvalid(): boolean {
return this.form.get('name').invalid || this.form.get('name').pending ||
this.form.get('description').invalid || this.form.get('description').pending ||
this.form.get('status').invalid || this.form.get('status').pending;
}
thirdStepInvalid(): boolean {
return this.form.get('everyFormatType').invalid || this.form.get('everyFormatType').pending ||
(this.form.get('everyFormatType').value === false && (this.form.get('formatType').invalid || this.form.get('formatType').pending));
}
fourthStepInvalid(): boolean {
return this.form.get('everyDataObjectVersion').invalid ||
this.form.get('everyDataObjectVersion').pending ||
(this.form.get('everyDataObjectVersion').value === false &&
(this.form.get('dataObjectVersion').invalid ||
this.form.get('dataObjectVersion').pending));
}
seventhStepInvalid(): boolean {
return this.checkParentIdControl.invalid || this.checkParentIdControl.pending ||
(this.form.get('checkParentLink').value === 'REQUIRED' && this.checkParentIdControl.value.included.length === 0);
}
get stepProgress() {
return ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR;
}
}