fixed relative/absolute paths

This commit is contained in:
Art Lowel
2017-06-08 16:59:49 +02:00
parent 9e1f7848b6
commit 2c7f646b71
5 changed files with 28 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
import { Injectable } from "@angular/core";
import { Inject, Injectable } from "@angular/core";
import { DataService } from "./data.service";
import { Collection } from "../shared/collection.model";
import { ObjectCacheService } from "../cache/object-cache.service";
@@ -8,6 +8,7 @@ import { NormalizedCollection } from "../cache/models/normalized-collection.mode
import { CoreState } from "../core.reducers";
import { RequestService } from "./request.service";
import { RemoteDataBuildService } from "../cache/builders/remote-data-build.service";
import { GLOBAL_CONFIG, GlobalConfig } from "../../../config";
@Injectable()
export class CollectionDataService extends DataService<NormalizedCollection, Collection> {
@@ -18,9 +19,10 @@ export class CollectionDataService extends DataService<NormalizedCollection, Col
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected store: Store<CoreState>
protected store: Store<CoreState>,
@Inject(GLOBAL_CONFIG) EnvConfig: GlobalConfig
) {
super(NormalizedCollection);
super(NormalizedCollection, EnvConfig);
}
}

View File

@@ -1,4 +1,4 @@
import { Injectable } from "@angular/core";
import { Inject, Injectable } from "@angular/core";
import { DataService } from "./data.service";
import { Community } from "../shared/community.model";
import { ObjectCacheService } from "../cache/object-cache.service";
@@ -8,6 +8,7 @@ import { NormalizedCommunity } from "../cache/models/normalized-community.model"
import { CoreState } from "../core.reducers";
import { RequestService } from "./request.service";
import { RemoteDataBuildService } from "../cache/builders/remote-data-build.service";
import { GLOBAL_CONFIG, GlobalConfig } from "../../../config";
@Injectable()
export class CommunityDataService extends DataService<NormalizedCommunity, Community> {
@@ -18,9 +19,10 @@ export class CommunityDataService extends DataService<NormalizedCommunity, Commu
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected store: Store<CoreState>
protected store: Store<CoreState>,
@Inject(GLOBAL_CONFIG) EnvConfig: GlobalConfig
) {
super(NormalizedCommunity);
super(NormalizedCommunity, EnvConfig);
}
}

View File

@@ -10,6 +10,9 @@ import { CoreState } from "../core.reducers";
import { RequestService } from "./request.service";
import { RemoteDataBuildService } from "../cache/builders/remote-data-build.service";
import { GenericConstructor } from "../shared/generic-constructor";
import { Inject } from "@angular/core";
import { GLOBAL_CONFIG, GlobalConfig } from "../../../config";
import { RESTURLCombiner } from "../url-combiner/rest-url-combiner";
export abstract class DataService<TNormalized extends CacheableObject, TDomain> {
protected abstract objectCache: ObjectCacheService;
@@ -19,7 +22,10 @@ export abstract class DataService<TNormalized extends CacheableObject, TDomain>
protected abstract store: Store<CoreState>;
protected abstract endpoint: string;
constructor(private normalizedResourceType: GenericConstructor<TNormalized>) {
constructor(
private normalizedResourceType: GenericConstructor<TNormalized>,
protected EnvConfig: GlobalConfig
) {
}
@@ -28,7 +34,7 @@ export abstract class DataService<TNormalized extends CacheableObject, TDomain>
if (hasValue(scopeID)) {
result += `?scope=${scopeID}`
}
return result;
return new RESTURLCombiner(this.EnvConfig, result).toString();
}
findAll(scopeID?: string): RemoteData<Array<TDomain>> {
@@ -40,7 +46,7 @@ export abstract class DataService<TNormalized extends CacheableObject, TDomain>
}
protected getFindByIDHref(resourceID): string {
return `${this.endpoint}/${resourceID}`;
return new RESTURLCombiner(this.EnvConfig, `${this.endpoint}/${resourceID}`).toString();
}
findById(id: string): RemoteData<TDomain> {

View File

@@ -1,4 +1,4 @@
import { Injectable } from "@angular/core";
import { Inject, Injectable } from "@angular/core";
import { DataService } from "./data.service";
import { Item } from "../shared/item.model";
import { ObjectCacheService } from "../cache/object-cache.service";
@@ -8,6 +8,7 @@ import { CoreState } from "../core.reducers";
import { NormalizedItem } from "../cache/models/normalized-item.model";
import { RequestService } from "./request.service";
import { RemoteDataBuildService } from "../cache/builders/remote-data-build.service";
import { GLOBAL_CONFIG, GlobalConfig } from "../../../config";
@Injectable()
export class ItemDataService extends DataService<NormalizedItem, Item> {
@@ -18,8 +19,9 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected store: Store<CoreState>
protected store: Store<CoreState>,
@Inject(GLOBAL_CONFIG) EnvConfig: GlobalConfig
) {
super(NormalizedItem);
super(NormalizedItem, EnvConfig);
}
}

View File

@@ -18,15 +18,15 @@ export class DSpaceRESTv2Service {
/**
* Performs a request to the REST API with the `get` http method.
*
* @param relativeURL
* A URL, relative to the basepath of the rest api
* @param absoluteURL
* A URL
* @param options
* A RequestOptionsArgs object, with options for the http call.
* @return {Observable<string>}
* An Observablse<string> containing the response from the server
*/
get(relativeURL: string, options?: RequestOptionsArgs): Observable<DSpaceRESTV2Response> {
return this.http.get(new RESTURLCombiner(this.EnvConfig, relativeURL).toString(), options)
get(absoluteURL: string, options?: RequestOptionsArgs): Observable<DSpaceRESTV2Response> {
return this.http.get(absoluteURL, options)
.map(res => ({ payload: res.json(), statusCode: res.statusText }))
.catch(err => {
console.log('Error: ', err);