Commit 000458e5 authored by Jie Yuan's avatar Jie Yuan

add service to fetch sitenameandsource obj

parent b3847b7e
......@@ -9,6 +9,7 @@ import {AuthService} from './auth.service';
import {HostName} from './model/hostname';
import {ServiceComponent} from './model/service-component';
import {Site} from './model/site';
import { SitenameAndSource } from './model/sitenameAndSource';
@Injectable()
export class SiteShortService {
......@@ -136,6 +137,33 @@ export class SiteShortService {
}
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;
}
/**
......@@ -341,4 +369,37 @@ export class SiteShortService {
}
getSiteNameAndSourceListFromSource(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 + '/siteNamesAndSources/all';
} else {
getUrl = this.sharedService.siteURL + '/siteNamesAndSources/' + source + '/all';
}
if ( sessionStorage.getItem('authHeader') !== '') {
const headers = new HttpHeaders( true ? {
'Authorization' : sessionStorage.getItem('authHeader'),
'Content-Type' : 'application/json'
} : {}
);
this.httpClient.get<SitenameAndSource[]>(getUrl , {headers : headers })
.subscribe(
(nameList: SitenameAndSource[]) => {
resolve(nameList);
},
(error) => {
reject(error);
}
);
}
});
return promise;
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
import {Subscription} from 'rxjs/Subscription';
import { Site } from './model/site';
import {SitenameAndSource} from './model/sitenameAndSource';
import {AuthService} from './auth.service';
import {SharedService} from './shared-service';
......@@ -148,6 +149,38 @@ export class SiteService {
return promise;
}
getSiteNameAndSourceListFromSource(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 + '/siteNamesAndSources/all';
} else {
getUrl = this.sharedService.siteURL + '/siteNamesAndSources/' + source + '/all';
}
if ( sessionStorage.getItem('authHeader') !== '') {
const headers = new HttpHeaders( true ? {
'Authorization' : sessionStorage.getItem('authHeader'),
'Content-Type' : 'application/json'
} : {}
);
this.httpClient.get<SitenameAndSource[]>(getUrl , {headers : headers })
.subscribe(
(nameList: SitenameAndSource[]) => {
resolve(nameList);
},
(error) => {
reject(error);
}
);
}
});
return promise;
}
setSelectedSite(newSelectedSite: Site) {
this.currentSelectedSite = newSelectedSite;
......
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