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

add sitename and source info within sidebar

parent 82e35cc8
......@@ -8,22 +8,23 @@
<img src="assets/mainLogo.png"/>
</div>
<p></p>
<div class="form-div">
<div class="form-div">
<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 >
<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>
......
......@@ -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');
}
......@@ -79,8 +80,6 @@ export class SiteComponent implements OnInit, OnDestroy {
}else {
this.shortgiisUrl = this.site.giisUrl;
}
}
......@@ -99,79 +98,58 @@ 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();
const ltmp = sessionStorage.getItem(stmp) ;
if( ltmp !== null) {
const ldata = JSON.parse(ltmp);
if ( source === 'dpmt') {
this.dpmtSiteNames = ldata;
} else if (source === 'gocdb') {
this.gocdbSiteNames = ldata;
} else if (source === 'eosc') {
this.eoscSiteNames = ldata;
}
} else {
this.siteService.getSiteNameListFromSource(source)
.then((ldata: string[]) => {
if ( source === 'dpmt') {
this.dpmtSiteNames = ldata;
} else if (source === 'gocdb') {
this.gocdbSiteNames = ldata;
} else if (source === 'eosc') {
this.eoscSiteNames = ldata;
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.dpmtSiteNameAndSources = ldata;
} else if (source === 'gocdb') {
this.gocdbSiteNameAndSources = ldata;
} else if (source === 'eosc') {
this.eoscSiteNameAndSources = ldata;
}
} else {
this.siteService.getSiteNameAndSourceListFromSource(source)
.then((ldata: SitenameAndSource[]) => {
if ( source === 'dpmt') {
this.dpmtSiteNameAndSources = ldata;
} else if (source === 'gocdb') {
this.gocdbSiteNameAndSources = ldata;
} else if (source === 'eosc') {
this.eoscSiteNameAndSources = ldata;
}
const tmp = 'JsonSiteNameSourceList' + source.toUpperCase();
sessionStorage.setItem(tmp, JSON.stringify(ldata));
}
const tmp = 'JsonSiteNameList' + source.toUpperCase();
sessionStorage.setItem(tmp, JSON.stringify(ldata));
}
).catch((error) => {
console.log('Loading server list from DPMT: ', error);
});
).catch((error) => {
console.log('Loading server list from DPMT: ', error);
});
}
}
}
onSiteNameSelected(name: string) {
console.log('Selected new site: ' , name);
this.siteService.getASite(name)
.then(
(asite: Site) => {
sessionStorage.setItem('currentSelectedSite', JSON.stringify(asite) );
this.site = asite;
if ( this.site.hostNames !== null && this.site.hostNames.length >0) {
this.hasHosts = true;
} else {
this.hasHosts = false;
}
this.siteUpdateSubscription = this.siteService.siteSubscription.subscribe(
(newSite: Site) => {
this.site = newSite;
}
);
this.setNameLists();
this.cuturls();
}
).catch(
error => {
console.log('Error while loading sites ');
console.log(error);
}
);
}
public onClickSite(source: string) {
......@@ -198,6 +176,41 @@ export class SiteComponent implements OnInit, OnDestroy {
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) );
this.site = asite;
if ( this.site.hostNames !== null && this.site.hostNames.length >0) {
this.hasHosts = true;
} else {
this.hasHosts = false;
}
this.siteUpdateSubscription = this.siteService.siteSubscription.subscribe(
(newSite: Site) => {
this.site = newSite;
}
);
this.setNameSourceLists();
this.cuturls();
}
).catch(
error => {
console.log('Error while loading sites ');
console.log(error);
}
);
}
}
\ No newline at end of file
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment