Newer
Older
import { Component, OnInit, ViewChild, 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 { MatSidenav } from '@angular/material/sidenav';
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';
declare function $j(selector: any): any;
@Component({
styleUrls: ['home.component.scss'],
providers: [NotificationService, AppService]
export class HomeComponent implements OnInit {
lang : any = LANG;
loading : boolean = false;
thumbnailUrl : string;
docUrl : string = '';
homeData : any;
homeMessage : string;
dataSource : any;
currentDate : string = "";

Alex ORLUC
committed
nbMpDocs : number = 0;
public innerHtml : SafeHtml;
displayedColumns : string[] = ['res_id', 'subject', 'creation_date'];
@ViewChild('snav', { static: true }) snav: MatSidenav;
@ViewChild('snav2', { static: true }) sidenavRight: MatSidenav;
@ViewChildren(MatExpansionPanel) viewPanels: QueryList<MatExpansionPanel>;
constructor(
public http: HttpClient,
public dialog: MatDialog,
private sanitizer: DomSanitizer,
private notify: NotificationService,
private headerService: HeaderService,
public appService: AppService
) {
(<any>window).pdfWorkerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.min.js';
if (this.appService.getViewMode()) {
this.displayedColumns = ['res_id', 'subject'];
}
window['MainHeaderComponent'].setSnav(this.snav);
window['MainHeaderComponent'].setSnavRight(null);
let event = new Date();
let 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) => {
this.dataSource = new MatTableDataSource(data.lastResources);
this.loading = false;
viewDocument(row: any) {
window.open("../../rest/resources/" + row.res_id + "/content?mode=view", "_blank");
this.thumbnailUrl = '../../rest/resources/' + row.res_id + '/thumbnail';

Alex ORLUC
committed
$j('#listContent').css({"overflow":"hidden"});
}
closeThumbnail() {
$j('#viewThumbnail').hide();

Alex ORLUC
committed
$j('#listContent').css({"overflow":"auto"});
goToDetail(row:any) {
this.http.get("../../rest/resources/" + row.res_id + "/isAllowed")
.subscribe((data: any) => {
if (data['isAllowed']) {
location.href = "index.php?page=details&dir=indexing_searching&id=" + 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;
}