From 9d4ba71a3b425aa214c0f706d6bb9f985f3936ae Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Mon, 15 Aug 2016 12:28:51 +0200 Subject: [PATCH] Rework js controllers fixes #3 --- js/controller/AppController.js | 13 -- js/controller/ArchiveController.js | 165 -------------------- js/controller/BoardController.js | 21 +-- js/controller/CardController.js | 9 +- js/controller/ListController.js | 6 +- js/public/app.js | 215 +++------------------------ templates/part.board.sidebarView.php | 10 +- templates/part.boardlist.php | 2 +- templates/part.card.php | 16 +- templates/part.navigation.php | 9 +- templates/part.settings.php | 6 +- 11 files changed, 57 insertions(+), 415 deletions(-) delete mode 100644 js/controller/ArchiveController.js diff --git a/js/controller/AppController.js b/js/controller/AppController.js index 8c5f455df..a9d8e6012 100644 --- a/js/controller/AppController.js +++ b/js/controller/AppController.js @@ -1,19 +1,6 @@ - app.controller('AppController', function ($scope, $location, $http, $route, $log, $rootScope, $stateParams) { $rootScope.sidebar = { show: false }; $scope.sidebar = $rootScope.sidebar; - - $scope.search = function (value) { - if (value === '') { - $location.search('search', null); - } else { - $location.search('search', value); - } - $scope.searchText = value; - }; - - $rootScope.searchText = $location.search().search; - }); \ No newline at end of file diff --git a/js/controller/ArchiveController.js b/js/controller/ArchiveController.js deleted file mode 100644 index 196e381a3..000000000 --- a/js/controller/ArchiveController.js +++ /dev/null @@ -1,165 +0,0 @@ - -app.controller('ArchiveController', function ($rootScope, $scope, $stateParams, StatusService, BoardService, StackService, CardService, LabelService, $state, $transitions) { - - $scope.sidebar = $rootScope.sidebar; - - $scope.id = $stateParams.boardId; - $scope.status={}, - $scope.newLabel={}; - $scope.status.boardtab = $stateParams.detailTab; - $scope.state = $state.current; - - console.log($scope.state); - $scope.stackservice = StackService; - $scope.boardservice = BoardService; - $scope.cardservice = CardService; - $scope.statusservice = StatusService.getInstance(); - $scope.labelservice = LabelService; - - $scope.foo = function(state) { - console.log(state); - } - - - // fetch data - StackService.clear(); - $scope.statusservice.retainWaiting(); - $scope.statusservice.retainWaiting(); - - BoardService.fetchOne($scope.id).then(function(data) { - $scope.statusservice.releaseWaiting(); - }, function(error) { - $scope.statusservice.setError('Error occured', error); - }); - - console.log($scope); - StackService.fetchArchived($scope.id).then(function(data) { - console.log(data); - $scope.statusservice.releaseWaiting(); - }, function(error) { - $scope.statusservice.setError('Error occured', error); - }); - - - - - - BoardService.searchUsers(); - - - - - $scope.cardDelete = function(card) { - CardService.delete(card.id); - StackService.deleteCard(card); - - } - - - // TODO: move to filter? - // Lighten Color of the board for background usage - $scope.rgblight = function (hex) { - var result = /^([A-Fa-f\d]{2})([A-Fa-f\d]{2})([A-Fa-f\d]{2})$/i.exec(hex); - var color = result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; - if(result !== null) { - var rgba = "rgba(" + color.r + "," + color.g + "," + color.b + ",0.7)"; - return rgba; - } else { - return "#"+hex; - } - }; - - // TODO: move to filter? - // RGB2HLS by Garry Tan - // http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c - $scope.textColor = function (hex) { - var result = /^([A-Fa-f\d]{2})([A-Fa-f\d]{2})([A-Fa-f\d]{2})$/i.exec(hex); - var color = result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; - if(result !== null) { - r = color.r/255; - g = color.g/255; - b = color.b/255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h, s, l = (max + min) / 2; - - if(max == min){ - h = s = 0; // achromatic - }else{ - var d = max - min; - s = l > 0.5 ? d / (2 - max - min) : d / (max + min); - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - // TODO: Maybe just darken/lighten the color - if(l<0.5) { - return "#ffffff"; - } else { - return "#000000"; - } - //var rgba = "rgba(" + color.r + "," + color.g + "," + color.b + ",0.7)"; - //return rgba; - } else { - return "#aa0000"; - } - }; - - - - // settings for card sorting - $scope.sortOptions = { - itemMoved: function (event) { - // TODO: Implement reodering here - event.source.itemScope.modelValue.status = event.dest.sortableScope.$parent.column; - var order = event.dest.index; - var card = event.source.itemScope.c; - var newStack = event.dest.sortableScope.$parent.s.id; - card.stackId = newStack; - CardService.update(card); - - CardService.reorder(card, order).then(function(data) { - StackService.data[newStack].addCard(card); - }); - }, - orderChanged: function (event) { - // TODO: Implement ordering here - var order = event.dest.index; - var card = event.source.itemScope.c; - CardService.reorder(card, order); - }, - scrollableContainer: '#board', - containerPositioning: 'relative', - containment: '#board', - // auto scroll on drag - dragMove: function (itemPosition, containment, eventObj) { - if (eventObj) { - var container = $("#board"); - var offset = container.offset(); - targetX = eventObj.pageX - (offset.left || container.scrollLeft()); - targetY = eventObj.pageY - (offset.top || container.scrollTop()); - if (targetX < offset.left) { - container.scrollLeft(container.scrollLeft() - 50); - } else if (targetX > container.width()) { - container.scrollLeft(container.scrollLeft() + 50); - } - if (targetY < offset.top) { - container.scrollTop(container.scrollTop() - 50); - } else if (targetY > container.height()) { - container.scrollTop(container.scrollTop() + 50); - } - } - } - }; - -}); diff --git a/js/controller/BoardController.js b/js/controller/BoardController.js index cc840ee5d..e014f45ef 100644 --- a/js/controller/BoardController.js +++ b/js/controller/BoardController.js @@ -57,6 +57,12 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St $scope.filterData('order', $scope.searchText); } }; + $scope.checkCanEdit = function() { + if($scope.archived) { + return false; + } + return true; + } // filter cards here, as ng-sortable will not work nicely with html-inline filters $scope.filterData = function (order, text) { @@ -154,24 +160,19 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St LabelService.update(label); } - $scope.addAcl = function(sharee) { + $scope.aclAdd = function(sharee) { sharee.boardId = $scope.id; BoardService.addAcl(sharee); $scope.status.addSharee = null; } - $scope.deleteAcl = function(acl) { + $scope.aclDelete = function(acl) { BoardService.deleteAcl(acl.id); } - $scope.updateAcl = function(acl) { + $scope.aclUpdate = function(acl) { BoardService.updateAcl(acl); } - $scope.checkCanEdit = function() { - if($scope.archived) { - return false; - } - return true; - } + // settings for card sorting $scope.sortOptions = { @@ -188,7 +189,7 @@ app.controller('BoardController', function ($rootScope, $scope, $stateParams, St }); }, orderChanged: function (event) { - // TODO: Implement ordering here (set new order of all cards in stack) + // TODO: Implement reordering here (set new order of all cards in stack) // then maybe also call $scope.filterData('order')? var order = event.dest.index; var card = event.source.itemScope.c; diff --git a/js/controller/CardController.js b/js/controller/CardController.js index 4c2bff1e8..2178c09ce 100644 --- a/js/controller/CardController.js +++ b/js/controller/CardController.js @@ -20,20 +20,19 @@ app.controller('CardController', function ($scope, $rootScope, $routeParams, $lo }); // handle rename to update information on the board as well - $scope.renameCard = function(card) { + $scope.cardRename = function(card) { CardService.rename(card).then(function(data) { StackService.updateCard(card); $scope.status.renameCard = false; }); }; - - $scope.updateCard = function(card) { + $scope.cardUpdate = function(card) { CardService.update(CardService.getCurrent()); $scope.status.description = false; } - $scope.editDescription = function() { - $scope.status.description = true; + $scope.cardEditDescription = function() { + $scope.status.cardEditDescription = true; } $scope.labelAssign = function(element, model) { diff --git a/js/controller/ListController.js b/js/controller/ListController.js index 1657a7425..4075f97fa 100644 --- a/js/controller/ListController.js +++ b/js/controller/ListController.js @@ -13,7 +13,7 @@ app.controller('ListController', function ($scope, $location, BoardService) { $scope.newBoard.color = color; }; - $scope.createBoard = function () { + $scope.boardCreate = function () { BoardService.create($scope.newBoard) .then(function (response) { $scope.newBoard = {}; @@ -22,11 +22,11 @@ app.controller('ListController', function ($scope, $location, BoardService) { $scope.status.createBoard = 'Unable to insert board: ' + error.message; }); }; - $scope.updateBoard = function(board) { + $scope.boardUpdate = function(board) { BoardService.update(board); board.status.edit = false; }; - $scope.deleteBoard = function(board) { + $scope.boardDelete = function(board) { // TODO: Ask for confirmation //if (confirm('Are you sure you want to delete this?')) { BoardService.delete(board.id); diff --git a/js/public/app.js b/js/public/app.js index 0b4a2f870..5013821ec 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -111,191 +111,12 @@ app.run(["$document", "$rootScope", "$transitions", function ($document, $rootSc }]); - app.controller('AppController', ["$scope", "$location", "$http", "$route", "$log", "$rootScope", "$stateParams", function ($scope, $location, $http, $route, $log, $rootScope, $stateParams) { $rootScope.sidebar = { show: false }; $scope.sidebar = $rootScope.sidebar; - - $scope.search = function (value) { - if (value === '') { - $location.search('search', null); - } else { - $location.search('search', value); - } - $scope.searchText = value; - }; - - $rootScope.searchText = $location.search().search; - }]); - -app.controller('ArchiveController', ["$rootScope", "$scope", "$stateParams", "StatusService", "BoardService", "StackService", "CardService", "LabelService", "$state", "$transitions", function ($rootScope, $scope, $stateParams, StatusService, BoardService, StackService, CardService, LabelService, $state, $transitions) { - - $scope.sidebar = $rootScope.sidebar; - - $scope.id = $stateParams.boardId; - $scope.status={}, - $scope.newLabel={}; - $scope.status.boardtab = $stateParams.detailTab; - $scope.state = $state.current; - - console.log($scope.state); - $scope.stackservice = StackService; - $scope.boardservice = BoardService; - $scope.cardservice = CardService; - $scope.statusservice = StatusService.getInstance(); - $scope.labelservice = LabelService; - - $scope.foo = function(state) { - console.log(state); - } - - - // fetch data - StackService.clear(); - $scope.statusservice.retainWaiting(); - $scope.statusservice.retainWaiting(); - - BoardService.fetchOne($scope.id).then(function(data) { - $scope.statusservice.releaseWaiting(); - }, function(error) { - $scope.statusservice.setError('Error occured', error); - }); - - console.log($scope); - StackService.fetchArchived($scope.id).then(function(data) { - console.log(data); - $scope.statusservice.releaseWaiting(); - }, function(error) { - $scope.statusservice.setError('Error occured', error); - }); - - - - - - BoardService.searchUsers(); - - - - - $scope.cardDelete = function(card) { - CardService.delete(card.id); - StackService.deleteCard(card); - - } - - - // TODO: move to filter? - // Lighten Color of the board for background usage - $scope.rgblight = function (hex) { - var result = /^([A-Fa-f\d]{2})([A-Fa-f\d]{2})([A-Fa-f\d]{2})$/i.exec(hex); - var color = result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; - if(result !== null) { - var rgba = "rgba(" + color.r + "," + color.g + "," + color.b + ",0.7)"; - return rgba; - } else { - return "#"+hex; - } - }; - - // TODO: move to filter? - // RGB2HLS by Garry Tan - // http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c - $scope.textColor = function (hex) { - var result = /^([A-Fa-f\d]{2})([A-Fa-f\d]{2})([A-Fa-f\d]{2})$/i.exec(hex); - var color = result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null; - if(result !== null) { - r = color.r/255; - g = color.g/255; - b = color.b/255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h, s, l = (max + min) / 2; - - if(max == min){ - h = s = 0; // achromatic - }else{ - var d = max - min; - s = l > 0.5 ? d / (2 - max - min) : d / (max + min); - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - // TODO: Maybe just darken/lighten the color - if(l<0.5) { - return "#ffffff"; - } else { - return "#000000"; - } - //var rgba = "rgba(" + color.r + "," + color.g + "," + color.b + ",0.7)"; - //return rgba; - } else { - return "#aa0000"; - } - }; - - - - // settings for card sorting - $scope.sortOptions = { - itemMoved: function (event) { - // TODO: Implement reodering here - event.source.itemScope.modelValue.status = event.dest.sortableScope.$parent.column; - var order = event.dest.index; - var card = event.source.itemScope.c; - var newStack = event.dest.sortableScope.$parent.s.id; - card.stackId = newStack; - CardService.update(card); - - CardService.reorder(card, order).then(function(data) { - StackService.data[newStack].addCard(card); - }); - }, - orderChanged: function (event) { - // TODO: Implement ordering here - var order = event.dest.index; - var card = event.source.itemScope.c; - CardService.reorder(card, order); - }, - scrollableContainer: '#board', - containerPositioning: 'relative', - containment: '#board', - // auto scroll on drag - dragMove: function (itemPosition, containment, eventObj) { - if (eventObj) { - var container = $("#board"); - var offset = container.offset(); - targetX = eventObj.pageX - (offset.left || container.scrollLeft()); - targetY = eventObj.pageY - (offset.top || container.scrollTop()); - if (targetX < offset.left) { - container.scrollLeft(container.scrollLeft() - 50); - } else if (targetX > container.width()) { - container.scrollLeft(container.scrollLeft() + 50); - } - if (targetY < offset.top) { - container.scrollTop(container.scrollTop() - 50); - } else if (targetY > container.height()) { - container.scrollTop(container.scrollTop() + 50); - } - } - } - }; - -}]); - app.controller('BoardController', ["$rootScope", "$scope", "$stateParams", "StatusService", "BoardService", "StackService", "CardService", "LabelService", "$state", "$transitions", "$filter", function ($rootScope, $scope, $stateParams, StatusService, BoardService, StackService, CardService, LabelService, $state, $transitions, $filter) { $scope.sidebar = $rootScope.sidebar; @@ -355,6 +176,12 @@ app.controller('BoardController', ["$rootScope", "$scope", "$stateParams", "Stat $scope.filterData('order', $scope.searchText); } }; + $scope.checkCanEdit = function() { + if($scope.archived) { + return false; + } + return true; + } // filter cards here, as ng-sortable will not work nicely with html-inline filters $scope.filterData = function (order, text) { @@ -452,24 +279,19 @@ app.controller('BoardController', ["$rootScope", "$scope", "$stateParams", "Stat LabelService.update(label); } - $scope.addAcl = function(sharee) { + $scope.aclAdd = function(sharee) { sharee.boardId = $scope.id; BoardService.addAcl(sharee); $scope.status.addSharee = null; } - $scope.deleteAcl = function(acl) { + $scope.aclDelete = function(acl) { BoardService.deleteAcl(acl.id); } - $scope.updateAcl = function(acl) { + $scope.aclUpdate = function(acl) { BoardService.updateAcl(acl); } - $scope.checkCanEdit = function() { - if($scope.archived) { - return false; - } - return true; - } + // settings for card sorting $scope.sortOptions = { @@ -486,7 +308,7 @@ app.controller('BoardController', ["$rootScope", "$scope", "$stateParams", "Stat }); }, orderChanged: function (event) { - // TODO: Implement ordering here (set new order of all cards in stack) + // TODO: Implement reordering here (set new order of all cards in stack) // then maybe also call $scope.filterData('order')? var order = event.dest.index; var card = event.source.itemScope.c; @@ -541,20 +363,19 @@ app.controller('CardController', ["$scope", "$rootScope", "$routeParams", "$loca }); // handle rename to update information on the board as well - $scope.renameCard = function(card) { + $scope.cardRename = function(card) { CardService.rename(card).then(function(data) { StackService.updateCard(card); $scope.status.renameCard = false; }); }; - - $scope.updateCard = function(card) { + $scope.cardUpdate = function(card) { CardService.update(CardService.getCurrent()); $scope.status.description = false; } - $scope.editDescription = function() { - $scope.status.description = true; + $scope.cardEditDescription = function() { + $scope.status.cardEditDescription = true; } $scope.labelAssign = function(element, model) { @@ -584,7 +405,7 @@ app.controller('ListController', ["$scope", "$location", "BoardService", functio $scope.newBoard.color = color; }; - $scope.createBoard = function () { + $scope.boardCreate = function () { BoardService.create($scope.newBoard) .then(function (response) { $scope.newBoard = {}; @@ -593,11 +414,11 @@ app.controller('ListController', ["$scope", "$location", "BoardService", functio $scope.status.createBoard = 'Unable to insert board: ' + error.message; }); }; - $scope.updateBoard = function(board) { + $scope.boardUpdate = function(board) { BoardService.update(board); board.status.edit = false; }; - $scope.deleteBoard = function(board) { + $scope.boardDelete = function(board) { // TODO: Ask for confirmation //if (confirm('Are you sure you want to delete this?')) { BoardService.delete(board.id); diff --git a/templates/part.board.sidebarView.php b/templates/part.board.sidebarView.php index 9195420da..9293121cb 100644 --- a/templates/part.board.sidebarView.php +++ b/templates/part.board.sidebarView.php @@ -17,7 +17,7 @@
- + {{ $item.participant }} @@ -46,18 +46,18 @@ {{ acl.participant }} - + - + - + - t('Discard share')); ?> + t('Discard share')); ?> diff --git a/templates/part.boardlist.php b/templates/part.boardlist.php index 6762cff87..7e1ff0c39 100644 --- a/templates/part.boardlist.php +++ b/templates/part.boardlist.php @@ -33,7 +33,7 @@ t('Create new board')); ?>
+ class="ng-pristine ng-valid" ng-submit="boardCreate()"> diff --git a/templates/part.card.php b/templates/part.card.php index 3f67ba758..924f1df48 100644 --- a/templates/part.card.php +++ b/templates/part.card.php @@ -8,14 +8,14 @@
 

- + - -
{{ +
{{ cardservice.getCurrent().title }}

@@ -66,13 +66,13 @@

Description

- -
+
  • -
  • +
  • @@ -28,7 +28,7 @@
    -
    +
    @@ -44,12 +44,11 @@ t('Create a new board')); ?>
    - +
    -

    +

    diff --git a/templates/part.settings.php b/templates/part.settings.php index 2f9a861d3..411eb1cbf 100644 --- a/templates/part.settings.php +++ b/templates/part.settings.php @@ -4,8 +4,8 @@ data-apps-slide-toggle="#app-settings-content" >
    -
    - t('We will provide some options here!')); ?> +