Skip to content
Snippets Groups Projects
Commit 9eb02822 authored by Maël AUDEON's avatar Maël AUDEON Committed by Makhtar DIAGNE
Browse files

[DLAB-4011] Fix initial values in color inputs

parent 0a43cbd9
No related branches found
No related tags found
1 merge request!1Feature/design/1
import {Component, forwardRef, Input} from '@angular/core';
import {ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, ValidatorFn, Validators} from '@angular/forms';
import {
ControlValueAccessor,
FormBuilder,
FormGroup,
NG_VALUE_ACCESSOR,
ValidatorFn,
Validators
} from '@angular/forms';
import {ThemeService} from 'ui-frontend-common';
export const COLORS_INPUT_ACCESSOR: any = {
......@@ -27,23 +34,21 @@ export class CustomerColorsInputComponent implements ControlValueAccessor {
onChange: (colors: {[key: string]: string}) => void;
onTouched: () => void;
validator: ValidatorFn;
validator: ValidatorFn = Validators.pattern(/#([0-9A-Fa-f]{6})/);
constructor(private formBuilder: FormBuilder, private themeService: ThemeService) {
this.validator = Validators.pattern(/#([0-9A-Fa-f]{6})/);
this.colorForm = this.formBuilder.group({
primary: [themeService.themeColors['vitamui-primary'], this.validator],
secondary: [themeService.themeColors['vitamui-secondary'], this.validator]
primary: ['', this.validator],
secondary: ['', this.validator]
});
}
writeValue(colors: {[key: string]: string}) {
this.colors = {
primary: colors['vitamui-primary'],
secondary: colors['vitamui-secondary']
};
writeValue(colors: {primary: string, secondary: string}) {
this.colorForm.get('primary').setValue(colors.primary);
this.colorForm.get('secondary').setValue(colors.secondary);
this.overloadLocalTheme();
}
registerOnChange(fn: (colors: {[key: string]: string}) => void) {
......
......@@ -83,8 +83,11 @@ export class GraphicIdentityUpdateComponent implements OnInit {
this.graphicIdentityForm.get('hasCustomGraphicIdentity').setValue(this.customer.hasCustomGraphicIdentity);
this.hasCustomGraphicIdentity = this.graphicIdentityForm.get('hasCustomGraphicIdentity').value;
this.graphicIdentityForm.get('themeColors').value.primary = this.themeService.getThemeColors(this.customer.themeColors);
const customerTheme = this.themeService.getThemeColors(this.customer.themeColors);
this.graphicIdentityForm.get('themeColors').setValue({
primary: customerTheme['vitamui-primary'],
secondary: customerTheme['vitamui-secondary']
});
this.graphicIdentityForm.get('hasCustomGraphicIdentity').valueChanges.subscribe(() => {
......@@ -157,26 +160,17 @@ export class GraphicIdentityUpdateComponent implements OnInit {
this.handleImage(files);
}
updateForCustomerModel(formData: any): any {
console.log('form data to theme colors');
console.log(formData);
const themeColors: {[key: string]: string} = {};
for (const key in formData) {
if (formData.hasOwnProperty(key)) {
themeColors[key] = formData[key];
}
}
return themeColors;
}
updateGraphicIdentity() {
const themeFormValues = this.graphicIdentityForm.get('themeColors').value;
const formData = {
id : this.customer.id,
hasCustomGraphicIdentity: this.graphicIdentityForm.get('hasCustomGraphicIdentity').value,
themeColors: this.graphicIdentityForm.get('themeColors').value
themeColors: {
'vitamui-primary': themeFormValues.primary,
'vitamui-secondary': themeFormValues.secondary
}
};
this.customerService.patch(formData, this.imageToUpload)
.subscribe(
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment