add checkbox to language editor UI

This commit is contained in:
amentis 2023-11-30 10:37:58 +02:00
parent 40ae38e8d9
commit 4417532935
4 changed files with 23 additions and 22 deletions

View File

@ -90,7 +90,7 @@ public class LanguageServiceImpl implements LanguageService {
} }
data.setCode(model.getCode()); data.setCode(model.getCode());
data.setPayload(model.getPayload()); data.setPayload(model.getPayload() != null && model.getPayload().length() > 0 ? model.getPayload() : null);
data.setOrdinal(model.getOrdinal()); data.setOrdinal(model.getOrdinal());
data.setUpdatedAt(Instant.now()); data.setUpdatedAt(Instant.now());

View File

@ -64,6 +64,9 @@
<mat-error *ngIf="formGroup.get('payload').hasError('required')"> <mat-error *ngIf="formGroup.get('payload').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> {{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
<h9 class="col-12">{{'LANGUAGE-EDITOR.FIELDS.OVERRIDE' | translate}}
<mat-checkbox (change)="overrideFromFile($event, formGroup.get('code').value)"></mat-checkbox>
</h9>
</div> </div>
</div> </div>
</mat-card-content> </mat-card-content>

View File

@ -28,6 +28,7 @@ import { LanguageEditorResolver } from './language-editor.resolver';
import { LanguageEditorService } from './language-editor.service'; import { LanguageEditorService } from './language-editor.service';
import { LanguageEditorModel } from './language-editor.model'; import { LanguageEditorModel } from './language-editor.model';
import { LanguageHttpService } from '@app/core/services/language/language.http.service'; import { LanguageHttpService } from '@app/core/services/language/language.http.service';
import { MatCheckboxChange } from '@angular/material/checkbox';
@Component({ @Component({
@ -43,6 +44,7 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
formGroup: UntypedFormGroup = null; formGroup: UntypedFormGroup = null;
showInactiveDetails = false; showInactiveDetails = false;
availableLanguageCodes: string[] = []; availableLanguageCodes: string[] = [];
currentPayload: string = null;
protected get canDelete(): boolean { protected get canDelete(): boolean {
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteLanguage); return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteLanguage);
@ -106,20 +108,12 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
prepareForm(data: Language) { prepareForm(data: Language) {
try { try {
if(data && data.payload == null){ if(data && data.payload){
this.languageHttpService.getSingleWithCode(data.code, LanguageEditorResolver.lookupFields()) this.currentPayload = data.payload;
.pipe(takeUntil(this._destroyed))
.subscribe(language => {
data.payload = language.payload;
this.editorModel = data ? new LanguageEditorModel().fromModel(data) : new LanguageEditorModel();
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
this.buildForm();
});
}else{
this.editorModel = data ? new LanguageEditorModel().fromModel(data) : new LanguageEditorModel();
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
this.buildForm();
} }
this.editorModel = data ? new LanguageEditorModel().fromModel(data) : new LanguageEditorModel();
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
this.buildForm();
} catch (error) { } catch (error) {
this.logger.error('Could not parse Language item: ' + data + error); this.logger.error('Could not parse Language item: ' + data + error);
this.uiNotificationService.snackBarNotification(this.language.instant('COMMONS.ERRORS.DEFAULT'), SnackBarNotificationLevel.Error); this.uiNotificationService.snackBarNotification(this.language.instant('COMMONS.ERRORS.DEFAULT'), SnackBarNotificationLevel.Error);
@ -197,13 +191,16 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} }
public selectedCodeChanged(code: string){ public overrideFromFile(matCheckBox: MatCheckboxChange, code: string){
this.languageHttpService.getSingleWithCode(code, LanguageEditorResolver.lookupFields()) if(matCheckBox.checked == true){
.pipe(takeUntil(this._destroyed)) this.languageHttpService.getSingleWithCode(code, LanguageEditorResolver.lookupFields())
.subscribe(language => { .pipe(takeUntil(this._destroyed))
this.formGroup.get('payload').patchValue(language.payload); .subscribe(language => {
}); this.formGroup.get('payload').patchValue(language.payload);
});
}else{
this.formGroup.get('payload').patchValue(this.currentPayload);
}
} }
} }

View File

@ -1191,7 +1191,8 @@
"FIELDS": { "FIELDS": {
"CODE": "Code", "CODE": "Code",
"PAYLOAD": "Payload", "PAYLOAD": "Payload",
"ORDINAL": "Ordinal" "ORDINAL": "Ordinal",
"OVERRIDE": "Override from file"
}, },
"ACTIONS": { "ACTIONS": {
"SAVE": "Save", "SAVE": "Save",