Newer
Older
import { Component, OnInit, Input, ViewChild, Output, EventEmitter } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { NotificationService } from '@service/notification/notification.service';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatMenuTrigger } from '@angular/material/menu';
import { Router } from '@angular/router';
import { ConfirmComponent } from '../../../plugins/modal/confirm.component';
import { filter, exhaustMap, tap, map, catchError } from 'rxjs/operators';
import { HeaderService } from '@service/header.service';

Alex ORLUC
committed
import { FoldersService } from '../folders.service';

Hamza HRAMCHI
committed
import { PrivilegeService } from '@service/privileges.service';
@Component({
selector: 'app-folder-action-list',
templateUrl: 'folder-action-list.component.html',
styleUrls: ['folder-action-list.component.scss'],
})
export class FolderActionListComponent implements OnInit {
loading: boolean = false;
@ViewChild(MatMenuTrigger, { static: false }) contextMenu: MatMenuTrigger;
@Output() triggerEvent = new EventEmitter<string>();
contextMenuPosition = { x: '0px', y: '0px' };
contextMenuTitle = '';
currentAction: any = {};
basketInfo: any = {};
contextResId = 0;
currentLock: any = null;
arrRes: any[] = [];

Hamza HRAMCHI
committed
isSelectedFreeze: any;
isSelectedBinding: any;

Alex ORLUC
committed
basketList: any = {
groups: [],
list: []
};
@Input() selectedRes: any;
@Input() totalRes: number;
@Input() contextMode: boolean;
@Input() currentFolderInfo: any;

Hamza HRAMCHI
committed
@Input('currentResource') currentResource: any = {};
@Output() refreshEvent = new EventEmitter<string>();
@Output() refreshPanelFolders = new EventEmitter<string>();

Alex ORLUC
committed
constructor(
public translate: TranslateService,
public http: HttpClient,
private notify: NotificationService,
public dialog: MatDialog,

Alex ORLUC
committed
private router: Router,

Alex ORLUC
committed
private headerService: HeaderService,

Hamza HRAMCHI
committed
private foldersService: FoldersService,
public privilegeService: PrivilegeService,
ngOnInit(): void { }
open(x: number, y: number, row: any) {
// Adjust the menu anchor position
this.contextMenuPosition.x = x + 'px';
this.contextMenuPosition.y = y + 'px';

Hamza HRAMCHI
committed
this.getFreezeBindingValue(this.contextResId);
this.contextMenuTitle = row.chrono;
this.contextResId = row.resId;

Hamza HRAMCHI
committed
this.currentResource = row;
// Opens the menu
this.contextMenu.openMenu();
// prevents default
return false;
}
refreshFolders() {
}
refreshDaoAfterAction() {
this.refreshEvent.emit();
}
unclassify() {
this.dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.delete'), msg: 'Voulez-vous enlever <b>' + this.selectedRes.length + '</b> document(s) du classement ?' } });
this.dialogRef.afterClosed().pipe(
filter((data: string) => data === 'ok'),
exhaustMap(() => this.http.request('DELETE', '../rest/folders/' + this.currentFolderInfo.id + '/resources', { body: { resources: this.selectedRes } })),
this.notify.success(this.translate.instant('lang.removedFromFolder'));

Alex ORLUC
committed
this.foldersService.getPinnedFolders();
}),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
return of(false);

Alex ORLUC
committed
getBaskets() {

Florian Azizian
committed
this.http.get('../rest/resources/' + this.selectedRes + '/baskets').pipe(

Alex ORLUC
committed
tap((data: any) => {
this.basketList.groups = data.groupsBaskets.filter((x: any, i: any, a: any) => x && a.map((info: any) => info.groupId).indexOf(x.groupId) === i);
this.basketList.list = data.groupsBaskets;
}),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
return of(false);

Alex ORLUC
committed
})
).subscribe();
}
goTo(basket: any) {
if (this.contextMenuTitle !== this.translate.instant('lang.undefined')) {
this.router.navigate(['/basketList/users/' + this.headerService.user.id + '/groups/' + basket.groupId + '/baskets/' + basket.basketId], { queryParams: { chrono: '"' + this.contextMenuTitle + '"' } });
} else {
this.router.navigate(['/basketList/users/' + this.headerService.user.id + '/groups/' + basket.groupId + '/baskets/' + basket.basketId]);
}

Alex ORLUC
committed
}
unFollow() {
this.dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.delete'), msg: this.translate.instant('lang.stopFollowingAlert') } });
this.dialogRef.afterClosed().pipe(
filter((data: string) => data === 'ok'),
exhaustMap(() => this.http.request('DELETE', '../rest/resources/unfollow', { body: { resources: this.selectedRes } })),
tap((data: any) => {
this.notify.success(this.translate.instant('lang.removedFromFolder'));
this.headerService.nbResourcesFollowed -= data.unFollowed;
this.refreshDaoAfterAction();
}),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
return of(false);
})
).subscribe();
}

Hamza HRAMCHI
committed
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
toggleFreezing(value) {
this.http.put('../rest/archival/freezeRetentionRule', { resources: this.selectedRes, freeze : value }).pipe(
tap(() => {
if (value) {
this.notify.success(this.translate.instant('lang.retentionRuleFrozen'));
} else {
this.notify.success(this.translate.instant('lang.retentionRuleThawed'));
}
}
),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
return of(false);
})
).subscribe();
}
toogleBinding(value) {
this.http.put('../rest/archival/binding', { resources: this.selectedRes, binding : value }).pipe(
tap(() => {
if (value) {
this.notify.success(this.translate.instant('lang.bindingMail'));
} else if (value === false) {
this.notify.success(this.translate.instant('lang.noBindingMal'));
} else {
this.notify.success(this.translate.instant('lang.bindingUndefined'));
}
}
),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
return of(false);
})
).subscribe();
}

Hamza HRAMCHI
committed
getFreezeBindingValue(id) {
this.http.get(`../rest/resources/${id}?light=true`).pipe(
tap((infos: any) => {
this.isSelectedFreeze = infos.retentionFrozen;
this.isSelectedBinding = infos.binding;

Hamza HRAMCHI
committed
}),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
}