Added a functional Language Editor
This commit is contained in:
parent
d119a723f3
commit
cb9509ee4f
|
@ -1,5 +1,8 @@
|
|||
package eu.eudat.controllers;
|
||||
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -8,9 +11,8 @@ import org.springframework.http.MediaType;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
|
@ -43,4 +45,14 @@ public class LanguageController {
|
|||
|
||||
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "update/{lang}", method = RequestMethod.POST)
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<String>> updateLang(@PathVariable String lang, @RequestBody String json) throws Exception {
|
||||
String fileName = this.environment.getProperty("language.path") + lang + ".json";
|
||||
OutputStream os = new FileOutputStream(fileName);
|
||||
os.write(json.getBytes());
|
||||
os.close();
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<String>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Updated").payload("Updated"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,6 +164,14 @@ const appRoutes: Routes = [
|
|||
title: 'GENERAL.TITLES.PROFILE'
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'language-editor',
|
||||
loadChildren: () => import('./ui/language-editor/language-editor.module').then(m => m.LanguageEditorModule),
|
||||
data: {
|
||||
breadcrumb: true,
|
||||
title: 'Language Editor'
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'login/admin',
|
||||
loadChildren: () => import('./ui/auth/admin-login/admin-login.module').then(m => m.AdminLoginModule),
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
import { environment } from 'environments/environment';
|
||||
import { Observable } from 'rxjs';
|
||||
import { HttpResponse, HttpClient } from '@angular/common/http';
|
||||
import { BaseHttpService } from '../http/base-http.service';
|
||||
import { Language } from '@app/models/language/Language';
|
||||
|
||||
const availableLanguages: any[] = require('../../../../assets/resources/language.json');
|
||||
|
||||
@Injectable()
|
||||
export class LanguageService {
|
||||
private currentLanguage: string = 'en';
|
||||
private languageUrl = `${environment.Server}language`;
|
||||
|
||||
constructor(
|
||||
private translate: TranslateService
|
||||
private translate: TranslateService,
|
||||
private http: HttpClient,
|
||||
private baseHttp: BaseHttpService
|
||||
) {}
|
||||
|
||||
public changeLanguage(lang: string) {
|
||||
|
@ -19,4 +28,22 @@ export class LanguageService {
|
|||
return this.currentLanguage;
|
||||
}
|
||||
|
||||
public getCurrentLanguageJSON(): Observable<HttpResponse<Blob>> {
|
||||
return this.http.get(`${this.languageUrl}/${this.currentLanguage}`, { responseType: 'blob', observe: 'response' });
|
||||
}
|
||||
|
||||
public updateLanguage(json: string): Observable<String> {
|
||||
return this.baseHttp.post<string>(`${this.languageUrl}/update/${this.currentLanguage}`, json);
|
||||
}
|
||||
|
||||
public getCurrentLanguageName() {
|
||||
let result: string = '';
|
||||
availableLanguages.forEach(language => {
|
||||
if (language.value === this.currentLanguage) {
|
||||
result = this.translate.instant(language.label);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
</mat-menu>
|
||||
</div> -->
|
||||
|
||||
<div class="col-md-auto" *ngIf="!isAuthenticated()">
|
||||
<div class="col-md-auto" *ngIf="!(isAuthenticated() && onLanguageEditor())">
|
||||
<button mat-icon-button [matMenuTriggerFor]="languageMenu">
|
||||
<mat-icon>language</mat-icon>
|
||||
</button>
|
||||
|
|
|
@ -29,6 +29,7 @@ export class NavbarComponent extends BaseComponent implements OnInit {
|
|||
private sidebarVisible: boolean;
|
||||
languages = availableLanguages;
|
||||
language = this.languages[0];
|
||||
currentRoute: string;
|
||||
|
||||
|
||||
constructor(location: Location,
|
||||
|
@ -45,6 +46,7 @@ export class NavbarComponent extends BaseComponent implements OnInit {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.currentRoute = this.router.url;
|
||||
this.listTitles = GENERAL_ROUTES.filter(listTitle => listTitle);
|
||||
this.listTitles.push(DMP_ROUTES.filter(listTitle => listTitle));
|
||||
// this.listTitles.push(HISTORY_ROUTES.filter(listTitle => listTitle));
|
||||
|
@ -54,6 +56,7 @@ export class NavbarComponent extends BaseComponent implements OnInit {
|
|||
this.router.events.subscribe((event) => {
|
||||
this.sidebarClose();
|
||||
var $layer: any = document.getElementsByClassName('close-layer')[0];
|
||||
this.currentRoute = this.router.url;
|
||||
if ($layer) {
|
||||
$layer.remove();
|
||||
this.mobile_menu_visible = 0;
|
||||
|
@ -69,6 +72,10 @@ export class NavbarComponent extends BaseComponent implements OnInit {
|
|||
return !(!this.authentication.current());
|
||||
}
|
||||
|
||||
public onLanguageEditor(): boolean {
|
||||
return this.currentRoute === '/language-editor';
|
||||
}
|
||||
|
||||
sidebarOpen() {
|
||||
const toggleButton = this.toggleButton;
|
||||
const body = document.getElementsByTagName('body')[0];
|
||||
|
|
|
@ -50,7 +50,8 @@ export const PUBLIC_ROUTES: RouteInfo[] = [
|
|||
export const ADMIN_ROUTES: RouteInfo[] = [
|
||||
{ path: '/dmp-profiles', title: 'SIDE-BAR.DMP-TEMPLATES', icon: 'library_books' },
|
||||
{ path: '/dataset-profiles', title: 'SIDE-BAR.DATASET-TEMPLATES', icon: 'library_books' },
|
||||
{ path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' }
|
||||
{ path: '/users', title: 'SIDE-BAR.USERS', icon: 'people' },
|
||||
{ path: '/language-editor', title: 'Language Editor', icon: 'language'}
|
||||
];
|
||||
// export const HISTORY_ROUTES: RouteInfo[] = [
|
||||
// { path: '/typography', title: 'SIDE-BAR.HISTORY-VISITED', icon: 'visibility'},
|
||||
|
|
Loading…
Reference in New Issue