Skip to content

Commit

Permalink
Get rid of project specific decorate
Browse files Browse the repository at this point in the history
Replaced with opce-project-autocompleter
  • Loading branch information
oliverguenther committed Dec 20, 2024
1 parent 1eb468e commit e903da1
Showing 1 changed file with 0 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core';
import { NgSelectComponent } from '@ng-select/ng-select';
import {
IProjectAutocompleteItem,
} from 'core-app/shared/components/autocompleter/project-autocompleter/project-autocomplete-item';
import {
IAutocompleteItem,
OpAutocompleterComponent,
Expand All @@ -43,18 +40,7 @@ export const autocompleteSelectDecorationSelector = 'autocomplete-select-decorat

@Component({
template: `
<op-project-autocompleter
*ngIf="isProjectField()"
[model]="currentProjectSelection"
[multiple]="multiple"
[labelForId]="labelForId"
(change)="updateProjectSelection($event)"
[appendTo]="appendTo"
>
</op-project-autocompleter>
<ng-select
*ngIf="!isProjectField()"
[items]="options"
[labelForId]="labelForId"
bindLabel="label"
Expand All @@ -79,9 +65,6 @@ export class AutocompleteSelectDecorationComponent extends OpAutocompleterCompon
/** Get the selected options */
public selected:SelectItem|SelectItem[];

/** Get the selected options especially for the project autocompleter */
public currentProjectSelection:{ id:string, name:string }|{ id:string, name:string }[];

/** The field key (e.g. status, type, or project) */
@Input() key:string;

Expand All @@ -104,9 +87,6 @@ export class AutocompleteSelectDecorationComponent extends OpAutocompleterCompon

// Set initial selection
this.setInitialSelection(data);
if (this.isProjectField()) {
this.setInitialProjectSelection();
}

if (!this.multiple) {
this.selected = (this.selected as SelectItem[])[0];
Expand Down Expand Up @@ -151,40 +131,4 @@ export class AutocompleteSelectDecorationComponent extends OpAutocompleterCompon
.find(`input[name="${this.inputName}"]`)
.remove();
}

updateProjectSelection(items:IProjectAutocompleteItem|IProjectAutocompleteItem[]):void {
items = _.castArray(items);
const mappedItems = items.map(item => {
const selectedItem:SelectItem = {
label: item.name,
value: item.id.toString(),
selected: true,
};

return selectedItem;
});

this.updateSelection(mappedItems);
}

setInitialProjectSelection():void {
const items = _.castArray(this.selected);
if (items.length === 0) return;

if (this.multiple) {
this.currentProjectSelection = items.map((item:SelectItem) => ({
id: item.value,
name: item.label,
}));
} else {
this.currentProjectSelection = {
id: items[0].value,
name: items[0].label,
};
}
}

isProjectField():boolean {
return this.key === 'project';
}
}

0 comments on commit e903da1

Please sign in to comment.