From ff3ae562a3cc3f183e1197449e18f6bf58a86542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 16 Mar 2016 09:06:53 +0100 Subject: [PATCH] Add duration field --- .../wp-edit-duration-field.directive.html | 6 +++ .../wp-edit-duration-field.module.ts | 34 ++++++++++++++ .../wp-edit-field/wp-edit-field.config.ts | 7 +-- .../app/ui_components/duration-directive.js | 46 +++++++++++++++++++ frontend/app/ui_components/index.js | 1 + 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 frontend/app/components/wp-edit/wp-edit-field/wp-edit-duration-field.directive.html create mode 100644 frontend/app/components/wp-edit/wp-edit-field/wp-edit-duration-field.module.ts create mode 100644 frontend/app/ui_components/duration-directive.js diff --git a/frontend/app/components/wp-edit/wp-edit-field/wp-edit-duration-field.directive.html b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-duration-field.directive.html new file mode 100644 index 0000000000..3d5ae421e7 --- /dev/null +++ b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-duration-field.directive.html @@ -0,0 +1,6 @@ + diff --git a/frontend/app/components/wp-edit/wp-edit-field/wp-edit-duration-field.module.ts b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-duration-field.module.ts new file mode 100644 index 0000000000..0e2252044e --- /dev/null +++ b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-duration-field.module.ts @@ -0,0 +1,34 @@ +// -- 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. +// ++ + +import {Field} from "./wp-edit-field.module"; +import {WorkPackageEditFieldService} from "./wp-edit-field.service"; + +export class DurationField extends Field { + public template:string = '/components/wp-edit/wp-edit-field/wp-edit-duration-field.directive.html' +} diff --git a/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.config.ts b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.config.ts index e6cf285c34..c5db78dc39 100644 --- a/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.config.ts +++ b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.config.ts @@ -29,6 +29,8 @@ import {WorkPackageEditFieldService} from "./wp-edit-field.service"; import {Field} from "./wp-edit-field.module"; import {TextField} from "./wp-edit-text-field.module"; +import {IntegerField} from "./wp-edit-integer-field.module"; +import {DurationField} from "./wp-edit-duration-field.module"; import {SelectField} from "./wp-edit-select-field.module"; import {FloatField} from "./wp-edit-float-field.module"; import {IntegerField} from "./wp-edit-integer-field.module"; @@ -38,9 +40,6 @@ import {DateField} from "./wp-edit-date-field.module"; //TODO: Implement class DateRangeField extends Field {} -//TODO: Implement -class DurationField extends Field {} - //TODO: Implement class TextareaField extends Field {} @@ -52,6 +51,8 @@ angular wpEditField.defaultType = 'text'; wpEditField .addFieldType(TextField, 'text', ['String']) + .addFieldType(IntegerField, 'integer', ['Integer']) + .addFieldType(DurationField, 'duration', ['Duration']) .addFieldType(SelectField, 'select', ['Priority', 'Status', 'Type', diff --git a/frontend/app/ui_components/duration-directive.js b/frontend/app/ui_components/duration-directive.js new file mode 100644 index 0000000000..049c5c7620 --- /dev/null +++ b/frontend/app/ui_components/duration-directive.js @@ -0,0 +1,46 @@ +//-- 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. +//++ + +module.exports = function($filter, TimezoneService) { + return { + restrict:'A', + require: 'ngModel', + link: function(scope, element, attrs, ngModelController) { + ngModelController.$parsers.push(function(value) { + if (value) { + var minutes = Number(moment.duration(value, 'hours').asMinutes().toFixed(2)); + return moment.duration(minutes, 'minutes'); + } + }); + + ngModelController.$formatters.push(function(value) { + return TimezoneService.formattedDuration(value); + }); + } + }; +}; diff --git a/frontend/app/ui_components/index.js b/frontend/app/ui_components/index.js index 4780afd2e9..4aab85bd04 100644 --- a/frontend/app/ui_components/index.js +++ b/frontend/app/ui_components/index.js @@ -112,5 +112,6 @@ angular.module('openproject.uiComponents') .directive('confirmPopup', ['$window', require('./confirm-popup-directive')]) .directive('clickOnKeypress', [require('./click-on-keypress-directive')]) .directive('floatValue', ['$filter', require('./float-directive')]) + .directive('durationValue', ['$filter', 'TimezoneService', require('./duration-directive')]) .filter('external2internalFloat', ['$locale', require('./external-2-internal-float-filter')]) .filter('internal2externalFloat', ['$locale', require('./internal-2-external-float-filter')]);