diff --git a/client/scripts/controllers/EBPSettingsController.js b/client/scripts/controllers/EBPSettingsController.js index e96f5f19..96058471 100644 --- a/client/scripts/controllers/EBPSettingsController.js +++ b/client/scripts/controllers/EBPSettingsController.js @@ -1,17 +1,8 @@ -require('../app').controller('EBPSettingsController', /* @ngInject */function ($q, $stateParams, EBPSpecies) { +require('../app').controller('EBPSettingsController', /* @ngInject */function ($scope, $q, $stateParams, EBPSpecies) { const $ctrl = this $ctrl.selected = 'sources' - if ($stateParams.settings) { $ctrl.selected = $stateParams.settings } - - $ctrl.requestSpecies = function () { - $q.resolve(EBPSpecies.query().$promise).then(function (species) { - $ctrl.species = species - }) - } - - $ctrl.requestSpecies() }) diff --git a/client/scripts/controllers/EBPSpeciesController.js b/client/scripts/controllers/EBPSpeciesController.js new file mode 100644 index 00000000..11d1d513 --- /dev/null +++ b/client/scripts/controllers/EBPSpeciesController.js @@ -0,0 +1,47 @@ +require('../app').controller('EBPSpeciesController', /* @ngInject */function ($scope, $q, $stateParams, EBPSpecies) { + const $ctrl = this + + $ctrl.page = 1 + $ctrl.pageSize = 20 + + $ctrl.requestSpecies = function () { + $q.resolve(EBPSpecies.query().$promise).then(function (rows) { + $ctrl.count = rows.$$response.data.$$response.count + $ctrl.species = rows + $ctrl.pageChanged() + }) + } + + $ctrl.pageChanged = function () { + const start = ($ctrl.page - 1) * $ctrl.pageSize + $ctrl.visible = $ctrl.species.slice(start, start + $ctrl.pageSize) + } + + $ctrl.remove = function (idx) { + const start = ($ctrl.page - 1) * $ctrl.pageSize + $ctrl.species.splice(start + idx, 1) + $ctrl.count = $ctrl.species.length + if (start >= $ctrl.species.length && $ctrl.page > 0) { + $ctrl.page-- + } + $ctrl.pageChanged() + $scope.editform.$setDirty() + } + + $ctrl.add = function (key) { + const len = $ctrl.species.push({ + ebpId: null, + sbNameLa: null, + sbNameEn: null + }) + $ctrl.page = Math.ceil(len / $ctrl.pageSize) + $ctrl.pageChanged() + $scope.editform.$setDirty() + } + + $ctrl.save = function () { + // TODO: save + } + + $ctrl.requestSpecies() +}) diff --git a/client/views/ebp.html b/client/views/ebp.html index c4f910e1..9ae16448 100644 --- a/client/views/ebp.html +++ b/client/views/ebp.html @@ -40,7 +40,7 @@