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

43 lines (40 loc) 1.72 kB
app.service('$list', function ($http, blockUI, mySocket) { this.getMetadata = function (callback) { blockUI.start("A obter listagens disponíveis..."); $http.get('/api/list/getall').then(function (response) { response.data.forEach(function (list) { list.values = {}; }); callback(response.data); }).catch(function (response) { console.log(response); swal("Atenção", "Não foi possível obter as listagens disponíveis, por favor actualize a página", "warning"); callback([]); }).finally(function () { blockUI.stop(); }); }; this.get = function (list, dbs, channel, callback) { if (dbs.length === 0) return swal("Atenção", "Selecione pelo menos uma exploração", "warning"); blockUI.start("A obter listagem..."); $http.get('/api/list/values/' + list.name, { params: { query: list.values, dbs: dbs } }).then(function (response) { mySocket.on(channel, function (data) { if (typeof data.ok !== 'undefined') { blockUI.stop(); callback(data.ok); } else if (typeof data.error !== 'undefined') { blockUI.stop(); swal("Ocorreu um erro", data.error, "error"); callback([]); } else if (typeof data.message !== 'undefined') { blockUI.message(data.message); } }); }).catch(function (response) { swal("Atenção", response.data, "warning"); blockUI.stop(); }); }; });