Generating the correct URL for service models
Change-Id: I2b004176b74043f46ee96b0bad4f0659422836da
diff --git a/src/app/core/services/helpers/config.helpers.ts b/src/app/core/services/helpers/config.helpers.ts
index 0ec20cd..241d380 100644
--- a/src/app/core/services/helpers/config.helpers.ts
+++ b/src/app/core/services/helpers/config.helpers.ts
@@ -275,7 +275,7 @@
item.$save()
.then((res) => {
- if (res.status === 403 || res.status === 405 || res.status === 500) {
+ if (res.status === 403 || res.status === 405 || res.status === 404 || res.status === 500) {
// TODO understand why 405 does not go directly in catch (it may be related to ng-rest-gw)
throw new Error();
}
diff --git a/src/app/datasources/helpers/model-discoverer.service.ts b/src/app/datasources/helpers/model-discoverer.service.ts
index b1382bd..1078853 100644
--- a/src/app/datasources/helpers/model-discoverer.service.ts
+++ b/src/app/datasources/helpers/model-discoverer.service.ts
@@ -24,6 +24,7 @@
export interface IXosModelDiscovererService {
discover(): ng.IPromise<boolean>;
get(modelName: string): IXosModel;
+ getApiUrlFromModel(model: IXosModel): string;
}
export class XosModelDiscovererService implements IXosModelDiscovererService {
@@ -59,6 +60,16 @@
return _.find(this.xosModels, m => m.name === modelName);
}
+ public getApiUrlFromModel(model: IXosModel): string {
+ if (model.app === 'core') {
+ return `/core/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`;
+ }
+ else {
+ const serviceName = this.serviceNameFromAppName(model.app);
+ return `/${serviceName}/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`;
+ }
+ }
+
public discover() {
const d = this.$q.defer();
this.progressBar.start();
@@ -133,16 +144,6 @@
return parentState;
}
- private getApiUrlFromModel(model: IXosModel): string {
- if (model.app === 'core') {
- return `/core/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`;
- }
- else {
- const serviceName = this.serviceNameFromAppName(model.app);
- return `/${serviceName}/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`;
- }
- }
-
// add a service state and navigation item if it is not already there
private addService(model: IXosModel): string {
const serviceName: string = this.serviceNameFromAppName(model.app);
diff --git a/src/app/views/crud/crud.ts b/src/app/views/crud/crud.ts
index 6b30edc..90d3342 100644
--- a/src/app/views/crud/crud.ts
+++ b/src/app/views/crud/crud.ts
@@ -89,8 +89,7 @@
// if it is the create page
if ($stateParams['id'] === 'add') {
// generate a resource for an empty model
- // TODO get the proper URL from model discoverer
- const endpoint = this.StoreHelpers.urlFromCoreModel(this.data.model);
+ const endpoint = this.XosModelDiscovererService.getApiUrlFromModel(this.XosModelDiscovererService.get(this.data.model));
const resource = this.ModelRest.getResource(endpoint);
this.model = new resource({});
}
@@ -110,4 +109,3 @@
controllerAs: 'vm',
controller: CrudController
};
-