diff --git a/app/js/services/dataset.js b/app/js/services/dataset.js new file mode 100644 index 0000000..38c7daa --- /dev/null +++ b/app/js/services/dataset.js @@ -0,0 +1,73 @@ +'use strict'; + +var servicesModule = require('./_index.js'); + +/** + * @ngInject + */ +function DatasetService($q, $http) { + + var service = {}; + + service.list = function() { + return $http({ + cache: true, + url: 'data/config.json', + method: 'GET' + }); + }; + + service.get = function(id) { + return $q(function(resolve, reject) { + service.list().then(function(response) { + for (let entry of response.data.tempest) { + if (entry.id === id) { + resolve(entry); + return; + } + } + + reject("Dataset not found with ID: " + id); + }, function(reason) { + reject(reason); + }); + }); + }; + + service.raw = function(dataset) { + return $http({ + cache: true, + url: dataset.raw, + method: 'GET' + }); + }; + + service.details = function(dataset) { + return $http({ + cache: true, + url: dataset.details, + method: 'GET' + }); + }; + + service.tree = function(dataset) { + return $http({ + cache: true, + url: dataset.tree, + method: 'GET' + }); + }; + + service.dstat = function(dataset) { + return $http({ + cache: true, + url: dataset.dstat, + method: 'GET' + }); + }; + + return service; + +} + +servicesModule.service('datasetService', DatasetService);