mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 04:15:28 +02:00
* chore(project): install prettier and lint-staged * chore(project): apply prettier to html too * chore(project): git ignore eslintcache * chore(project): add a comment about format script * chore(prettier): update printWidth * chore(prettier): remove useTabs option * chore(prettier): add HTML validation * refactor(prettier): fix closing tags * feat(prettier): define angular parser for html templates * style(prettier): run prettier on codebase Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
import { StoridgeSnapshotModel } from '../models/snapshot';
|
|
|
|
angular.module('portainer.integrations.storidge').factory('StoridgeSnapshotService', [
|
|
'$q',
|
|
'Storidge',
|
|
function StoridgeSnapshotServiceFactory($q, Storidge) {
|
|
'use strict';
|
|
var service = {};
|
|
|
|
service.snapshots = snapshots;
|
|
service.snapshot = snapshot;
|
|
service.create = create;
|
|
service.remove = remove;
|
|
|
|
function snapshots(volumeId) {
|
|
var deferred = $q.defer();
|
|
|
|
Storidge.querySnapshots({ id: volumeId })
|
|
.$promise.then(function success(data) {
|
|
var snapshotsData = data.snapshots;
|
|
let snapshotsArray = [];
|
|
for (const key in snapshotsData) {
|
|
if (snapshotsData.hasOwnProperty(key)) {
|
|
snapshotsArray.push(snapshotsData[key]);
|
|
}
|
|
}
|
|
var snapshots = snapshotsArray.map(function (snapshot) {
|
|
return new StoridgeSnapshotModel(snapshot);
|
|
});
|
|
deferred.resolve(snapshots);
|
|
})
|
|
.catch(function error(err) {
|
|
deferred.reject({ msg: 'Unable to retrieve Storidge snapshots', err: err });
|
|
});
|
|
|
|
return deferred.promise;
|
|
}
|
|
|
|
function snapshot(id) {
|
|
var deferred = $q.defer();
|
|
|
|
Storidge.getSnapshot({ id: id })
|
|
.$promise.then(function success(data) {
|
|
var snapshot = new StoridgeSnapshotModel(data.snapshot);
|
|
deferred.resolve(snapshot);
|
|
})
|
|
.catch(function error(err) {
|
|
deferred.reject({ msg: 'Unable to retrieve Storidge snapshot', err: err });
|
|
});
|
|
|
|
return deferred.promise;
|
|
}
|
|
|
|
function create(volumeId, description) {
|
|
var deferred = $q.defer();
|
|
Storidge.createSnapshot({ id: volumeId, opts: { description: description } })
|
|
.$promise.then(function success(data) {
|
|
deferred.resolve(data);
|
|
})
|
|
.catch(function error(err) {
|
|
deferred.reject({ msg: 'Unable to create Storidge volume snapshot', err: err });
|
|
});
|
|
|
|
return deferred.promise;
|
|
}
|
|
|
|
function remove(id) {
|
|
var deferred = $q.defer();
|
|
|
|
Storidge.removeSnapshot({ id: id })
|
|
.$promise.then(function success() {
|
|
deferred.resolve();
|
|
})
|
|
.catch(function error(err) {
|
|
deferred.reject({ msg: 'Unable to remove Storidge volume snapshot', err: err });
|
|
});
|
|
|
|
return deferred.promise;
|
|
}
|
|
|
|
return service;
|
|
},
|
|
]);
|