Fixing relations pointing to _decl models
Change-Id: I78662dcacf5ef042aed297da42a2ea5f10a7c993
diff --git a/src/app/core/services/helpers/config.helpers.spec.ts b/src/app/core/services/helpers/config.helpers.spec.ts
index f0fb2a7..5883434 100644
--- a/src/app/core/services/helpers/config.helpers.spec.ts
+++ b/src/app/core/services/helpers/config.helpers.spec.ts
@@ -244,9 +244,10 @@
});
describe('the private methods', () => {
- let modelStoreMock, toastr, auth, stateMock;
+ let modelStoreMock, toastr, auth, stateMock, logMock;
- beforeEach(angular.mock.inject((_toastr_, AuthService) => {
+ beforeEach(angular.mock.inject(($log, _toastr_, AuthService) => {
+ logMock = $log;
modelStoreMock = {
query: () => {
const subject = new BehaviorSubject([
@@ -277,7 +278,7 @@
test: 2
};
it('should add the formatted data to the column definition', () => {
- service = new ConfigHelpers(stateMock, toastr, modelStoreMock);
+ service = new ConfigHelpers(logMock, stateMock, toastr, modelStoreMock);
service['populateRelated'](item, item.test, field);
expect(item['test-formatted']).toBe('second');
});
@@ -293,7 +294,7 @@
};
it('should add the available choice to the select', () => {
- service = new ConfigHelpers(stateMock, toastr, modelStoreMock);
+ service = new ConfigHelpers(logMock, stateMock, toastr, modelStoreMock);
service['populateSelectField'](field, input);
expect(input.options).toEqual([
{id: 1, label: 'test'},
diff --git a/src/app/core/services/helpers/config.helpers.ts b/src/app/core/services/helpers/config.helpers.ts
index 78a767e..8ff81a2 100644
--- a/src/app/core/services/helpers/config.helpers.ts
+++ b/src/app/core/services/helpers/config.helpers.ts
@@ -40,6 +40,7 @@
export class ConfigHelpers implements IXosConfigHelpersService {
static $inject = [
+ '$log',
'$state',
'toastr',
'XosModelStore'];
@@ -64,6 +65,7 @@
];
constructor(
+ private $log: ng.ILogService,
private $state: ng.ui.IStateService,
private toastr: ng.toastr.IToastrService,
private XosModelStore: IXosModelStoreService
@@ -352,15 +354,25 @@
// augment a select field with related model informations
private populateSelectField(field: IXosModelDefsField, input: IXosFormInput): void {
+
+ if (field.relation.model.indexOf('_decl') > -1) {
+ field.relation.model = field.relation.model.replace('_decl', '');
+ }
+
this.XosModelStore.query(field.relation.model)
- .subscribe(res => {
- input.options = _.map(res, item => {
- let opt = {id: item.id, label: item.humanReadableName ? item.humanReadableName : item.name};
- if (!angular.isDefined(item.humanReadableName) && !angular.isDefined(item.name)) {
- opt.label = item.id;
- }
- return opt;
- });
- });
+ .subscribe(
+ res => {
+ input.options = _.map(res, item => {
+ let opt = {id: item.id, label: item.humanReadableName ? item.humanReadableName : item.name};
+ if (!angular.isDefined(item.humanReadableName) && !angular.isDefined(item.name)) {
+ opt.label = item.id;
+ }
+ return opt;
+ });
+ },
+ err => {
+ this.$log.error(`[XOSConfigHelpers] Failed to build relations for ${field.relation.model}`);
+ }
+ );
}
}