Moved urlFromCoreModel into ConfigHelpers
Change-Id: Ida841fb362a2cc6dbf7f080d71687db4e9ad996d
diff --git a/src/app/core/services/helpers/config.helpers.spec.ts b/src/app/core/services/helpers/config.helpers.spec.ts
index 2431ccb..432bd7e 100644
--- a/src/app/core/services/helpers/config.helpers.spec.ts
+++ b/src/app/core/services/helpers/config.helpers.spec.ts
@@ -117,4 +117,9 @@
expect(cfg.actions.length).toBe(1);
});
});
+
+ it('should convert a core model name in an URL', () => {
+ expect(service.urlFromCoreModel('Slice')).toBe('/core/slices');
+ expect(service.urlFromCoreModel('Xos')).toBe('/core/xosses');
+ });
});
diff --git a/src/app/core/services/helpers/config.helpers.ts b/src/app/core/services/helpers/config.helpers.ts
index 332c60c..fc836e7 100644
--- a/src/app/core/services/helpers/config.helpers.ts
+++ b/src/app/core/services/helpers/config.helpers.ts
@@ -16,6 +16,7 @@
pluralize(string: string, quantity?: number, count?: boolean): string;
toLabel(string: string, pluralize?: boolean): string;
toLabels(string: string[], pluralize?: boolean): string[];
+ urlFromCoreModel(name: string): string;
}
export class ConfigHelpers {
@@ -44,11 +45,11 @@
pluralize.addPluralRule(/slice$/i, 'slices');
}
- pluralize(string: string, quantity?: number, count?: boolean): string {
+ public pluralize(string: string, quantity?: number, count?: boolean): string {
return pluralize(string, quantity, count);
}
- toLabels(strings: string[], pluralize?: boolean): string[] {
+ public toLabels(strings: string[], pluralize?: boolean): string[] {
if (angular.isArray(strings)) {
return _.map(strings, s => {
return this.toLabel(s, pluralize);
@@ -56,7 +57,7 @@
}
}
- toLabel(string: string, pluralize?: boolean): string {
+ public toLabel(string: string, pluralize?: boolean): string {
if (pluralize) {
string = this.pluralize(string);
@@ -69,7 +70,7 @@
return this.capitalizeFirst(string);
}
- modelToTableCfg(model: IModeldef, baseUrl: string): IXosTableCfg {
+ public modelToTableCfg(model: IModeldef, baseUrl: string): IXosTableCfg {
const cfg = {
columns: this.modelFieldsToColumnsCfg(model.fields, baseUrl),
filter: 'fulltext',
@@ -100,7 +101,7 @@
return cfg;
}
- modelFieldsToColumnsCfg(fields: IXosModelDefsField[], baseUrl: string): IXosTableColumn[] {
+ public modelFieldsToColumnsCfg(fields: IXosModelDefsField[], baseUrl: string): IXosTableColumn[] {
const columns = _.map(fields, (f) => {
if (this.excluded_fields.indexOf(f.name) > -1) {
@@ -138,6 +139,10 @@
return columns;
};
+ public urlFromCoreModel(name: string): string {
+ return `/core/${this.pluralize(name.toLowerCase())}`;
+ }
+
private fromCamelCase(string: string): string {
return string.split(/(?=[A-Z])/).map(w => w.toLowerCase()).join(' ');
}
diff --git a/src/app/datasources/helpers/model.helpers.spec.ts b/src/app/datasources/helpers/model.helpers.spec.ts
deleted file mode 100644
index ee23b28..0000000
--- a/src/app/datasources/helpers/model.helpers.spec.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import * as angular from 'angular';
-import 'angular-mocks';
-import 'angular-ui-router';
-
-import {IXosModelHelpersService, ModelHelpers} from './model.helpers';
-
-let service: IXosModelHelpersService;
-describe('The ModelHelpers service', () => {
-
- beforeEach(() => {
- angular
- .module('test', [])
- .service('ModelHelpers', ModelHelpers);
-
- angular.mock.module('test');
- });
-
- beforeEach(angular.mock.inject((
- ModelHelpers: IXosModelHelpersService,
- ) => {
- service = ModelHelpers;
- }));
-
- it('should convert a core model name in an URL', () => {
- expect(service.urlFromCoreModel('Slice')).toBe('/core/slices');
- });
-
-});
diff --git a/src/app/datasources/helpers/model.helpers.ts b/src/app/datasources/helpers/model.helpers.ts
deleted file mode 100644
index 81825d3..0000000
--- a/src/app/datasources/helpers/model.helpers.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-export interface IXosModelHelpersService {
- urlFromCoreModel(name: string): string;
-}
-
-export class ModelHelpers {
- urlFromCoreModel(name: string): string {
- return `/core/${name.toLowerCase()}s`;
- }
-}
diff --git a/src/app/datasources/helpers/store.helpers.spec.ts b/src/app/datasources/helpers/store.helpers.spec.ts
index b2085e3..f0168b6 100644
--- a/src/app/datasources/helpers/store.helpers.spec.ts
+++ b/src/app/datasources/helpers/store.helpers.spec.ts
@@ -2,10 +2,10 @@
import 'angular-mocks';
import 'angular-ui-router';
import {StoreHelpers, IStoreHelpersService} from './store.helpers';
-import {ModelHelpers} from './model.helpers';
import {ModelRest} from '../rest/model.rest';
import {BehaviorSubject} from 'rxjs';
import {IWSEvent} from '../websocket/global';
+import {ConfigHelpers} from '../../core/services/helpers/config.helpers';
let service: IStoreHelpersService;
let subject: BehaviorSubject<any>;
@@ -16,8 +16,8 @@
beforeEach(() => {
angular
- .module('test', ['ngResource'])
- .service('ModelHelpers', ModelHelpers) // NOTE evaluate mock
+ .module('test', ['ngResource', 'toastr'])
+ .service('ConfigHelpers', ConfigHelpers) // NOTE evaluate mock
.service('ModelRest', ModelRest) // NOTE evaluate mock
.service('StoreHelpers', StoreHelpers);
diff --git a/src/app/datasources/helpers/store.helpers.ts b/src/app/datasources/helpers/store.helpers.ts
index 99662da..1458d81 100644
--- a/src/app/datasources/helpers/store.helpers.ts
+++ b/src/app/datasources/helpers/store.helpers.ts
@@ -1,18 +1,18 @@
import {BehaviorSubject} from 'rxjs';
import * as _ from 'lodash';
import {IWSEvent} from '../websocket/global';
-import {IXosModelHelpersService} from './model.helpers';
import {IXosResourceService} from '../rest/model.rest';
+import {IXosConfigHelpersService} from '../../core/services/helpers/config.helpers';
export interface IStoreHelpersService {
updateCollection(event: IWSEvent, subject: BehaviorSubject<any>): BehaviorSubject<any>;
}
export class StoreHelpers {
- static $inject = ['ModelHelpers', 'ModelRest'];
+ static $inject = ['ConfigHelpers', 'ModelRest'];
constructor (
- private modelHelpers: IXosModelHelpersService,
+ private configHelpers: IXosConfigHelpersService,
private modelRest: IXosResourceService
) {
}
@@ -27,7 +27,7 @@
const isDeleted: boolean = _.includes(event.msg.changed_fields, 'deleted');
// generate a resource for the model
- const endpoint = this.modelHelpers.urlFromCoreModel(event.model);
+ const endpoint = this.configHelpers.urlFromCoreModel(event.model);
const resource = this.modelRest.getResource(endpoint);
const model = new resource(event.msg.object);
diff --git a/src/app/datasources/index.ts b/src/app/datasources/index.ts
index b6897ed..7a14a9a 100644
--- a/src/app/datasources/index.ts
+++ b/src/app/datasources/index.ts
@@ -5,12 +5,12 @@
import {StoreHelpers} from './helpers/store.helpers';
import {SynchronizerStore} from './stores/synchronizer.store';
import {ModeldefsService} from './rest/modeldefs.rest';
-import {ModelHelpers} from './helpers/model.helpers';
+import {xosCore} from '../core/index';
export const xosDataSources = 'xosDataSources';
angular
- .module('xosDataSources', ['ngCookies', 'ngResource'])
+ .module('xosDataSources', ['ngCookies', 'ngResource', xosCore])
.service('ModelRest', ModelRest)
.service('AuthService', AuthService)
.service('WebSocket', WebSocketEvent);
@@ -18,7 +18,6 @@
angular
.module('xosDataSources')
.service('StoreHelpers', StoreHelpers)
- .service('ModelHelpers', ModelHelpers)
.service('SynchronizerStore', SynchronizerStore)
.service('ModelStore', ModelStore)
.service('ModelDefs', ModeldefsService);
diff --git a/src/app/datasources/stores/model.store.spec.ts b/src/app/datasources/stores/model.store.spec.ts
index 49b9338..dd19c27 100644
--- a/src/app/datasources/stores/model.store.spec.ts
+++ b/src/app/datasources/stores/model.store.spec.ts
@@ -7,7 +7,7 @@
import {StoreHelpers} from '../helpers/store.helpers';
import {ModelRest} from '../rest/model.rest';
import {AppConfig} from '../../config/app.config';
-import {ModelHelpers} from '../helpers/model.helpers';
+import {ConfigHelpers} from '../../core/services/helpers/config.helpers';
let service: IModelStoreService;
let httpBackend: ng.IHttpBackendService;
@@ -37,12 +37,12 @@
beforeEach(() => {
angular
- .module('ModelStore', ['ngResource'])
+ .module('ModelStore', ['ngResource', 'toastr'])
.service('WebSocket', MockWs)
.service('StoreHelpers', StoreHelpers) // TODO mock
.service('ModelRest', ModelRest) // TODO mock
.service('ModelStore', ModelStore)
- .service('ModelHelpers', ModelHelpers); // TODO mock
+ .service('ConfigHelpers', ConfigHelpers); // TODO mock
angular.mock.module('ModelStore');
});
diff --git a/src/app/datasources/stores/model.store.ts b/src/app/datasources/stores/model.store.ts
index 34e2951..21f42ac 100644
--- a/src/app/datasources/stores/model.store.ts
+++ b/src/app/datasources/stores/model.store.ts
@@ -4,20 +4,20 @@
import {IWSEvent, IWSEventService} from '../websocket/global';
import {IXosResourceService} from '../rest/model.rest';
import {IStoreHelpersService} from '../helpers/store.helpers';
-import {IXosModelHelpersService} from '../helpers/model.helpers';
+import {IXosConfigHelpersService} from '../../core/services/helpers/config.helpers';
export interface IModelStoreService {
query(model: string): Observable<any>;
}
export class ModelStore {
- static $inject = ['WebSocket', 'StoreHelpers', 'ModelRest', 'ModelHelpers'];
+ static $inject = ['WebSocket', 'StoreHelpers', 'ModelRest', 'ConfigHelpers'];
private _collections: any; // NOTE contains a map of {model: BehaviourSubject}
constructor(
private webSocket: IWSEventService,
private storeHelpers: IStoreHelpersService,
private ModelRest: IXosResourceService,
- private ModelHelpers: IXosModelHelpersService
+ private ConfigHelpers: IXosConfigHelpersService
) {
this._collections = {};
}
@@ -43,7 +43,7 @@
private loadInitialData(model: string) {
// NOTE check what is the correct pattern to pluralize this
- const endpoint = this.ModelHelpers.urlFromCoreModel(model);
+ const endpoint = this.ConfigHelpers.urlFromCoreModel(model);
this.ModelRest.getResource(endpoint).query().$promise
.then(
res => {