Commit 6b3f3fea authored by Diego Rey's avatar Diego Rey
Browse files

Update i18n in login with routes and add 404 page

parent 2d1d3b99
...@@ -5,13 +5,15 @@ import { AuthGuard } from './shared/guards/auth.guard'; ...@@ -5,13 +5,15 @@ import { AuthGuard } from './shared/guards/auth.guard';
const routes: Routes = [ const routes: Routes = [
{ path: '', loadChildren: './layout/layout.module#LayoutModule', canActivate: [AuthGuard] }, { path: '', loadChildren: './layout/layout.module#LayoutModule', canActivate: [AuthGuard] },
{ path: 'login', loadChildren: './login/login.module#LoginModule' }, { path: 'login', loadChildren: './login/login.module#LoginModule', data: { language: navigator.language && (navigator.language.split('-')[0] == 'es' || navigator.language.split('-')[0] == 'en') ? navigator.language.split('-')[0] : 'es' }},
{ path: 'es/login', loadChildren: './login/login.module#LoginModule', data: { language: 'es' }},
{ path: 'en/login', loadChildren: './login/login.module#LoginModule', data: { language: 'en' }},
{ path: 'not-found', loadChildren: './not-found/not-found.module#NotFoundModule' }, { path: 'not-found', loadChildren: './not-found/not-found.module#NotFoundModule' },
{ path: '**', redirectTo: 'not-found' } { path: '**', redirectTo: 'not-found' }
]; ];
@NgModule({ @NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })], imports: [RouterModule.forRoot(routes)],
exports: [RouterModule] exports: [RouterModule]
}) })
export class AppRoutingModule { } export class AppRoutingModule { }
...@@ -11,10 +11,14 @@ import { TranslateService } from '@ngx-translate/core'; ...@@ -11,10 +11,14 @@ import { TranslateService } from '@ngx-translate/core';
providers: [GHCIService] providers: [GHCIService]
}) })
export class LayoutComponent implements OnInit { export class LayoutComponent implements OnInit {
constructor(public router: Router, public translate: TranslateService) { } translateService: any;
constructor(public router: Router, public translate: TranslateService) {
this.translateService = translate;
}
ngOnInit() { ngOnInit() {
if (this.router.url === '/') { if (this.router.url === '/') {
this.router.navigate(['/login']); this.router.navigate(['/'+this.translateService.get('i18n.code').value+'/login']);
} }
} }
} }
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
class="form-control input-underline input-lg" class="form-control input-underline input-lg"
placeholder='{{ "i18n.object.password" | translate | titleCase }}'> placeholder='{{ "i18n.object.password" | translate | titleCase }}'>
</div> </div>
<div class="form-group" style="margin-bottom: 0px; text-align: left;"> <!-- <div class="form-group" style="margin-bottom: 0px; text-align: left;">
<div ngbDropdown class="d-inline-block language-switcher"> <div ngbDropdown class="d-inline-block language-switcher">
<button class="btn btn-outline-secondary" id="input-lang" ngbDropdownToggle> <button class="btn btn-outline-secondary" id="input-lang" ngbDropdownToggle>
<span class="flag-icon flag-icon-{{model.language.flagCode}}"></span> <span class="flag-icon flag-icon-{{model.language.flagCode}}"></span>
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div> -->
</div> </div>
<a class="btn rounded-btn" style="background: transparent;color: white;cursor: pointer;width: 159px;margin-right: 3px;" (click)=login()> {{ "i18n.action.login" | translate | titleCase }} </a> <a class="btn rounded-btn" style="background: transparent;color: white;cursor: pointer;width: 159px;margin-right: 3px;" (click)=login()> {{ "i18n.action.login" | translate | titleCase }} </a>
......
...@@ -33,15 +33,21 @@ export class LoginComponent implements OnInit { ...@@ -33,15 +33,21 @@ export class LoginComponent implements OnInit {
private router: Router, private router: Router,
private sessionService: SessionService, private sessionService: SessionService,
private authenticationService: AuthenticationService, private authenticationService: AuthenticationService,
public translate: TranslateService public translate: TranslateService,
) { } ) { }
ngOnInit() { ngOnInit() {
let currentSession = sessionStorage.getItem("currentUser"); console.log('this.route', this.route.snapshot.data['language']);
let langCode = currentSession ? JSON.parse(currentSession).language : 'es'; console.log('return', this.route.snapshot.queryParams['returnUrl']);
if (langCode) {
this.model.language = this.getLanguageElementByCode(langCode); // let currentSession = sessionStorage.getItem("currentUser");
} // let langCode = currentSession ? JSON.parse(currentSession).language : 'es';
// if (langCode) {
// this.model.language = this.getLanguageElementByCode(langCode);
// }
this.model.language = this.getLanguageElementByCode(this.route.snapshot.data['language']);
this.translate.use(this.model.language.code);
// reset login status // reset login status
this.authenticationService.logout(); this.authenticationService.logout();
......
...@@ -7,7 +7,9 @@ const routes: Routes = [ ...@@ -7,7 +7,9 @@ const routes: Routes = [
]; ];
@NgModule({ @NgModule({
imports: [RouterModule.forChild(routes)], imports: [
RouterModule.forChild(routes)
],
exports: [RouterModule] exports: [RouterModule]
}) })
export class NotFoundRoutingModule { export class NotFoundRoutingModule {
......
<div class="welcome-page"> <div class="welcome-page">
<div class="row"> <div class="row">
<div class="col-md-10 push-md-1"> <div class="col-md-10 push-md-1">
<h1>404 - Page Not Found</h1> <h1>404 - {{ "i18n.msg.404.title" | translate }}</h1>
<p class="lead">This page does not exist</p> <p class="lead">{{ "i18n.msg.404.descrp" | translate }}</p>
<p class="lead"> <p class="lead">
<a class="btn rounded-btn" [routerLink]="['/login']">Restart</a> <a class="btn rounded-btn" [routerLink]="[urlLogin]">
{{ "i18n.msg.404.return" | translate }}
</a>
</p> </p>
</div> </div>
</div> </div>
......
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
@Component({ @Component({
selector: 'app-not-found', selector: 'app-not-found',
templateUrl: './not-found.component.html', templateUrl: './not-found.component.html',
styleUrls: ['not-found.component.scss'] styleUrls: ['not-found.component.scss']
}) })
export class NotFoundComponent { } export class NotFoundComponent {
translateService: any;
urlLogin: string;
constructor(public translate: TranslateService) {
this.translateService = translate;
this.urlLogin = '/'+this.translateService.get('i18n.code').value+'/login';
}
}
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { I18nModule } from '../shared/modules/translate/i18n.module';
import { NotFoundComponent } from './not-found.component'; import { NotFoundComponent } from './not-found.component';
import { NotFoundRoutingModule } from './not-found-routing.module'; import { NotFoundRoutingModule } from './not-found-routing.module';
@NgModule({ @NgModule({
imports: [ imports: [
I18nModule,
NotFoundRoutingModule, NotFoundRoutingModule,
RouterModule RouterModule
], ],
......
...@@ -4,6 +4,7 @@ import { AuthenticationService } from '../../services/authentication.service'; ...@@ -4,6 +4,7 @@ import { AuthenticationService } from '../../services/authentication.service';
import { SessionService } from '../../services/session.service'; import { SessionService } from '../../services/session.service';
import { GHCIService } from '../../services/ghci.service'; import { GHCIService } from '../../services/ghci.service';
import { Usuario } from '../../objects/usuario'; import { Usuario } from '../../objects/usuario';
import { TranslateService } from '@ngx-translate/core';
@Component({ @Component({
selector: 'app-header', selector: 'app-header',
...@@ -12,11 +13,14 @@ import { Usuario } from '../../objects/usuario'; ...@@ -12,11 +13,14 @@ import { Usuario } from '../../objects/usuario';
}) })
export class HeaderComponent implements OnInit { export class HeaderComponent implements OnInit {
usuario: Usuario; usuario: Usuario;
translateService: any;
constructor( constructor(
private authService: AuthenticationService, private authService: AuthenticationService,
private router : Router, private router : Router,
private sessionService : SessionService, private sessionService : SessionService,
private ghciService : GHCIService) { private ghciService : GHCIService,
public translate: TranslateService) {
this.translateService = translate;
this.usuario = authService.getUser(); this.usuario = authService.getUser();
} }
ngOnInit() {} ngOnInit() {}
...@@ -34,6 +38,6 @@ export class HeaderComponent implements OnInit { ...@@ -34,6 +38,6 @@ export class HeaderComponent implements OnInit {
logout(){ logout(){
this.sessionService.reset(); this.sessionService.reset();
this.ghciService.desconectarWS(); this.ghciService.desconectarWS();
this.router.navigate(['/login']); this.router.navigate(['/'+this.translateService.get('i18n.code').value+'/login']);
} }
} }
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router'; import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { TranslateService } from '@ngx-translate/core';
@Injectable() @Injectable()
export class AuthGuard implements CanActivate { export class AuthGuard implements CanActivate {
translateService: any;
constructor(private router: Router){ constructor(private router: Router, public translate: TranslateService){
this.translateService = translate;
} }
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean { canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
...@@ -14,7 +16,7 @@ export class AuthGuard implements CanActivate { ...@@ -14,7 +16,7 @@ export class AuthGuard implements CanActivate {
if(sessionStorage.getItem('currentUser')){ if(sessionStorage.getItem('currentUser')){
return true; return true;
} }
this.router.navigate(['/login']); this.router.navigate(['/'+this.translateService.get('i18n.code').value+'/login']);
return false; return false;
} }
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ import { Observable, Subject } from 'rxjs/Rx'; ...@@ -4,7 +4,7 @@ import { Observable, Subject } from 'rxjs/Rx';
import { WebsocketService } from './websocket.service'; import { WebsocketService } from './websocket.service';
import { AuthenticationService } from './authentication.service'; import { AuthenticationService } from './authentication.service';
import { GHCI_URL } from '../config'; import { GHCI_URL } from '../config';
import { TranslateService } from '@ngx-translate/core';
declare var $:any; declare var $:any;
declare var that :any ; declare var that :any ;
...@@ -29,12 +29,14 @@ export class GHCIService { ...@@ -29,12 +29,14 @@ export class GHCIService {
private warningText :string = ""; private warningText :string = "";
private lastError : number = -1; private lastError : number = -1;
private lastWarning :number = -1; private lastWarning :number = -1;
translateService: any;
private console_error_class : string = "jqconsole-asd"; private console_error_class : string = "jqconsole-asd";
consoleBuffer = []; consoleBuffer = [];
constructor(private authService:AuthenticationService,private router: Router){ constructor(private authService:AuthenticationService,private router: Router, public translate: TranslateService){
this.translateService = translate;
console.log("contructor ghci"); console.log("contructor ghci");
this.conectarWS(GHCI_URL, authService.getUser().cedula, authService.getToken(), authService.getLanguage()); this.conectarWS(GHCI_URL, authService.getUser().cedula, authService.getToken(), authService.getLanguage());
setInterval( this.checkConnection.bind(this), 5000); setInterval( this.checkConnection.bind(this), 5000);
...@@ -89,7 +91,7 @@ export class GHCIService { ...@@ -89,7 +91,7 @@ export class GHCIService {
this.connection.onclose = function(reason){ this.connection.onclose = function(reason){
//Codigo que indica la falta de permisos (sesion expirada por ejemplo) //Codigo que indica la falta de permisos (sesion expirada por ejemplo)
if(reason.code == 1008){ if(reason.code == 1008){
this.router.navigate(['/login']); this.router.navigate(['/'+this.translateService.get('i18n.code').value+'/login']);
} }
console.log('Conexión con web socket cerrada',reason); console.log('Conexión con web socket cerrada',reason);
}.bind(this) }.bind(this)
......
...@@ -6,20 +6,26 @@ import { Archivo, Evaluacion } from '../objects/archivo'; ...@@ -6,20 +6,26 @@ import { Archivo, Evaluacion } from '../objects/archivo';
import { Grupo } from '../objects/grupo'; import { Grupo } from '../objects/grupo';
import { SERVER } from '../config'; import { SERVER } from '../config';
import { TranslateService } from '@ngx-translate/core';
import { AuthenticationService } from './authentication.service'; import { AuthenticationService } from './authentication.service';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/catch';
@Injectable() @Injectable()
export class HaskellService { export class HaskellService {
translateService: any;
/** /**
* Creates a new HaskellService with the injected Http. * Creates a new HaskellService with the injected Http.
* @param {Http} http - The injected Http. * @param {Http} http - The injected Http.
* @constructor * @constructor
*/ */
constructor(private http: Http, private router: Router, private authService: AuthenticationService) {} constructor(
private http: Http, private router: Router,
private authService: AuthenticationService,
public translate: TranslateService) {
this.translateService = translate;
}
getArchivos(cedula:string): Observable<Archivo[]> { getArchivos(cedula:string): Observable<Archivo[]> {
let headers = new Headers({ 'Content-Type': 'application/json', 'Authorization':'Bearer '+this.authService.getToken() }); let headers = new Headers({ 'Content-Type': 'application/json', 'Authorization':'Bearer '+this.authService.getToken() });
...@@ -111,7 +117,7 @@ export class HaskellService { ...@@ -111,7 +117,7 @@ export class HaskellService {
*/ */
private handleError (error: any) { private handleError (error: any) {
if(error.status == 401){ if(error.status == 401){
this.router.navigate(['/login']); this.router.navigate(['/'+this.translateService.get('i18n.code').value+'/login']);
} }
// In a real world app, we might use a remote logging infrastructure // In a real world app, we might use a remote logging infrastructure
// We'd also dig deeper into the error to get a better message // We'd also dig deeper into the error to get a better message
......
...@@ -3,7 +3,7 @@ import { Router } from '@angular/router'; ...@@ -3,7 +3,7 @@ import { Router } from '@angular/router';
import { Http, Headers, Response, RequestOptions } from '@angular/http'; import { Http, Headers, Response, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { Usuario, Configuracion } from '../objects/usuario'; import { Usuario, Configuracion } from '../objects/usuario';
import { TranslateService } from '@ngx-translate/core';
import { AuthenticationService } from './authentication.service'; import { AuthenticationService } from './authentication.service';
import 'rxjs/add/operator/map' import 'rxjs/add/operator/map'
import 'rxjs/add/operator/catch' import 'rxjs/add/operator/catch'
...@@ -12,7 +12,14 @@ import { SERVER } from '../config'; ...@@ -12,7 +12,14 @@ import { SERVER } from '../config';
@Injectable() @Injectable()
export class UsuarioService { export class UsuarioService {
constructor(private http: Http, private router: Router, private authService: AuthenticationService) {} translateService: any;
constructor(
private http: Http, private router: Router,
private authService: AuthenticationService,
public translate: TranslateService) {
this.translateService = translate;
}
actualizarConfiguracion(cedula: string, config: Configuracion) { actualizarConfiguracion(cedula: string, config: Configuracion) {
let headers = new Headers({ 'Content-Type': 'application/json', 'Authorization':'Bearer '+this.authService.getToken() }); let headers = new Headers({ 'Content-Type': 'application/json', 'Authorization':'Bearer '+this.authService.getToken() });
...@@ -29,7 +36,7 @@ export class UsuarioService { ...@@ -29,7 +36,7 @@ export class UsuarioService {
private handleError(error: any) { private handleError(error: any) {
if(error.status == 401){ if(error.status == 401){
this.router.navigate(['/login']); this.router.navigate(['/'+this.translateService.get('i18n.code').value+'/login']);
} }
let errMsg = (error.message) ? error.message : let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error'; error.status ? `${error.status} - ${error.statusText}` : 'Server error';
......
{ {
"i18n" : { "i18n" : {
"code" : "en",
"action" : { "action" : {
"login" : "login", "login" : "login",
"new" : "new", "new" : "new",
...@@ -68,6 +69,11 @@ ...@@ -68,6 +69,11 @@
} }
}, },
"msg" : { "msg" : {
"404" : {
"title": "Page Not Found",
"descrp": "Sorry, this page does not exist.",
"return": "Return"
},
"codemirror" : { "codemirror" : {
"fontSize" : "Font Size", "fontSize" : "Font Size",
"functionWarnings": "Show warnings of use of functions", "functionWarnings": "Show warnings of use of functions",
......
{ {
"i18n" : { "i18n" : {
"code" : "es",
"action" : { "action" : {
"login" : "iniciar sesión", "login" : "iniciar sesión",
"new" : "nuevo", "new" : "nuevo",
...@@ -68,6 +69,11 @@ ...@@ -68,6 +69,11 @@
} }
}, },
"msg" : { "msg" : {
"404" : {
"title": "Página no encontrada",
"descrp": "Lo sentimos, esta páina no existe.",
"return": "Volver"
},
"codemirror" : { "codemirror" : {
"fontSize" : "Tamaño de fuente", "fontSize" : "Tamaño de fuente",
"functionWarnings": "Mostrar advertencias de uso de funciones", "functionWarnings": "Mostrar advertencias de uso de funciones",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment