Newer
Older
import { Component, OnInit, QueryList, ViewChildren } from '@angular/core';

Alex ORLUC
committed
import { LANG } from '../translate.component';
import { MatDialog } from '@angular/material/dialog';
import { MatExpansionPanel } from '@angular/material/expansion';
import { MatTableDataSource } from '@angular/material/table';

Alex ORLUC
committed
import { NotificationService } from '../notification.service';
import { HeaderService } from '../../service/header.service';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { AppService } from '../../service/app.service';
import { Router } from '@angular/router';
declare var $: any;
templateUrl: 'home.component.html',
styleUrls: ['home.component.scss'],
providers: [AppService]
export class HomeComponent implements OnInit {
lang: any = LANG;
loading: boolean = false;
thumbnailUrl: string;
docUrl: string = '';
homeData: any;
homeMessage: string;
dataSource: any;
currentDate: string = '';
nbMpDocs: number = 0;
public innerHtml: SafeHtml;
displayedColumns: string[] = ['res_id', 'subject', 'creation_date'];
@ViewChildren(MatExpansionPanel) viewPanels: QueryList<MatExpansionPanel>;
public http: HttpClient,
public dialog: MatDialog,
private sanitizer: DomSanitizer,
private notify: NotificationService,
private headerService: HeaderService,
public appService: AppService,
private router: Router
(<any>window).pdfWorkerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.min.js';
if (this.appService.getViewMode()) {
this.displayedColumns = ['res_id', 'subject'];
}
const event = new Date();
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
this.currentDate = event.toLocaleDateString(this.lang.langISO, options);
this.http.get('../../rest/home')
.subscribe((data: any) => {
this.homeData = data;

Alex ORLUC
committed
this.homeMessage = data['homeMessage'];
}
ngAfterViewInit(): void {
this.http.get('../../rest/home/lastRessources')
.subscribe((data: any) => {
setTimeout(() => {
this.dataSource = new MatTableDataSource(data.lastResources);
this.loading = false;
}, 0);
});
viewDocument(row: any) {
window.open('../../rest/resources/' + row.res_id + '/content?mode=view', '_blank');
viewThumbnail(row: any) {
const timeStamp = +new Date();
this.thumbnailUrl = '../../rest/resources/' + row.res_id + '/thumbnail?tsp=' + timeStamp;
$('#viewThumbnail').show();
$('#listContent').css({ 'overflow': 'hidden' });
$('#viewThumbnail').hide();
$('#listContent').css({ 'overflow': 'auto' });
goToDetail(row: any) {
this.http.get('../../rest/resources/' + row.res_id + '/isAllowed')
.subscribe((data: any) => {
if (data['isAllowed']) {
this.router.navigate([`/resources/${row.res_id}`]);
} else {
this.notify.error(this.lang.documentOutOfPerimeter);
}
}, () => {
this.notify.error(this.lang.errorOccured);
});

Alex ORLUC
committed
updateNbMpDocs(ev: any) {
this.nbMpDocs = ev;
}