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(' ');
}