From 3c16be0dbb22f454b63d76b5887ce155c5c475ad Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Fri, 15 Apr 2016 10:40:54 +0000 Subject: [PATCH] Show a modal when editing worklists in a board This allows the existing lanes of a board to be made automatic! Change-Id: I9e28b8c01b2b15d999fc416939abdd4da556ea3e --- .../controller/board_detail_controller.js | 29 ++-- src/app/boards/template/detail.html | 18 ++- .../controller/add_worklist_controller.js | 1 + .../controller/worklist_edit_controller.js | 125 ++++++++++++++++++ src/app/worklists/template/new.html | 2 +- 5 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 src/app/worklists/controller/worklist_edit_controller.js diff --git a/src/app/boards/controller/board_detail_controller.js b/src/app/boards/controller/board_detail_controller.js index baf464a5..3addee4e 100644 --- a/src/app/boards/controller/board_detail_controller.js +++ b/src/app/boards/controller/board_detail_controller.js @@ -235,19 +235,24 @@ angular.module('sb.board').controller('BoardDetailController', * create a worklist to represent the lane if one doesn't exist * already. */ - $scope.toggleEditLane = function(lane) { - if (lane.worklist.editing) { - if (lane.worklist.id === null) { - lane.worklist.$create().then(function(list) { - lane.list_id = list.id; - $scope.board.$update(); - }); - } else { - Worklist.update({id: lane.worklist.id}, - lane.worklist); + $scope.editWorklist = function(worklist) { + var modalInstance = $modal.open({ + size: 'lg', + templateUrl: 'app/worklists/template/new.html', + controller: 'WorklistEditController', + resolve: { + worklist: function() { + return worklist; + }, + board: function() { + return $scope.board; + } } - } - lane.worklist.editing = !lane.worklist.editing; + }); + + modalInstance.result.finally(function() { + loadBoard(); + }); }; /** diff --git a/src/app/boards/template/detail.html b/src/app/boards/template/detail.html index a1448295..ed71baa8 100644 --- a/src/app/boards/template/detail.html +++ b/src/app/boards/template/detail.html @@ -334,22 +334,17 @@
+ href="/#!/worklist/{{lane.worklist.id}}"> {{ lane.worklist.title }} - + + + -
@@ -371,7 +366,10 @@
- {{ lane.worklist.title }} + + {{ lane.worklist.title }} +
diff --git a/src/app/worklists/controller/add_worklist_controller.js b/src/app/worklists/controller/add_worklist_controller.js index 63f26c27..0040c048 100644 --- a/src/app/worklists/controller/add_worklist_controller.js +++ b/src/app/worklists/controller/add_worklist_controller.js @@ -119,4 +119,5 @@ angular.module('sb.worklist').controller('AddWorklistController', $scope.resourceTypes = ['Story']; $scope.showAddFilter = true; $scope.newFilter = angular.copy(blankFilter); + $scope.modalTitle = 'New Worklist'; }); diff --git a/src/app/worklists/controller/worklist_edit_controller.js b/src/app/worklists/controller/worklist_edit_controller.js new file mode 100644 index 00000000..c2e79422 --- /dev/null +++ b/src/app/worklists/controller/worklist_edit_controller.js @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2015-2016 Codethink Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +/** + * Controller for the "new worklist" modal popup. + */ +angular.module('sb.worklist').controller('WorklistEditController', + function ($scope, $modalInstance, $state, worklist, board, Worklist) { + 'use strict'; + + var blankFilter = { + type: 'Story', + filter_criteria: [{ + negative: false, + field: null, + value: null, + title: null + }] + }; + + /** + * Saves the worklist. + */ + $scope.save = function () { + $scope.isSaving = true; + Worklist.update($scope.worklist, function () { + $scope.isSaving = false; + $modalInstance.dismiss('success'); + }); + }; + + /** + * Close this modal without saving. + */ + $scope.close = function () { + $modalInstance.dismiss('cancel'); + }; + + $scope.setType = function(type) { + $scope.newFilter.type = type; + $scope.resourceTypes = [type]; + $scope.$broadcast('refresh-types'); + }; + + $scope.setCriterion = function(criterion, tag) { + criterion.field = tag.type; + criterion.value = tag.value.toString(); + criterion.title = tag.title; + }; + + $scope.addCriterion = function(filter) { + filter.filter_criteria.push({ + negative: false, + field: null, + value: null, + title: null + }); + }; + + $scope.removeTag = function(criterion) { + if ($scope.newFilter.filter_criteria.length > 1) { + var idx = $scope.newFilter.filter_criteria.indexOf(criterion); + $scope.newFilter.filter_criteria.splice(idx, 1); + } else { + criterion.field = null; + criterion.value = null; + criterion.title = null; + } + }; + + $scope.checkNewFilter = function() { + var valid = true; + angular.forEach( + $scope.newFilter.filter_criteria, + function(criterion) { + if (criterion.field == null || + criterion.value == null || + criterion.title == null) { + valid = false; + } + } + ); + return valid; + }; + + $scope.remove = function(filter) { + var idx = $scope.worklist.filters.indexOf(filter); + Worklist.Filters.delete({ + id: $scope.worklist.id, + filter_id: filter.id + }); + $scope.worklist.filters.splice(idx, 1); + }; + + $scope.saveNewFilter = function() { + var added = angular.copy($scope.newFilter); + Worklist.Filters.create( + {id: $scope.worklist.id}, added, function(result) { + $scope.worklist.filters.push(result); + } + ); + $scope.showAddFilter = false; + $scope.newFilter = angular.copy(blankFilter); + }; + + $scope.isSaving = false; + $scope.worklist = worklist; + $scope.resourceTypes = ['Story']; + $scope.showAddFilter = false; + $scope.newFilter = angular.copy(blankFilter); + $scope.modalTitle = 'Edit Worklist'; + }); diff --git a/src/app/worklists/template/new.html b/src/app/worklists/template/new.html index 45e8124c..e8ada232 100644 --- a/src/app/worklists/template/new.html +++ b/src/app/worklists/template/new.html @@ -17,7 +17,7 @@
-

New Worklist

+

{{ modalTitle }}