Skip to content
Snippets Groups Projects
home.component.ts 3.67 KiB
Newer Older
  • Learn to ignore specific revisions
  • Florian Azizian's avatar
    Florian Azizian committed
    import { ChangeDetectorRef, Component, OnInit, ViewChild, QueryList, ViewChildren } 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';
    
    Florian Azizian's avatar
    Florian Azizian committed
    import { NotificationService } from './notification.service';
    
    import { MatDialog, MatSidenav, MatExpansionPanel, MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
    
    Florian Azizian's avatar
    Florian Azizian committed
    
    import { AutoCompletePlugin } from '../plugins/autocomplete.plugin';
    
    import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
    
    import { startWith, switchMap, map, catchError } from 'rxjs/operators';
    
    Florian Azizian's avatar
    Florian Azizian committed
    
    declare function $j(selector: any): any;
    
    declare var angularGlobals: any;
    
    @Component({
        templateUrl: "../../../Views/home.component.html",
        styleUrls: ['../../../css/profile.component.css'],
        providers: [NotificationService]
    })
    export class HomeComponent extends AutoCompletePlugin implements OnInit {
    
        private _mobileQueryListener: () => void;
        mobileQuery: MediaQueryList;
    
    Florian Azizian's avatar
    Florian Azizian committed
        mobileMode: boolean   = false;
    
    Florian Azizian's avatar
    Florian Azizian committed
        coreUrl: string;
        lang: any = LANG;
    
        loading: boolean = false;
    
        docUrl : string = '';
        public innerHtml: SafeHtml;
    
    Florian Azizian's avatar
    Florian Azizian committed
    
    
        @ViewChild('snav') snav: MatSidenav;
        @ViewChild('snav2') sidenavRight: MatSidenav;
        
    
    Florian Azizian's avatar
    Florian Azizian committed
    
        @ViewChildren(MatExpansionPanel) viewPanels: QueryList<MatExpansionPanel>;
        homeData: any;
    
        dataSource: any;
        displayedColumns: string[] = ['res_id', 'subject', 'creation_date'];
    
    Florian Azizian's avatar
    Florian Azizian committed
    
    
        currentDate : string = "";
    
    
        constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, public dialog: MatDialog, private sanitizer: DomSanitizer) {
    
    Florian Azizian's avatar
    Florian Azizian committed
            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);
        }
    
        ngOnInit(): void {
    
            if (this.mobileMode) {
                this.displayedColumns = ['res_id', 'subject'];
            }
    
    
            window['MainHeaderComponent'].refreshTitle(this.lang.home);
            window['MainHeaderComponent'].setSnav(this.snav);
    
            window['MainHeaderComponent'].setSnavRight(null);
    
    Florian Azizian's avatar
    Florian Azizian committed
            this.coreUrl = angularGlobals.coreUrl;
    
            let event = new Date();
            let options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
    
            this.currentDate = event.toLocaleDateString('fr-FR', options);
    
    Florian Azizian's avatar
    Florian Azizian committed
            this.loading = false;
    
            this.http.get(this.coreUrl + "rest/home")
            .subscribe((data: any) => {
                this.homeData = data;
                this.loading = false;
    
                setTimeout(() => {
                    this.dataSource = new MatTableDataSource(this.homeData.lastResources);
                }, 0);
    
        goTo(row:any){
    
            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(
                    "<object style='height:100%;width:100%;' data='" + this.docUrl + "' type='application/pdf' class='embed-responsive-item'>" +
                    "<div>Le document "+row.res_id+" ne peut pas être chargé</div>" +
                    "</object>");  
    
                this.sidenavRight.open();
    
            }
        }
    
        goToDetail(row:any){
            location.href = "index.php?page=details&dir=indexing_searching&id="+row.res_id;
        }