Plato on Github
Report Home
lib\model\Modalities.js
Maintainability
81.82
Lines of code
93
Difficulty
13.94
Estimated Errors
0.26
Function weight
By Complexity
By SLOC
/** * @ngdoc service * @name predicsis.jsSDK.models.Modalities * @requires $q * @requires Restangular * @requires Jobs * @description * <table> * <tr> * <td><span class="badge post">post</span> <kbd>/modalities_sets</kbd></td> * <td><kbd>{@link predicsis.jsSDK.models.Modalities#methods_create Modalities.create()}</kbd></td> * <td><span class="badge async">async</span></td> * </tr> * <tr> * <td><span class="badge get">get</span> <kbd>/modalities_sets</kbd></td> * <td><kbd>{@link predicsis.jsSDK.models.Modalities#methods_all Modalities.all()}</kbd></td> * <td></td> * </tr> * <tr> * <td><span class="badge get">get</span> <kbd>/modalities_sets/:id</kbd></td> * <td><kbd>{@link predicsis.jsSDK.models.Modalities#methods_get Modalities.get()}</kbd></td> * <td></td> * </tr> * <tr> * <td><span class="badge delete">delete</span> <kbd>/modalities_sets/:id</kbd></td> * <td><kbd>{@link predicsis.jsSDK.models.Modalities#methods_delete Modalities.delete()}</kbd></td> * <td></td> * </tr> * <tfoot> * <tr><td colspan="3">Official documentation is available at https://developer.predicsis.com/doc/v1/dictionary/modalities/</td></tr> * </tfoot> * </table> */ angular .module('predicsis.jsSDK.models') .service('Modalities', function($q, Restangular, Jobs) { 'use strict'; function modality(id) { return Restangular.one('modalities_sets', id); } function modalities() { return Restangular.all('modalities_sets'); } // ----------------------------------------------------------------------------------------------------------------- /** * @ngdoc function * @name create * @methodOf predicsis.jsSDK.models.Modalities * @description Send POST request to the <code>modalities_sets</code> API resource. * * You can / must give the following parameters to ask for a modalities set creation: * <pre> * { * variable_id: "5329601c1757f446e6000002" * dataset_id: "53c7dea470632d3417020000", * } * </pre> * * Both <code>variable_id</code> and <code>dataset_id</code> are required. * * @param {Object} params See above example. * @return {Promise} Returned modalities set does not contain modalities themselves. * If you want them, you must explicitly {@link predicsis.jsSDK.models.Modalities#methods_get get} them. * In fact, you will get an object like: * <pre> * { * id": "53fdfa7070632d0fc5030000", * created_at: "2014-05-02T17:13:56.687Z", * user_id: "5363b25c687964476d000000", * dataset_id: "53c7dea470632d3417020000", * variable_id: "5329601c1757f446e6000002", * job_ids: [ "53c8c88970632d3b9a030001" ] * } * </pre> */ this.create = function(params) { return Jobs.wrapAsyncPromise(modalities().post({modalities_set: params})) .then(function(result) { return modality(result.id).get(); }); }; /** * @ngdoc function * @name all * @methodOf predicsis.jsSDK.models.Modalities * @description Get all (or a list of) generated modalities sets * @param {Array} [modalitiesSetIds] List of modalities sets ids you want to fetch * @return {Promise} A list of modalities sets */ this.all = function(modalitiesSetIds) { if(modalitiesSetIds === undefined) { return modalities().getList(); } else { modalitiesSetIds = modalitiesSetIds || []; return $q.all(modalitiesSetIds.map(function(id) { return modality(id).get(); })); } }; /** * @ngdoc function * @name get * @methodOf predicsis.jsSDK.models.Modalities * @description Get a single modalities set by its id * @param {String} id Modalities set identifier * @return {Promise} A modalities set */ this.get = function(id) { return modality(id).get(); }; /** * @ngdoc function * @name delete * @methodOf predicsis.jsSDK.models.Modalities * @description Permanently destroy a specified source * @param {String} id Id of the source you want to remove * @return {Promise} A removed source */ this.delete = function(id) { return modality(id).remove(); }; });