From dd80914f587da49320ce6277984d8a2c15754f31 Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Thu, 15 Oct 2015 21:12:15 +0200 Subject: [PATCH] Ask user for confirmation when changing states [ci skip] --- .../app/templates/work_packages.list.html | 3 +- .../app/templates/work_packages.show.html | 3 +- .../work_package_edit_actions.html | 9 ++-- .../work-package-edit-actions-directive.js | 19 +++++++- .../integration/mocks/work-packages-exp.js | 4 +- .../integration/mocks/work-packages.json | 44 +++++++++++++++++++ .../pages/work-package-show-page.js | 4 +- .../work-packages/work-package-edit-spec.js | 35 +++++++++++++++ 8 files changed, 112 insertions(+), 9 deletions(-) diff --git a/frontend/app/templates/work_packages.list.html b/frontend/app/templates/work_packages.list.html index cda1b4e5bc..192b947ad8 100644 --- a/frontend/app/templates/work_packages.list.html +++ b/frontend/app/templates/work_packages.list.html @@ -110,7 +110,8 @@ -
+
  • -
  • diff --git a/frontend/app/templates/work_packages/work_package_edit_actions.html b/frontend/app/templates/work_packages/work_package_edit_actions.html index a2f6277712..585cc03a93 100644 --- a/frontend/app/templates/work_packages/work_package_edit_actions.html +++ b/frontend/app/templates/work_packages/work_package_edit_actions.html @@ -1,11 +1,14 @@
    - - -
    diff --git a/frontend/app/work_packages/directives/work-package-edit-actions-directive.js b/frontend/app/work_packages/directives/work-package-edit-actions-directive.js index e5d72f5dc9..cfbef61a73 100644 --- a/frontend/app/work_packages/directives/work-package-edit-actions-directive.js +++ b/frontend/app/work_packages/directives/work-package-edit-actions-directive.js @@ -29,13 +29,28 @@ module.exports = function () { return { restrict: 'E', + replace: true, templateUrl: '/templates/work_packages/work_package_edit_actions.html', + scope: {}, - controller: ['$scope', 'I18n', 'EditableFieldsState', function ($scope, I18n, - EditableFieldsState) { + controller: ['$scope', 'I18n', 'EditableFieldsState', '$window', function ($scope, I18n, + EditableFieldsState, $window) { angular.extend($scope, { I18n: I18n, efs: EditableFieldsState + }); + + $scope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) { + if (EditableFieldsState.editAll.state + && toParams.workPackageId !== fromParams.workPackageId) { + + if (!$window.confirm(I18n.t('js.text_are_you_sure'))) { + event.preventDefault(); + + } else { + EditableFieldsState.editAll.cancel(); + } + } }) }] }; diff --git a/frontend/tests/integration/mocks/work-packages-exp.js b/frontend/tests/integration/mocks/work-packages-exp.js index dbf3cde7aa..10e2c498e1 100644 --- a/frontend/tests/integration/mocks/work-packages-exp.js +++ b/frontend/tests/integration/mocks/work-packages-exp.js @@ -30,10 +30,12 @@ module.exports = function(app) { var fs = require('fs'); var express = require('express'); var workPackagesRouter = express.Router(); + workPackagesRouter.get('/', function(req, res) { fs.readFile(__dirname + '/work-packages.json', 'utf8', function(err, text) { res.send(text); }); }); - app.use('/api/experimental/work_packages', workPackagesRouter); + + app.use(/\/api\/experimental\/(projects\/.*\/)?work_packages/, workPackagesRouter); }; diff --git a/frontend/tests/integration/mocks/work-packages.json b/frontend/tests/integration/mocks/work-packages.json index 65045e23f4..868f346211 100644 --- a/frontend/tests/integration/mocks/work-packages.json +++ b/frontend/tests/integration/mocks/work-packages.json @@ -394,6 +394,50 @@ }, "updated_at": "2014-10-22T13:25:56Z" }, + { + "_actions": [ + "edit", + "move", + "copy", + "duplicate", + "delete" + ], + "_links": { + "copy": "/work_packages/move/new?copy=true&ids%5B%5D=16923", + "delete": "/work_packages/bulk?ids%5B%5D=16923&method=delete", + "duplicate": "/projects/openproject/work_packages/new?copy_from=16923", + "edit": "/work_packages/16923/edit", + "move": "/work_packages/move/new?ids%5B%5D=16923" + }, + "assigned_to": { + "firstname": "Karol", + "id": 9248, + "name": "Karol Skolar" + }, + "created_at": "2014-10-22T13:25:56Z", + "custom_values": [], + "id": 820, + "parent_id": null, + "status": { + "id": 1, + "name": "new" + }, + "subject": "The other work package (820.json)", + "type": { + "color_id": 8, + "created_at": "11/13/2013/ 13:11 PM", + "id": 4, + "in_aggregation": true, + "is_default": false, + "is_in_roadmap": false, + "is_milestone": false, + "is_standard": false, + "name": "Task", + "position": 2, + "updated_at": "05/13/2014/ 12:10 PM" + }, + "updated_at": "2014-10-22T13:25:56Z" + }, { "_actions": [ "edit", diff --git a/frontend/tests/integration/pages/work-package-show-page.js b/frontend/tests/integration/pages/work-package-show-page.js index 12079f6310..1cff7edf18 100644 --- a/frontend/tests/integration/pages/work-package-show-page.js +++ b/frontend/tests/integration/pages/work-package-show-page.js @@ -41,7 +41,7 @@ WorkPackageShowPage.prototype = { }, toolBar: { - edit: $('.button.icon-edit'), + edit: $('.edit-all-button'), overview: $('#work-packages-details-view-button'), watch: $('[id*="watch"]'), dropDown: $('#action-show-more-dropdown-menu > button'), @@ -51,6 +51,8 @@ WorkPackageShowPage.prototype = { listView: $('#work-packages-list-view-button') }, + listViewWorkPackage: $('#work-package-820 .subject a'), + get: function() { browser.get('/work_packages/' + this.wpId + '/activity'); } diff --git a/frontend/tests/integration/specs/work-packages/work-package-edit-spec.js b/frontend/tests/integration/specs/work-packages/work-package-edit-spec.js index ad753a5375..c1e563f3e9 100644 --- a/frontend/tests/integration/specs/work-packages/work-package-edit-spec.js +++ b/frontend/tests/integration/specs/work-packages/work-package-edit-spec.js @@ -101,6 +101,41 @@ describe('Work package edit', function() { }); expectBetweenViews(); + + describe('when clicking on a work package in the list view', function () { + var confirm, url; + + beforeEach(function () { + browser.getCurrentUrl().then(function (currentUrl) { + url = currentUrl; + }); + + page.listViewWorkPackage.click().then(function () { + confirm = browser.switchTo().alert(); + }); + }); + + it('should show a confirmation dialog', function () { + expect(protractor.ExpectedConditions.alertIsPresent()()).to.eventually.be.true; + confirm.dismiss(); + }); + + it('should change the route when the confirmation is accepted', function () { + confirm.accept().then(function () { + browser.getCurrentUrl().then(function (newUrl) { + expect(newUrl).to.not.equal(url); + }) + }); + }); + + it('should change nothing when the confirmation is dismissed', function () { + confirm.dismiss().then(function () { + browser.getCurrentUrl().then(function (newUrl) { + expect(newUrl).to.equal(url); + }) + }); + }); + }); }); describe('when triggering the cancel action', function () {