Newer
Older
import { Component, OnInit, ViewChild, EventEmitter, ViewContainerRef } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { LANG } from '../../translate.component';

Alex ORLUC
committed
import { merge, Observable, of as observableOf, Subject, of, Subscription } from 'rxjs';
import { NotificationService } from '../../notification.service';

Alex ORLUC
committed
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatPaginator } from '@angular/material/paginator';
import { MatSidenav } from '@angular/material/sidenav';
import { MatSort } from '@angular/material/sort';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

Alex ORLUC
committed
import { startWith, switchMap, map, catchError, takeUntil, tap, exhaustMap, filter } from 'rxjs/operators';
import { ActivatedRoute, Router } from '@angular/router';
import { HeaderService } from '../../../service/header.service';
import { Overlay } from '@angular/cdk/overlay';
import { PanelListComponent } from '../../list/panel/panel-list.component';
import { AppService } from '../../../service/app.service';
import { PanelFolderComponent } from '../panel/panel-folder.component';

Alex ORLUC
committed
import { BasketHomeComponent } from '../../basket/basket-home.component';
import { ConfirmComponent } from '../../../plugins/modal/confirm.component';
import { FolderActionListComponent } from '../folder-action-list/folder-action-list.component';
import { FiltersListService } from '../../../service/filtersList.service';

