UNPKG

zettapi_client

Version:

Client side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project

63 lines (55 loc) 2.24 kB
app.directive('zlList', function(zapiPath) { return { restrict: 'E', scope: { dbs: '=', channel: '@' }, replace: false, templateUrl: zapiPath + '/directives/list/list.html', controller: function($scope, $list, NgTableParams, $httpParamSerializer, $timeout) { $scope.items = []; $scope.tableParams = null; $scope.list = { name: "", parameters: [], values: {} }; $scope.selectedDbs = []; initialize(); $scope.reset = function() { $scope.items = []; $scope.tableParams = null; }; $scope.get = function(list) { $list.get(list, $scope.selectedDbs, $scope.channel, function(items) { var initialParams = {}, params = { dataset: items }; if (list.group) { initialParams.group = list.group; } if (typeof list.groupOptions !== 'undefined') { params.groupOptions = list.groupOptions; } $scope.items = items; $scope.tableParams = new NgTableParams(initialParams, params); }); }; $scope.getExcelUrl = function(list) { return '/api/list/values/' + list.name + '?xls=1&' + $httpParamSerializer({ query: list.values, dbs: $scope.selectedDbs }); }; $scope.applySearch = function(search) { var criteria = angular.copy(search.text); if (search.inverted) { criteria = "!" + criteria; } $scope.tableParams.filter({ $: criteria }); }; function initialize() { $timeout(function() { //selecionar automáticamente caso seja apenas 1 db if ($scope.dbs.length === 1) $scope.selectedDbs.push($scope.dbs[0]); $list.getMetadata(function(lists) { $scope.lists = lists; }); }); } } }; });