Add DatasetService to read and manage config.json
.
The DatasetService is intended to load and manage any number of configured data sources as specified in `config.json`. It also enforces use of Angular's built-in content caching to improve loading times of already-accessed datasets. Change-Id: Ibb161a171d6375bf024bf8c0ab051c3f1a97f760
This commit is contained in:
parent
8be1f587d7
commit
37e06a5723
73
app/js/services/dataset.js
Normal file
73
app/js/services/dataset.js
Normal file
@ -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);
|
Loading…
Reference in New Issue
Block a user