This commit is contained in:
Julius Haertl
2016-06-15 14:05:19 +02:00
parent ae9d5da329
commit cf3bbcb888
35 changed files with 686 additions and 465 deletions

View File

@@ -1,70 +1,39 @@
app.controller('ListController', function ($scope, $location, boardFactory, BoardService) {
app.controller('ListController', function ($scope, $location, BoardService) {
$scope.boards = null;
$scope.newBoard = {};
$scope.status = {};
$scope.colors = ['31CC7C', '317CCC', 'FF7A66', 'F1DB50', '7C31CC', 'CC317C', '3A3B3D', 'CACBCD'];
$scope.boardservice = BoardService;
BoardService.fetchAll().then(function(data) {
console.log($scope.boardservice);
console.log(data);
}, function(error) {
//$scope.setStatus('error','Error occured', error);
});
$scope.getBoards = function() {
boardFactory.getBoards()
.then(function (response) {
$scope.boards = response.data;
for (var i = 0; i < $scope.boards.length; i++) {
$scope.boards[i].status = {
'edit': false,
}
}
}, function (error) {
$scope.status.getBoards = 'Unable to load customer data: ' + error.message;
});
}
BoardService.fetchAll(); // TODO: show error when loading fails
$scope.selectColor = function(color) {
$scope.newBoard.color = color;
};
$scope.createBoard = function () {
boardFactory.createBoard($scope.newBoard)
BoardService.create($scope.newBoard)
.then(function (response) {
$scope.boards.push(response.data);
$scope.newBoard = {};
$scope.status.addBoard=false;
}, function(error) {
$scope.status.createBoard = 'Unable to insert board: ' + error.message;
});
};
$scope.updateBoard = function(board) {
boardFactory.updateBoard(board)
.then(function (response) {
board = response.data;
}, function(error) {
$scope.status.createBoard = 'Unable to insert board: ' + error.message;
});
BoardService.update(board);
board.status.edit = false;
$scope.$apply();
};
$scope.deleteBoard = function(board) {
// TODO: Ask for confirmation
//if (confirm('Are you sure you want to delete this?')) {
BoardService.delete(board.id);
//}
};
$scope.selectColor = function(color) {
$scope.newBoard.color = color;
};
$scope.deleteBoard = function (index) {
var board = $scope.boards[index];
boardFactory.deleteBoard(board.id)
.then(function (response) {
$scope.status.deleteBoard = 'Deleted Board';
$scope.boards.splice( index, 1 );
}, function(error) {
$scope.status.deleteBoard = 'Unable to insert board: ' + error.message;
});
};
$scope.getBoards();
});