Alex ORLUC
committed
import { trigger, transition, style, animate } from '@angular/animations';
import { FoldersService } from '../folders.service';
declare function $j(selector: any): any;
@Component({
templateUrl: "folder-document-list.component.html",
styleUrls: ['folder-document-list.component.scss'],

Alex ORLUC
committed
providers: [NotificationService, AppService]
lang: any = LANG;
loading: boolean = false;
docUrl: string = '';
public innerHtml: SafeHtml;
basketUrl: string;
homeData: any;

Alex ORLUC
committed
injectDatasParam = {
resId: 0,
editable: false
};
currentResource: any = {};
filtersChange = new EventEmitter();
dragInit: boolean = true;

Alex ORLUC
committed
dialogRef: MatDialogRef<any>;
@ViewChild('snav', { static: true }) sidenavLeft: MatSidenav;
@ViewChild('snav2', { static: true }) sidenavRight: MatSidenav;
displayedColumnsBasket: string[] = ['resId'];
displayedMainData: any = [
{
'cssClasses': ['softColorData', 'align_centerData', 'chronoData'],
'icon': ''
},
{
'value': 'subject',
'cssClasses': ['longData'],
'icon': ''
}
];
resultListDatabase: ResultListHttpDao | null;
data: any;
resultsLength = 0;
isLoadingResults = true;
listProperties: any = {};
currentChrono: string = '';
currentMode: string = '';
thumbnailUrl: string = '';
allResInBasket: number[] = [];
selectedDiffusionTab: number = 0;

Alex ORLUC
committed
id: 0,
'label': '',
'ownerDisplayName': '',
'entitiesSharing': []

Alex ORLUC
committed
folderInfoOpened: boolean = false;
private destroy$ = new Subject<boolean>();

Alex ORLUC
committed
subscription: Subscription;
@ViewChild('actionsListContext', { static: true }) actionsList: FolderActionListComponent;
@ViewChild('appPanelList', { static: true }) appPanelList: PanelListComponent;
currentSelectedChrono: string = '';
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild('tableBasketListSort', { static: true }) sort: MatSort;

Alex ORLUC
committed
@ViewChild('panelFolder', { static: false }) panelFolder: PanelFolderComponent;
@ViewChild('basketHome', { static: true }) basketHome: BasketHomeComponent;

Alex ORLUC
committed
private router: Router,
private route: ActivatedRoute,
public http: HttpClient,
public dialog: MatDialog,
private sanitizer: DomSanitizer,
private headerService: HeaderService,

Alex ORLUC
committed
public filtersListService: FiltersListService,

Alex ORLUC
committed
private notify: NotificationService,
public overlay: Overlay,
public viewContainerRef: ViewContainerRef,
public appService: AppService,
private foldersService: FoldersService) {

Alex ORLUC
committed

Alex ORLUC
committed
$j("link[href='merged_css.php']").remove();

Alex ORLUC
committed
// Event after process action
this.subscription = this.foldersService.catchEvent().subscribe((result: any) => {
if (result.type === 'refreshFolderInformations') {
if(result.content.id == this.folderInfo.id) {
this.refreshFolderInformations();
}
}
});
this.loading = false;
this.isLoadingResults = false;
this.route.params.subscribe(params => {

Alex ORLUC
committed
this.folderInfoOpened = false;
this.dragInit = true;

Alex ORLUC
committed
this.http.get('../../rest/folders/' + params['folderId'])
.subscribe((data: any) => {
this.folderInfo =
{
'id': params['folderId'],
'label': data.folder.label,
'ownerDisplayName': data.folder.ownerDisplayName,
'entitiesSharing': data.folder.sharing.entities.map((entity: any) => entity.label),

Alex ORLUC
committed
};
this.foldersService.setFolder(this.folderInfo);
this.headerService.setHeader(this.folderInfo.label, '', 'fa fa-folder-open');

Alex ORLUC
committed
this.basketHome.togglePanel(false);

Alex ORLUC
committed

Alex ORLUC
committed
});
this.basketUrl = '../../rest/folders/' + params['folderId'] + '/resources';
this.filtersListService.filterMode = false;
this.selectedRes = [];
this.sidenavRight.close();
window['MainHeaderComponent'].setSnav(this.sidenavLeft);
window['MainHeaderComponent'].setSnavRight(null);
this.listProperties = this.filtersListService.initListsProperties(this.headerService.user.id, 0, params['folderId'], 'folder');
setTimeout(() => {
this.dragInit = false;
}, 1000);
this.initResultList();
},
(err: any) => {
this.notify.handleErrors(err);
});
}
ngOnDestroy() {
this.destroy$.next(true);

Alex ORLUC
committed
this.subscription.unsubscribe();
this.resultListDatabase = new ResultListHttpDao(this.http, this.filtersListService);
// If the user changes the sort order, reset back to the first page.
this.paginator.pageIndex = this.listProperties.page;
this.paginator.pageSize = this.listProperties.pageSize;
this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
// When list is refresh (sort, page, filters)
merge(this.sort.sortChange, this.paginator.page, this.filtersChange)
.pipe(
takeUntil(this.destroy$),
startWith({}),
switchMap(() => {
this.isLoadingResults = true;
return this.resultListDatabase!.getRepoIssues(
this.sort.active, this.sort.direction, this.paginator.pageIndex, this.basketUrl, this.filtersListService.getUrlFilters(), this.paginator.pageSize);
}),
map(data => {
// Flip flag to show that loading has finished.
this.isLoadingResults = false;
data = this.processPostData(data);

Alex ORLUC
committed
this.allResInBasket = data.allResources;
//this.headerService.setHeader('Dossier : ' + this.folderInfo.label);
return data.resources;
}),
catchError((err: any) => {
this.notify.handleErrors(err);
this.router.navigate(['/home']);
this.isLoadingResults = false;
return observableOf([]);
})
).subscribe(data => this.data = data);
}
goTo(row: any) {
this.filtersListService.filterMode = false;
if (this.docUrl == '../../rest/resources/' + row.resId + '/content' && this.sidenavRight.opened) {
this.sidenavRight.close();
} else {
this.docUrl = '../../rest/resources/' + row.resId + '/content';
this.currentChrono = row.chrono;
this.innerHtml = this.sanitizer.bypassSecurityTrustHtml(
"<iframe style='height:100%;width:100%;' src='" + this.docUrl + "' class='embed-responsive-item'>" +
"</iframe>");
this.sidenavRight.open();
}
}
goToDetail(row: any) {
location.href = "index.php?page=details&dir=indexing_searching&id=" + row.resId;
}
togglePanel(mode: string, row: any) {

Alex ORLUC
committed
let thisSelect = { checked: true };
let thisDeselect = { checked: false };
row.checked = true;
this.toggleAllRes(thisDeselect);
this.toggleRes(thisSelect, row);
if (this.currentResource.resId == row.resId && this.sidenavRight.opened && this.currentMode == mode) {
this.sidenavRight.close();
} else {
this.currentMode = mode;
this.currentResource = row;
this.appPanelList.loadComponent(mode, row);
this.sidenavRight.open();
}
}
refreshBadgeNotes(nb: number) {
this.currentResource.countNotes = nb;

Alex ORLUC
committed
}

Alex ORLUC
committed
refreshFolderInformations() {
this.http.get('../../rest/folders/' + this.folderInfo.id)
.subscribe((data: any) => {
this.folderInfo =
{
'id': data.folder.id,
'label': data.folder.label,
'ownerDisplayName': data.folder.ownerDisplayName,
'entitiesSharing': data.folder.sharing.entities.map((entity: any) => entity.label),
};
this.headerService.setHeader(this.folderInfo.label, '', 'fa fa-folder-open');
});
}
refreshBadgeAttachments(nb: number) {
this.currentResource.countAttachments = nb;
}
refreshDao() {
this.paginator.pageIndex = this.listProperties.page;
this.filtersChange.emit();
}

Alex ORLUC
committed
refreshDaoAfterAction() {
this.sidenavRight.close();
this.refreshDao();
const e: any = { checked: false };
this.toggleAllRes(e);
}
Guillaume Heurtier
committed
if (row.hasDocument) {
this.thumbnailUrl = '../../rest/resources/' + row.resId + '/thumbnail';
$j('#viewThumbnail').show();
$j('#listContent').css({"overflow": "hidden"});
}
}
closeThumbnail() {
$j('#viewThumbnail').hide();
$j('#listContent').css({ "overflow": "auto" });
}
processPostData(data: any) {
data.resources.forEach((element: any) => {
// Process main datas
Object.keys(element).forEach((key) => {
if (key == 'statusImage' && element[key] == null) {
element[key] = 'fa-question undefined';
Guillaume Heurtier
committed
} else if ((element[key] == null || element[key] == '') && ['closingDate', 'countAttachments', 'countNotes', 'display', 'mailTracking', 'hasDocument'].indexOf(key) === -1) {
element[key] = this.lang.undefined;
}
});
element['checked'] = this.selectedRes.indexOf(element['resId']) !== -1;
return data;
}
toggleRes(e: any, row: any) {
if (e.checked) {
if (this.selectedRes.indexOf(row.resId) === -1) {
this.selectedRes.push(row.resId);
row.checked = true;
}
} else {
let index = this.selectedRes.indexOf(row.resId);
this.selectedRes.splice(index, 1);
row.checked = false;
}
}
toggleAllRes(e: any) {
this.selectedRes = [];
if (e.checked) {
this.data.forEach((element: any) => {
element['checked'] = true;
});
this.selectedRes = JSON.parse(JSON.stringify(this.allResInBasket));
} else {
this.data.forEach((element: any) => {
element['checked'] = false;
});
}
}
selectSpecificRes(row: any) {

Alex ORLUC
committed
let thisSelect = { checked: true };
let thisDeselect = { checked: false };
this.toggleAllRes(thisDeselect);
this.toggleRes(thisSelect, row);
}
open({ x, y }: MouseEvent, row: any) {

Alex ORLUC
committed
let thisSelect = { checked: true };
let thisDeselect = { checked: false };
if (row.checked === false) {
row.checked = true;
this.toggleAllRes(thisDeselect);
this.toggleRes(thisSelect, row);
}
this.actionsList.open(x, y, row)
// prevents default
return false;

Alex ORLUC
committed
listTodrag() {
return this.foldersService.getDragIds();

Alex ORLUC
committed
}
toggleMailTracking(row: any) {
if (!row.mailTracking) {
this.http.post('../../rest/resources/follow', {resources: [row.resId]}).pipe(
tap(() => this.headerService.addFollowedDocument()),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
} else {
this.http.request('DELETE', '../../rest/resources/unfollow', { body: { resources: [row.resId] } }).pipe(
tap(() => this.headerService.removeFollowedDocument()),
catchError((err: any) => {
this.notify.handleErrors(err);
return of(false);
})
).subscribe();
}
row.mailTracking = !row.mailTracking;
}
Guillaume Heurtier
committed
viewDocument(row: any) {
window.open("../../rest/resources/" + row.resId + "/content?mode=view", "_blank");
}
}
export interface BasketList {

Alex ORLUC
committed
allResources: number[];
}
export class ResultListHttpDao {
constructor(private http: HttpClient, private filtersListService: FiltersListService) { }
getRepoIssues(sort: string, order: string, page: number, href: string, filters: string, pageSize: number): Observable<BasketList> {
this.filtersListService.updateListsPropertiesPage(page);
this.filtersListService.updateListsPropertiesPageSize(pageSize);
let offset = page * pageSize;
const requestUrl = `${href}?limit=${pageSize}&offset=${offset}${filters}`;
return this.http.get<BasketList>(requestUrl);
}
}