Skip to content

Commit

Permalink
Merge pull request #997 from gisaia/fix/powerbarsManageColors
Browse files Browse the repository at this point in the history
fix: correct typing when managing powerbars and donuts colors
  • Loading branch information
QuCMGisaia authored Sep 23, 2024
2 parents 9a5fd84 + 988b1ae commit 4bfdba7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { WidgetFormBuilder } from '../widget-form-builder';
import { ArlasColorService } from 'arlas-web-components';

import { WidgetConfigFormGroup } from '@shared-models/widget-config-form';
import { addToColorManualValuesCtrl } from '@utils/tools';

export class DonutConfigForm extends WidgetConfigFormGroup {

Expand Down Expand Up @@ -116,15 +117,15 @@ export class DonutConfigForm extends WidgetConfigFormGroup {
(Array.from(this.customControls.dataStep.aggregationmodels.value)[0] as any).field)
.then((keywords: Array<string>) => {
keywords.forEach((k: string, index: number) => {
this.addToColorManualValuesCtrl({
addToColorManualValuesCtrl({
keyword: k,
color: this.colorService.getColor(k)
}, index);
}, this.globalKeysToColortrl, index);
});
this.addToColorManualValuesCtrl({
addToColorManualValuesCtrl({
keyword: 'OTHER',
color: defaultConfig.otherColor
});
}, this.globalKeysToColortrl);

const sub: Subscription = dialog.open(DialogColorTableComponent, {
data: {
Expand All @@ -140,7 +141,7 @@ export class DonutConfigForm extends WidgetConfigFormGroup {
result.forEach((kc: KeywordColor) => {
/** after closing the dialog, save the [keyword, color] list in the ARLAS color service */
(this.colorService.colorGenerator as ArlasColorGeneratorLoader).updateKeywordColor(kc.keyword, kc.color);
this.addToColorManualValuesCtrl(kc);
addToColorManualValuesCtrl(kc, this.globalKeysToColortrl);
});
}
sub.unsubscribe();
Expand Down Expand Up @@ -195,22 +196,6 @@ export class DonutConfigForm extends WidgetConfigFormGroup {
}
}
};

private addToColorManualValuesCtrl(kc: KeywordColor, index?: number) {
if (!Object.values(this.globalKeysToColortrl.controls)
.find(keywordColorGrp => keywordColorGrp.get('keyword').value === kc.keyword)) {
const keywordColorGrp = new FormGroup({
keyword: new FormControl(kc.keyword),
color: new FormControl(kc.color)
});
if (index !== undefined) {
this.globalKeysToColortrl.insert(index, keywordColorGrp);
} else {
this.globalKeysToColortrl.push(keywordColorGrp);
}
}
}

}

@Injectable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ export class PowerbarConfigForm extends WidgetConfigFormGroup {
addToColorManualValuesCtrl({
keyword: k,
color: this.colorService.getColor(k)
}, this.globalKeysToColortrl.controls, index);
}, this.globalKeysToColortrl, index);
});
addToColorManualValuesCtrl({
keyword: 'OTHER',
color: defaultConfig.otherColor
}, this.globalKeysToColortrl.controls);
}, this.globalKeysToColortrl);

const sub = dialog.open(DialogColorTableComponent, {
data: {
Expand All @@ -249,7 +249,7 @@ export class PowerbarConfigForm extends WidgetConfigFormGroup {
result.forEach((kc: KeywordColor) => {
/** after closing the dialog, save the [keyword, color] list in the ARLAS color service */
(colorService.colorGenerator as ArlasColorGeneratorLoader).updateKeywordColor(kc.keyword, kc.color);
addToColorManualValuesCtrl(kc, this.globalKeysToColortrl.controls);
addToColorManualValuesCtrl(kc, this.globalKeysToColortrl);
});
}
sub.unsubscribe();
Expand Down
10 changes: 5 additions & 5 deletions src/app/utils/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ export function camelize(str) {
});
}

export function addToColorManualValuesCtrl(kc: KeywordColor, controls: any, index?: number) {
if (!Object.values(controls)
.find(keywordColorGrp => (keywordColorGrp as any).get('keyword').value === kc.keyword)) {
export function addToColorManualValuesCtrl(kc: KeywordColor, fa: FormArray, index?: number) {
if (!Object.values(fa.controls)
.find(keywordColorGrp => keywordColorGrp.get('keyword').value === kc.keyword)) {
const keywordColorGrp = new FormGroup({
keyword: new FormControl(kc.keyword),
color: new FormControl(kc.color)
});
if (index !== undefined) {
controls.insert(index, keywordColorGrp);
fa.insert(index, keywordColorGrp);
} else {
controls.push(keywordColorGrp);
fa.push(keywordColorGrp);
}
}
}
Expand Down

0 comments on commit 4bfdba7

Please sign in to comment.