JS: Fix scrutinizer warnings and indentation for services
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
committed by
Julius Härtl
parent
9014ae1490
commit
320f2bf5c8
@@ -20,152 +20,152 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.factory('ApiService', function($http, $q){
|
/** global: oc_defaults */
|
||||||
var ApiService = function(http, endpoint) {
|
app.factory('ApiService', function ($http, $q) {
|
||||||
this.endpoint = endpoint;
|
var ApiService = function (http, endpoint) {
|
||||||
this.baseUrl = OC.generateUrl('/apps/deck/' + endpoint);
|
this.endpoint = endpoint;
|
||||||
this.http = http;
|
this.baseUrl = OC.generateUrl('/apps/deck/' + endpoint);
|
||||||
this.q = $q;
|
this.http = http;
|
||||||
this.data = {};
|
this.q = $q;
|
||||||
this.id = null;
|
this.data = {};
|
||||||
this.sorted = [];
|
this.id = null;
|
||||||
};
|
this.sorted = [];
|
||||||
|
};
|
||||||
|
|
||||||
ApiService.prototype.fetchAll = function(){
|
ApiService.prototype.fetchAll = function () {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
$http.get(this.baseUrl).then(function (response) {
|
$http.get(this.baseUrl).then(function (response) {
|
||||||
var objects = response.data;
|
var objects = response.data;
|
||||||
objects.forEach(function (obj) {
|
objects.forEach(function (obj) {
|
||||||
self.data[obj.id] = obj;
|
self.data[obj.id] = obj;
|
||||||
});
|
});
|
||||||
deferred.resolve(self.data);
|
deferred.resolve(self.data);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
deferred.reject('Fetching ' + self.endpoint + ' failed');
|
deferred.reject('Fetching ' + self.endpoint + ' failed');
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiService.prototype.fetchOne = function (id) {
|
ApiService.prototype.fetchOne = function (id) {
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
if(id===undefined) {
|
if (id === undefined) {
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
$http.get(this.baseUrl + '/' + id).then(function (response) {
|
$http.get(this.baseUrl + '/' + id).then(function (response) {
|
||||||
data = response.data;
|
var data = response.data;
|
||||||
if(self.data[data.id]===undefined) {
|
if (self.data[data.id] === undefined) {
|
||||||
self.data[data.id] = response.data;
|
self.data[data.id] = response.data;
|
||||||
}
|
}
|
||||||
$.each(response.data, function(key, value) {
|
$.each(response.data, function (key, value) {
|
||||||
self.data[data.id][key] = value;
|
self.data[data.id][key] = value;
|
||||||
});
|
});
|
||||||
deferred.resolve(response.data);
|
deferred.resolve(response.data);
|
||||||
|
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
deferred.reject('Fetching ' + self.endpoint + ' failed');
|
deferred.reject('Fetching ' + self.endpoint + ' failed');
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiService.prototype.create = function (entity) {
|
ApiService.prototype.create = function (entity) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
$http.post(this.baseUrl, entity).then(function (response) {
|
$http.post(this.baseUrl, entity).then(function (response) {
|
||||||
self.add(response.data);
|
self.add(response.data);
|
||||||
deferred.resolve(response.data);
|
deferred.resolve(response.data);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
deferred.reject('Fetching' + self.endpoint + ' failed');
|
deferred.reject('Fetching' + self.endpoint + ' failed');
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiService.prototype.update = function (entity) {
|
ApiService.prototype.update = function (entity) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
$http.put(this.baseUrl + '/' + entity.id, entity).then(function (response) {
|
$http.put(this.baseUrl + '/' + entity.id, entity).then(function (response) {
|
||||||
self.add(response.data);
|
self.add(response.data);
|
||||||
deferred.resolve(response.data);
|
deferred.resolve(response.data);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
deferred.reject('Updating ' + self.endpoint + ' failed');
|
deferred.reject('Updating ' + self.endpoint + ' failed');
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ApiService.prototype.delete = function (id) {
|
ApiService.prototype.delete = function (id) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
$http.delete(this.baseUrl + '/' + id).then(function (response) {
|
$http.delete(this.baseUrl + '/' + id).then(function (response) {
|
||||||
self.remove(id);
|
self.remove(id);
|
||||||
deferred.resolve(response.data);
|
deferred.resolve(response.data);
|
||||||
|
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
deferred.reject('Deleting ' + self.endpoint + ' failed');
|
deferred.reject('Deleting ' + self.endpoint + ' failed');
|
||||||
});
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// methods for managing data
|
|
||||||
ApiService.prototype.clear = function() {
|
|
||||||
this.data = {};
|
|
||||||
};
|
|
||||||
ApiService.prototype.add = function (entity) {
|
|
||||||
var element = this.data[entity.id];
|
|
||||||
if(element===undefined) {
|
|
||||||
this.data[entity.id] = entity;
|
|
||||||
} else {
|
|
||||||
Object.keys(entity).forEach(function (key) {
|
|
||||||
element[key] = entity[key];
|
|
||||||
});
|
|
||||||
element.status = {};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ApiService.prototype.remove = function(id) {
|
|
||||||
if (this.data[id] !== undefined) {
|
|
||||||
delete this.data[id];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ApiService.prototype.addAll = function (entities) {
|
|
||||||
var self = this;
|
|
||||||
angular.forEach(entities, function(entity) {
|
|
||||||
self.add(entity);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ApiService.prototype.getCurrent = function () {
|
// methods for managing data
|
||||||
return this.data[this.id];
|
ApiService.prototype.clear = function () {
|
||||||
};
|
this.data = {};
|
||||||
|
};
|
||||||
|
ApiService.prototype.add = function (entity) {
|
||||||
|
var element = this.data[entity.id];
|
||||||
|
if (element === undefined) {
|
||||||
|
this.data[entity.id] = entity;
|
||||||
|
} else {
|
||||||
|
Object.keys(entity).forEach(function (key) {
|
||||||
|
element[key] = entity[key];
|
||||||
|
});
|
||||||
|
element.status = {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ApiService.prototype.remove = function (id) {
|
||||||
|
if (this.data[id] !== undefined) {
|
||||||
|
delete this.data[id];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ApiService.prototype.addAll = function (entities) {
|
||||||
|
var self = this;
|
||||||
|
angular.forEach(entities, function (entity) {
|
||||||
|
self.add(entity);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ApiService.prototype.getCurrent = function () {
|
||||||
|
return this.data[this.id];
|
||||||
|
};
|
||||||
|
|
||||||
ApiService.prototype.unsetCurrrent = function () {
|
ApiService.prototype.unsetCurrrent = function () {
|
||||||
this.id = null;
|
this.id = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
ApiService.prototype.getData = function () {
|
||||||
|
return $.map(this.data, function (value, index) {
|
||||||
|
return [value];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
ApiService.prototype.getData = function() {
|
ApiService.prototype.getAll = function () {
|
||||||
return $.map(this.data, function(value, index) {
|
return this.data;
|
||||||
return [value];
|
};
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ApiService.prototype.getAll = function () {
|
ApiService.prototype.getName = function () {
|
||||||
return this.data;
|
var funcNameRegex = /function (.{1,})\(/;
|
||||||
};
|
var results = (funcNameRegex).exec((this).constructor.toString());
|
||||||
|
return (results && results.length > 1) ? results[1] : "";
|
||||||
|
};
|
||||||
|
|
||||||
ApiService.prototype.getName = function() {
|
return ApiService;
|
||||||
var funcNameRegex = /function (.{1,})\(/;
|
|
||||||
var results = (funcNameRegex).exec((this).constructor.toString());
|
|
||||||
return (results && results.length > 1) ? results[1] : "";
|
|
||||||
};
|
|
||||||
|
|
||||||
return ApiService;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,11 +20,12 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.factory('BoardService', function(ApiService, $http, $q){
|
/** global: OC */
|
||||||
var BoardService = function($http, ep, $q) {
|
app.factory('BoardService', function (ApiService, $http, $q) {
|
||||||
ApiService.call(this, $http, ep, $q);
|
var BoardService = function ($http, ep, $q) {
|
||||||
};
|
ApiService.call(this, $http, ep, $q);
|
||||||
BoardService.prototype = angular.copy(ApiService.prototype);
|
};
|
||||||
|
BoardService.prototype = angular.copy(ApiService.prototype);
|
||||||
|
|
||||||
BoardService.prototype.delete = function (id) {
|
BoardService.prototype.delete = function (id) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
@@ -113,7 +114,7 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.generateAcl = function(type, ocsItem) {
|
BoardService.prototype.generateAcl = function (type, ocsItem) {
|
||||||
return {
|
return {
|
||||||
boardId: null,
|
boardId: null,
|
||||||
id: null,
|
id: null,
|
||||||
@@ -148,74 +149,73 @@ app.factory('BoardService', function(ApiService, $http, $q){
|
|||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.deleteAcl = function(acl) {
|
BoardService.prototype.deleteAcl = function (acl) {
|
||||||
var board = this.getCurrent();
|
var board = this.getCurrent();
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
$http.delete(this.baseUrl + '/' + acl.boardId + '/acl/' + acl.id).then(function (response) {
|
$http.delete(this.baseUrl + '/' + acl.boardId + '/acl/' + acl.id).then(function (response) {
|
||||||
delete board.acl[response.data.id];
|
delete board.acl[response.data.id];
|
||||||
deferred.resolve(response.data);
|
deferred.resolve(response.data);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
deferred.reject('Error deleting ACL ' + acl.id);
|
deferred.reject('Error deleting ACL ' + acl.id);
|
||||||
});
|
});
|
||||||
acl = null;
|
acl = null;
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.updateAcl = function(acl) {
|
BoardService.prototype.updateAcl = function (acl) {
|
||||||
var board = this.getCurrent();
|
var board = this.getCurrent();
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
var self = this;
|
var self = this;
|
||||||
var _acl = acl;
|
var _acl = acl;
|
||||||
$http.put(this.baseUrl + '/' + acl.boardId + '/acl', _acl).then(function (response) {
|
$http.put(this.baseUrl + '/' + acl.boardId + '/acl', _acl).then(function (response) {
|
||||||
board.acl[_acl.id] = response.data;
|
board.acl[_acl.id] = response.data;
|
||||||
deferred.resolve(response.data);
|
deferred.resolve(response.data);
|
||||||
}, function (error) {
|
}, function (error) {
|
||||||
deferred.reject('Error updating ACL ' + _acl);
|
deferred.reject('Error updating ACL ' + _acl);
|
||||||
});
|
});
|
||||||
acl = null;
|
acl = null;
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.canRead = function() {
|
BoardService.prototype.canRead = function () {
|
||||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
if (!this.getCurrent() || !this.getCurrent().permissions) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.getCurrent().permissions['PERMISSION_READ'];
|
return this.getCurrent().permissions['PERMISSION_READ'];
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.canEdit = function() {
|
BoardService.prototype.canEdit = function () {
|
||||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
if (!this.getCurrent() || !this.getCurrent().permissions) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.getCurrent().permissions['PERMISSION_EDIT'];
|
return this.getCurrent().permissions['PERMISSION_EDIT'];
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.canManage = function(board) {
|
BoardService.prototype.canManage = function (board) {
|
||||||
if(board !== null && board !== undefined) {
|
if (board !== null && board !== undefined) {
|
||||||
return board.permissions['PERMISSION_MANAGE'];
|
return board.permissions['PERMISSION_MANAGE'];
|
||||||
}
|
}
|
||||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
if (!this.getCurrent() || !this.getCurrent().permissions) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.getCurrent().permissions['PERMISSION_MANAGE'];
|
return this.getCurrent().permissions['PERMISSION_MANAGE'];
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.canShare = function() {
|
BoardService.prototype.canShare = function () {
|
||||||
if(!this.getCurrent() || !this.getCurrent().permissions) {
|
if (!this.getCurrent() || !this.getCurrent().permissions) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.getCurrent().permissions['PERMISSION_SHARE'];
|
return this.getCurrent().permissions['PERMISSION_SHARE'];
|
||||||
};
|
};
|
||||||
|
|
||||||
BoardService.prototype.isArchived = function () {
|
BoardService.prototype.isArchived = function () {
|
||||||
if(!this.getCurrent() || this.getCurrent().archived) {
|
if (!this.getCurrent() || this.getCurrent().archived) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
service = new BoardService($http, 'boards', $q);
|
return new BoardService($http, 'boards', $q);
|
||||||
return service;
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,11 +20,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
app.factory('LabelService', function(ApiService, $http, $q){
|
app.factory('LabelService', function (ApiService, $http, $q) {
|
||||||
var LabelService = function($http, ep, $q) {
|
var LabelService = function ($http, ep, $q) {
|
||||||
ApiService.call(this, $http, ep, $q);
|
ApiService.call(this, $http, ep, $q);
|
||||||
};
|
};
|
||||||
LabelService.prototype = angular.copy(ApiService.prototype);
|
LabelService.prototype = angular.copy(ApiService.prototype);
|
||||||
service = new LabelService($http, 'labels', $q);
|
return new LabelService($http, 'labels', $q);
|
||||||
return service;
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user