🐛 Fix bug when typing new image type
continuous-integration/drone/push Build is passing Details

master
Alix JEUDI--LEMOINE 1 week ago
parent d57ac3b312
commit dc9315804c

@ -50,16 +50,17 @@
Types d'images autorisés Types d'images autorisés
</label> </label>
<div class="space-y-2"> <div class="space-y-2">
<div *ngFor="let imgType of config.allowed_image_types" class="flex items-center"> <div *ngFor="let imgType of localImageTypes; let i = index" class="flex items-center">
<input <input
type="text" type="text"
[value]="imgType" [value]="imgType"
[name]="'type_' + imgType" (input)="updateImageType(i, $event)"
[name]="'type_' + i"
class="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md dark:bg-gray-700 dark:text-white" class="flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md dark:bg-gray-700 dark:text-white"
/> />
<button <button
type="button" type="button"
(click)="removeImageType(imgType)" (click)="removeImageType(i)"
class="ml-2 text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300" class="ml-2 text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300"
> >
Supprimer Supprimer

@ -21,6 +21,8 @@ export class ConfigComponent implements OnInit {
max_friends_per_user: 100 max_friends_per_user: 100
}; };
localImageTypes: string[] = [];
constructor(private configService: ConfigService) {} constructor(private configService: ConfigService) {}
ngOnInit(): void { ngOnInit(): void {
@ -30,12 +32,15 @@ export class ConfigComponent implements OnInit {
loadConfig(): void { loadConfig(): void {
this.configService.loadConfig().subscribe(config => { this.configService.loadConfig().subscribe(config => {
this.config = config; this.config = config;
this.localImageTypes = [...config.allowed_image_types];
}); });
} }
saveConfig(): void { saveConfig(): void {
this.config.allowed_image_types = [...this.localImageTypes];
this.configService.saveConfig(this.config).subscribe(config => { this.configService.saveConfig(this.config).subscribe(config => {
this.config = config; this.config = config;
this.localImageTypes = [...config.allowed_image_types];
alert('Configuration enregistrée avec succès'); alert('Configuration enregistrée avec succès');
}); });
} }
@ -45,13 +50,15 @@ export class ConfigComponent implements OnInit {
} }
addImageType(): void { addImageType(): void {
this.config.allowed_image_types.push(''); this.localImageTypes.push('');
}
removeImageType(index: number): void {
this.localImageTypes.splice(index, 1);
} }
removeImageType(type: string): void { updateImageType(index: number, event: Event): void {
const index = this.config.allowed_image_types.indexOf(type); const input = event.target as HTMLInputElement;
if (index > -1) { this.localImageTypes[index] = input.value;
this.config.allowed_image_types.splice(index, 1);
}
} }
} }
Loading…
Cancel
Save