Make user guide multilingual

This commit is contained in:
George Kalampokis 2020-12-10 11:34:01 +02:00
parent 3b00b76f19
commit ca38f0b0a4
10 changed files with 12867 additions and 10 deletions

View File

@ -1,6 +1,8 @@
package eu.eudat.controllers;
import eu.eudat.logic.security.claims.ClaimedAuthorities;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.models.data.userguide.UserGuide;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
@ -19,6 +21,8 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static eu.eudat.types.Authorities.ADMIN;
@RestController
@CrossOrigin
@RequestMapping(value = {"/api/userguide/"})
@ -31,13 +35,16 @@ public class UserGuideController {
this.environment = environment;
}
@RequestMapping(path = "current", method = RequestMethod.GET )
public ResponseEntity getUserGuide() throws IOException {
@RequestMapping(path = "{lang}", method = RequestMethod.GET )
public ResponseEntity getUserGuide(@PathVariable(name = "lang") String lang) throws IOException {
Stream<Path> walk = Files.walk(Paths.get(this.environment.getProperty("userguide.path")));
List<String> result = walk.filter(Files::isRegularFile)
.map(Path::toString).collect(Collectors.toList());
String fileName = result.get(0);
String fileName = result.stream().filter(guide -> guide.contains("_" + lang)).findFirst().orElse(null);
if (fileName == null) {
fileName = result.stream().filter(guide -> guide.contains("_en")).findFirst().get();
}
InputStream is = new FileInputStream(fileName);
String[] filepath = fileName.split("\\.")[0].split("\\\\");
@ -60,7 +67,7 @@ public class UserGuideController {
@RequestMapping(value = "current", method = RequestMethod.POST)
public @ResponseBody
ResponseEntity<ResponseItem<String>> updateGuide(@RequestBody UserGuide guide) throws Exception {
ResponseEntity<ResponseItem<String>> updateGuide(@RequestBody UserGuide guide, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception {
String fileName = this.environment.getProperty("userguide.path") + guide.getName() + ".html";
OutputStream os = new FileOutputStream(fileName);
os.write(guide.getHtml().getBytes());

View File

@ -19,8 +19,8 @@ export class UserGuideService {
this.userGuideUrl = `${configurationService.server}userguide`;
}
public getUserGuide(): Observable<HttpResponse<Blob>> {
return this.http.get(`${this.userGuideUrl}/current`, { responseType: 'blob', observe: 'response', headers: {'Content-type': 'text/html',
public getUserGuide(lang: string): Observable<HttpResponse<Blob>> {
return this.http.get(`${this.userGuideUrl}/${lang}`, { responseType: 'blob', observe: 'response', headers: {'Content-type': 'text/html',
'Accept': 'text/html',
'Access-Control-Allow-Origin': this.configurationService.app,
'Access-Control-Allow-Credentials': 'true'} });

View File

@ -9,6 +9,8 @@ import { Router } from '@angular/router';
import { isNullOrUndefined } from 'util';
import { environment } from 'environments/environment';
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
import { AuthService } from '@app/core/services/auth/auth.service';
import { LanguageService } from '@app/core/services/language/language.service';
@Component({
selector: 'app-user-guide-editor',
@ -23,7 +25,8 @@ export class UserGuideEditorComponent extends BaseComponent implements OnInit {
private uiNotificationService: UiNotificationService,
private translate: TranslateService,
private router: Router,
private configurationService: ConfigurationService
private configurationService: ConfigurationService,
private languageService: LanguageService
) { super(); }
ngOnInit() {
@ -32,7 +35,7 @@ export class UserGuideEditorComponent extends BaseComponent implements OnInit {
name: [''],
html: ['']
});
this.userGuideService.getUserGuide().pipe(takeUntil(this._destroyed)).subscribe(data => {
this.userGuideService.getUserGuide(this.languageService.getCurrentLanguage()).pipe(takeUntil(this._destroyed)).subscribe(data => {
const contentDispositionHeader = data.headers.get('Content-Disposition');
const filename = contentDispositionHeader.split(';')[1].trim().split('=')[1].replace(/"/g, '');

View File

@ -3,6 +3,7 @@ import { UserGuideService } from '@app/core/services/user-guide/user-guide.servi
import { BaseComponent } from '@common/base/base.component';
import { takeUntil } from 'rxjs/internal/operators/takeUntil';
import { DomSanitizer } from '@angular/platform-browser';
import { LanguageService } from '@app/core/services/language/language.service';
@Component({
selector: 'app-user-guide-content',
@ -17,12 +18,13 @@ export class UserGuideContentComponent extends BaseComponent implements OnInit,
constructor(
private userGuideService: UserGuideService,
private sanitizer: DomSanitizer
private sanitizer: DomSanitizer,
private languageService: LanguageService
) { super(); }
ngOnInit() {
this.scrollEvent = ((ev) => this.scroll(ev));
this.userGuideService.getUserGuide()
this.userGuideService.getUserGuide(this.languageService.getCurrentLanguage())
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
const blob = new Blob([response.body], { type: 'text/html' });

2569
user-guide/UserGuide_en.html Normal file

File diff suppressed because it is too large Load Diff

2569
user-guide/UserGuide_es.html Normal file

File diff suppressed because it is too large Load Diff

2569
user-guide/UserGuide_gr.html Normal file

File diff suppressed because it is too large Load Diff

2569
user-guide/UserGuide_sk.html Normal file

File diff suppressed because it is too large Load Diff

2569
user-guide/UserGuide_tr.html Normal file

File diff suppressed because it is too large Load Diff