2023-01-27 23:05:55 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
2023-01-29 00:09:18 +00:00
|
|
|
import { LanguageData } from './language.model';
|
2023-01-27 23:05:55 +00:00
|
|
|
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
|
|
|
|
import { ConfigData } from './configdata';
|
|
|
|
|
2023-02-17 14:48:26 +00:00
|
|
|
var Buffer = require('buffer/').Buffer;
|
|
|
|
|
2023-01-27 23:05:55 +00:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
|
|
|
|
export class LanguageService {
|
2023-02-17 14:48:26 +00:00
|
|
|
//
|
|
|
|
// URL for test using REST API to local MariaDB database
|
2023-03-04 00:21:34 +00:00
|
|
|
// private baseURL = 'http://localhost:8080/zgointl';
|
2023-02-17 14:48:26 +00:00
|
|
|
//
|
|
|
|
// URL for test using REST API to local MongoDB database
|
|
|
|
// private baseURL = 'http://localhost:5000/zgointl';
|
|
|
|
//
|
|
|
|
// URL for access MongoDB database from remote server
|
2023-03-04 00:21:34 +00:00
|
|
|
private baseURL = ConfigData.Be_URL + 'api/getlang';
|
2023-05-12 14:02:45 +00:00
|
|
|
private loginURL = ConfigData.Be_URL + 'getloginlang';
|
|
|
|
private mainURL = ConfigData.Be_URL + 'getmainlang';
|
|
|
|
private scanURL = ConfigData.Be_URL + 'getscanlang';
|
2023-01-27 23:05:55 +00:00
|
|
|
|
2023-01-31 03:17:40 +00:00
|
|
|
public zgoLanguage: string = '';
|
2023-01-27 23:05:55 +00:00
|
|
|
|
2023-05-08 16:50:11 +00:00
|
|
|
private session: string|null = '';
|
|
|
|
|
2023-01-31 03:17:40 +00:00
|
|
|
constructor(private http:HttpClient) {
|
2023-05-08 16:50:11 +00:00
|
|
|
this.session = localStorage.getItem('s4z_token');
|
2023-01-27 23:05:55 +00:00
|
|
|
}
|
|
|
|
|
2023-01-31 03:17:40 +00:00
|
|
|
getViewElements ( viewName:string ) {
|
|
|
|
//
|
|
|
|
// Get default language from localStorage
|
|
|
|
//
|
2023-02-17 14:48:26 +00:00
|
|
|
const def_zgoLanguage = localStorage.getItem('zgo_language');
|
|
|
|
//
|
|
|
|
// Set authorizacion paramaters
|
|
|
|
//
|
|
|
|
const Auth = 'Basic ' + Buffer.from(ConfigData.UsrPwd).toString('base64');
|
|
|
|
const reqHeaders = new HttpHeaders().set('Authorization', Auth);
|
2023-01-31 03:17:40 +00:00
|
|
|
|
|
|
|
if ( def_zgoLanguage == null ) {
|
|
|
|
this.zgoLanguage = 'en-US';
|
|
|
|
localStorage.setItem('zgo_language',this.zgoLanguage);
|
|
|
|
} else {
|
|
|
|
this.zgoLanguage = def_zgoLanguage;
|
|
|
|
}
|
|
|
|
//
|
2023-02-17 14:48:26 +00:00
|
|
|
// Get component's text data from language database
|
2023-01-31 03:17:40 +00:00
|
|
|
//
|
2023-05-08 16:50:11 +00:00
|
|
|
const params = new HttpParams().append('session', this.session!);
|
2023-05-12 14:02:45 +00:00
|
|
|
if (viewName === 'login') {
|
|
|
|
return this.http.get<LanguageData>(this.loginURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params});
|
|
|
|
} else if (viewName === 'main') {
|
|
|
|
return this.http.get<LanguageData>(this.mainURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params});
|
|
|
|
} else if (viewName === 'scan') {
|
|
|
|
return this.http.get<LanguageData>(this.scanURL + '/?lang=' + this.zgoLanguage, {headers: reqHeaders, params: params});
|
|
|
|
} else {
|
|
|
|
return this.http.get<LanguageData>(this.baseURL +
|
|
|
|
'/?lang=' + this.zgoLanguage +
|
|
|
|
'&component=' + viewName
|
|
|
|
,{ headers : reqHeaders
|
2023-05-08 16:50:11 +00:00
|
|
|
, params: params
|
|
|
|
}
|
2023-05-12 14:02:45 +00:00
|
|
|
);
|
|
|
|
}
|
2023-01-27 23:05:55 +00:00
|
|
|
}
|
|
|
|
}
|