Make user input stay when switching between views

pull/3701/head
Alex Dik 9 years ago committed by Jens Ulferts
parent 5c9975fd64
commit 42e27e41a3
  1. 9
      frontend/app/work_packages/directives/work-package-field-directive.js
  2. 21
      frontend/app/work_packages/services/editable-fields-state.js
  3. 25
      frontend/tests/integration/pages/work-package-show-page.js
  4. 12
      frontend/tests/integration/specs/work-packages/work-package-edit-spec.js
  5. 17
      frontend/tests/unit/tests/work_packages/services/editable-fields-state-test.js

@ -44,9 +44,8 @@ module.exports = function(WorkPackageFieldService, EditableFieldsState) {
};
this.updateWriteValue = function() {
this.writeValue = _.cloneDeep(WorkPackageFieldService.getValue(
EditableFieldsState.workPackage,
this.field
this.writeValue = EditableFieldsState.editAll.getFieldValue(this.field)
|| _.cloneDeep(WorkPackageFieldService.getValue(EditableFieldsState.workPackage, this.field
));
};
@ -56,6 +55,10 @@ module.exports = function(WorkPackageFieldService, EditableFieldsState) {
this.updateWriteValue();
this.editTitle = I18n.t('js.inplace.button_edit', { attribute: this.getLabel() });
}
$scope.$watch('fieldController.writeValue', angular.bind(this, function (newValue) {
EditableFieldsState.editAll.addFieldValue(this.field, newValue);
}))
}
return {

@ -27,6 +27,8 @@
//++
module.exports = function($q, $rootScope, NotificationsService) {
var editAllState = false;
var EditableFieldsState = {
workPackage: null,
errors: null,
@ -66,7 +68,24 @@ module.exports = function($q, $rootScope, NotificationsService) {
editAll: {
focusField: 'subject',
state: false,
fieldValues: {},
get state() {
return editAllState;
},
set state(state) {
editAllState = state;
if (!state) this.fieldValues = {};
},
addFieldValue: function (field, value) {
this.fieldValues[field] = value;
},
getFieldValue: function (field) {
return this.fieldValues[field];
},
get allowed() {
return EditableFieldsState.workPackage && !!EditableFieldsState.workPackage.links.update;

@ -26,19 +26,24 @@
// See doc/COPYRIGHT.rdoc for more details.
//++
module.exports = function WorkPackageShowPage() {
function WorkPackageShowPage() {}
var wpId = 819;
WorkPackageShowPage.prototype = {
this.editButton = $('.button[title="Edit"]');
this.focusElement = $('#work-package-subject .focus-input');
this.editableFields = $$('.focus-input');
this.editActions = {
wpId: 819,
editButton: $('.button[title="Edit"]'),
focusElement: $('#work-package-subject .focus-input'),
overviewButton: $('#work-packages-details-view-button'),
editableFields: $$('.focus-input'),
editActions: {
container: $('.work-packages--edit-actions'),
cancel: $('.work-packages--edit-actions .button:last-child')
};
},
this.get = function() {
browser.get('/work_packages/' + wpId + '/activity');
};
get: function() {
browser.get('/work_packages/' + this.wpId + '/activity');
}
};
module.exports = WorkPackageShowPage;

@ -34,7 +34,6 @@ describe('Work package edit', function() {
expectFocusEquals = function (id) {
var activeId = browser.driver.switchTo().activeElement().getId();
expect(activeId).to.eventually.deep.equal(id);
};
describe('when clicking edit button on show page', function () {
@ -57,6 +56,17 @@ describe('Work package edit', function() {
expect(page.editActions.container.isDisplayed()).to.eventually.be.true;
});
it('should keep the user input when switching to overview mode', function () {
var val = 'my_value';
page.focusElement.sendKeys(val);
page.overviewButton.click().then(function () {
page.focusElement.isPresent().then(function () {
expect(page.focusElement.getAttribute('value')).to.eventually.equal(val);
});
});
});
describe('when triggering the edit actions', function () {
it('should cancel editing when the cancel button is clicked', function () {
page.editActions.cancel.click();

@ -100,5 +100,22 @@ describe('EditableFieldsState service', function () {
it('is not allowed if th WP update action does not exist', function () {
expect(eAll.allowed).to.be.false;
});
describe('field value storage', function () {
var field = 'my_field', value = 'my_val';
beforeEach(function () {
eAll.addFieldValue(field, value);
});
it('saves and retrieves the correct value', function () {
expect(eAll.getFieldValue(field)).to.equal(value);
});
it('clears stored values when edit all mode is turned off', function () {
eAll.stop();
expect(eAll.getFieldValue(field)).to.be.falsy;
});
});
});
});

Loading…
Cancel
Save