Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit c3f02a8

Browse files
committed
fix(base-resource): Error if data not founded
1 parent 2c9e435 commit c3f02a8

File tree

4 files changed

+69
-42
lines changed

4 files changed

+69
-42
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"demo-link": "npm link src",
4949
"demo-lite_server": "lite-server -c demo/bs-config.json",
5050
"demo-serve": "ng serve --host 0.0.0.0 --aot",
51-
"demo-serve_mockapi": "ng serve --host 0.0.0.0 --aot --environment=mockapi",
51+
"demo-serve_mockapi": "ng serve --host 0.0.0.0 --aot=false --environment=mockapi",
5252
"demo-gh_pages": "npm-run-all demo-build demo-deploy",
5353
"demo-prod_build": "ng build --base-href / --prod --aot --build-optimizer",
5454
"demo-dev_build": "ng build --base-href / --aot",

src/base/base-resources-grid/base-resource-select-input/base-resource-select-input.component.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export class BaseResourceSelectInputComponent extends BaseComponent {
6969
this.modelAsStringChange.emit(this.modelAsString);
7070
}
7171
get statusListMessage() {
72+
if (!this.cachedResourcesService) {
73+
return '';
74+
}
7275
if (this.cachedResourcesService.statusList === EndpointStatusEnum.Ok) {
7376
return '';
7477
} else {
@@ -96,16 +99,18 @@ export class BaseResourceSelectInputComponent extends BaseComponent {
9699
if (this.inputElement) {
97100
this.inputElement.hardValue = this.hardValue;
98101
}
99-
this.cachedResourcesService.items$.subscribe(
100-
(pageTypes: any[]) => {
101-
this.items = pageTypes;
102-
if (this.inputElement) {
103-
this.inputElement.items = this.items;
104-
this.inputElement.init();
105-
}
106-
}, (errors: any) => {
107-
this.items = [];
108-
});
102+
if (!this.cachedResourcesService) {
103+
this.cachedResourcesService.items$.subscribe(
104+
(pageTypes: any[]) => {
105+
this.items = pageTypes;
106+
if (this.inputElement) {
107+
this.inputElement.items = this.items;
108+
this.inputElement.init();
109+
}
110+
}, (errors: any) => {
111+
this.items = [];
112+
});
113+
}
109114
super.init();
110115
if (this.lookupTooltip === undefined) {
111116
this.lookupTooltip = this.translateService.instant('Select');
@@ -116,6 +121,8 @@ export class BaseResourceSelectInputComponent extends BaseComponent {
116121
}
117122
search() {
118123
const filter: any = {};
119-
this.cachedResourcesService.loadAll('', filter);
124+
if (!this.cachedResourcesService) {
125+
this.cachedResourcesService.loadAll('', filter);
126+
}
120127
}
121128
}

src/base/base-resources-grid/base-resources-grid.component.ts

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,39 @@ export class BaseResourcesGridComponent extends BaseComponent {
3838
}
3939

4040
get meta() {
41-
return this.cachedResourceService.meta;
41+
if (this.cachedResourceService) {
42+
return this.cachedResourceService.meta;
43+
}
44+
return {};
4245
}
4346
set columns(columns) {
44-
if (JSON.stringify(this.cachedResourceService.columns) !== JSON.stringify(columns)) {
47+
if (this.cachedResourceService && JSON.stringify(this.cachedResourceService.columns) !== JSON.stringify(columns)) {
4548
this.cachedResourceService.columns = columns;
4649
this.search(true);
4750
}
4851
}
4952
get columns(): any {
50-
if (this.cachedResourceService.columns === undefined) {
53+
if (this.cachedResourceService && this.cachedResourceService.columns === undefined) {
5154
this.cachedResourceService.columns = { id: { sort: 'desc' } };
55+
return this.cachedResourceService.columns;
5256
}
53-
return this.cachedResourceService.columns;
57+
return {};
5458
}
5559
set mockedItems(items) {
56-
this.cachedResourceService.mockedItems = items;
60+
if (this.cachedResourceService) {
61+
this.cachedResourceService.mockedItems = items;
62+
}
5763
}
5864
get mockedItems() {
59-
return this.cachedResourceService.mockedItems;
65+
if (this.cachedResourceService) {
66+
return this.cachedResourceService.mockedItems;
67+
}
68+
return [];
6069
}
6170
get statusListMessage() {
71+
if (!this.cachedResourceService) {
72+
return '';
73+
}
6274
if (this.cachedResourceService.statusList === EndpointStatusEnum.Ok) {
6375
return '';
6476
} else {
@@ -70,21 +82,25 @@ export class BaseResourcesGridComponent extends BaseComponent {
7082
this.onEnter.emit(true);
7183
}
7284
pageChanged(event: any): void {
73-
this.cachedResourceService.meta.curPage = event.page;
74-
this.cachedResourceService.meta.perPage = event.itemsPerPage;
75-
this.search();
85+
if (this.cachedResourceService) {
86+
this.cachedResourceService.meta.curPage = event.page;
87+
this.cachedResourceService.meta.perPage = event.itemsPerPage;
88+
this.search();
89+
}
7690
}
7791
init() {
78-
this.cachedResourceService.items$.subscribe(
79-
(items: any[]) => {
80-
this.items = items;
81-
if (this.items) {
82-
this.selectItem(this.items[0], null, true);
83-
}
84-
}, (errors: any) => {
85-
this.items = [];
86-
this.selectItem(null);
87-
});
92+
if (this.cachedResourceService) {
93+
this.cachedResourceService.items$.subscribe(
94+
(items: any[]) => {
95+
this.items = items;
96+
if (this.items) {
97+
this.selectItem(this.items[0], null, true);
98+
}
99+
}, (errors: any) => {
100+
this.items = [];
101+
this.selectItem(null);
102+
});
103+
}
88104
super.init();
89105
this.loadAll = this.loadAll === undefined ? true : this.loadAll;
90106

@@ -120,7 +136,9 @@ export class BaseResourcesGridComponent extends BaseComponent {
120136
}
121137
search(ignoreCache?: boolean) {
122138
const filter: any = {};
123-
this.cachedResourceService.ignoreCache = ignoreCache;
124-
this.cachedResourceService.loadAll(this.searchText, filter);
139+
if (this.cachedResourceService) {
140+
this.cachedResourceService.ignoreCache = ignoreCache;
141+
this.cachedResourceService.loadAll(this.searchText, filter);
142+
}
125143
}
126144
}

src/shared/helpers/repository.helper.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ export class RepositoryHelper {
5858
}
5959
}
6060
let key: string;
61-
for (const columnKey in repositoryService.columns) {
62-
if (repositoryService.columns.hasOwnProperty(columnKey)) {
63-
key = columnKey.split('.').map(item => _.camelCase(item)).join('.');
64-
if (repositoryService.columns[columnKey]['sort']) {
65-
if (repositoryService.columns[columnKey]['sort'] === 'asc') {
66-
uri.append('sort[]', _.snakeCase(key));
67-
}
68-
if (repositoryService.columns[columnKey]['sort'] === 'desc') {
69-
uri.append('sort[]', `-${_.snakeCase(key)}`);
61+
if (repositoryService.columns) {
62+
for (const columnKey in repositoryService.columns) {
63+
if (repositoryService.columns.hasOwnProperty(columnKey)) {
64+
key = columnKey.split('.').map(item => _.camelCase(item)).join('.');
65+
if (repositoryService.columns[columnKey]['sort']) {
66+
if (repositoryService.columns[columnKey]['sort'] === 'asc') {
67+
uri.append('sort[]', _.snakeCase(key));
68+
}
69+
if (repositoryService.columns[columnKey]['sort'] === 'desc') {
70+
uri.append('sort[]', `-${_.snakeCase(key)}`);
71+
}
7072
}
7173
}
7274
}

0 commit comments

Comments
 (0)