Newer
Older
import { Component, OnInit, ViewChild } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { LANG } from '../../translate.component';
import { NotificationService } from '../../notification.service';
import { HeaderService } from '../../../service/header.service';
import { MatDialog } from '@angular/material/dialog';
import { MatSidenav } from '@angular/material/sidenav';
import { AppService } from '../../../service/app.service';
import { tap, catchError, finalize, exhaustMap } from 'rxjs/operators';
import { of } from 'rxjs';
import { SortPipe } from '../../../plugins/sorting.pipe';
import { IndexingFormComponent } from '../../indexation/indexing-form/indexing-form.component';
import { ActivatedRoute, Router } from '@angular/router';
declare function $j(selector: any): any;
@Component({
templateUrl: "indexing-model-administration.component.html",
styleUrls: [
'indexing-model-administration.component.scss',
'../../indexation/indexing-form/indexing-form.component.scss'
],
providers: [NotificationService, AppService, SortPipe]
})
export class IndexingModelAdministrationComponent implements OnInit {
@ViewChild('snav', { static: true }) public sidenavLeft: MatSidenav;
@ViewChild('snav2', { static: true }) public sidenavRight: MatSidenav;
@ViewChild('indexingForm', { static: false }) indexingForm: IndexingFormComponent;
lang: any = LANG;
indexingModel: any = {
id: 0,
label: '',
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
default: false,
owner: 0,
private: false
};
indexingModelClone: any;
indexingModelsCustomFields: any[] = [];
creationMode: boolean = true;
availableFields: any[] = [
{
identifier: 'priority',
label: this.lang.priority,
type: 'select',
values: []
},
{
identifier: 'confidential',
label: this.lang.confidential,
type: 'radio',
values: ['yes', 'no']
},
{
identifier: 'initiator',
label: this.lang.initiator,
type: 'select',
values: []
},
{
identifier: 'processLimitDate',
label: this.lang.processLimitDate,
type: 'date',
values: []
},
{
identifier: 'arrivalDate',
label: this.lang.arrivalDate,
type: 'date',
values: []
}
];
availableCustomFields: any[] = [];
categoriesList: any [];
constructor(
public http: HttpClient,
private route: ActivatedRoute,
private router: Router,
private notify: NotificationService,
public dialog: MatDialog,
private headerService: HeaderService,
public appService: AppService,
) {
}
ngOnInit(): void {
window['MainHeaderComponent'].setSnav(this.sidenavLeft);
window['MainHeaderComponent'].setSnavRight(this.sidenavRight);
this.route.params.subscribe((params) => {
if (typeof params['id'] == "undefined") {
this.creationMode = true;
this.headerService.setHeader(this.lang.indexingModelCreation);
this.http.get('../../rest/categories').pipe(
tap((data: any) => {
this.categoriesList = data.categories;
}),
finalize(() => this.loading = false),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
this.indexingModelClone = JSON.parse(JSON.stringify(this.indexingModel));
} else {
this.creationMode = false;
this.http.get("../../rest/indexingModels/" + params['id']).pipe(
tap((data: any) => {
this.indexingModel = data.indexingModel;
this.headerService.setHeader(this.lang.indexingModelModification, this.indexingModel.label);
this.indexingModelClone = JSON.parse(JSON.stringify(this.indexingModel));
}),
exhaustMap(() => this.http.get('../../rest/categories')),
tap((data: any) => {
this.categoriesList = data.categories;
}),
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
finalize(() => this.loading = false),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
}
});
}
onSubmit() {
this.indexingModel.fields = this.indexingForm.getDatas();
if (this.creationMode) {
this.http.post("../../rest/indexingModels", this.indexingModel).pipe(
tap((data: any) => {
this.indexingForm.setModification();
this.setModification();
this.router.navigate(['/administration/indexingModels']);
this.notify.success(this.lang.indexingModelAdded);
}),
finalize(() => this.loading = false),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
} else {
this.http.put("../../rest/indexingModels/" + this.indexingModel.id, this.indexingModel).pipe(
tap((data: any) => {
this.indexingForm.setModification();
this.setModification();
this.router.navigate(['/administration/indexingModels']);
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
this.notify.success(this.lang.indexingModelUpdated);
}),
finalize(() => this.loading = false),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
}
}
isModified() {
let compare: string = '';
let compareClone: string = '';
compare = JSON.stringify(this.indexingModel);
compareClone = JSON.stringify(this.indexingModelClone);
if (compare !== compareClone) {
return true;
} else {
return false;
}
}
setModification() {
this.indexingModelClone = JSON.parse(JSON.stringify(this.indexingModel));
}
changeCategory(ev: any) {
this.indexingForm.changeCategory(ev.value);
}