Newer
Older
import { ChangeDetectorRef, Component, OnInit, ViewChild, EventEmitter, ComponentFactoryResolver } from '@angular/core';
import { MediaMatcher } from '@angular/cdk/layout';
import { HttpClient } from '@angular/common/http';
import { LANG } from '../translate.component';
import { merge, Observable, of as observableOf } from 'rxjs';
import { NotificationService } from '../notification.service';
import { MatDialog, MatSidenav, MatPaginator, MatSort, MatBottomSheet } from '@angular/material';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { startWith, switchMap, map, catchError } from 'rxjs/operators';
import { ActivatedRoute, Router } from '@angular/router';
import { HeaderService } from '../../service/header.service';
import { FiltersListService } from '../../service/filtersList.service';
import { NotesListComponent } from '../notes/notes.component';
import { AttachmentsListComponent } from '../attachments/attachments-list.component';
import { DiffusionsListComponent } from '../diffusions/diffusions-list.component';
import { FiltersToolComponent } from './filters/filters-tool.component';
import { ActionsListComponent } from '../actions/actions-list.component';
declare function $j(selector: any): any;
declare var angularGlobals: any;
@Component({
templateUrl: "basket-list.component.html",
styleUrls: ['basket-list.component.scss'],
providers: [NotificationService],
})
export class BasketListComponent implements OnInit {
private _mobileQueryListener: () => void;
mobileQuery: MediaQueryList;
coreUrl: string;
lang: any = LANG;
loading: boolean = false;
public innerHtml: SafeHtml;
basketUrl: string;
homeData: any;
@ViewChild('snav') sidenavLeft: MatSidenav;
@ViewChild('snav2') sidenavRight: MatSidenav;
displayedColumnsBasket: string[] = ['res_id'];
displayedMainData: any = [
{
'value': 'alt_identifier',
'cssClasses': ['softColorData', 'align_centerData', 'chronoData'],
'value': 'subject',
'cssClasses': ['longData'],
displayedSecondaryData: any = [];
resultListDatabase: ResultListHttpDao | null;
resultsLength = 0;
isLoadingResults = true;
selectedRes: number[] = [];
allResInBasket: number[] = [];
@ViewChild('filtersTool') filtersTool: FiltersToolComponent;
@ViewChild('actionsList') actionsList: ActionsListComponent;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild('tableBasketListSort') sort: MatSort;
constructor(changeDetectorRef: ChangeDetectorRef, private router: Router, private route: ActivatedRoute, media: MediaMatcher, public http: HttpClient, public dialog: MatDialog, private sanitizer: DomSanitizer, private bottomSheet: MatBottomSheet, private headerService: HeaderService, public filtersListService: FiltersListService, private notify: NotificationService, private componentFactoryResolver: ComponentFactoryResolver) {
this.mobileMode = angularGlobals.mobileMode;
$j("link[href='merged_css.php']").remove();
this.mobileQuery = media.matchMedia('(max-width: 768px)');
this._mobileQueryListener = () => changeDetectorRef.detectChanges();
this.mobileQuery.addListener(this._mobileQueryListener);
}
ngOnInit(): void {
this.coreUrl = angularGlobals.coreUrl;
this.loading = false;
$j('.mat-paginator-navigation-previous').hide();
$j('.mat-paginator-navigation-next').hide();
this.http.get(this.coreUrl + "rest/home")
.subscribe((data: any) => {
this.homeData = data;
});
this.route.params.subscribe(params => {
this.basketUrl = '../../rest/resourcesList/users/' + params['userSerialId'] + '/groups/' + params['groupSerialId'] + '/baskets/' + params['basketId'];
this.currentBasketInfo = {
ownerId: params['userSerialId'],
groupId: params['groupSerialId'],
basketId: params['basketId']
};
this.filtersListService.filterMode = false;
window['MainHeaderComponent'].setSnav(this.sidenavLeft);
window['MainHeaderComponent'].setSnavRight(null);
this.listProperties = this.filtersListService.initListsProperties(this.currentBasketInfo.ownerId, this.currentBasketInfo.groupId, this.currentBasketInfo.basketId);
(err: any) => {
this.notify.handleErrors(err);
});
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.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
// When list is refresh (sort, page, filters)
merge(this.sort.sortChange, this.paginator.page, this.filtersChange)
.pipe(
startWith({}),
switchMap(() => {
this.isLoadingResults = true;
return this.resultListDatabase!.getRepoIssues(
this.sort.active, this.sort.direction, this.paginator.pageIndex, this.basketUrl, this.filtersListService.getUrlFilters());
}),
map(data => {
// Flip flag to show that loading has finished.
this.isLoadingResults = false;
data = this.processPostData(data);
this.resultsLength = data.count;
this.allResInBasket = data.allResources;
this.headerService.setHeader(data.basketLabel, this.resultsLength + ' ' + this.lang.entries);
return data.resources;
}),
this.notify.handleErrors(err);
this.router.navigate(['/home']);
this.isLoadingResults = false;
return observableOf([]);
})
).subscribe(data => this.data = data);
this.filtersListService.filterMode = false;
if (this.docUrl == this.coreUrl + 'rest/res/' + row.res_id + '/content' && this.sidenavRight.opened) {
this.sidenavRight.close();
} else {
this.docUrl = this.coreUrl + 'rest/res/' + row.res_id + '/content';
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.res_id;
}
openBottomSheet(row: any): void {
this.bottomSheet.open(NotesListComponent, {
data: { resId: row.res_id, chrono: row.alt_identifier },
panelClass: 'note-width-bottom-sheet'
});
}
openAttachSheet(row: any): void {
this.bottomSheet.open(AttachmentsListComponent, {
data: { resId: row.res_id, chrono: row.alt_identifier },
});
this.bottomSheet.open(DiffusionsListComponent, {
data: { resId: row.res_id, chrono: row.alt_identifier },
});
}
this.paginator.pageIndex = this.listProperties.page;
filterThis(value: string) {
this.filtersTool.setInputSearch(value);
}
viewThumbnail(row: any) {
this.thumbnailUrl = this.coreUrl + 'rest/res/' + row.res_id + '/thumbnail';
$j('#listContent').css({ "overflow": "hidden" });
}
closeThumbnail() {
$j('#viewThumbnail').hide();
$j('#listContent').css({ "overflow": "auto" });
}
processPostData(data: any) {
this.displayedSecondaryData = [];
data.resources.forEach((element: any) => {
Object.keys(element).forEach((key) => {
if (key == 'statusImage' && element[key] == null) {
element[key] = 'fa-question undefined';
} else if ((element[key] == null || element[key] == '') && ['closingDate', 'countAttachments', 'countNotes', 'display'].indexOf(key) === -1) {
element[key] = this.lang.undefined;
// Process secondary datas
element.display.forEach((key: any) => {
key.displayTitle = key.displayValue;
if ((key.displayValue == null || key.displayValue == '') && ['getCreationAndProcessLimitDates', 'getParallelOpinionsNumber'].indexOf(key.value) === -1) {
key.displayValue = this.lang.undefined;
key.displayTitle = '';
} else if (["getSenders", "getRecipients"].indexOf(key.value) > -1) {
if (key.displayValue.length > 1) {
key.displayTitle = key.displayValue.join(' - ');
key.displayValue = '<b>' + key.displayValue.length + '</b> ' + this.lang.contacts;
key.displayValue = key.displayValue[0];
} else if (key.value == 'getCreationAndProcessLimitDates') {
} else if (key.value == 'getVisaWorkflow') {
let formatWorkflow: any = [];
let content = '';
let user = '';
let displayTitle: string[] = [];
key.displayValue.forEach((visa: any, key: number) => {
content = '';
user = visa.user;
displayTitle.push(user);
user = '<u>' + user + '</u>';
}
content = '<i class="fa fa-hourglass-half"></i> <span title="' + this.lang[visa.mode + 'User'] + '">' + user + '</span>';
content = '<span color="accent" style=""><i class="fa fa-check"></i> <span title="' + this.lang[visa.mode + 'User'] + '">' + user + '</span></span>';
content = '<b color="primary">' + content + '</b>';
}
//TRUNCATE DISPLAY LIST
const index = key.displayValue.map((e: any) => { return e.current; }).indexOf(true);
if (index > 0) {
formatWorkflow = formatWorkflow.slice(index - 1);
formatWorkflow = formatWorkflow.reverse();
formatWorkflow = formatWorkflow.slice((formatWorkflow.length - index) - 1);
formatWorkflow = formatWorkflow.reverse();
} else if (index === -1) {
formatWorkflow = formatWorkflow.slice(formatWorkflow.length - 2);
}
if (index >= 2 || (index == -1 && key.displayValue.length >= 3)) {
formatWorkflow.unshift('...');
}
if (index != -1 && index - 2 <= key.displayValue.length && key.displayValue.length >= 3) {
formatWorkflow.push('...');
}
key.displayValue = formatWorkflow.join(' <i class="fas fa-long-arrow-alt-right"></i> ');
key.displayTitle = displayTitle.join(' - ');
} else if (key.value == 'getSignatories') {
let userList: any[] = [];
key.displayValue.forEach((visa: any) => {
userList.push(visa.user);
});
key.displayValue = userList.join(', ');
key.displayTitle = userList.join(', ');
} else if (key.value == 'getParallelOpinionsNumber') {
key.displayTitle = key.displayValue + ' ' + this.lang.opinionsSent;
if (key.displayValue > 0) {
key.displayValue = '<b color="primary">' + key.displayValue + '</b> ' + this.lang.opinionsSent;
} else {
key.displayValue = key.displayValue + ' ' + this.lang.opinionsSent;
}
key.label = this.lang[key.value];
if (this.selectedRes.indexOf(element['res_id']) === -1) {
element['checked'] = false;
} else {
element['checked'] = true;
}
toggleRes(e: any, resId: any) {
if (e.checked) {
if (this.selectedRes.indexOf(resId) === -1) {
this.selectedRes.push(resId);
}
} else {
let index = this.selectedRes.indexOf(resId);
this.selectedRes.splice(index, 1);
}
}
toggleAllRes(e: any) {
this.selectedRes = [];
if (e.checked) {
this.data.forEach((element: any) => {
element['checked'] = true;
});
this.selectedRes = this.allResInBasket;
} else {
this.data.forEach((element: any) => {
element['checked'] = false;
});
}
}
launchEvent() {
/* FOR TEST */
let action = 'confirmAction';
try {
this.actionsList[action]();
}
catch (error) {
alert("L'action n'existe pas!");
}
}
export interface BasketList {
resources: any[];
basketLabel: string,
allResources: number[]
export class ResultListHttpDao {
constructor(private http: HttpClient, private filtersListService: FiltersListService) { }
getRepoIssues(sort: string, order: string, page: number, href: string, filters: string): Observable<BasketList> {
this.filtersListService.updateListsPropertiesPage(page);
let offset = page * 10;
const requestUrl = `${href}?limit=10&offset=${offset}${filters}`;
return this.http.get<BasketList>(requestUrl);
}