OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Create display and edit fields for project status
Wieland Lindenthal156669c6d1b1
diff --git a/app/assets/stylesheets/content/_autocomplete.sass b/app/assets/stylesheets/content/_autocomplete.sassindex 9461738f55b..00613b38ab2 100644--- a/app/assets/stylesheets/content/_autocomplete.sass+++ b/app/assets/stylesheets/content/_autocomplete.sass@@ -189,17 +189,7 @@ mark.ui-autocomplete-match.ng-select&.traffic-lightsmax-width: 300px- &.ng-select-disabled- > .ng-select-container- background: none- border: none- box-shadow: none.ng-select-containermin-height: 56px !importantheight: 56px !important- .ng-value-container- padding-left: 0- .ng-arrow-wrapper- display: none- .ng-select.ng-select-single .ng-select-containerdiff --git a/app/assets/stylesheets/content/_index.sass b/app/assets/stylesheets/content/_index.sassindex 5f756741a0b..eb47c096992 100644--- a/app/assets/stylesheets/content/_index.sass+++ b/app/assets/stylesheets/content/_index.sass@@ -71,6 +71,7 @@@import content/grid@import content/resizer@import content/version+@import content/project_status@import content/menus/_project_autocompletion@import content/menus/_menu_blocksdiff --git a/app/assets/stylesheets/content/_project_status.sass b/app/assets/stylesheets/content/_project_status.sassnew file mode 100644index 00000000000..fe123c0ce74--- /dev/null+++ b/app/assets/stylesheets/content/_project_status.sass@@ -0,0 +1,41 @@+$gray: #CCCCCC+$red: #E73E3D+$orange: #FFB030+$green: #00D12D++.bulb+ display: inline-block+ width: 40px+ height: 40px+ border-radius: 50%+ border-width: 10px+ border-style: solid+ margin-right: 7px+ vertical-align: middle+ &.-not-set+ border-color: $gray+ background-color: adjust-color($gray, $alpha: -0.7)+ &.-off-track+ border-color: $red+ background-color: adjust-color($red, $alpha: -0.7)+ &.-at-risk+ border-color: $orange+ background-color: adjust-color($orange, $alpha: -0.7)+ &.-on-track+ border-color: $green+ background-color: adjust-color($green, $alpha: -0.7)++.status-name+ text-transform: uppercase+ font-weight: bold+ &.-not-set+ color: $gray+ &.-off-track+ color: $red+ &.-at-risk+ color: $orange+ &.-on-track+ color: $green++.explanation+ margin-top: 9px\ No newline at end of filediff --git a/frontend/src/app/modules/fields/display/display-field.initializer.ts b/frontend/src/app/modules/fields/display/display-field.initializer.tsindex 1c17def4dd7..e8d96f3f452 100644--- a/frontend/src/app/modules/fields/display/display-field.initializer.ts+++ b/frontend/src/app/modules/fields/display/display-field.initializer.ts@@ -46,6 +46,7 @@ import {TypeDisplayField} from "core-app/modules/fields/display/field-types/typeimport {UserDisplayField} from "core-app/modules/fields/display/field-types/user-display-field.module";import {MultipleUserFieldModule} from "core-app/modules/fields/display/field-types/multiple-user-display-field.module";import {WorkPackageIdDisplayField} from "core-app/modules/fields/display/field-types/wp-id-display-field.module";+import {ProjectStatusDisplayField} from "core-app/modules/fields/display/field-types/project-status-display-field.module";export function initializeCoreDisplayFields(displayFieldService:DisplayFieldService) {return () => {@@ -74,6 +75,7 @@ export function initializeCoreDisplayFields(displayFieldService:DisplayFieldServ.addFieldType(ProgressDisplayField, 'progress', ['percentageDone']).addFieldType(WorkPackageDisplayField, 'work_package', ['WorkPackage']).addFieldType(IdDisplayField, 'id', ['id'])+ .addFieldType(ProjectStatusDisplayField, 'project_status', ['ProjectStatus']).addFieldType(UserDisplayField, 'user', ['User']);displayFieldServicediff --git a/frontend/src/app/modules/fields/display/field-types/project-status-display-field.module.ts b/frontend/src/app/modules/fields/display/field-types/project-status-display-field.module.tsnew file mode 100644index 00000000000..4ac6292c1e9--- /dev/null+++ b/frontend/src/app/modules/fields/display/field-types/project-status-display-field.module.ts@@ -0,0 +1,58 @@+// -- 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 "core-app/modules/fields/display/display-field.module";+import {I18nService} from "core-app/modules/common/i18n/i18n.service";++export class ProjectStatusDisplayField extends DisplayField {+ readonly I18n:I18nService = this.$injector.get(I18nService);+ public render(element:HTMLElement, displayText:string):void {+ const code = this.value;++ element.innerHTML = `+ <span class="bulb ${this.projectStatusCodeCssClass(code)}"></span>+ <span class="status-name ${this.projectStatusCodeCssClass(code)}">${this.projectStatusI18n(code)}</span>+ `;+ }++ private projectStatusCodeCssClass(code:string|null|undefined):string {+ code = this.ensureDefaultCode(code);++ return '-' + code.replace(' ', '-');+ }++ private projectStatusI18n(code:string|null|undefined):string {+ code = this.ensureDefaultCode(code);++ return this.I18n.t('js.grid.widgets.project_status.' + code.replace(' ', '_'));+ }++ private ensureDefaultCode(code:string|null|undefined):string {+ return code ? code : 'not set';+ }+}diff --git a/frontend/src/app/modules/fields/edit/edit-field.initializer.ts b/frontend/src/app/modules/fields/edit/edit-field.initializer.tsindex 3ba4c05116f..797bd503980 100644--- a/frontend/src/app/modules/fields/edit/edit-field.initializer.ts+++ b/frontend/src/app/modules/fields/edit/edit-field.initializer.ts@@ -40,6 +40,8 @@ import {FormattableEditFieldComponent} from "core-app/modules/fields/edit/field-import {WorkPackageCommentFieldComponent} from "core-components/work-packages/work-package-comment/wp-comment-field.component";import {SelectAutocompleterRegisterService} from "core-app/modules/fields/edit/field-types/select-autocompleter-register.service";import {VersionAutocompleterComponent} from "core-app/modules/common/autocomplete/version-autocompleter.component";+import {ProjectStatusDisplayField} from "core-app/modules/fields/display/field-types/project-status-display-field.module";+import {ProjectStatusEditFieldComponent} from "core-app/modules/fields/edit/field-types/project-status-edit-field.component";export function initializeCoreEditFields(editFieldService:EditFieldService, selectAutocompleterRegisterService:SelectAutocompleterRegisterService) {@@ -66,6 +68,7 @@ export function initializeCoreEditFields(editFieldService:EditFieldService, sele.addFieldType(BooleanEditFieldComponent, 'boolean', ['Boolean']).addFieldType(DateEditFieldComponent, 'date', ['Date']).addFieldType(FormattableEditFieldComponent, 'wiki-textarea', ['Formattable'])+ .addFieldType(ProjectStatusEditFieldComponent, 'project_status', ['ProjectStatus']).addFieldType(WorkPackageCommentFieldComponent, '_comment', ['comment']);selectAutocompleterRegisterService.register(VersionAutocompleterComponent, 'Version');diff --git a/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.html b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.htmlnew file mode 100644index 00000000000..0003ffed663--- /dev/null+++ b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.html@@ -0,0 +1,10 @@+<ng-select [items]="availableStatuses"+ [(ngModel)]="currentStatusCode"+ bindLabel="name"+ bindValue="code"+ class="traffic-lights">+ <ng-template ng-label-tmp let-item="item">+ <span class="bulb" [ngClass]="item.colorClass"></span>+ <span class="status-name" [ngClass]="item.colorClass">{{item.name}}</span>+ </ng-template>+</ng-select>\ No newline at end of filediff --git a/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.sass b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.sassnew file mode 100644index 00000000000..e69de29bb2ddiff --git a/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.tsnew file mode 100644index 00000000000..a53800d98e2--- /dev/null+++ b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.ts@@ -0,0 +1,225 @@+// -- 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 {CollectionResource} from 'core-app/modules/hal/resources/collection-resource';+import {HalResource} from 'core-app/modules/hal/resources/hal-resource';+import {I18nService} from 'core-app/modules/common/i18n/i18n.service';+import {Component, OnInit, ViewChild} from "@angular/core";+import {EditFieldComponent} from "core-app/modules/fields/edit/edit-field.component";+import {ValueOption} from "core-app/modules/fields/edit/field-types/select-edit-field.component";+import {NgSelectComponent} from "@ng-select/ng-select";+import {untilComponentDestroyed} from "ng2-rx-componentdestroyed";++@Component({+ templateUrl: './project-status-edit-field.component.html',+ styleUrls: ['./project-status-edit-field.component.sass']+})+export class ProjectStatusEditFieldComponent extends EditFieldComponent implements OnInit {+ @ViewChild(NgSelectComponent, { static: true }) public ngSelectComponent:NgSelectComponent;++ readonly I18n:I18nService = this.injector.get(I18nService);++ public currentStatusCode:string = 'not set';+ public availableStatuses:any[] = [+ {+ code: 'not set',+ name: this.I18n.t('js.grid.widgets.project_status.not_set'),+ colorClass: '-gray',+ },+ {+ code: 'off track',+ name: this.I18n.t('js.grid.widgets.project_status.off_track'),+ colorClass: '-red',+ },+ {+ code: 'on track',+ name: this.I18n.t('js.grid.widgets.project_status.on_track'),+ colorClass: '-green',+ },+ {+ code: 'at risk',+ name: this.I18n.t('js.grid.widgets.project_status.at_risk'),+ colorClass: '-orange',+ },+ ];++ public options:any[] = [];+ public valueOptions:ValueOption[];+++ public appendTo:any = null;+ private hiddenOverflowContainer = '.__hidden_overflow_container';++ public currentValueInvalid:boolean = false;+ private nullOption:ValueOption;+ private _selectedOption:ValueOption[];++ /** Since we need to wait for values to be loaded, remember if the user activated this field*/+ private requestFocus = false;++ ngOnInit() {+ this.handler+ .$onUserActivate+ .pipe(+ untilComponentDestroyed(this),+ )+ .subscribe(() => {+ this.requestFocus = this.options.length === 0;++ // If we already have all values loaded, open now.+ if (!this.requestFocus) {+ this.openAutocompleteSelectField();+ }+ });++ super.ngOnInit();+ this.appendTo = this.overflowingSelector;+ }++ public get value() {+ const val = this.resource[this.name];+ return val ? val[0] : val;+ }++ /**+ * Map the selected hal resource(s) to the value options so that ngOptions will track them.+ * We cannot pass the HalResources themselves as angular will copy them on every digest due to trackBy+ * @returns {any}+ */+ public buildSelectedOption() {+ const value:HalResource[] = this.resource[this.name];+ return value ? value.map(val => this.findValueOption(val)) : [];+ }++ public get selectedOption() {+ return this._selectedOption;+ }++ /**+ * Map the ValueOption to the actual HalResource option+ * @param val+ */+ public set selectedOption(val:ValueOption[]) {+ // this._selectedOption = val;+ // let mapper = (val:ValueOption) => {+ // let option = _.find(this.options, o => o.$href === val.$href) || this.nullOption;+ //+ // // Special case 'null' value, which angular+ // // only understands in ng-options as an empty string.+ // if (option && option.$href === '') {+ // option.$href = null;+ // }+ //+ // return option;+ // };+ //+ // this.resource[this.name] = _.castArray(val).map(el => mapper(el));+ }++ public onOpen() {+ jQuery(this.hiddenOverflowContainer).one('scroll', () => {+ this.ngSelectComponent.close();+ });+ }++ public onClose() {+ // Nothing to do+ }++ // public repositionDropdown() {+ // if (this.ngSelectComponent && this.ngSelectComponent.dropdownPanel) {+ // setTimeout(() => this.ngSelectComponent.dropdownPanel.adjustPosition(), 0);+ // }+ // }++ private openAutocompleteSelectField() {+ // The timeout takes care that the opening is added to the end of the current call stack.+ // Thus we can be sure that the autocompleter is rendered and ready to be opened.+ let that = this;+ window.setTimeout(function () {+ that.ngSelectComponent.open();+ }, 0);+ }++ private findValueOption(option?:HalResource):ValueOption {+ let result;++ if (option) {+ result = _.find(this.valueOptions, (valueOption) => valueOption.$href === option.$href)!;+ }++ return result || this.nullOption;+ }++ // private setValues(availableValues:any[], sortValuesByName:boolean = false) {+ // if (sortValuesByName) {+ // availableValues.sort(function (a:any, b:any) {+ // let nameA = a.name.toLowerCase();+ // let nameB = b.name.toLowerCase();+ // return nameA < nameB ? -1 : nameA > nameB ? 1 : 0;+ // });+ // }+ //+ // this.options = availableValues || [];+ // this.valueOptions = this.options.map(el => {+ // return { name: el.name, $href: el.$href };+ // });+ // this._selectedOption = this.buildSelectedOption();+ // this.checkCurrentValueValidity();+ //+ // if (this.options.length > 0 && this.requestFocus) {+ // this.openAutocompleteSelectField();+ // this.requestFocus = false;+ // }+ // }++ protected initialize() {+ super.initialize();+ this.loadValues();+ }++ private loadValues() {+ let allowedValues = this.schema.allowedValues;+ if (Array.isArray(allowedValues)) {+ this.setValues(allowedValues);+ } else if (this.schema.allowedValues) {+ return this.schema.allowedValues.$load().then((values:CollectionResource) => {+ // The select options of the project shall be sorted+ if (values.count > 0 && (values.elements[0] as any)._type === 'Project') {+ this.setValues(values.elements, true);+ } else {+ this.setValues(values.elements);+ }+ });+ } else {+ this.setValues([]);+ }+ return Promise.resolve();+ }++}diff --git a/frontend/src/app/modules/fields/openproject-fields.module.ts b/frontend/src/app/modules/fields/openproject-fields.module.tsindex c656c90ac99..faf1a9307f1 100644--- a/frontend/src/app/modules/fields/openproject-fields.module.ts+++ b/frontend/src/app/modules/fields/openproject-fields.module.ts@@ -52,6 +52,7 @@ import {SelectAutocompleterRegisterService} from "core-app/modules/fields/edit/fimport {EditFormComponent} from "core-app/modules/fields/edit/edit-form/edit-form.component";import {WorkPackageEditFieldComponent} from "core-app/modules/fields/edit/field-types/work-package-edit-field.component";import {EditableAttributeFieldComponent} from "core-app/modules/fields/edit/field/editable-attribute-field.component";+import {ProjectStatusEditFieldComponent} from "core-app/modules/fields/edit/field-types/project-status-edit-field.component";@NgModule({imports: [@@ -91,6 +92,7 @@ import {EditableAttributeFieldComponent} from "core-app/modules/fields/edit/fielWorkPackageEditFieldComponent,EditFormComponent,EditableAttributeFieldComponent,+ ProjectStatusEditFieldComponent,],entryComponents: [EditFormPortalComponent,@@ -106,6 +108,7 @@ import {EditableAttributeFieldComponent} from "core-app/modules/fields/edit/fielTextEditFieldComponent,WorkPackageEditFieldComponent,EditableAttributeFieldComponent,+ ProjectStatusEditFieldComponent,]})export class OpenprojectFieldsModule { }diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rbindex b3f8f6e6649..6c59442d138 100644--- a/lib/api/v3/projects/project_representer.rb+++ b/lib/api/v3/projects/project_representer.rb@@ -184,10 +184,10 @@ module APIsetter: ->(fragment:,represented:, **) {represented.status ||= {}represented.status[:code] = if fragment.nil?- nil- else- fragment.strip.tr(' ', '_').underscore.to_sym- end+ nil+ else+ fragment.strip.tr(' ', '_').underscore.to_sym+ end}def _type