Commit 151a10d2 authored by Jie Yuan's avatar Jie Yuan
Browse files

add site name and source in fulltable

parent 550c52df
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -14,8 +14,8 @@
  <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>
@@ -25,8 +25,8 @@
  <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>
@@ -36,8 +36,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>
@@ -55,7 +55,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>
@@ -63,7 +63,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>
+78 −42
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import {ServiceComponentRow} from '../../model/service-component-row';
import {HostName} from '../../model/hostname';
import {ServiceComponent} from '../../model/service-component';
import { AuthService } from 'src/app/auth.service';
import {SitenameAndSource} from '../../model/sitenameAndSource';



@@ -32,9 +33,9 @@ export class FulltableComponent implements OnInit , DoCheck, AfterViewInit{
  serverList: Site[];

  dataSource: MatTableDataSource<ServiceComponentRow>;
  eoscSiteNames: string[];
  gocdbSiteNames: string[];
  dpmtSiteNames: string[];
  eoscSiteNameAndSources: SitenameAndSource[];
  dpmtSiteNameAndSources: SitenameAndSource[];
  gocdbSiteNameAndSources: SitenameAndSource[];
  username: string;
  defaultPageSizeOptions: number[] =[10,20,40,80];
  
@@ -105,7 +106,7 @@ export class FulltableComponent implements OnInit , DoCheck, AfterViewInit{
      }
    );
    
    this.setNameLists();
    this.setNameSourceLists();
    sessionStorage.setItem('preSitePage', 'Service');
    
     
@@ -310,35 +311,80 @@ export class FulltableComponent implements OnInit , DoCheck, AfterViewInit{
  }
  

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


  onSiteNameSelected(name: string) {
    console.log('Selected new site: ' , name);
    this.siteService.getASite(name)
        .then(
          (asite: Site) => {
            sessionStorage.setItem('currentSelectedSite', JSON.stringify(asite) );
            this.router.navigate(['/dashboard/site'], { relativeTo: this.route });
          }
        ).catch(
          error => {
            console.log('Error while loading sites ');
            console.log(error);
          }
        );
  }

  onSiteNameAndSourceSelected(siteNameSource: SitenameAndSource) {
    console.log('Selected new eosc site: ' , siteNameSource.siteName + ' from ' + siteNameSource.siteSource);
    sessionStorage.setItem('preSitePage','Service');
    //const tmp = siteNameSource.siteSource.toUpperCase() + siteNameSource.siteName;
    //this.onSiteNameSelected(tmp);
    this.siteService.getASiteById(siteNameSource.siteId)
    .then(
      (asite: Site) => {
        sessionStorage.setItem('currentSelectedSite', JSON.stringify(asite) );
        this.router.navigate(['/dashboard/site'], { relativeTo: this.route });
      }
    ).catch(
      error => {
        console.log('Error while loading sites ');
        console.log(error);
      }
    );
  
  }

  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) => {
@@ -348,22 +394,12 @@ export class FulltableComponent implements OnInit , DoCheck, AfterViewInit{
      }



    
    
  }
  onSiteNameSelected(name: string) {
    console.log('Selected new site: ' , name);
    this.siteService.getASite(name)
        .then(
          (asite: Site) => {
            sessionStorage.setItem('currentSelectedSite', JSON.stringify(asite) );
            this.router.navigate(['/dashboard/site'], { relativeTo: this.route });
          }
        ).catch(
          error => {
            console.log('Error while loading sites ');
            console.log(error);
          }
        );
  }