js/controller/ListController.js   A
last analyzed

Complexity

Total Complexity 15
Complexity/F 1.25

Size

Lines of Code 56
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 0
c 1
b 1
f 0
nc 2
dl 0
loc 56
rs 10
wmc 15
mnd 1
bc 14
fnc 12
bpm 1.1666
cpm 1.25
noi 5
1
2
/*
3
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *  
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *  
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *  
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *  
22
 */
23
24
app.controller('ListController', function ($scope, $location, $filter, BoardService, $element) {
25
	$scope.boards = [];
26
	$scope.newBoard = {};
27
	$scope.status = {};
28
	$scope.colors = ['0082c9', '00c9c6','00c906', 'c92b00', 'F1DB50', '7C31CC', '3A3B3D', 'CACBCD'];
29
	$scope.boardservice = BoardService;
30
	$scope.newBoard.color = $scope.colors[0];
31
32
	// FIXME: not nice, but we want to load this only once
33
	if($element.attr('id') === 'app-navigation') {
34
		BoardService.fetchAll().then(function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
35
			$scope.filterData();
36
		}, function (error) {
0 ignored issues
show
Unused Code introduced by
The parameter error is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
37
			// TODO: show error when loading fails
38
		});
39
	}
40
41
	$scope.filterData = function () {
42
		angular.copy($scope.boardservice.getData(), $scope.boardservice.sorted);
43
		$scope.boardservice.sorted = $filter('orderBy')($scope.boardservice.sorted, 'title');
44
	};
45
46
	$scope.selectColor = function(color) {
47
		$scope.newBoard.color = color;
48
	};
49
50
	$scope.boardCreate = function() {
51
		if(!$scope.newBoard.title || !$scope.newBoard.color) {
52
			$scope.status.addBoard=false;
53
			return;
54
		}
55
		BoardService.create($scope.newBoard)
56
			.then(function (response) {
0 ignored issues
show
Unused Code introduced by
The parameter response is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
57
				$scope.newBoard = {};
58
				$scope.newBoard.color = $scope.colors[0];
59
				$scope.status.addBoard=false;
60
				$scope.filterData();
61
			}, function(error) {
62
				$scope.status.createBoard = 'Unable to insert board: ' + error.message;
63
			});
64
	};
65
66
	$scope.boardUpdate = function(board) {
67
		BoardService.update(board).then(function(data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
68
			$scope.filterData();
69
		});
70
		board.status.edit = false;
71
	};
72
73
	$scope.boardDelete = function(board) {
74
		BoardService.delete(board.id).then(function (data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
75
			$scope.filterData();
76
		});
77
	};
78
79
});
80
81