Newer
Older
import { ChangeDetectorRef, Component, OnInit, ViewChild, QueryList, ViewChildren } from '@angular/core';
import { MediaMatcher } from '@angular/cdk/layout';
import { HttpClient } from '@angular/common/http';

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

Alex ORLUC
committed
import { NotificationService } from '../notification.service';
import { HeaderService } from '../../service/header.service';

Alex ORLUC
committed
import { AutoCompletePlugin } from '../../plugins/autocomplete.plugin';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
declare function $j(selector: any): any;
declare var angularGlobals: any;
@Component({
styleUrls: ['home.component.scss'],
providers: [NotificationService]
})
export class HomeComponent extends AutoCompletePlugin implements OnInit {
private _mobileQueryListener : () => void;
mobileQuery : MediaQueryList;
mobileMode : boolean = false;
coreUrl : string;
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') snav: MatSidenav;
@ViewChild('snav2') sidenavRight: MatSidenav;
@ViewChildren(MatExpansionPanel) viewPanels: QueryList<MatExpansionPanel>;
constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, public dialog: MatDialog, private sanitizer: DomSanitizer, private notify: NotificationService, private headerService: HeaderService) {
super(http, ['users']);
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);
(<any>window).pdfWorkerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.min.js';
if (this.mobileMode) {
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('fr-FR', options);
.subscribe((data: any) => {
this.homeData = data;

Alex ORLUC
committed
this.homeMessage = data['homeMessage'];
});
}
ngAfterViewInit(): void {
this.http.get(this.coreUrl + "rest/home/lastRessources")
.subscribe((data: any) => {
this.dataSource = new MatTableDataSource(data.lastResources);
this.loading = 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';

Alex ORLUC
committed
this.innerHtml = this.sanitizer.bypassSecurityTrustHtml(
"<iframe style='height:100%;width:100%;' src='" + this.docUrl + "' class='embed-responsive-item'>" +
"</iframe>");
this.sidenavRight.open();

Alex ORLUC
committed
this.thumbnailUrl = this.coreUrl+'rest/res/' + 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(this.coreUrl + "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;
}