Commit 3b1b25b1 authored by Gaëlle FOURNIER's avatar Gaëlle FOURNIER
Browse files

Tslint fixes


Co-authored-by: default avatarbenemart <benedicte.martinez@cea.fr>
parent 3ecf6ae3
......@@ -34,16 +34,16 @@
* 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 {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 {Subscription} from 'rxjs';
import {ConfirmDialogService, Option} from 'ui-frontend-common';
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 { Subscription } from 'rxjs';
import { ConfirmDialogService, Option } from 'ui-frontend-common';
import {AccessContract, FilingPlanMode} from 'projects/vitamui-library/src/public-api';
import {AgencyService} from '../../agency/agency.service';
import {AccessContractService} from '../access-contract.service';
import {AccessContractCreateValidators} from './access-contract-create.validators';
import { AccessContract, FilingPlanMode } from 'projects/vitamui-library/src/public-api';
import { AgencyService } from '../../agency/agency.service';
import { AccessContractService } from '../access-contract.service';
import { AccessContractCreateValidators } from './access-contract-create.validators';
const PROGRESS_BAR_MULTIPLICATOR = 100;
......@@ -71,7 +71,7 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy {
private stepCount = 4;
private keyPressSubscription: Subscription;
@ViewChild('fileSearch', {static: false}) fileSearch: any;
@ViewChild('fileSearch', { static: false }) fileSearch: any;
constructor(
public dialogRef: MatDialogRef<AccessContractCreateComponent>,
......@@ -88,7 +88,7 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy {
accessLogControl = new FormControl(true);
allNodes = new FormControl(false);
ruleFilter = new FormControl(false);
selectNodesControl = new FormControl({included: [], excluded: []});
selectNodesControl = new FormControl({ included: [], excluded: [] });
accessContractSelect = new FormControl(null, Validators.required);
originatingAgencies: Option[] = [];
......@@ -96,28 +96,28 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy {
// FIXME: Get list from common var ?
rules: Option[] = [
{key: 'StorageRule', label: 'Durée d\'utilité courante', info: ''},
{key: 'ReuseRule', label: 'Durée de réutilisation', info: ''},
{key: 'ClassificationRule', label: 'Durée de classification', info: ''},
{key: 'DisseminationRule', label: 'Délai de diffusion', info: ''},
{key: 'AccessRule', label: 'Durée d\'utilité administrative', info: ''},
{key: 'AppraisalRule', label: 'Délai de communicabilité', info: ''}
{ key: 'StorageRule', label: 'Durée d\'utilité courante', info: '' },
{ key: 'ReuseRule', label: 'Durée de réutilisation', info: '' },
{ key: 'ClassificationRule', label: 'Durée de classification', info: '' },
{ key: 'DisseminationRule', label: 'Délai de diffusion', info: '' },
{ key: 'AccessRule', label: 'Durée d\'utilité administrative', info: '' },
{ key: 'AppraisalRule', label: 'Délai de communicabilité', info: '' }
];
// FIXME: Get list from common var ?
usages: Option[] = [
{key: 'BinaryMaster', label: 'Archives numériques originales', info: ''},
{key: 'Dissemination', label: 'Copies de diffusion', info: ''},
{key: 'Thumbnail', label: 'Vignettes', info: ''},
{key: 'TextContent', label: 'Contenu textuel', info: ''},
{key: 'PhysicalMaster', label: 'Archives physiques', info: ''}
{ key: 'BinaryMaster', label: 'Archives numériques originales', info: '' },
{ key: 'Dissemination', label: 'Copies de diffusion', info: '' },
{ key: 'Thumbnail', label: 'Vignettes', info: '' },
{ key: 'TextContent', label: 'Contenu textuel', info: '' },
{ key: 'PhysicalMaster', label: 'Archives physiques', info: '' }
];
ngOnInit() {
console.log('tenantIdentifier', this.tenantIdentifier);
this.agencyService.getAll().subscribe(agencies =>
this.originatingAgencies = agencies.map(x => ({label: x.name, key: x.identifier}))
this.originatingAgencies = agencies.map(x => ({ label: x.name, key: x.identifier }))
);
this.accessContractService.getAll().subscribe((value) => {
......@@ -177,8 +177,8 @@ export class AccessContractCreateComponent implements OnInit, OnDestroy {
}
onSubmit() {
if (this.lastStepInvalid()) {
return;
if (this.lastStepInvalid()) {
return;
}
const accessContract = this.form.value as AccessContract;
this.accessContractService.create(accessContract).subscribe(
......
......@@ -39,8 +39,8 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {ActivatedRoute, Router} from '@angular/router';
import {AppRootComponent, Option} from 'ui-frontend-common';
import {AccessContractService} from '../access-contract/access-contract.service';
import {VitamUISnackBar} from '../shared/vitamui-snack-bar';
import {AdminDslService} from './admin-dsl.service';
import {VitamUISnackBar} from "../shared/vitamui-snack-bar";
@Component({
selector: 'app-admin-dsl',
......@@ -106,8 +106,8 @@ export class AdminDslComponent extends AppRootComponent implements OnInit {
const dsl = this.form.value.dsl;
try {
return dsl.length > 1 && !!JSON.parse(dsl);
} catch(syntaxError) {
this.snackBar.open("Format de la requête invalide", null, {
} catch (syntaxError) {
this.snackBar.open('Format de la requête invalide', null, {
panelClass: 'vitamui-snack-bar',
duration: 1000
});
......
......@@ -4,7 +4,7 @@ import {NO_ERRORS_SCHEMA} from '@angular/core';
import {FormBuilder, ReactiveFormsModule} from '@angular/forms';
import {MatDialog, MatDialogRef, MatSelectModule, MatSidenavModule} from '@angular/material';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {ActivatedRoute} from '@angular/router';
import {ActivatedRoute, Router} from '@angular/router';
import {of} from 'rxjs';
import {GlobalEventService, InjectorModule, LoggerModule} from 'ui-frontend-common';
import {VitamUICommonTestModule} from 'ui-frontend-common/testing';
......@@ -22,6 +22,7 @@ describe('AuditComponent', () => {
params: of({tenantIdentifier: 1}),
data: of({appId: 'AUDIT_APP'})
};
const routerSpy = jasmine.createSpyObj('Router', ['navigate']);
TestBed.configureTestingModule({
imports:
......@@ -40,7 +41,8 @@ describe('AuditComponent', () => {
GlobalEventService,
{provide: MatDialogRef, useValue: matDialogRefSpy},
{provide: MatDialog, useValue: {}},
{provide: ActivatedRoute, useValue: activatedRouteMock}
{provide: ActivatedRoute, useValue: activatedRouteMock},
{provide: Router, useValue: routerSpy}
],
schemas: [NO_ERRORS_SCHEMA]
})
......
......@@ -38,8 +38,8 @@ import {Injectable} from '@angular/core';
import {AbstractControl, AsyncValidatorFn} from '@angular/forms';
import {of, timer} from 'rxjs';
import {ContextPermission} from "vitamui-library";
import {map, switchMap, take} from 'rxjs/operators';
import {ContextPermission} from 'vitamui-library';
import {ContextService} from '../context.service';
@Injectable()
......@@ -76,9 +76,9 @@ export class ContextCreateValidators {
public permissionInvalid() {
return (control: AbstractControl) => {
switch(this.checkTenantsValid(control.value)) {
case 'tenant': return of({ 'permissionsTenant': true });
case 'empty': return of({ 'noPermissions': true });
switch (this.checkTenantsValid(control.value)) {
case 'tenant': return of({ permissionsTenant: true });
case 'empty': return of({ noPermissions: true });
default: return of(null);
}
};
......@@ -89,13 +89,13 @@ export class ContextCreateValidators {
return 'empty';
}
for (let permission of value) {
for (const permission of value) {
if (!permission.tenant) {
return 'tenant';
}
}
return null;
};
}
}
......@@ -36,13 +36,13 @@
*/
/* tslint:disable:no-use-before-declare */
import {Component, forwardRef, Input, OnInit} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import {ContextPermission} from 'projects/vitamui-library/src/public-api';
import {AuthService, Option} from 'ui-frontend-common';
import {Tenant} from 'ui-frontend-common/app/modules/models/customer';
import {AccessContractService} from '../../../access-contract/access-contract.service';
import {IngestContractService} from '../../../ingest-contract/ingest-contract.service';
import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { ContextPermission } from 'projects/vitamui-library/src/public-api';
import { AuthService, Option } from 'ui-frontend-common';
import { Tenant } from 'ui-frontend-common/app/modules/models/customer';
import { AccessContractService } from '../../../access-contract/access-contract.service';
import { IngestContractService } from '../../../ingest-contract/ingest-contract.service';
export const CONTEXT_PERMISSION_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
......@@ -58,9 +58,10 @@ export const CONTEXT_PERMISSION_VALUE_ACCESSOR: any = {
})
export class ContextEditPermissionComponent implements ControlValueAccessor, OnInit {
constructor(private accessService: AccessContractService,
private ingestService: IngestContractService,
private authService: AuthService) {
constructor(
private accessService: AccessContractService,
private ingestService: IngestContractService,
private authService: AuthService) {
}
permissions: ContextPermission[];
......@@ -84,7 +85,7 @@ export class ContextEditPermissionComponent implements ControlValueAccessor, OnI
const accessTenants: Tenant[] = accessTenantsInfo ? accessTenantsInfo.tenants : [];
accessTenants.forEach((tenant) => {
if (!this.tenants.find(appTenant => appTenant.key === '' + tenant.identifier)) {
this.tenants.push({key: '' + tenant.identifier, label: tenant.name});
this.tenants.push({ key: '' + tenant.identifier, label: tenant.name });
}
this.accessService.getAllForTenant('' + tenant.identifier).subscribe(
accessContracts => {
......@@ -100,7 +101,7 @@ export class ContextEditPermissionComponent implements ControlValueAccessor, OnI
const ingestTenants: Tenant[] = ingestTenantsInfo ? ingestTenantsInfo.tenants : [];
ingestTenants.forEach((tenant) => {
if (!this.tenants.find(appTenant => appTenant.key === '' + tenant.identifier)) {
this.tenants.push({key: '' + tenant.identifier, label: tenant.name});
this.tenants.push({ key: '' + tenant.identifier, label: tenant.name });
}
this.ingestService.getAllForTenant('' + tenant.identifier).subscribe(
ingestContracts => {
......@@ -117,29 +118,39 @@ export class ContextEditPermissionComponent implements ControlValueAccessor, OnI
onDelete(index: number) {
this.permissions.splice(index, 1);
this.onChange && this.onChange(this.permissions);
if (this.onChange) {
this.onChange(this.permissions);
}
}
onAdd() {
this.permissions.push({tenant: '', accessContracts: [], ingestContracts: []});
this.onChange && this.onChange(this.permissions);
this.permissions.push({ tenant: '', accessContracts: [], ingestContracts: [] });
if (this.onChange) {
this.onChange(this.permissions);
}
}
onTenantSelect() {
this.onChange && this.onChange(this.permissions);
if (this.onChange) {
this.onChange(this.permissions);
}
}
onContractSelect() {
this.onChange && this.onChange(this.permissions);
if (this.onChange) {
this.onChange(this.permissions);
}
}
writeValue(value: ContextPermission[]) {
if (value) {
this.permissions = value;
} else {
this.permissions = [{tenant: null, accessContracts: [], ingestContracts: []}];
this.permissions = [{ tenant: null, accessContracts: [], ingestContracts: [] }];
}
if (this.onChange) {
this.onChange(this.permissions);
}
this.onChange && this.onChange(this.permissions);
}
registerOnChange(fn: any): void {
......
......@@ -34,17 +34,17 @@
* 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 {Component, EventEmitter, Input, Output} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Context} from 'projects/vitamui-library/src/public-api';
import {Observable, of} from 'rxjs';
import {catchError, filter, map, switchMap} from 'rxjs/operators';
import {diff} from 'ui-frontend-common';
import {extend, isEmpty} from 'underscore';
import {ContextPermission} from "vitamui-library";
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Context } from 'projects/vitamui-library/src/public-api';
import { Observable, of } from 'rxjs';
import { catchError, filter, map, switchMap } from 'rxjs/operators';
import { diff } from 'ui-frontend-common';
import { extend, isEmpty } from 'underscore';
import { ContextPermission } from 'vitamui-library';
import {ContextService} from '../../context.service';
import {ContextCreateValidators} from "../../context-create/context-create.validators";
import { ContextCreateValidators } from '../../context-create/context-create.validators';
import { ContextService } from '../../context.service';
@Component({
......@@ -57,11 +57,15 @@ export class ContextPermissionTabComponent {
@Output() updated: EventEmitter<boolean> = new EventEmitter<boolean>();
form: FormGroup;
previousValue = (): Context => {
return this._context
};
submited: boolean = false;
submited = false;
// tslint:disable-next-line:variable-name
private _context: Context;
previousValue = (): Context => {
return this._context;
}
@Input()
set context(context: Context) {
......@@ -69,7 +73,7 @@ export class ContextPermissionTabComponent {
context.permissions = [];
}
for (let permission of context.permissions) {
for (const permission of context.permissions) {
if (!permission.accessContracts) {
permission.accessContracts = [];
}
......@@ -83,8 +87,6 @@ export class ContextPermissionTabComponent {
this.updated.emit(false);
}
get context(): Context { return this._context; }
// tslint:disable-next-line:variable-name
private _context: Context;
@Input()
set readOnly(readOnly: boolean) {
......@@ -128,11 +130,11 @@ export class ContextPermissionTabComponent {
samePermission(p1: ContextPermission[], p2: ContextPermission[]): boolean {
if (!p1 && !p2) { return true; }
if (!p1 || !p2) { return false; }
if (p1.length != p2.length) {
if (p1.length !== p2.length) {
return false;
}
for(let i = 0; i < p1.length; i++) {
for (let i = 0; i < p1.length; i++) {
if (p1[i].tenant !== p2[i].tenant) {
return false;
}
......@@ -165,7 +167,7 @@ export class ContextPermissionTabComponent {
prepareSubmit(): Observable<Context> {
return of(diff(this.form.getRawValue(), this.previousValue())).pipe(
filter((formData) => !isEmpty(formData)),
map((formData) => extend({id: this.previousValue().id, identifier: this.previousValue().identifier}, formData)),
map((formData) => extend({ id: this.previousValue().id, identifier: this.previousValue().identifier }, formData)),
switchMap((formData: { id: string, [key: string]: any }) => this.contextService.patch(formData).pipe(catchError(() => of(null)))));
}
......@@ -179,19 +181,18 @@ export class ContextPermissionTabComponent {
this.context = response;
}
);
},() => {
}, () => {
this.submited = false;
});
}
resetForm(context: Context) {
console.log('Reset: ', context);
this.form.reset(context, { emitEvent: false });
let permissionCopy: ContextPermission[] = [];
for (let permission of context.permissions) {
const permissionCopy: ContextPermission[] = [];
for (const permission of context.permissions) {
permissionCopy.push(new ContextPermission(permission.tenant,
[...(permission.accessContracts ? permission.accessContracts: [])],
[...(permission.ingestContracts ? permission.ingestContracts: [])]));
[...(permission.accessContracts ? permission.accessContracts : [])],
[...(permission.ingestContracts ? permission.ingestContracts : [])]));
}
this.form.controls.permissions.setValue(permissionCopy);
}
......
......@@ -12,6 +12,7 @@ describe('IngestContractObjectTabComponent', () => {
const ingestContractValue = {
everyDataObjectVersion: true,
masterMandatory: true,
dataObjectVersion: ['']
};
......
......@@ -28,7 +28,7 @@ export class IngestContractObjectTabComponent implements OnInit {
{key: 'Dissemination', label: 'Diffusion', info: ''},
{key: 'Thumbnail', label: 'Vignette', info: ''},
{key: 'TextContent', label: 'Contenu brut', info: ''},
{key: 'PhysicalMaster', label: 'Originel papier', info: ''}
{key: 'PhysicalMaster', label: 'Original papier', info: ''}
];
previousValue = (): IngestContract => {
......@@ -59,15 +59,6 @@ export class IngestContractObjectTabComponent implements OnInit {
}
}
// FIXME: Get list from common var ?
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: '' }
];
constructor(
private formBuilder: FormBuilder,
private ingestContractService: IngestContractService
......
......@@ -3,7 +3,7 @@ import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {FormBuilder, ReactiveFormsModule} from '@angular/forms';
import {MatDialog, MatSelectModule, MatSidenavModule} from '@angular/material';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {ActivatedRoute} from '@angular/router';
import {ActivatedRoute, Router} from '@angular/router';
import {of} from 'rxjs';
import {InjectorModule, LoggerModule} from 'ui-frontend-common';
import {VitamUICommonTestModule} from 'ui-frontend-common/testing';
......@@ -34,7 +34,8 @@ describe('ProbativeValueComponent', () => {
providers: [
FormBuilder,
{provide: MatDialog, useValue: {}},
{provide: ActivatedRoute, useValue: activatedRouteMock}
{provide: ActivatedRoute, useValue: activatedRouteMock},
{ provide: Router, useValue: { navigate: () => {} } }
],
schemas: [NO_ERRORS_SCHEMA]
})
......
......@@ -35,22 +35,34 @@
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {ActivatedRoute} from '@angular/router';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { AuthService } from '../../../auth.service';
import { LogbookService } from '../../logbook.service';
import {of} from 'rxjs';
import {AccessContractService} from '../../../access-contract/access-contract.service';
import {SecurisationService} from '../../securisation.service';
import { SecurisationCheckTabComponent } from './securisation-check-tab.component';
describe('OperationHistoryTabComponent', () => {
fdescribe('SecurisationCheckTabComponent', () => {
let component: SecurisationCheckTabComponent;
let fixture: ComponentFixture<SecurisationCheckTabComponent>;
beforeEach(async(() => {
const activatedRouteMock = {
params: of({tenantIdentifier: 1}),
data: of({appId: 'TRACEABILITY_APP'})
};
const accessContractServiceMock = {
getAllForTenant: () => of([])
};
TestBed.configureTestingModule({
declarations: [ SecurisationCheckTabComponent ],
providers: [
{ provide: AuthService, useValue: {}},
{ provide: LogbookService, useValue: {}},
{provide: AccessContractService, useValue: accessContractServiceMock},
{provide: SecurisationService, useValue: {}},
{provide: ActivatedRoute, useValue: activatedRouteMock}
],
schemas: [NO_ERRORS_SCHEMA],
})
......
......@@ -34,13 +34,12 @@
* 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 { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { SecurisationService } from "../../securisation.service";
import {AccessContractService} from "../../../access-contract/access-contract.service";
import {ActivatedRoute} from "@angular/router";
import {AccessContract} from "vitamui-library";
import {ApiEvent, Event, LogbookApiService} from "ui-frontend-common";
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {ApiEvent, Event, LogbookApiService} from 'ui-frontend-common';
import {AccessContract} from 'vitamui-library';
import {AccessContractService} from '../../../access-contract/access-contract.service';
import {SecurisationService} from '../../securisation.service';
@Component({
selector: 'app-securisation-check-tab',
......@@ -48,7 +47,7 @@ import {ApiEvent, Event, LogbookApiService} from "ui-frontend-common";
styleUrls: ['./securisation-check-tab.component.scss']
})
export class SecurisationCheckTabComponent implements OnChanges {
export class SecurisationCheckTabComponent implements OnChanges, OnInit {
@Input() id: string;
events: Event[] = [];
......@@ -57,7 +56,10 @@ export class SecurisationCheckTabComponent implements OnChanges {
accessContracts: AccessContract[];
accessContractId: string;
constructor(private securisationService: SecurisationService, private accessContractService: AccessContractService, private route: ActivatedRoute) { }
constructor(
private securisationService: SecurisationService,
private accessContractService: AccessContractService,
private route: ActivatedRoute) { }
ngOnInit() {
......@@ -85,6 +87,6 @@ export class SecurisationCheckTabComponent implements OnChanges {
this.securisationService.checkTraceabilityOperation(this.id, this.accessContractId).subscribe((response: {$results: ApiEvent[]}) => {
this.events = response.$results.map(LogbookApiService.toEvent)[0].events;