create Supportive Material query public

This commit is contained in:
amentis 2023-11-06 15:25:04 +02:00
parent 9b9cf0de4d
commit 11bb1a3c8c
14 changed files with 106 additions and 80 deletions

View File

@ -38,7 +38,7 @@ public class SupportiveMaterialCensor extends BaseCensor {
if (fields == null || fields.isEmpty()) if (fields == null || fields.isEmpty())
return; return;
this.authService.authorizeForce(Permission.BrowseDmpBlueprint); this.authService.authorizeForce(Permission.BrowseSupportiveMaterial);
} }
} }

View File

@ -6,6 +6,7 @@ import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.enums.ReferenceSourceType; import eu.eudat.commons.enums.ReferenceSourceType;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.ReferenceEntity; import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.Reference;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.data.query.QueryBase;
@ -213,18 +214,18 @@ public class ReferenceQuery extends QueryBase<ReferenceEntity> {
@Override @Override
protected String fieldNameOf(FieldResolver item) { protected String fieldNameOf(FieldResolver item) {
if (item.match(ReferenceEntity._id)) return ReferenceEntity._id; if (item.match(ReferenceEntity._id)) return ReferenceEntity._id;
else if (item.match(ReferenceEntity._label)) return ReferenceEntity._label; else if (item.match(Reference._label)) return ReferenceEntity._label;
else if (item.match(ReferenceEntity._description)) return ReferenceEntity._description; else if (item.match(Reference._description)) return ReferenceEntity._description;
else if (item.match(ReferenceEntity._createdAt)) return ReferenceEntity._createdAt; else if (item.match(Reference._createdAt)) return ReferenceEntity._createdAt;
else if (item.match(ReferenceEntity._updatedAt)) return ReferenceEntity._updatedAt; else if (item.match(Reference._updatedAt)) return ReferenceEntity._updatedAt;
else if (item.match(ReferenceEntity._isActive)) return ReferenceEntity._isActive; else if (item.match(Reference._isActive)) return ReferenceEntity._isActive;
else if (item.match(ReferenceEntity._definition)) return ReferenceEntity._definition; else if (item.match(Reference._definition)) return ReferenceEntity._definition;
else if (item.match(ReferenceEntity._abbreviation)) return ReferenceEntity._abbreviation; else if (item.match(Reference._abbreviation)) return ReferenceEntity._abbreviation;
else if (item.match(ReferenceEntity._reference)) return ReferenceEntity._reference; else if (item.match(Reference._reference)) return ReferenceEntity._reference;
else if (item.match(ReferenceEntity._source)) return ReferenceEntity._source; else if (item.match(Reference._source)) return ReferenceEntity._source;
else if (item.match(ReferenceEntity._sourceType)) return ReferenceEntity._sourceType; else if (item.match(Reference._sourceType)) return ReferenceEntity._sourceType;
else if (item.match(ReferenceEntity._type)) return ReferenceEntity._type; else if (item.match(Reference._type)) return ReferenceEntity._type;
//else if (item.prefix(ReferenceEntity._createdBy)) return ReferenceEntity._createdBy; //else if (item.prefix(Reference._createdBy)) return ReferenceEntity._createdBy;
else return null; else return null;
} }

View File

@ -210,6 +210,7 @@ public class SupportiveMaterialQuery extends QueryBase<SupportiveMaterialEntity>
if (item.match(SupportiveMaterial._id)) return SupportiveMaterialEntity._id; if (item.match(SupportiveMaterial._id)) return SupportiveMaterialEntity._id;
else if (item.match(SupportiveMaterial._type)) return SupportiveMaterialEntity._type; else if (item.match(SupportiveMaterial._type)) return SupportiveMaterialEntity._type;
else if (item.match(SupportiveMaterial._languageCode)) return SupportiveMaterialEntity._languageCode; else if (item.match(SupportiveMaterial._languageCode)) return SupportiveMaterialEntity._languageCode;
else if (item.match(SupportiveMaterial._payload)) return SupportiveMaterialEntity._payload;
else if (item.match(SupportiveMaterial._createdAt)) return SupportiveMaterialEntity._createdAt; else if (item.match(SupportiveMaterial._createdAt)) return SupportiveMaterialEntity._createdAt;
else if (item.match(SupportiveMaterial._updatedAt)) return SupportiveMaterialEntity._updatedAt; else if (item.match(SupportiveMaterial._updatedAt)) return SupportiveMaterialEntity._updatedAt;
else if (item.match(SupportiveMaterial._isActive)) return SupportiveMaterialEntity._isActive; else if (item.match(SupportiveMaterial._isActive)) return SupportiveMaterialEntity._isActive;

View File

@ -133,7 +133,7 @@ public class SupportiveMaterialServiceImpl implements SupportiveMaterialService{
} else { } else {
List<SupportiveMaterialEntity> datas = this.queryFactory.query(SupportiveMaterialQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).languageCodes(model.getLanguageCode()).types(model.getType()).collect(); List<SupportiveMaterialEntity> datas = this.queryFactory.query(SupportiveMaterialQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).languageCodes(model.getLanguageCode()).types(model.getType()).collect();
if(datas != null){ if(datas != null && !datas.isEmpty()){
throw new MyApplicationException("Could not create a new Data with same type and lang code !"); throw new MyApplicationException("Could not create a new Data with same type and lang code !");
} }

View File

@ -112,26 +112,23 @@ public class SupportiveMaterialController {
return model; return model;
} }
@GetMapping("get/{lang}") @PostMapping("public")
public ResponseEntity<byte[]> getMaterial(@PathVariable(name = "lang") String lang, int field) throws IOException { public ResponseEntity<byte[]> queryPublic(@RequestBody SupportiveMaterialLookup lookup) throws IOException {
if( !EnumUtils.isValidEnum(SupportiveMaterialFieldType.class, SupportiveMaterialFieldType.of((short) field).name())){ logger.debug("querying {}", SupportiveMaterial.class.getSimpleName());
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
this.censorFactory.censor(SupportiveMaterialCensor.class).censor(lookup.getProject(), null);
SupportiveMaterialQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
List<SupportiveMaterialEntity> datas = query.collectAs(lookup.getProject());
if (datas.size() == 1){
return new ResponseEntity<>(datas.get(0).getPayload().getBytes(), HttpStatus.OK);
} }
try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty(SupportiveMaterialFieldType.of((short) field).name().toLowerCase() +".path"))))) { try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty(lookup.getTypes().stream().toList().get(0).name().toLowerCase() +".path"))))) {
return this.supportiveMaterialService.getResponseEntity(lang, paths); return this.supportiveMaterialService.getResponseEntity(lookup.getLanguageCodes().get(0), paths);
} }
} }
// @PostMapping("persist")
// public @ResponseBody
// ResponseEntity<ResponseItem<String>> persist(@RequestBody SupportiveMaterialPersist model) throws IOException {
// this.authorizationService.authorizeForce(Permission.AdminRole);
//
// //String fileName = this.environment.getProperty(model.getName()+ ".path");
// this.supportiveMaterialService.persist(model);
// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Updated").payload("Updated"));
// }
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional

