JS: Fix scrutinizer warnings and indentation for services

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-10-04 15:38:08 +02:00
committed by Julius Härtl
parent 9014ae1490
commit 320f2bf5c8
3 changed files with 192 additions and 193 deletions

View File

@@ -20,8 +20,9 @@
*
*/
app.factory('ApiService', function($http, $q){
var ApiService = function(http, endpoint) {
/** global: oc_defaults */
app.factory('ApiService', function ($http, $q) {
var ApiService = function (http, endpoint) {
this.endpoint = endpoint;
this.baseUrl = OC.generateUrl('/apps/deck/' + endpoint);
this.http = http;
@@ -31,7 +32,7 @@ app.factory('ApiService', function($http, $q){
this.sorted = [];
};
ApiService.prototype.fetchAll = function(){
ApiService.prototype.fetchAll = function () {
var deferred = $q.defer();
var self = this;
$http.get(this.baseUrl).then(function (response) {
@@ -51,17 +52,17 @@ app.factory('ApiService', function($http, $q){
this.id = id;
var deferred = $q.defer();
if(id===undefined) {
if (id === undefined) {
return deferred.promise;
}
var self = this;
$http.get(this.baseUrl + '/' + id).then(function (response) {
data = response.data;
if(self.data[data.id]===undefined) {
var data = response.data;
if (self.data[data.id] === undefined) {
self.data[data.id] = response.data;
}
$.each(response.data, function(key, value) {
$.each(response.data, function (key, value) {
self.data[data.id][key] = value;
});
deferred.resolve(response.data);
@@ -114,12 +115,12 @@ app.factory('ApiService', function($http, $q){
// methods for managing data
ApiService.prototype.clear = function() {
ApiService.prototype.clear = function () {
this.data = {};
};
ApiService.prototype.add = function (entity) {
var element = this.data[entity.id];
if(element===undefined) {
if (element === undefined) {
this.data[entity.id] = entity;
} else {
Object.keys(entity).forEach(function (key) {
@@ -128,14 +129,14 @@ app.factory('ApiService', function($http, $q){
element.status = {};
}
};
ApiService.prototype.remove = function(id) {
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) {
angular.forEach(entities, function (entity) {
self.add(entity);
});
};
@@ -149,9 +150,8 @@ app.factory('ApiService', function($http, $q){
};
ApiService.prototype.getData = function() {
return $.map(this.data, function(value, index) {
ApiService.prototype.getData = function () {
return $.map(this.data, function (value, index) {
return [value];
});
};
@@ -160,7 +160,7 @@ app.factory('ApiService', function($http, $q){
return this.data;
};
ApiService.prototype.getName = function() {
ApiService.prototype.getName = function () {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());
return (results && results.length > 1) ? results[1] : "";

View File

@@ -20,8 +20,9 @@
*
*/
app.factory('BoardService', function(ApiService, $http, $q){
var BoardService = function($http, ep, $q) {
/** global: OC */
app.factory('BoardService', function (ApiService, $http, $q) {
var BoardService = function ($http, ep, $q) {
ApiService.call(this, $http, ep, $q);
};
BoardService.prototype = angular.copy(ApiService.prototype);
@@ -113,7 +114,7 @@ app.factory('BoardService', function(ApiService, $http, $q){
return deferred.promise;
};
BoardService.prototype.generateAcl = function(type, ocsItem) {
BoardService.prototype.generateAcl = function (type, ocsItem) {
return {
boardId: null,
id: null,
@@ -148,7 +149,7 @@ app.factory('BoardService', function(ApiService, $http, $q){
return deferred.promise;
};
BoardService.prototype.deleteAcl = function(acl) {
BoardService.prototype.deleteAcl = function (acl) {
var board = this.getCurrent();
var deferred = $q.defer();
var self = this;
@@ -162,7 +163,7 @@ app.factory('BoardService', function(ApiService, $http, $q){
return deferred.promise;
};
BoardService.prototype.updateAcl = function(acl) {
BoardService.prototype.updateAcl = function (acl) {
var board = this.getCurrent();
var deferred = $q.defer();
var self = this;
@@ -177,45 +178,44 @@ app.factory('BoardService', function(ApiService, $http, $q){
return deferred.promise;
};
BoardService.prototype.canRead = function() {
if(!this.getCurrent() || !this.getCurrent().permissions) {
BoardService.prototype.canRead = function () {
if (!this.getCurrent() || !this.getCurrent().permissions) {
return false;
}
return this.getCurrent().permissions['PERMISSION_READ'];
};
BoardService.prototype.canEdit = function() {
if(!this.getCurrent() || !this.getCurrent().permissions) {
BoardService.prototype.canEdit = function () {
if (!this.getCurrent() || !this.getCurrent().permissions) {
return false;
}
return this.getCurrent().permissions['PERMISSION_EDIT'];
};
BoardService.prototype.canManage = function(board) {
if(board !== null && board !== undefined) {
BoardService.prototype.canManage = function (board) {
if (board !== null && board !== undefined) {
return board.permissions['PERMISSION_MANAGE'];
}
if(!this.getCurrent() || !this.getCurrent().permissions) {
if (!this.getCurrent() || !this.getCurrent().permissions) {
return false;
}
return this.getCurrent().permissions['PERMISSION_MANAGE'];
};
BoardService.prototype.canShare = function() {
if(!this.getCurrent() || !this.getCurrent().permissions) {
BoardService.prototype.canShare = function () {
if (!this.getCurrent() || !this.getCurrent().permissions) {
return false;
}
return this.getCurrent().permissions['PERMISSION_SHARE'];
};
BoardService.prototype.isArchived = function () {
if(!this.getCurrent() || this.getCurrent().archived) {
if (!this.getCurrent() || this.getCurrent().archived) {
return true;
}
return false;
};
service = new BoardService($http, 'boards', $q);
return service;
return new BoardService($http, 'boards', $q);
});

View File

@@ -20,11 +20,10 @@
*
*/
app.factory('LabelService', function(ApiService, $http, $q){
var LabelService = function($http, ep, $q) {
app.factory('LabelService', function (ApiService, $http, $q) {
var LabelService = function ($http, ep, $q) {
ApiService.call(this, $http, ep, $q);
};
LabelService.prototype = angular.copy(ApiService.prototype);
service = new LabelService($http, 'labels', $q);
return service;
return new LabelService($http, 'labels', $q);
});