Commit 550c52df authored by Jie Yuan's avatar Jie Yuan
Browse files

add sitename and source info within sidebar

parent 82e35cc8
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -12,18 +12,19 @@
  <mat-form-field>
  <mat-label>------DPMT------</mat-label>
  <mat-select>
    <mat-option *ngFor="let name of dpmtSiteNames" [value]="name" (click)="onSiteNameSelected(name)">
      {{name}}
    <mat-option *ngFor="let dpmtsite of dpmtSiteNameAndSources"  (click)="onSiteNameAndSourceSelected(dpmtsite)">
      {{dpmtsite.siteName}}
    </mat-option>
  </mat-select>
</mat-form-field>
</div >

  <div class="form-div">
  <mat-form-field>
  <mat-label>------GOCDB------</mat-label>
  <mat-select>
    <mat-option *ngFor="let namegoc of gocdbSiteNames" [value]="namegoc"(click)="onSiteNameSelected(namegoc)">
      {{namegoc}}
    <mat-option *ngFor="let gocdbsite of gocdbSiteNameAndSources" (click)="onSiteNameAndSourceSelected(gocdbsite)">
      {{gocdbsite.siteName}}
    </mat-option>
  </mat-select>
</mat-form-field>
@@ -33,8 +34,8 @@
  <mat-form-field>
  <mat-label>------EOSC------</mat-label>
  <mat-select>
    <mat-option *ngFor="let name2 of eoscSiteNames" [value]="name2" (click)="onSiteNameSelected(name2)">
      {{name2}}
    <mat-option *ngFor="let asite of eoscSiteNameAndSources"  (click)="onSiteNameAndSourceSelected(asite)">
      {{asite.siteName + "--" + asite.siteSource}}
    </mat-option>
  </mat-select>
</mat-form-field>
@@ -51,7 +52,7 @@

  <span class="example-fill-remaining-space"></span>

  <button class="menu-button" mat-button [matMenuTriggerFor]="menusite">Site</button>
  <button class="menu-button" mat-button [matMenuTriggerFor]="menusite">Sites</button>
<mat-menu  #menusite="matMenu">
  <button mat-menu-item  (click)="onClickSite('dpmt')">DPMT</button>
  <button mat-menu-item (click)="onClickSite('gocdb')">GOCDB</button>
@@ -59,7 +60,7 @@
</mat-menu> 

&nbsp; &nbsp;
<button class="menu-button" mat-button [matMenuTriggerFor]="menuservice">Service</button>
<button class="menu-button" mat-button [matMenuTriggerFor]="menuservice">Services</button>
<mat-menu #menuservice="matMenu">
  <button mat-menu-item (click)="onClickService('dpmt')">DPMT</button>
  <button mat-menu-item (click)="onClickService('gocdb')">GOCDB</button>
+86 −73
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import {ActivatedRoute, Router} from '@angular/router';
import {Site} from '../../model/site';
import {SiteService} from '../../site.service';
import { AuthService } from 'src/app/auth.service';
import {SitenameAndSource} from '../../model/sitenameAndSource';