View File

@ -300,6 +300,28 @@ permissions:
allowAnonymous: false allowAnonymous: false
allowAuthenticated: false allowAuthenticated: false
# SupportiveMaterial Permissions
BrowseSupportiveMaterial:
roles:
- Admin
clients: [ ]
allowAnonymous: yes
allowAuthenticated: yes
EditSupportiveMaterial:
roles:
- Admin
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
DeleteSupportiveMaterial:
roles:
- Admin
claims: [ ]
clients: [ ]
allowAnonymous: false
allowAuthenticated: false
# DmpDescriptionTemplate Permissions # DmpDescriptionTemplate Permissions
BrowseDmpDescriptionTemplate: BrowseDmpDescriptionTemplate:
roles: roles:

View File

@ -1,17 +0,0 @@
<p>&nbsp;</p>
<p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
</p>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>&Sigma;&chi;&epsilon;&tau;&iota;&kappa;ά &mu;&epsilon; &tau;&omicron; Argos</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p>&Tau;&omicron; ARGOS &epsilon;ί&nu;&alpha;&iota; έ&nu;&alpha; &delta;&iota;&alpha;&delta;&iota;&kappa;&tau;&upsilon;&alpha;&kappa;ό &epsilon;&rho;&gamma;&alpha;&lambda;&epsilon;ί&omicron; &gamma;&iota;&alpha; &tau;&eta;&nu; &upsilon;&pi;&omicron;&sigma;&tau;ή&rho;&iota;&xi;&eta; &alpha;&upsilon;&tau;&omicron;&mu;&alpha;&tau;&omicron;&pi;&omicron;&iota;&eta;&mu;έ&nu;&omega;&nu; &delta;&iota;&alpha;&delta;&iota;&kappa;&alpha;&sigma;&iota;ώ&nu; &gamma;&iota;&alpha; &tau;&eta; &delta;&eta;&mu;&iota;&omicron;&upsilon;&rho;&gamma;ί&alpha;, &tau;&eta; &delta;&iota;&alpha;&chi;&epsilon;ί&rho;&iota;&sigma;&eta;, &tau;&eta;&nu; &kappa;&omicron;&iota;&nu;ή &chi;&rho;ή&sigma;&eta; &kappa;&alpha;&iota; &tau;&eta; &sigma;ύ&nu;&delta;&epsilon;&sigma;&eta; &tau;&omega;&nu; DMP &mu;&epsilon; &epsilon;&rho;&epsilon;&upsilon;&nu;&eta;&tau;&iota;&kappa;ά &alpha;&nu;&tau;&iota;&kappa;&epsilon;ί&mu;&epsilon;&nu;&alpha; &sigma;&tau;&alpha; &omicron;&pi;&omicron;ί&alpha; &alpha;&nu;&tau;&iota;&sigma;&tau;&omicron;&iota;&chi;&omicron;ύ&nu;. &Alpha;&pi;&omicron;&tau;&epsilon;&lambda;&epsilon;ί &kappa;&omicron;&iota;&nu;ή &pi;&rho;&omicron;&sigma;&pi;ά&theta;&epsilon;&iota;&alpha; &tau;&omicron;&upsilon; OpenAIRE &kappa;&alpha;&iota; &tau;&eta;&sigmaf; EUDAT &nu;&alpha; &pi;&alpha;&rho;&alpha;&delta;ώ&sigma;&omicron;&upsilon;&nu; &mu;&iota;&alpha; &alpha;&nu;&omicron;&iota;&chi;&tau;ή &pi;&lambda;&alpha;&tau;&phi;ό&rho;&mu;&alpha; &gamma;&iota;&alpha; &tau;&omicron;&nu; &Sigma;&chi;&epsilon;&delta;&iota;&alpha;&sigma;&mu;ό &Delta;&iota;&alpha;&chi;&epsilon;ί&rho;&iota;&sigma;&eta;&sigmaf; &Delta;&epsilon;&delta;&omicron;&mu;έ&nu;&omega;&nu; &pi;&omicron;&upsilon; &nu;&alpha; &alpha;&nu;&tau;&iota;&mu;&epsilon;&tau;&omega;&pi;ί&zeta;&epsilon;&iota; &tau;&iota;&sigmaf; &beta;έ&lambda;&tau;&iota;&sigma;&tau;&epsilon;&sigmaf; &pi;&rho;&alpha;&kappa;&tau;&iota;&kappa;έ&sigmaf; FAIR &kappa;&alpha;&iota; Open &kappa;&alpha;&iota; &nu;&alpha; &mu;&eta;&nu; &pi;&rho;&omicron;ϋ&pi;&omicron;&theta;έ&tau;&epsilon;&iota; &epsilon;&mu;&pi;ό&delta;&iota;&alpha; &gamma;&iota;&alpha; &tau;&eta; &chi;&rho;ή&sigma;&eta; &kappa;&alpha;&iota; &tau;&eta;&nu; &upsilon;&iota;&omicron;&theta;έ&tau;&eta;&sigma;ή &tau;&eta;&sigmaf;. &Tau;&omicron; &kappa;ά&nu;&epsilon;&iota; &epsilon;&phi;&alpha;&rho;&mu;ό&zeta;&omicron;&nu;&tau;&alpha;&sigmaf; &kappa;&omicron;&iota;&nu;ά &pi;&rho;ό&tau;&upsilon;&pi;&alpha; &gamma;&iota;&alpha; &mu;&eta;&chi;&alpha;&nu;&iota;&kappa;ά &epsilon;&nu;&epsilon;&rho;&gamma;ά DMPs, ό&pi;&omega;&sigmaf; &omicron;&rho;ί&zeta;&omicron;&nu;&tau;&alpha;&iota; &alpha;&pi;ό &tau;&eta;&nu; &pi;&alpha;&gamma;&kappa;ό&sigma;&mu;&iota;&alpha; &kappa;&omicron;&iota;&nu;ό&tau;&eta;&tau;&alpha; &epsilon;&rho;&epsilon;&upsilon;&nu;&eta;&tau;&iota;&kappa;ώ&nu; &delta;&epsilon;&delta;&omicron;&mu;έ&nu;&omega;&nu; &tau;&eta;&sigmaf; RDA &kappa;&alpha;&iota; &epsilon;&pi;&iota;&kappa;&omicron;&iota;&nu;&omega;&nu;ώ&nu;&tau;&alpha;&sigmaf; &kappa;&alpha;&iota; &delta;&iota;&alpha;&beta;&omicron;&upsilon;&lambda;&epsilon;ύ&omicron;&nu;&tau;&alpha;&sigmaf; &tau;&omicron;&upsilon;&sigmaf; &epsilon;&rho;&epsilon;&upsilon;&nu;&eta;&tau;έ&sigmaf;, &tau;&iota;&sigmaf; &epsilon;&rho;&epsilon;&upsilon;&nu;&eta;&tau;&iota;&kappa;έ&sigmaf; &kappa;&omicron;&iota;&nu;ό&tau;&eta;&tau;&epsilon;&sigmaf; &kappa;&alpha;&iota; &tau;&omicron;&upsilon;&sigmaf; &chi;&rho;&eta;&mu;&alpha;&tau;&omicron;&delta;ό&tau;&epsilon;&sigmaf; &gamma;&iota;&alpha; &nu;&alpha; &pi;&rho;&omicron;&beta;&lambda;&eta;&mu;&alpha;&tau;&iota;&sigma;&tau;&omicron;ύ&nu; &kappa;&alpha;&lambda;ύ&tau;&epsilon;&rho;&alpha; &gamma;&iota;&alpha; &tau;&iota;&sigmaf; &alpha;&nu;ά&gamma;&kappa;&epsilon;&sigmaf; &tau;&omicron;&upsilon;&sigmaf;.<br><br>&Tau;&omicron; ARGOS &pi;&alpha;&rho;έ&chi;&epsilon;&iota; έ&nu;&alpha; &epsilon;&upsilon;έ&lambda;&iota;&kappa;&tau;&omicron; &pi;&epsilon;&rho;&iota;&beta;ά&lambda;&lambda;&omicron;&nu; &kappa;&alpha;&iota; &mu;&iota;&alpha; &epsilon;ύ&kappa;&omicron;&lambda;&eta; &delta;&iota;&epsilon;&pi;&alpha;&phi;ή &gamma;&iota;&alpha; &tau;&eta;&nu; &pi;&lambda;&omicron;ή&gamma;&eta;&sigma;&eta; &kappa;&alpha;&iota; &chi;&rho;ή&sigma;&eta; &tau;&omega;&nu; &chi;&rho;&eta;&sigma;&tau;ώ&nu;.</p>
</div>
</div>
</div>

