Keep inplace edit values between views

... while also keeping empty values

[ci skip]
pull/3701/head
Alex Dik 9 years ago committed by Jens Ulferts
parent 5aeccc2d2c
commit fefbaa14bb
  1. 8
      frontend/app/components/inplace-edit/directives/work-package-field/work-package-field.directive.js
  2. 41
      frontend/app/components/inplace-edit/services/inplace-edit.service.js
  3. 51
      frontend/app/components/inplace-edit/services/inplace-edit.service.test.js
  4. 1
      frontend/tests/integration/pages/work-package-show-page.js
  5. 13
      frontend/tests/integration/specs/work-packages/work-package-edit-spec.js

@ -46,9 +46,11 @@ function workPackageField() {
};
}
function WorkPackageFieldController($scope, EditableFieldsState, inplaceEditField) {
function WorkPackageFieldController($scope, EditableFieldsState, inplaceEdit) {
var workPackage = EditableFieldsState.workPackage;
this.state = EditableFieldsState;
$scope.field = new inplaceEditField(EditableFieldsState.workPackage, this.fieldName);
$scope.field = new inplaceEdit.form(workPackage).field(this.fieldName);
var field = $scope.field;
if (field.isEditable()) {
@ -57,5 +59,5 @@ function WorkPackageFieldController($scope, EditableFieldsState, inplaceEditFiel
this.editTitle = I18n.t('js.inplace.button_edit', { attribute: field.getLabel() });
}
}
WorkPackageFieldController.$inject = ['$scope', 'EditableFieldsState', 'inplaceEditField'];
WorkPackageFieldController.$inject = ['$scope', 'EditableFieldsState', 'inplaceEdit'];

@ -28,29 +28,42 @@
angular
.module('openproject.inplace-edit')
.factory('inplaceEditField', inplaceEditField);
.factory('inplaceEdit', inplaceEdit);
function inplaceEditField(WorkPackageFieldService) {
function Field(resource, name) {
function inplaceEdit(WorkPackageFieldService) {
var forms = {};
function Form(resource) {
this.resource = resource;
this.name = name;
this.value = this.getValue();
this.fields = {};
Object.defineProperties(this, {
text: {
get: function() {
return this.format();
}
}
});
this.field = function (name) {
return this.fields[name] = this.fields[name] || new Field(this.resource, name);
}
}
function Field(resource, name) {
this.resource = resource;
this.name = name;
this.value = !_.isUndefined(this.value) ? this.value : _.cloneDeep(this.getValue());
}
Object.defineProperties(Field.prototype, {
text: {
get: function() {
return this.format();
}
}
});
_.forOwn(WorkPackageFieldService, function (property, name) {
Field.prototype[name] = _.isFunction(property) && function () {
return property(this.resource, this.name);
} || property;
});
return Field;
return {
form: function (resource) {
return forms[resource.props.id] = forms[resource.props.id] || new Form(resource);
}
};
}
inplaceEditField.$indect = ['WorkPackageFieldService'];
inplaceEdit.$indect = ['WorkPackageFieldService'];

@ -0,0 +1,51 @@
// -- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 3.
//
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
// ++
describe('Inplace edit service', function () {
var inplaceEdit,
resources = [{ props: { id: 1 } }, { props: { id: 2 } }],
WorkPackageFieldService = {};
beforeEach(angular.mock.module('openproject.inplace-edit', function ($provide) {
$provide.constant('WorkPackageFieldService', WorkPackageFieldService);
WorkPackageFieldService.getValue = sinon.stub()
}));
beforeEach(inject(function(_inplaceEdit_) {
inplaceEdit = _inplaceEdit_;
inplaceEdit.form(resources[0]).field('myField');
inplaceEdit.form(resources[1]).field('myField');
inplaceEdit.form(resources[1]).field('myOtherField');
}));
it('should return a form by resource', function () {
expect(Object.keys(inplaceEdit.form(resources[0]).fields).length).to.equal(1);
expect(Object.keys(inplaceEdit.form(resources[1]).fields).length).to.equal(2);
});
});

@ -33,6 +33,7 @@ WorkPackageShowPage.prototype = {
wpId: 819,
focusElement: $('#work-package-subject .focus-input'),
focusElementValue: $('#work-package-subject span.inplace-edit--read-value > span:first-child'),
descriptionInput: $('#work-package-description .focus-input'),
editableFields: $$('.focus-input'),
editActions: {

@ -55,8 +55,7 @@ describe('Work package edit', function() {
page.get();
page.toolBar.edit.isPresent().then(function () {
page.toolBar.edit.click();
page.focusElement.sendKeys(val);
})
});
});
it('should focus the subject field when used', function() {
@ -83,15 +82,23 @@ describe('Work package edit', function() {
describe('when switching to overview mode', function () {
beforeEach(function () {
page.focusElement.sendKeys(val);
page.descriptionInput.clear();
browser.wait(page.toolBar.overview.click);
});
it('should keep the user input when switching to overview mode', function () {
it('should keep the user input', function () {
page.focusElement.isPresent().then(function () {
expect(page.focusElement.getAttribute('value')).to.eventually.equal(val);
});
});
it('should keep empty user input', function () {
page.descriptionInput.isPresent().then(function () {
expect(page.descriptionInput.getAttribute('value')).to.eventually.equal('');
})
});
it('should disable the filter-toggle button', function () {
expect(page.toolBar.filter.isEnabled()).to.eventually.be.false;
});

Loading…
Cancel
Save