Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Thomas Georgios Giannos 2023-11-29 13:10:00 +02:00
commit f5f5d6345f
6 changed files with 66 additions and 31 deletions

View File

@ -31,14 +31,14 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import java.io.IOException; import java.io.IOException;
import java.util.AbstractMap; import java.util.*;
import java.util.List; import java.util.stream.Collectors;
import java.util.Map;
import java.util.UUID;
@RestController @RestController
@RequestMapping(path = {"api/v2/language"}) @RequestMapping(path = {"api/v2/language"})
@ -127,6 +127,21 @@ public class LanguageV2Controller {
return model; return model;
} }
@PostMapping("available-languages")
public QueryResult<String> queryLanguageCodes(@RequestBody LanguageLookup lookup) {
logger.debug("querying {}", Language.class.getSimpleName());
this.censorFactory.censor(LanguageCensor.class).censor(lookup.getProject(), null);
LanguageQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic);
List<LanguageEntity> data = query.collectAs(lookup.getProject());
List<Language> models = this.builderFactory.builder(LanguageBuilder.class).authorize(AuthorizationFlags.OwnerOrDmpAssociatedOrPermissionOrPublic).build(lookup.getProject(), data);
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
return new QueryResult<>(models.stream().map(x -> x.getCode()).collect(Collectors.toList()), count);
}
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
public Language persist(@MyValidate @RequestBody LanguagePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException { public Language persist(@MyValidate @RequestBody LanguagePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException {

View File

@ -44,6 +44,11 @@ export class LanguageV2Service {
catchError((error: any) => throwError(error))); catchError((error: any) => throwError(error)));
} }
queryAvailableCodes(q: LanguageLookup): Observable<QueryResult<string>> {
const url = `${this.apiBase}/available-languages`;
return this.http.post<QueryResult<string>>(url, q).pipe(catchError((error: any) => throwError(error)));
}
persist(item: LanguagePersist): Observable<Language> { persist(item: LanguagePersist): Observable<Language> {
const url = `${this.apiBase}/persist`; const url = `${this.apiBase}/persist`;
@ -83,7 +88,7 @@ export class LanguageV2Service {
valueAssign: (item: Language) => item.id, valueAssign: (item: Language) => item.id,
}; };
private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): LanguageLookup { public buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): LanguageLookup {
const lookup: LanguageLookup = new LanguageLookup(); const lookup: LanguageLookup = new LanguageLookup();
lookup.page = { size: 100, offset: 0 }; lookup.page = { size: 100, offset: 0 };
if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; } if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; }

View File

