Use card data from CardService so we don't need to store objects twice

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-06-12 17:16:34 +02:00
parent 0137b882c5
commit 757b041f73
4 changed files with 28 additions and 22 deletions

View File

@@ -135,7 +135,6 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
var header = $('.section-header.card-description');
header.find('.save-indicator.unsaved').hide();
header.find('.save-indicator.saved').fadeIn(250).fadeOut(1000);
StackService.updateCard($scope.status.edit);
});
$('#markdown input[type=checkbox]').removeAttr('disabled');
@@ -178,7 +177,6 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
var header = $('.section-header.card-description');
header.find('.save-indicator.unsaved').hide();
header.find('.save-indicator.saved').fadeIn(250).fadeOut(1000);
StackService.updateCard($scope.status.edit);
$scope.status.saving = false;
});
}
@@ -187,7 +185,6 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
// handle rename to update information on the board as well
$scope.cardRename = function (card) {
CardService.rename(card).then(function (data) {
StackService.updateCard(card);
$scope.status.renameCard = false;
});
};
@@ -197,19 +194,16 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
var header = $('.section-content.card-description');
header.find('.save-indicator.unsaved').hide();
header.find('.save-indicator.saved').fadeIn(500).fadeOut(1000);
StackService.updateCard(card);
});
};
$scope.labelAssign = function (element, model) {
CardService.assignLabel($scope.cardId, element.id).then(function (data) {
StackService.updateCard(CardService.getCurrent());
});
};
$scope.labelRemove = function (element, model) {
CardService.removeLabel($scope.cardId, element.id).then(function (data) {
StackService.updateCard(CardService.getCurrent());
});
};
@@ -224,7 +218,6 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
newDate.year(duedate.year());
element.duedate = newDate.toISOString();
CardService.update(element);
StackService.updateCard(element);
};
$scope.setDuedateTime = function (time) {
var element = CardService.getCurrent();
@@ -236,14 +229,12 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
newDate.minute(time.minute());
element.duedate = newDate.toISOString();
CardService.update(element);
StackService.updateCard(element);
};
$scope.resetDuedate = function () {
var element = CardService.getCurrent();
element.duedate = null;
CardService.update(element);
StackService.updateCard(element);
};
/**
@@ -267,14 +258,12 @@ app.controller('CardController', function ($scope, $rootScope, $sce, $location,
$scope.addAssignedUser = function(item) {
CardService.assignUser(CardService.getCurrent(), item.uid).then(function (data) {
StackService.updateCard(CardService.getCurrent());
});
$scope.status.showAssignUser = false;
};
$scope.removeAssignedUser = function(uid) {
CardService.unassignUser(CardService.getCurrent(), uid).then(function (data) {
StackService.updateCard(CardService.getCurrent());
});
};

View File

@@ -163,6 +163,10 @@ app.factory('ApiService', function ($http, $q) {
return this.data;
};
ApiService.prototype.get = function (id) {
return this.data[id];
};
ApiService.prototype.getName = function () {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());

View File

@@ -21,7 +21,7 @@
*/
import app from '../app/App.js';
app.factory('StackService', function (ApiService, $http, $q) {
app.factory('StackService', function (ApiService, CardService, $http, $q) {
var StackService = function ($http, ep, $q) {
ApiService.call(this, $http, ep, $q);
};
@@ -32,6 +32,12 @@ app.factory('StackService', function (ApiService, $http, $q) {
$http.get(this.baseUrl + '/' + boardId).then(function (response) {
self.clear();
self.addAll(response.data);
// When loading a stack add cards to the CardService so we can fetch
// information from there. That way we don't need to refresh the whole
// stack data during digest if some value changes
angular.forEach(response.data, function (entity) {
CardService.addAll(entity.cards);
});
deferred.resolve(self.data);
}, function (error) {
deferred.reject('Error while loading stacks');
@@ -45,6 +51,9 @@ app.factory('StackService', function (ApiService, $http, $q) {
$http.get(this.baseUrl + '/' + boardId + '/archived').then(function (response) {
self.clear();
self.addAll(response.data);
angular.forEach(response.data, function (entity) {
CardService.addAll(entity.cards);
});
deferred.resolve(self.data);
}, function (error) {
deferred.reject('Error while loading stacks');
@@ -119,7 +128,7 @@ app.factory('StackService', function (ApiService, $http, $q) {
}
};
// FIXME: Should not sure popup but proper undo mechanism
// FIXME: Should not show popup but proper undo mechanism
StackService.prototype.delete = function (id) {
var deferred = $q.defer();
var self = this;