add query available language endpoint
This commit is contained in:
parent
5b5f547b27
commit
3dd7a42224
|
@ -31,14 +31,14 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path = {"api/v2/language"})
|
||||
|
@ -127,6 +127,21 @@ public class LanguageV2Controller {
|
|||
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")
|
||||
@Transactional
|
||||
public Language persist(@MyValidate @RequestBody LanguagePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException {
|
||||
|
|
|
@ -44,6 +44,11 @@ export class LanguageV2Service {
|
|||
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> {
|
||||
const url = `${this.apiBase}/persist`;
|
||||
|
||||
|
@ -83,7 +88,7 @@ export class LanguageV2Service {
|
|||
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();
|
||||
lookup.page = { size: 100, offset: 0 };
|
||||
if (excludedIds && excludedIds.length > 0) { lookup.excludedIds = excludedIds; }
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<div class="col-4" *ngIf="isNew">
|
||||
<mat-form-field class="w-100">
|
||||
<mat-label>{{'LANGUAGE-EDITOR.FIELDS.CODE' | translate}}</mat-label>
|
||||
<input matInput type="text" name="code" [formControl]="formGroup.get('code')" required>
|
||||
|
@ -37,6 +37,18 @@
|
|||
{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||
</mat-form-field>
|
||||
</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">
|
||||
<mat-form-field class="w-100">
|
||||
<mat-label>{{'LANGUAGE-EDITOR.FIELDS.PAYLOAD' | translate}}</mat-label>
|
||||
|
|
|
@ -27,7 +27,6 @@ import { map, takeUntil } from 'rxjs/operators';
|
|||
import { LanguageEditorResolver } from './language-editor.resolver';
|
||||
import { LanguageEditorService } from './language-editor.service';
|
||||
import { LanguageEditorModel } from './language-editor.model';
|
||||
import { MatChipEditedEvent, MatChipInputEvent } from '@angular/material/chips';
|
||||
import { LanguageV2Service } from '@app/core/services/language/language-v2.service';
|
||||
|
||||
|
||||
|
@ -43,6 +42,7 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
|
|||
isDeleted = false;
|
||||
formGroup: UntypedFormGroup = null;
|
||||
showInactiveDetails = false;
|
||||
availableLanguageCodes: string[] = [];
|
||||
|
||||
protected get canDelete(): boolean {
|
||||
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteLanguage);
|
||||
|
@ -88,6 +88,11 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
|
|||
ngOnInit(): void {
|
||||
this.matomoService.trackPageView('Admin: Languages');
|
||||
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) {
|
||||
|
@ -192,4 +197,13 @@ export class LanguageEditorComponent extends BaseEditor<LanguageEditorModel, Lan
|
|||
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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
<mat-form-field>
|
||||
<mat-label>{{'SUPPORTIVE-MATERIAL-EDITOR.FIELDS.LANGUAGE' | translate}}</mat-label>
|
||||
<mat-select (selectionChange)="selectedLangChanged($event.value)" name= "languageCode" [formControl]="formGroup.get('languageCode')">
|
||||
<mat-option *ngFor="let vis of visiblesLangTypes" [value]="vis.type">
|
||||
{{vis.name | translate}}
|
||||
<mat-option *ngFor="let languageCode of availableLanguageCodes" [value]="languageCode">
|
||||
{{languageCode}}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="formGroup.get('languageCode').hasError('required')">
|
||||
|
@ -29,7 +29,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- <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]="{
|
||||
base_url: '/tinymce',
|
||||
suffix: '.min',
|
||||
|
|
|
@ -33,12 +33,7 @@ import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog
|
|||
import { LanguageV2Service } from '@app/core/services/language/language-v2.service';
|
||||
import { nameof } from 'ts-simple-nameof';
|
||||
import { Language } from '@app/core/model/language/language';
|
||||
|
||||
|
||||
interface VisibleLangType{
|
||||
name: string;
|
||||
type: string;
|
||||
}
|
||||
import { LanguageLookup } from '@app/core/query/language.lookup';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -52,6 +47,7 @@ export class SupportiveMaterialEditorComponent extends BaseEditor<SupportiveMate
|
|||
isDeleted = false;
|
||||
formGroup: UntypedFormGroup = null;
|
||||
showInactiveDetails = false;
|
||||
availableLanguageCodes: string[] = []
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
visiblesLangTypes: VisibleLangType[] = [
|
||||
{name: "GENERAL.LANGUAGES.ENGLISH", type: "en"},
|
||||
{name: "GENERAL.LANGUAGES.GREEK", type: "gr"},
|
||||
{name: "GENERAL.LANGUAGES.SPANISH", type: "es"},
|
||||
{name: "GENERAL.LANGUAGES.GERMAN", type: "de"},
|
||||
{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"}
|
||||
|
||||
]
|
||||
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
this.languageV2Service.queryAvailableCodes(this.languageV2Service.buildAutocompleteLookup())
|
||||
.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(
|
||||
data => this.availableLanguageCodes = data.items,
|
||||
);
|
||||
}
|
||||
|
||||
getItem(itemId: Guid, successFunction: (item: SupportiveMaterial) => void) {
|
||||
this.supportiveMaterialService.getSingle(itemId, SupportiveMaterialEditorResolver.lookupFields())
|
||||
|
|
Loading…
Reference in New Issue