Commit cd721520 authored by Jie Yuan's avatar Jie Yuan
Browse files

change the sidebar fectch behavior, first name only, then fetch the site...

change the sidebar fectch behavior, first name only, then fetch the site information only one by click
parent ba20d36c
......@@ -32,8 +32,8 @@
<div id="collapseDPMT" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<li class="bold serverItemList" *ngFor="let serverData of serversListDPMT" routerLinkActive="active">
<a class="waves-effect waves-teal " (click)="onServerSelected(serverData)">{{serverData.idName}}</a>
<li class="bold serverItemList" *ngFor="let nameDPMT of nameListDPMT" routerLinkActive="active">
<a class="waves-effect waves-teal " (click)="onServerNameSelected(nameDPMT)">{{nameDPMT}}</a>
</li>
</div>
......@@ -49,8 +49,8 @@
<div id="collapseGOCDB" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<li class="bold serverItemList" *ngFor="let serverData of serversListGOCDB" routerLinkActive="active">
<a class="waves-effect waves-teal" (click)="onServerSelected(serverData)">{{serverData.idName}}</a>
<li class="bold serverItemList" *ngFor="let nameGOCDB of nameListGOCDB" routerLinkActive="active">
<a class="waves-effect waves-teal" (click)="onServerNameSelected(nameGOCDB)">{{nameGOCDB}}</a>
</li>
</div>
</div>
......
......@@ -21,6 +21,8 @@ export class SidebarComponent implements OnInit, AfterViewInit , DoCheck {
serversListDPMT: Site[];
/** Servers of GOCDB **/
serversListGOCDB: Site[];
nameListDPMT: string[];
nameListGOCDB: string[];
userLogged: boolean;
actions1 = new EventEmitter<string|MaterializeAction>();
......@@ -61,7 +63,8 @@ export class SidebarComponent implements OnInit, AfterViewInit , DoCheck {
if ( this.loginService.loggedIn === true && this.loginService.loggedIn !== this.userLogged) {
console.log('haha');
this.userLogged = true;
this.sitesUpdate();
//this.sitesUpdate();
this.siteNamesUpdate();
console.log('haha');
}
......@@ -111,6 +114,50 @@ export class SidebarComponent implements OnInit, AfterViewInit , DoCheck {
}
siteNamesUpdate() {
console.log('from sidebar component site names update');
if ( this.loginService.loggedIn ) {
/** Fetch all the servers from DPMT **/
const sessionData = sessionStorage.getItem('SiteNameListDPMT');
if (sessionData !== null) {
const list = JSON.parse(sessionData);
this.serversListDPMT = list;
} else {
this.siteService.getSiteNameListFromSource('dpmt')
.then((nameList: string[]) => {
this.nameListDPMT = nameList;
}
).catch((error) => {
console.log('Loading server list from DPMT: ', error);
this.nameListDPMT = [];
});
}
/** Fetch all the servers from GOCDB **/
const sessionData1 = sessionStorage.getItem('SiteNameListGOCDB');
if ( sessionData1 !== null) {
const list = JSON.parse(sessionData1);
this.nameListGOCDB = list;
} else {
this.siteService.getSiteNameListFromSource('gocdb')
.then((nameList: string[]) => {
this.nameListGOCDB = nameList;
}
).catch((error) => {
console.log('Loading server list from GOCDB: ', error);
this.nameListGOCDB = [];
});
console.log('from sidebar update ,authenticated');
}
}
}
sideNavActions = new EventEmitter<any | MaterializeAction>();
......@@ -165,6 +212,23 @@ export class SidebarComponent implements OnInit, AfterViewInit , DoCheck {
});
}
onServerNameSelected(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);
}
);
}
onGOCDBListSelected() {
console.log('GOCDB List selected');
//this.siteService.selectSourceSite('gocdb');
......
......@@ -18,6 +18,7 @@ export class SiteService {
//private URL = 'https://localhost:8443/api';
siteList: Site[];
siteNamesList: string[];
/** Site that is currently shown on the site page **/
currentSelectedSite: Site;
siteSubscription: EventEmitter<Site>;
......@@ -112,6 +113,41 @@ export class SiteService {
});
return promise;
}
getSiteNameListFromSource(source: String) {
console.log('Fetching server name lists from backend with source');
const promise = new Promise(
(resolve, reject) => {
/** Gets the sites from the source specified (GOCDB or DPMT) **/
let getUrl;
if (source === 'all') {
getUrl = this.sharedService.siteURL + '/siteNames/all';
} else {
getUrl = this.sharedService.siteURL + '/siteNames/' + source + '/all';
}
if ( sessionStorage.getItem('authHeader') !== '') {
const headers = new HttpHeaders( true ? {
'Authorization' : sessionStorage.getItem('authHeader'),
'Content-Type' : 'application/json'
} : {}
);
this.httpClient.get<string[]>(getUrl , {headers : headers })
.subscribe(
(nameList: string[]) => {
this.siteNamesList = nameList;
const tmp = 'JsonSiteNameList' + source.toUpperCase();
sessionStorage.setItem(tmp, JSON.stringify(this.siteNamesList));
resolve(this.siteNamesList);
},
(error) => {
reject(error);
}
);
}
});
return promise;
}
setSelectedSite(newSelectedSite: Site) {
......@@ -202,4 +238,35 @@ export class SiteService {
}
getASite(sitename: 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 + '/' + sitename;
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;
}
}
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