import { MatIconRegistry } from "@angular/material/icon";
import { DomSanitizer } from "@angular/platform-browser";
@@ -19,9 +20,11 @@ export class SiteComponent implements OnInit, OnDestroy {
  siteUpdateSubscription: Subscription;
  sidebarOpen: boolean = true;
  hasHosts: boolean  = false;
  eoscSiteNames: string[];
  gocdbSiteNames: string[];
  dpmtSiteNames: string[];
 
  eoscSiteNameAndSources: SitenameAndSource[];
  dpmtSiteNameAndSources: SitenameAndSource[];
  gocdbSiteNameAndSources: SitenameAndSource[];

  shorthomeUrl: string;
  shortgiisUrl: string;
  previousView: string;
@@ -54,11 +57,9 @@ export class SiteComponent implements OnInit, OnDestroy {
    this.siteUpdateSubscription = this.siteService.siteSubscription.subscribe(
      (newSite: Site) => {
        this.site = newSite;

       
      }
    );
    this.setNameLists();
    this.setNameSourceLists();
    console.log('site view constructed');
  }

@@ -80,8 +81,6 @@ export class SiteComponent implements OnInit, OnDestroy {
      this.shortgiisUrl = this.site.giisUrl;
    }



  }

  ngOnDestroy() {
@@ -99,39 +98,49 @@ export class SiteComponent implements OnInit, OnDestroy {
        this.router.navigate(['/dashboard/fullTableComponent'], { relativeTo: this.route });
      }
  }

  sidenavtoggle(){
    this.sidebarOpen = ! this.sidebarOpen;
  }

  setNameLists(){
    this.setNameListsFromSource('dpmt');
    this.setNameListsFromSource('gocdb');
    this.setNameListsFromSource('eosc');


  setNameSourceLists(){
    //this.setNameListsFromSource('dpmt');
    //this.setNameListsFromSource('gocdb');
    this.setNameAndSourceListsFromSource('dpmt');
    this.setNameAndSourceListsFromSource('gocdb');
    this.setNameAndSourceListsFromSource('eosc');
  }

  setNameListsFromSource(source: string){
    const stmp = 'JsonSiteNameList' + source.toUpperCase();

 



    setNameAndSourceListsFromSource(source: string){
      const stmp = 'JsonSiteNameSourceList' + source.toUpperCase();
      const ltmp = sessionStorage.getItem(stmp) ;
      if( ltmp !== null) {
          const ldata = JSON.parse(ltmp);
          if ( source === 'dpmt') {
          this.dpmtSiteNames = ldata;
            this.dpmtSiteNameAndSources = ldata;
          } else if (source === 'gocdb') {
          this.gocdbSiteNames = ldata;
            this.gocdbSiteNameAndSources = ldata;
          } else if (source === 'eosc') {
          this.eoscSiteNames = ldata;
            this.eoscSiteNameAndSources = ldata;
          }
      } else {
      this.siteService.getSiteNameListFromSource(source)
            .then((ldata: string[]) => {
        this.siteService.getSiteNameAndSourceListFromSource(source)
              .then((ldata: SitenameAndSource[]) => {
                if ( source === 'dpmt') {
                this.dpmtSiteNames = ldata;
                  this.dpmtSiteNameAndSources = ldata;
                } else if (source === 'gocdb') {
                this.gocdbSiteNames = ldata;
                  this.gocdbSiteNameAndSources = ldata;
                } else if (source === 'eosc') {
                this.eoscSiteNames = ldata;
                  this.eoscSiteNameAndSources = ldata;
                }
              const tmp = 'JsonSiteNameList' + source.toUpperCase();
                const tmp = 'JsonSiteNameSourceList' + source.toUpperCase();
                 sessionStorage.setItem(tmp, JSON.stringify(ldata));
              }
              ).catch((error) => {
@@ -139,12 +148,41 @@ export class SiteComponent implements OnInit, OnDestroy {
            });
        
      }
    }


  public onClickSite(source: string) {

    console.log('site clicked with');
  
    sessionStorage.setItem('preSitePage', 'Site')
    sessionStorage.setItem('currentSiteShortSource',source);
    sessionStorage.setItem('currentSiteShortSource', source);
    this.router.navigate(['/dashboard'], { relativeTo: this.route });
  
  }
  onSiteNameSelected(name: string) {
    console.log('Selected new site: ' , name);
    this.siteService.getASite(name)
  
  
  public onClickService(source: string) {
  
    console.log('service clicked with');
  
    sessionStorage.setItem('preSitePage', 'Service')
    sessionStorage.setItem('currentServiceSource',source);
    sessionStorage.setItem('currentSiteShortSource', source);
    this.router.navigate(['/dashboard/fullTableComponent'], { relativeTo: this.route });
  }
  
  onLogout(){
    this.authService.logout();
  }

  onSiteNameAndSourceSelected(siteNameSource: SitenameAndSource) {
    console.log('Selected new eosc site: ' , siteNameSource.siteName + ' from ' + siteNameSource.siteSource);
    sessionStorage.setItem('preSitePage','Site');
    //const tmp = siteNameSource.siteSource.toUpperCase() + siteNameSource.siteName;
    //this.onSiteNameSelected(tmp);
    this.siteService.getASiteById(siteNameSource.siteId)
    .then(
      (asite: Site) => {
        sessionStorage.setItem('currentSelectedSite', JSON.stringify(asite) );
@@ -158,11 +196,9 @@ export class SiteComponent implements OnInit, OnDestroy {
        this.siteUpdateSubscription = this.siteService.siteSubscription.subscribe(
          (newSite: Site) => {
            this.site = newSite; 
               
               
          }
        );
            this.setNameLists();
        this.setNameSourceLists();
        this.cuturls();
      }
    ).catch(
@@ -171,33 +207,10 @@ export class SiteComponent implements OnInit, OnDestroy {
        console.log(error);
      }
    );
  }

  public onClickSite(source: string) {

    console.log('site clicked with');
  
    sessionStorage.setItem('preSitePage', 'Site')
    sessionStorage.setItem('currentSiteShortSource',source);
    sessionStorage.setItem('currentSiteShortSource', source);
    this.router.navigate(['/dashboard'], { relativeTo: this.route });

  }
  

  public onClickService(source: string) {
  
    console.log('service clicked with');
  
    sessionStorage.setItem('preSitePage', 'Service')
    sessionStorage.setItem('currentServiceSource',source);
    sessionStorage.setItem('currentSiteShortSource', source);
    this.router.navigate(['/dashboard/fullTableComponent'], { relativeTo: this.route });
  }
  
  onLogout(){
    this.authService.logout();
  }
  

}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
@@ -333,4 +333,31 @@ export class SiteService {
  }


  getASiteById(siteId: string) {
    console.log('fetch a site with its name');
    const promise = new Promise(
      (resolve, reject) => {
        /** Gets the sites from the source specified (GOCDB or DPMT) **/
        const getUrl = this.sharedService.siteURL + '/id/' + siteId;
        if ( sessionStorage.getItem('authHeader') !== '') {
          const headers = new HttpHeaders( sessionStorage.getItem('authHeader') ? {
           'Authorization' : sessionStorage.getItem('authHeader'),
          'Content-Type' : 'application/json'
         } : {}
         );
         this.httpClient.get<Site>(getUrl , {headers : headers })
         .subscribe(
           (asite: Site) => {
             resolve(asite);
           },
           (error) => {
             reject(error);
           }
         );
        }
      });
    return promise;

  }

}
 No newline at end of file