diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/LanguageController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/LanguageController.java index 11e46900c..440922b11 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/LanguageController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/LanguageController.java @@ -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> 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().status(ApiMessageCode.SUCCESS_MESSAGE).message("Updated").payload("Updated")); + } } diff --git a/dmp-frontend/src/app/app-routing.module.ts b/dmp-frontend/src/app/app-routing.module.ts index 9b56a04b2..5a03dbf02 100644 --- a/dmp-frontend/src/app/app-routing.module.ts +++ b/dmp-frontend/src/app/app-routing.module.ts @@ -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), diff --git a/dmp-frontend/src/app/core/services/language/language.service.ts b/dmp-frontend/src/app/core/services/language/language.service.ts index 3b1054f4d..4999d6f8a 100644 --- a/dmp-frontend/src/app/core/services/language/language.service.ts +++ b/dmp-frontend/src/app/core/services/language/language.service.ts @@ -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> { + return this.http.get(`${this.languageUrl}/${this.currentLanguage}`, { responseType: 'blob', observe: 'response' }); + } + + public updateLanguage(json: string): Observable { + return this.baseHttp.post(`${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; + } + } diff --git a/dmp-frontend/src/app/ui/navbar/navbar.component.html b/dmp-frontend/src/app/ui/navbar/navbar.component.html index 76412ed28..7d8bcc749 100644 --- a/dmp-frontend/src/app/ui/navbar/navbar.component.html +++ b/dmp-frontend/src/app/ui/navbar/navbar.component.html @@ -36,7 +36,7 @@ --> -
+
diff --git a/dmp-frontend/src/app/ui/navbar/navbar.component.ts b/dmp-frontend/src/app/ui/navbar/navbar.component.ts index 23849a7ce..862d7fe69 100644 --- a/dmp-frontend/src/app/ui/navbar/navbar.component.ts +++ b/dmp-frontend/src/app/ui/navbar/navbar.component.ts @@ -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]; diff --git a/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts b/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts index f456542fe..1ddc24a89 100644 --- a/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts +++ b/dmp-frontend/src/app/ui/sidebar/sidebar.component.ts @@ -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'},