UNPKG

zettapi_client

Version:

Admin panel and client-side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project.

38 lines (35 loc) 1.65 kB
app.service('$graph', function($http, graphOptions, zapi) { this.get = function(driver, namespace, db, collection, query, obj, seriesKey, dataKey, labelsKey, callback) { var params = { query: query, obj: obj, seriesKey: seriesKey, dataKey: dataKey, labelsKey: labelsKey }; if (typeof driver === 'undefined') driver = 'mongo'; var url = zapi.serverUrl + '/api/graph/auto/' + namespace + '/' + db + '/' + collection + '/' + driver; $http.post(url, params).then(function(response) { response.data.options = angular.copy(graphOptions); if (response.data.series.length > 0) response.data.options.legend = { display: true }; callback(response.data); }).catch(function(response) { swal("Atenção", response.data, "warning"); callback(); }); }; this.custom = function(driver, namespace, db, graph, callback) { if (typeof driver === 'undefined') driver = 'mongo'; var url = zapi.serverUrl + '/api/graph/custom/' + namespace + '/' + db + '/' + graph + '/' + driver; $http.get(url, { cache: true }).then(function(response) { response.data.options = angular.copy(graphOptions); if (typeof response.data.series !== 'undefined') { if (response.data.series.length > 0) response.data.options.legend = { display: true }; } callback(response.data); }).catch(function(response) { swal("Atenção", response.data, "warning"); callback(); }); }; });