@ -29,7 +29,7 @@
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content>
<div class="row"> <div class="row">
<div class="col-4"> <div class="col-4" *ngIf="isNew">
<mat-form-field class="w-100"> <mat-form-field class="w-100">
<mat-label>{{'LANGUAGE-EDITOR.FIELDS.CODE' | translate}}</mat-label> <mat-label>{{'LANGUAGE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<input matInput type="text" name="code" [formControl]="formGroup.get('code')" required> <input matInput type="text" name="code" [formControl]="formGroup.get('code')" required>
@ -37,6 +37,18 @@
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> {{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
</div> </div>
<div class="col-4" *ngIf="!isNew">
<mat-form-field class="w-100">
<mat-label>{{'LANGUAGE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
<mat-select (selectionChange)="selectedCodeChanged($event.value)" name= "code" [formControl]="formGroup.get('code')">
<mat-option *ngFor="let languageCode of availableLanguageCodes" [value]="languageCode">
{{languageCode}}
</mat-option>
</mat-select>
<mat-error *ngIf="formGroup.get('code').hasError('required')">
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
</div>
<div class="col-12"> <div class="col-12">
<mat-form-field class="w-100"> <mat-form-field class="w-100">
<mat-label>{{'LANGUAGE-EDITOR.FIELDS.PAYLOAD' | translate}}</mat-label> <mat-label>{{'LANGUAGE-EDITOR.FIELDS.PAYLOAD' | translate}}</mat-label>

View File

@ -27,7 +27,6 @@ import { map, takeUntil } from 'rxjs/operators';
import { LanguageEditorResolver } from './language-editor.resolver'; 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 { MatChipEditedEvent, MatChipInputEvent } from '@angular/material/chips';
import { LanguageV2Service } from '@app/core/services/language/language-v2.service'; import { LanguageV2Service } from '@app/core/services/language/language-v2.service';
@ -43,6 +42,7 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
isDeleted = false; isDeleted = false;
formGroup: UntypedFormGroup = null; formGroup: UntypedFormGroup = null;
showInactiveDetails = false; showInactiveDetails = false;
availableLanguageCodes: string[] = [];
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);
@ -88,6 +88,11 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
ngOnInit(): void { ngOnInit(): void {
this.matomoService.trackPageView('Admin: Languages'); this.matomoService.trackPageView('Admin: Languages');
super.ngOnInit(); super.ngOnInit();
this.languageV2Service.queryAvailableCodes(this.languageV2Service.buildAutocompleteLookup())
.pipe(takeUntil(this._destroyed))
.subscribe(
data => this.availableLanguageCodes = data.items,
);
} }
getItem(itemId: Guid, successFunction: (item: Language) => void) { getItem(itemId: Guid, successFunction: (item: Language) => void) {
@ -192,4 +197,13 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
this.formService.validateAllFormFields(this.formGroup); this.formService.validateAllFormFields(this.formGroup);
} }
public selectedCodeChanged(code: string){
this.languageV2Service.getSingleWithCode(code, LanguageEditorResolver.lookupFields())
.pipe(takeUntil(this._destroyed))
.subscribe(language => {
this.formGroup.get('payload').patchValue(language.payload);
});
}
} }

View File

@ -19,8 +19,8 @@
<mat-form-field> <mat-form-field>
<mat-label>{{'SUPPORTIVE-MATERIAL-EDITOR.FIELDS.LANGUAGE' | translate}}</mat-label> <mat-label>{{'SUPPORTIVE-MATERIAL-EDITOR.FIELDS.LANGUAGE' | translate}}</mat-label>
<mat-select (selectionChange)="selectedLangChanged($event.value)" name= "languageCode" [formControl]="formGroup.get('languageCode')"> <mat-select (selectionChange)="selectedLangChanged($event.value)" name= "languageCode" [formControl]="formGroup.get('languageCode')">
<mat-option *ngFor="let vis of visiblesLangTypes" [value]="vis.type"> <mat-option *ngFor="let languageCode of availableLanguageCodes" [value]="languageCode">
{{vis.name | translate}} {{languageCode}}
</mat-option> </mat-option>
</mat-select> </mat-select>
<mat-error *ngIf="formGroup.get('languageCode').hasError('required')"> <mat-error *ngIf="formGroup.get('languageCode').hasError('required')">
@ -29,7 +29,7 @@
</div> </div>
</div> </div>
<!-- <mat-card-title><div>{{selectedMaterial.name | translate}}</div></mat-card-title> --> <!-- <mat-card-title><div>{{selectedMaterial.name | translate}}</div></mat-card-title> -->
<mat-card-content *ngIf="formGroup.get('type').value && formGroup.get('languageCode').value"> <mat-card-content *ngIf="formGroup.get('type').value>=0 && formGroup.get('languageCode').value">
<editor [init]="{ <editor [init]="{
base_url: '/tinymce', base_url: '/tinymce',
suffix: '.min', suffix: '.min',

View File

@ -33,12 +33,7 @@ import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog
import { LanguageV2Service } from '@app/core/services/language/language-v2.service'; import { LanguageV2Service } from '@app/core/services/language/language-v2.service';
import { nameof } from 'ts-simple-nameof'; import { nameof } from 'ts-simple-nameof';
import { Language } from '@app/core/model/language/language'; import { Language } from '@app/core/model/language/language';
import { LanguageLookup } from '@app/core/query/language.lookup';
interface VisibleLangType{
name: string;
type: string;
}
@Component({ @Component({
@ -52,6 +47,7 @@ export class SupportiveMaterialEditorComponent extends BaseEditor<SupportiveMate
isDeleted = false; isDeleted = false;
formGroup: UntypedFormGroup = null; formGroup: UntypedFormGroup = null;
showInactiveDetails = false; showInactiveDetails = false;
availableLanguageCodes: string[] = []
public supportiveMaterialTypeEnum = this.enumUtils.getEnumValues(SupportiveMaterialFieldType); public supportiveMaterialTypeEnum = this.enumUtils.getEnumValues(SupportiveMaterialFieldType);
@ -82,21 +78,14 @@ export class SupportiveMaterialEditorComponent extends BaseEditor<SupportiveMate
super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService); super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService);
} }
ngOnInit(): void {
visiblesLangTypes: VisibleLangType[] = [ super.ngOnInit();
{name: "GENERAL.LANGUAGES.ENGLISH", type: "en"}, this.languageV2Service.queryAvailableCodes(this.languageV2Service.buildAutocompleteLookup())
{name: "GENERAL.LANGUAGES.GREEK", type: "gr"}, .pipe(takeUntil(this._destroyed))
{name: "GENERAL.LANGUAGES.SPANISH", type: "es"}, .subscribe(
{name: "GENERAL.LANGUAGES.GERMAN", type: "de"}, data => this.availableLanguageCodes = data.items,
{name: "GENERAL.LANGUAGES.TURKISH", type: "tr"}, );
{name: "GENERAL.LANGUAGES.SLOVAK", type: "sk"}, }
{name: "GENERAL.LANGUAGES.SERBIAN", type: "sr"},
{name: "GENERAL.LANGUAGES.PORTUGUESE", type: "pt"},
{name: "GENERAL.LANGUAGES.CROATIAN", type: "hr"},
{name: "GENERAL.LANGUAGES.POLISH", type: "pl"}
]
getItem(itemId: Guid, successFunction: (item: SupportiveMaterial) => void) { getItem(itemId: Guid, successFunction: (item: SupportiveMaterial) => void) {
this.supportiveMaterialService.getSingle(itemId, SupportiveMaterialEditorResolver.lookupFields()) this.supportiveMaterialService.getSingle(itemId, SupportiveMaterialEditorResolver.lookupFields())