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
Fix ngSelect for project status edit field
Wieland Lindenthalc027f36150e0
diff --git a/app/assets/stylesheets/content/_autocomplete.sass b/app/assets/stylesheets/content/_autocomplete.sassindex 00613b38ab2..db43c8cfe17 100644--- a/app/assets/stylesheets/content/_autocomplete.sass+++ b/app/assets/stylesheets/content/_autocomplete.sass@@ -185,11 +185,4 @@ mark.ui-autocomplete-match.work-package-table--container .ng-dropdown-panelz-index: auto !important-// Project status widget-.ng-select- &.traffic-lights- max-width: 300px- .ng-select-container- min-height: 56px !important- height: 56px !importantdiff --git a/app/assets/stylesheets/content/_project_status.sass b/app/assets/stylesheets/content/_project_status.sassindex fe123c0ce74..0864f868b3d 100644--- a/app/assets/stylesheets/content/_project_status.sass+++ b/app/assets/stylesheets/content/_project_status.sass@@ -1,9 +1,21 @@-$gray: #CCCCCC-$red: #E73E3D-$orange: #FFB030-$green: #00D12D-.bulb++// Project status widget+.ng-select+ &.project-status+ max-width: 300px+ .ng-select-container+ min-height: 56px !important+ height: 56px !important++ .ng-input+ display: none++$project-status-gray: #CCCCCC+$project-status-red: #E73E3D+$project-status-orange: #FFB030+$project-status-green: #00D12D+.project-status--bulbdisplay: inline-blockwidth: 40pxheight: 40px@@ -13,29 +25,43 @@ $green: #00D12Dmargin-right: 7pxvertical-align: middle&.-not-set- border-color: $gray- background-color: adjust-color($gray, $alpha: -0.7)+ border-color: $project-status-gray+ background-color: adjust-color($project-status-gray, $alpha: -0.7)&.-off-track- border-color: $red- background-color: adjust-color($red, $alpha: -0.7)+ border-color: $project-status-red+ background-color: adjust-color($project-status-red, $alpha: -0.7)&.-at-risk- border-color: $orange- background-color: adjust-color($orange, $alpha: -0.7)+ border-color: $project-status-orange+ background-color: adjust-color($project-status-orange, $alpha: -0.7)&.-on-track- border-color: $green- background-color: adjust-color($green, $alpha: -0.7)+ border-color: $project-status-green+ background-color: adjust-color($project-status-green, $alpha: -0.7)-.status-name+.project-status--display-field+ height: 56px+ .status.-editable+ line-height: 50px+ border-radius: 4px+ &:hover+ cursor: pointer++.project-status--nametext-transform: uppercasefont-weight: bold&.-not-set- color: $gray+ color: $project-status-gray&.-off-track- color: $red+ color: $project-status-red&.-at-risk- color: $orange+ color: $project-status-orange&.-on-track- color: $green+ color: $project-status-green++.project-status--pulldown-icon+ font-size: 10px+ vertical-align: middle+ &:before+ color: lightgrey-.explanation+.project-status--explanationmargin-top: 9px\ No newline at end of filediff --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.tsindex 36d6c8fb338..17ab648e67f 100644--- 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.ts@@ -27,7 +27,6 @@// ++import {DisplayField} from "core-app/modules/fields/display/display-field.module";-import {I18nService} from "core-app/modules/common/i18n/i18n.service";import {projectStatusCodeCssClass, projectStatusI18n} from "core-app/modules/fields/helpers/project-status-helper";@@ -36,8 +35,9 @@ export class ProjectStatusDisplayField extends DisplayField {const code = this.value;element.innerHTML = `- <span class="bulb ${projectStatusCodeCssClass(code)}"></span>- <span class="status-name ${projectStatusCodeCssClass(code)}">${projectStatusI18n(code, this.I18n)}</span>+ <span class="project-status--bulb ${projectStatusCodeCssClass(code)}"></span>+ <span class="project-status--name ${projectStatusCodeCssClass(code)}">${projectStatusI18n(code, this.I18n)}</span>+ <span class="project-status--pulldown-icon icon icon-pulldown"></span>`;}}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.htmlindex 0003ffed663..22faf21afda 100644--- 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.html@@ -1,10 +1,19 @@<ng-select [items]="availableStatuses"- [(ngModel)]="currentStatusCode"+ [(ngModel)]="resource['status']"bindLabel="name"- bindValue="code"- class="traffic-lights">+ bindValue="value"+ class="project-status"+ (open)="onOpen()"+ (close)="onClose()"+ [appendTo]="hiddenOverflowContainer"+ [hideSelected]="true"+ [disabled]="inFlight"><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>+ <span class="project-status--bulb" [ngClass]="item.colorClass"></span>+ <span class="project-status--name" [ngClass]="item.colorClass">{{item.name}}</span>+ </ng-template>+ <ng-template ng-option-tmp let-item="item" let-index="index" let-search="searchTerm">+ <span class="project-status--bulb" [ngClass]="item.colorClass"></span>+ <span class="project-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.ts b/frontend/src/app/modules/fields/edit/field-types/project-status-edit-field.component.tsindex 536424fc0a6..5187810f5a7 100644--- 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.ts@@ -26,14 +26,11 @@// 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";+import {projectStatusCodeCssClass, projectStatusI18n} from "core-app/modules/fields/helpers/project-status-helper";@Component({templateUrl: './project-status-edit-field.component.html',@@ -44,120 +41,20 @@ export class ProjectStatusEditFieldComponent extends EditFieldComponent implemenreadonly 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',- },- ];+ private _availableStatusCodes:string[] = ['not set', 'off track', 'at risk', 'on track'];- public options:any[] = [];- public valueOptions:ValueOption[];+ public availableStatuses:any[] = this._availableStatusCodes.map((code:string):any => {+ return {+ code: code,+ name: projectStatusI18n(code, this.I18n),+ colorClass: projectStatusCodeCssClass(code),+ value: code === 'not set' ? null : code,+ };+ });-- 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;+ public hiddenOverflowContainer = 'body';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;@@ -166,60 +63,13 @@ export class ProjectStatusEditFieldComponent extends EditFieldComponent implemen}, 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();+ public onOpen() {+ jQuery(this.hiddenOverflowContainer).one('scroll', () => {+ this.ngSelectComponent.close();+ });}- 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();+ public onClose() {+ // Nothing to do}-}diff --git a/frontend/src/app/modules/grids/widgets/project-status/project-status.component.html b/frontend/src/app/modules/grids/widgets/project-status/project-status.component.htmlindex e52fd24706d..28c621972b7 100644--- a/frontend/src/app/modules/grids/widgets/project-status/project-status.component.html+++ b/frontend/src/app/modules/grids/widgets/project-status/project-status.component.html@@ -11,7 +11,8 @@<div class="grid--widget-content"><edit-form *ngIf="(project$ | async) as project" [resource]="project"><editable-attribute-field [resource]="project"- fieldName="status">+ fieldName="status"+ wrapperClasses="project-status--display-field"></editable-attribute-field><editable-attribute-field [resource]="project"fieldName="statusExplanation">