diff --git a/client/client/src/credit-list/credit-list.js b/client/client/src/credit-list/credit-list.js index c1d283e33..613a6eb30 100644 --- a/client/client/src/credit-list/credit-list.js +++ b/client/client/src/credit-list/credit-list.js @@ -1,9 +1,7 @@ import ngModule from '../module'; import FilterClientList from '../filterClientList'; -class ClientCreditList extends FilterClientList {} - ngModule.component('vnClientCreditList', { template: require('./credit-list.html'), - controller: ClientCreditList + controller: FilterClientList }); diff --git a/client/client/src/filterClientList.js b/client/client/src/filterClientList.js index 6b6f48bb9..e4946354a 100644 --- a/client/client/src/filterClientList.js +++ b/client/client/src/filterClientList.js @@ -1,40 +1,8 @@ -// Generic object to list models, related to the client, with mgCrud -export default class FilterClientList { +import FilterList from '../../core/src/lib/filterList'; +export default class FilterClientList extends FilterList { constructor($scope, $timeout, $state) { - this.$ = $scope; - this.$timeout = $timeout; - this.$state = $state; - - this.waitingMgCrud = 0; - this.clientFk = $state.params.id; - } - onOrder(field, order) { - this.filter(`${field} ${order}`); - } - filter(order) { - if (this.$.index && this.clientFk) { - this.waitingMgCrud = 0; - this.$.index.filter = { - page: 1, - size: 10, - clientFk: this.clientFk - }; - - if (order) { - this.$.index.filter.order = order; - } - - this.$.index.accept(); - } else if (!this.clientFk) { - throw new Error('Error: ClientFk not found'); - } else if (this.waitingMgCrud > 3) { - throw new Error('Error: Magic Crud is not loaded'); - } else { - this.waitingMgCrud++; - this.$timeout(() => { - this.filter(order); - }, 250); - } + super($scope, $timeout, $state); + this.modelName = 'clientFk'; } } FilterClientList.$inject = ['$scope', '$timeout', '$state']; diff --git a/client/client/src/greuge-list/greuge-list.js b/client/client/src/greuge-list/greuge-list.js index a2e5bd33a..0e91db0c7 100644 --- a/client/client/src/greuge-list/greuge-list.js +++ b/client/client/src/greuge-list/greuge-list.js @@ -1,9 +1,7 @@ import ngModule from '../module'; import FilterClientList from '../filterClientList'; -class ClientGreugeList extends FilterClientList {} - ngModule.component('vnClientGreugeList', { template: require('./greuge-list.html'), - controller: ClientGreugeList + controller: FilterClientList }); diff --git a/client/core/src/lib/filterList.js b/client/core/src/lib/filterList.js new file mode 100644 index 000000000..34789a41d --- /dev/null +++ b/client/core/src/lib/filterList.js @@ -0,0 +1,40 @@ +// Generic object to list models +export default class FilterList { + constructor($scope, $timeout, $state) { + this.$ = $scope; + this.$timeout = $timeout; + this.$state = $state; + + this.waitingMgCrud = 0; + this.modelId = $state.params.id; + } + onOrder(field, order) { + this.filter(`${field} ${order}`); + } + filter(order) { + if (this.$.index && this.modelId && this.modelName) { + this.waitingMgCrud = 0; + this.$.index.filter = { + page: 1, + size: 10 + }; + + this.$.index.filter[this.modelName] = this.modelId; + + if (order) { + this.$.index.filter.order = order; + } + + this.$.index.accept(); + } else if (!this.modelId || !this.modelName) { + throw new Error('Error: model not found'); + } else if (this.waitingMgCrud > 3) { + throw new Error('Error: Magic Crud is not loaded'); + } else { + this.waitingMgCrud++; + this.$timeout(() => { + this.filter(order); + }, 250); + } + } +} diff --git a/client/core/src/lib/index.js b/client/core/src/lib/index.js index 46c4e4882..0c8d89c9c 100644 --- a/client/core/src/lib/index.js +++ b/client/core/src/lib/index.js @@ -6,6 +6,7 @@ import './app'; import './interceptor'; import './aclService'; import './storageServices'; +import './filterList'; export * from './util'; export {default as splitingRegister} from './splitingRegister'; diff --git a/client/item/src/filterItemList.js b/client/item/src/filterItemList.js new file mode 100644 index 000000000..6c084944d --- /dev/null +++ b/client/item/src/filterItemList.js @@ -0,0 +1,8 @@ +import FilterList from '../../core/src/lib/filterList'; +export default class FilterItemList extends FilterList { + constructor($scope, $timeout, $state) { + super($scope, $timeout, $state); + this.modelName = 'itemFk'; + } +} +FilterItemList.$inject = ['$scope', '$timeout', '$state'];