From 3f7a598347614b245a032a0626517e2262422e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Thu, 6 Oct 2016 09:01:26 +0200 Subject: [PATCH] Add separate display Field for WP resources Adds a new WorkPackageDisplayField to display actual work package resources in properties (e.g., parent) to avoid showing `[object Object]`. Uses the work package ID as the link content. --- ...-display-work-package-field.directive.html | 12 ++++ .../wp-display-work-package-field.module.ts | 67 +++++++++++++++++++ .../wp-display-field.config.ts | 3 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 frontend/app/components/wp-display/field-types/wp-display-work-package-field.directive.html create mode 100644 frontend/app/components/wp-display/field-types/wp-display-work-package-field.module.ts diff --git a/frontend/app/components/wp-display/field-types/wp-display-work-package-field.directive.html b/frontend/app/components/wp-display/field-types/wp-display-work-package-field.directive.html new file mode 100644 index 0000000000..6c4d31bda0 --- /dev/null +++ b/frontend/app/components/wp-display/field-types/wp-display-work-package-field.directive.html @@ -0,0 +1,12 @@ + + + + {{ $ctrl.displayText }} + + + + + {{ $ctrl.displayText }} + diff --git a/frontend/app/components/wp-display/field-types/wp-display-work-package-field.module.ts b/frontend/app/components/wp-display/field-types/wp-display-work-package-field.module.ts new file mode 100644 index 0000000000..365840d8d9 --- /dev/null +++ b/frontend/app/components/wp-display/field-types/wp-display-work-package-field.module.ts @@ -0,0 +1,67 @@ +// -- 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 {DisplayField} from "../wp-display-field/wp-display-field.module"; +import {WorkPackageResource} from "../../api/api-v3/hal-resources/work-package-resource.service"; + +export class WorkPackageDisplayField extends DisplayField { + public template: string = '/components/wp-display/field-types/wp-display-work-package-field.directive.html'; + public text: Object; + + + constructor(public resource:WorkPackageResource, + public name:string, + public schema) { + super(resource, name, schema); + + this.text = { + linkTitle: this.I18n.t('js.work_packages.message_successful_show_in_fullscreen') + }; + } + + public get value() { + return this.resource[this.name]; + } + + public get wpId() { + if (this.value.$loaded) { + return this.value.id; + } + + // Read WP ID from href + return this.value.href.match(/(\d+)$/)[0]; + } + + public get valueString() { + return "#" + this.wpId; + } + + public isEmpty(): boolean { + return !this.value; + } +} diff --git a/frontend/app/components/wp-display/wp-display-field/wp-display-field.config.ts b/frontend/app/components/wp-display/wp-display-field/wp-display-field.config.ts index a347623061..50d75d2c86 100644 --- a/frontend/app/components/wp-display/wp-display-field/wp-display-field.config.ts +++ b/frontend/app/components/wp-display/wp-display-field/wp-display-field.config.ts @@ -40,7 +40,7 @@ import {ProgressDisplayField} from '../field-types/wp-display-progress-field.mod import {openprojectModule} from '../../../angular-modules'; import {SpentTimeDisplayField} from '../field-types/wp-display-spent-time-field.module'; import {IntegerDisplayField} from "../field-types/wp-display-integer-field.module"; - +import {WorkPackageDisplayField} from "../field-types/wp-display-work-package-field.module"; openprojectModule .run((wpDisplayField:WorkPackageDisplayFieldService) => { @@ -62,6 +62,7 @@ openprojectModule .addFieldType(DateTimeDisplayField, 'datetime', ['DateTime']) .addFieldType(BooleanDisplayField, 'boolean', ['Boolean']) .addFieldType(ProgressDisplayField, 'progress', ['percentageDone']) + .addFieldType(WorkPackageDisplayField, 'work_package', ['WorkPackage']) .addFieldType(SpentTimeDisplayField, 'spentTime', ['spentTime']) .addFieldType(IdDisplayField, 'id', ['id']); });