View File

@ -10,6 +10,7 @@ import { catchError } from "rxjs/operators";
import { Guid } from "@common/types/guid"; import { Guid } from "@common/types/guid";
import { nameof } from "ts-simple-nameof"; import { nameof } from "ts-simple-nameof";
import { IsActive } from "@app/core/common/enum/is-active.enum"; import { IsActive } from "@app/core/common/enum/is-active.enum";
import { SupportiveMaterialFieldType } from "@app/core/common/enum/supportive-material-field-type";
@Injectable() @Injectable()
export class SupportiveMaterialService{ export class SupportiveMaterialService{
@ -22,14 +23,10 @@ export class SupportiveMaterialService{
private get apiBase(): string { return `${this.configurationService.server}supportive-material`; } private get apiBase(): string { return `${this.configurationService.server}supportive-material`; }
public getMaterial(lang: string, field: number): Observable<HttpResponse<Blob>> { queryPublic(q: SupportiveMaterialLookup): Observable<HttpResponse<Blob>> {
return this.http.get(`${this.apiBase}/get/${lang}`, {params: {field}, responseType: 'blob', observe: 'response' }); return this.http.post<HttpResponse<Blob>>(`${this.apiBase}/public`, q , {responseType: 'blob', observe: 'response' });
} }
// public persist(item :SupportiveMaterialPersist): Observable<String> {
// return this.http.post<string>(`${this.apiBase}/persist`, item);
// }
query(q: SupportiveMaterialLookup): Observable<QueryResult<SupportiveMaterial>> { query(q: SupportiveMaterialLookup): Observable<QueryResult<SupportiveMaterial>> {
const url = `${this.apiBase}/query`; const url = `${this.apiBase}/query`;
return this.http.post<QueryResult<SupportiveMaterial>>(url, q).pipe(catchError((error: any) => throwError(error))); return this.http.post<QueryResult<SupportiveMaterial>>(url, q).pipe(catchError((error: any) => throwError(error)));
@ -63,7 +60,7 @@ export class SupportiveMaterialService{
// LOOKUP // LOOKUP
public static DefaultSupportiveMaterialLookup(params?: {}): SupportiveMaterialLookup{ public static DefaultSupportiveMaterialLookup(): SupportiveMaterialLookup{
const lookup = new SupportiveMaterialLookup(); const lookup = new SupportiveMaterialLookup();
lookup.project = { lookup.project = {

View File

@ -33,7 +33,11 @@ export class AboutComponent extends BaseComponent implements OnInit {
this.translate.onLangChange.subscribe((event: LangChangeEvent) => { this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/about'])); this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/about']));
}); });
this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.About) const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup();
lookup.languageCodes = [this.languageService.getCurrentLanguage()];
lookup.types = [SupportiveMaterialFieldType.About];
this.supportiveMaterialService.queryPublic(lookup)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(response => { .subscribe(response => {
const blob = new Blob([response.body], { type: 'text/html' }); const blob = new Blob([response.body], { type: 'text/html' });

View File

@ -28,7 +28,11 @@ export class FaqContentComponent extends BaseComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.matomoService.trackPageView('FAQ'); this.matomoService.trackPageView('FAQ');
this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.Faq) const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup();
lookup.languageCodes = [this.languageService.getCurrentLanguage()];
lookup.types = [SupportiveMaterialFieldType.Faq];
this.supportiveMaterialService.queryPublic(lookup)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(response => { .subscribe(response => {
const blob = new Blob([response.body], { type: 'text/html' }); const blob = new Blob([response.body], { type: 'text/html' });

View File

@ -36,7 +36,11 @@ export class GlossaryContentComponent extends BaseComponent implements OnInit {
this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/glossary'])); this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/glossary']));
}); });
this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.Glossary) const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup();
lookup.languageCodes = [this.languageService.getCurrentLanguage()];
lookup.types = [SupportiveMaterialFieldType.Glossary];
this.supportiveMaterialService.queryPublic(lookup)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(response => { .subscribe(response => {
const blob = new Blob([response.body], { type: 'text/html' }); const blob = new Blob([response.body], { type: 'text/html' });

View File

@ -33,7 +33,11 @@ export class TermsComponent extends BaseComponent implements OnInit {
this.translate.onLangChange.subscribe((event: LangChangeEvent) => { this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/terms-and-conditions'])); this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/terms-and-conditions']));
}); });
this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.TermsOfService) const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup();
lookup.languageCodes = [this.languageService.getCurrentLanguage()];
lookup.types = [SupportiveMaterialFieldType.TermsOfService];
this.supportiveMaterialService.queryPublic(lookup)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(response => { .subscribe(response => {
const blob = new Blob([response.body], { type: 'text/html' }); const blob = new Blob([response.body], { type: 'text/html' });

View File

@ -15,6 +15,7 @@ import { HttpClient } from '@angular/common/http';
import { SupportiveMaterialService } from '@app/core/services/supportive-material/supportive-material.service'; import { SupportiveMaterialService } from '@app/core/services/supportive-material/supportive-material.service';
import { SupportiveMaterialFieldType } from '@app/core/common/enum/supportive-material-field-type'; import { SupportiveMaterialFieldType } from '@app/core/common/enum/supportive-material-field-type';
import { SupportiveMaterialPersist } from '@app/core/model/supportive-material/supportive-material'; import { SupportiveMaterialPersist } from '@app/core/model/supportive-material/supportive-material';
import { Guid } from '@common/types/guid';
interface VisibleMaterialType{ interface VisibleMaterialType{
name: string; name: string;
@ -71,6 +72,7 @@ export class SupportiveMaterialEditorComponent extends BaseComponent implements
selectedMaterial: VisibleMaterialType; selectedMaterial: VisibleMaterialType;
selectedLang: VisibleLangType; selectedLang: VisibleLangType;
materialId: Guid = null;
ngOnInit() { ngOnInit() {
this.selectedMaterial = this.visiblesMaterialsTypes.find(x => x.type == SupportiveMaterialFieldType.Faq); this.selectedMaterial = this.visiblesMaterialsTypes.find(x => x.type == SupportiveMaterialFieldType.Faq);
@ -96,12 +98,21 @@ export class SupportiveMaterialEditorComponent extends BaseComponent implements
name: [''], name: [''],
html: [''] html: ['']
}); });
this.supportiveMaterialService.getMaterial(this.selectedLang.type, this.selectedMaterial.type).pipe(takeUntil(this._destroyed)).subscribe(data => { // this.supportiveMaterialService.getPublic(this.selectedLang.type, this.selectedMaterial.type).pipe(takeUntil(this._destroyed)).subscribe(data => {
const contentDispositionHeader = data.headers.get('Content-Disposition'); // const contentDispositionHeader = data.headers.get('Content-Disposition');
const filename = contentDispositionHeader.split(';')[1].trim().split('=')[1].replace(/"/g, ''); // const filename = contentDispositionHeader.split(';')[1].trim().split('=')[1].replace(/"/g, '');
this.formGroup.get('name').patchValue(filename); // this.formGroup.get('name').patchValue(filename);
this.loadFile(data.body); // this.loadFile(data.body);
// });
const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup();
lookup.types = [this.selectedMaterial.type];
lookup.languageCodes = [this.selectedLang.type];
this.supportiveMaterialService.query(lookup).pipe(takeUntil(this._destroyed)).subscribe(data => {
if(data.count == 1){
this.materialId = data.items[0].id;
this.formGroup.get('html').patchValue(data.items[0].payload);
}
}); });
} }
@ -118,30 +129,24 @@ export class SupportiveMaterialEditorComponent extends BaseComponent implements
return source; return source;
} }
loadFile(data: Blob) { // loadFile(data: Blob) {
const reader = new FileReader(); // const reader = new FileReader();
reader.addEventListener('load', () => { // reader.addEventListener('load', () => {
let result = this.parseText(reader.result as string); // let result = this.parseText(reader.result as string);
//result = result.replace(/class="href" path="/g, 'href="#'); // //result = result.replace(/class="href" path="/g, 'href="#');
this.formGroup.get('html').patchValue(result); // this.formGroup.get('html').patchValue(result);
}, false); // }, false);
reader.readAsText(data); // reader.readAsText(data);
} // }
submit() { submit() {
let result = this.parseText(this.formGroup.get('html').value); let result = this.parseText(this.formGroup.get('html').value);
//result = result.replace(/href="#/g, 'class="href" path="');
this.formGroup.get('html').patchValue(result); this.formGroup.get('html').patchValue(result);
//const item = {name: this.formGroup.value['name'], type: this.selectedMaterial.type ,html: this.formGroup.value['html']} as SupportiveMaterialPersist const item = {id: this.materialId,
const item = {id: null,
type: this.selectedMaterial.type, type: this.selectedMaterial.type,
languageCode: this.selectedLang.type, languageCode: this.selectedLang.type,
payload: this.formGroup.value['html']} as SupportiveMaterialPersist; payload: this.formGroup.value['html']} as SupportiveMaterialPersist;
// if(item.name.endsWith("_en.html") && this.selectedLang.type != "en" ){
// item.name = item.name.replace("_en.html", `_${this.selectedLang.type}.html`);
// }
this.supportiveMaterialService.persist(item).pipe(takeUntil(this._destroyed)) this.supportiveMaterialService.persist(item).pipe(takeUntil(this._destroyed))
.subscribe( .subscribe(
complete => { complete => {

View File

@ -51,7 +51,11 @@ export class UserGuideContentComponent extends BaseComponent implements OnInit {
this.translate.onLangChange.subscribe((event: LangChangeEvent) => { this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/user-guide'])); this.router.navigate(['/reload'], { skipLocationChange: true }).then(() => this.router.navigate(['/user-guide']));
}); });
this.supportiveMaterialService.getMaterial(this.languageService.getCurrentLanguage(), SupportiveMaterialFieldType.UserGuide) const lookup = SupportiveMaterialService.DefaultSupportiveMaterialLookup();
lookup.languageCodes = [this.languageService.getCurrentLanguage()];
lookup.types = [SupportiveMaterialFieldType.UserGuide];
this.supportiveMaterialService.queryPublic(lookup)
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(response => { .subscribe(response => {
const blob = new Blob([response.body], { type: 'text/html' }); const blob = new Blob([response.body], { type: 'text/html' });