refactoring and stack undo delete early wip
Signed-off-by: Manuel Arno Korfmann <manu@korfmann.info> stack soft delete done Signed-off-by: Manuel Arno Korfmann <manu@korfmann.info> stack undo delete done Signed-off-by: Manuel Arno Korfmann <manu@korfmann.info> stack undo: code review remarks and fixes Signed-off-by: Manuel Arno Korfmann <manu@korfmann.info>
This commit is contained in:
committed by
Julius Härtl
parent
f2795f120b
commit
ef4ce31c47
@@ -4,20 +4,20 @@
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
import app from '../app/App.js';
|
||||
@@ -42,7 +42,17 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
|
||||
$scope.board = BoardService.getCurrent();
|
||||
$scope.uploader = FileService.uploader;
|
||||
|
||||
$scope.deletedCards = [];
|
||||
$scope.deletedCards = {};
|
||||
$scope.deletedStacks = {};
|
||||
|
||||
$scope.$watch(function() {
|
||||
return $state.current;
|
||||
}, function(currentState) {
|
||||
if(currentState.name === 'board.detail') {
|
||||
$scope.loadDeletedEntity(CardService, 'deletedCards');
|
||||
$scope.loadDeletedEntity(StackService, 'deletedStacks');
|
||||
}
|
||||
});
|
||||
|
||||
// workaround for $stateParams changes not being propagated
|
||||
$scope.$watch(function() {
|
||||
@@ -138,9 +148,11 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
|
||||
});
|
||||
};
|
||||
|
||||
$scope.loadDeletedCards = function() {
|
||||
CardService.fetchDeleted($scope.id).then(function (data) {
|
||||
$scope.deletedCards = data;
|
||||
$scope.loadDeletedEntity = function(service, scopeKey) {
|
||||
service.fetchDeleted($scope.id).then(function (data) {
|
||||
for(i=0;i<data.length;i++) {
|
||||
$scope[scopeKey][data[i].id] = data[i];
|
||||
}
|
||||
}, function (error) {
|
||||
$scope.statusservice.setError('Error occured', error);
|
||||
});
|
||||
@@ -196,30 +208,30 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
|
||||
});
|
||||
};
|
||||
|
||||
$scope.stackDelete = function (stack) {
|
||||
$scope.stackservice.delete(stack.id).then(function() {
|
||||
$scope.deletedStacks[stack.id] = stack;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.stackUndoDelete = function (deletedStack) {
|
||||
StackService.undoDelete(deletedStack).then(function() {
|
||||
delete $scope.deletedStacks[deletedStack.id];
|
||||
});
|
||||
}
|
||||
|
||||
$scope.cardDelete = function (card) {
|
||||
OC.dialogs.confirm(t('deck', 'Are you sure you want to delete this card with all of its data?'), t('deck', 'Delete'), function(state) {
|
||||
if (!state) {
|
||||
return;
|
||||
}
|
||||
CardService.delete(card.id).then(function () {
|
||||
StackService.removeCard(card);
|
||||
$scope.deletedCards.push(card);
|
||||
});
|
||||
CardService.delete(card.id).then(function () {
|
||||
StackService.removeCard(card);
|
||||
$scope.deletedCards[card.id] = card;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.cardUndoDelete = function (deletedCard) {
|
||||
CardService.undoDelete(deletedCard);
|
||||
StackService.addCard(deletedCard);
|
||||
$scope.removeFromDeletedCards(deletedCard);
|
||||
};
|
||||
|
||||
$scope.removeFromDeletedCards = function(deletedCard) {
|
||||
for(var i=0;i<$scope.deletedCards.length;i++) {
|
||||
if($scope.deletedCards[i].id === deletedCard.id) {
|
||||
$scope.deletedCards.splice(i, 1);
|
||||
}
|
||||
}
|
||||
CardService.undoDelete(deletedCard).then(function() {
|
||||
StackService.addCard(deletedCard);
|
||||
delete $scope.deletedCards[deletedCard.id];
|
||||
});
|
||||
};
|
||||
|
||||
$scope.cardArchive = function (card) {
|
||||
@@ -262,7 +274,6 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
|
||||
// TODO: remove from cards
|
||||
};
|
||||
$scope.labelCreate = function (label) {
|
||||
alert(label);
|
||||
label.boardId = $scope.id;
|
||||
LabelService.create(label).then(function (data) {
|
||||
$scope.newStack.title = '';
|
||||
@@ -410,6 +421,4 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St
|
||||
}
|
||||
return card.attachmentCount;
|
||||
};
|
||||
|
||||
$scope.loadDeletedCards();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user