Skip to content

Commit

Permalink
Updated from generator v5.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Oct 30, 2018
1 parent c1ae597 commit f7e2d9e
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 75 deletions.
34 changes: 17 additions & 17 deletions package.json
Expand Up @@ -21,18 +21,18 @@
"generate": "ng generate"
},
"dependencies": {
"@angular/animations": "^6.1.7",
"@angular/common": "^6.1.7",
"@angular/compiler": "^6.1.7",
"@angular/core": "^6.1.7",
"@angular/forms": "^6.1.7",
"@angular/http": "^6.1.7",
"@angular/platform-browser": "^6.1.7",
"@angular/platform-browser-dynamic": "^6.1.7",
"@angular/router": "^6.1.7",
"@angular/animations": "^7.0.0",
"@angular/common": "^7.0.0",
"@angular/compiler": "^7.0.0",
"@angular/core": "^7.0.0",
"@angular/forms": "^7.0.0",
"@angular/http": "^7.0.0",
"@angular/platform-browser": "^7.0.0",
"@angular/platform-browser-dynamic": "^7.0.0",
"@angular/router": "^7.0.0",
"@ngx-translate/core": "^10.0.1",
"@angular/service-worker": "^6.1.7",
"@ng-bootstrap/ng-bootstrap": "^3.2.0",
"@angular/service-worker": "^7.0.0",
"@ng-bootstrap/ng-bootstrap": "^3.3.0",
"bootstrap": "^4.1.1",
"@fortawesome/fontawesome-free-webfonts": "^1.0.9",
"core-js": "^2.5.6",
Expand All @@ -41,10 +41,10 @@
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/cli": "~6.2.1",
"@angular/compiler-cli": "^6.1.7",
"@angular/language-service": "^6.1.7",
"@angular-devkit/build-angular": "~0.8.1",
"@angular/cli": "~7.0.2",
"@angular/compiler-cli": "^7.0.0",
"@angular/language-service": "^7.0.0",
"@angular-devkit/build-angular": "^0.10.2",
"@biesbjerg/ngx-translate-extract": "^2.3.4",
"@ngx-rocket/scripts": "^3.0.0",
"@types/jasmine": "^2.8.7",
Expand All @@ -70,13 +70,13 @@
"husky": "^0.14.3",
"protractor": "~5.4.0",
"puppeteer": "^1.4.0",
"stylelint": "~9.5.0",
"stylelint": "~9.6.0",
"stylelint-config-recommended-scss": "~3.2.0",
"stylelint-config-standard": "~18.2.0",
"stylelint-scss": "~3.3.0",
"ts-node": "~7.0.1",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
"typescript": "~3.1.3"
},
"prettier": {
"singleQuote": true,
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Expand Up @@ -23,7 +23,7 @@ import { AppRoutingModule } from './app-routing.module';
FormsModule,
HttpClientModule,
TranslateModule.forRoot(),
NgbModule.forRoot(),
NgbModule,
CoreModule,
SharedModule,
ShellModule,
Expand Down
26 changes: 22 additions & 4 deletions src/app/core/authentication/authentication.guard.spec.ts
@@ -1,5 +1,5 @@
import { TestBed, inject } from '@angular/core/testing';
import { Router } from '@angular/router';
import { Router, RouterStateSnapshot } from '@angular/router';

import { AuthenticationService } from './authentication.service';
import { MockAuthenticationService } from './authentication.service.mock';
Expand All @@ -9,11 +9,14 @@ describe('AuthenticationGuard', () => {
let authenticationGuard: AuthenticationGuard;
let authenticationService: MockAuthenticationService;
let mockRouter: any;
let mockSnapshot: RouterStateSnapshot;

beforeEach(() => {
mockRouter = {
navigate: jasmine.createSpy('navigate')
};
mockSnapshot = jasmine.createSpyObj<RouterStateSnapshot>('RouterStateSnapshot', ['toString']);

TestBed.configureTestingModule({
providers: [
AuthenticationGuard,
Expand All @@ -38,18 +41,33 @@ describe('AuthenticationGuard', () => {
});

it('should return true if user is authenticated', () => {
expect(authenticationGuard.canActivate()).toBe(true);
expect(authenticationGuard.canActivate(null, mockSnapshot)).toBe(true);
});

it('should return false and redirect to login if user is not authenticated', () => {
// Arrange
authenticationService.credentials = null;

// Act
const result = authenticationGuard.canActivate();
const result = authenticationGuard.canActivate(null, mockSnapshot);

// Assert
expect(mockRouter.navigate).toHaveBeenCalledWith(['/login'], {replaceUrl: true});
expect(mockRouter.navigate).toHaveBeenCalledWith(['/login'], {
queryParams: { redirect: undefined },
replaceUrl: true
});
expect(result).toBe(false);
});

it('should save url as queryParam if user is not authenticated', () => {
authenticationService.credentials = null;
mockRouter.url = '/about';
mockSnapshot.url = '/about';

authenticationGuard.canActivate(null, mockSnapshot);
expect(mockRouter.navigate).toHaveBeenCalledWith(['/login'], {
queryParams: { redirect: mockRouter.url },
replaceUrl: true
});
});
});
8 changes: 4 additions & 4 deletions src/app/core/authentication/authentication.guard.ts
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';

import { Logger } from '../logger.service';
import { AuthenticationService } from './authentication.service';
Expand All @@ -12,13 +12,13 @@ export class AuthenticationGuard implements CanActivate {
constructor(private router: Router,
private authenticationService: AuthenticationService) { }

canActivate(): boolean {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if (this.authenticationService.isAuthenticated()) {
return true;
}

log.debug('Not authenticated, redirecting...');
this.router.navigate(['/login'], { replaceUrl: true });
log.debug('Not authenticated, redirecting and adding redirect url...');
this.router.navigate(['/login'], { queryParams: { redirect: state.url }, replaceUrl: true });
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions src/app/core/authentication/authentication.service.ts
Expand Up @@ -33,8 +33,8 @@ export class AuthenticationService {

/**
* Authenticates the user.
* @param {LoginContext} context The login parameters.
* @return {Observable<Credentials>} The user credentials.
* @param context The login parameters.
* @return The user credentials.
*/
login(context: LoginContext): Observable<Credentials> {
// Replace by proper authentication call
Expand All @@ -48,7 +48,7 @@ export class AuthenticationService {

/**
* Logs out the user and clear credentials.
* @return {Observable<boolean>} True if the user was logged out successfully.
* @return True if the user was logged out successfully.
*/
logout(): Observable<boolean> {
// Customize credentials invalidation here
Expand All @@ -58,15 +58,15 @@ export class AuthenticationService {

/**
* Checks is the user is authenticated.
* @return {boolean} True if the user is authenticated.
* @return True if the user is authenticated.
*/
isAuthenticated(): boolean {
return !!this.credentials;
}

/**
* Gets the user credentials.
* @return {Credentials} The user credentials or null if the user is not authenticated.
* @return The user credentials or null if the user is not authenticated.
*/
get credentials(): Credentials | null {
return this._credentials;
Expand All @@ -76,8 +76,8 @@ export class AuthenticationService {
* Sets the user credentials.
* The credentials may be persisted across sessions by setting the `remember` parameter to true.
* Otherwise, the credentials are only persisted for the current session.
* @param {Credentials=} credentials The user credentials.
* @param {boolean=} remember True to remember credentials across sessions.
* @param credentials The user credentials.
* @param remember True to remember credentials across sessions.
*/
private setCredentials(credentials?: Credentials, remember?: boolean) {
this._credentials = credentials || null;
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/http/cache.interceptor.ts
Expand Up @@ -17,8 +17,8 @@ export class CacheInterceptor implements HttpInterceptor {

/**
* Configures interceptor options
* @param {{update: boolean}} options If update option is enabled, forces request to be made and updates cache entry.
* @return {CacheInterceptor} The configured instance.
* @param options If update option is enabled, forces request to be made and updates cache entry.
* @return The configured instance.
*/
configure(options?: { update?: boolean } | null): CacheInterceptor {
const instance = new CacheInterceptor(this.httpCacheService);
Expand Down
22 changes: 11 additions & 11 deletions src/app/core/http/http-cache.service.ts
Expand Up @@ -27,9 +27,9 @@ export class HttpCacheService {

/**
* Sets the cache data for the specified request.
* @param {!string} url The request URL.
* @param {ResponseOptions} data The received data.
* @param {Date=} lastUpdated The cache last update, current date is used if not specified.
* @param url The request URL.
* @param data The received data.
* @param lastUpdated The cache last update, current date is used if not specified.
*/
setCacheData(url: string, data: HttpResponse<any>, lastUpdated?: Date) {
this.cachedData[url] = {
Expand All @@ -42,8 +42,8 @@ export class HttpCacheService {

/**
* Gets the cached data for the specified request.
* @param {!string} url The request URL.
* @return {?ResponseOptions} The cached data or null if no cached data exists for this request.
* @param url The request URL.
* @return The cached data or null if no cached data exists for this request.
*/
getCacheData(url: string): HttpResponse<any> | null {
const cacheEntry = this.cachedData[url];
Expand All @@ -58,16 +58,16 @@ export class HttpCacheService {

/**
* Gets the cached entry for the specified request.
* @param {!string} url The request URL.
* @return {?HttpCacheEntry} The cache entry or null if no cache entry exists for this request.
* @param url The request URL.
* @return The cache entry or null if no cache entry exists for this request.
*/
getHttpCacheEntry(url: string): HttpCacheEntry | null {
return this.cachedData[url] || null;
}

/**
* Clears the cached entry (if exists) for the specified request.
* @param {!string} url The request URL.
* @param url The request URL.
*/
clearCache(url: string): void {
delete this.cachedData[url];
Expand All @@ -77,7 +77,7 @@ export class HttpCacheService {

/**
* Cleans cache entries older than the specified date.
* @param {date=} expirationDate The cache expiration date. If no date is specified, all cache is cleared.
* @param expirationDate The cache expiration date. If no date is specified, all cache is cleared.
*/
cleanCache(expirationDate?: Date) {
if (expirationDate) {
Expand All @@ -95,8 +95,8 @@ export class HttpCacheService {
/**
* Sets the cache persistence policy.
* Note that changing the cache persistence will also clear the cache from its previous storage.
* @param {'local'|'session'=} persistence How the cache should be persisted, it can be either local or session
* storage, or if no value is provided it will be only in-memory (default).
* @param persistence How the cache should be persisted, it can be either local or session storage, or if no value is
* provided it will be only in-memory (default).
*/
setPersistence(persistence?: 'local' | 'session') {
this.cleanCache();
Expand Down
8 changes: 4 additions & 4 deletions src/app/core/http/http.service.ts
Expand Up @@ -16,20 +16,20 @@ declare module '@angular/common/http/src/client' {

/**
* Enables caching for this request.
* @param {boolean} forceUpdate Forces request to be made and updates cache entry.
* @return {HttpClient} The new instance.
* @param forceUpdate Forces request to be made and updates cache entry.
* @return The new instance.
*/
cache(forceUpdate?: boolean): HttpClient;

/**
* Skips default error handler for this request.
* @return {HttpClient} The new instance.
* @return The new instance.
*/
skipErrorHandler(): HttpClient;

/**
* Do not use API prefix for this request.
* @return {HttpClient} The new instance.
* @return The new instance.
*/
disableApiPrefix(): HttpClient;

Expand Down
12 changes: 6 additions & 6 deletions src/app/core/i18n.service.ts
Expand Up @@ -12,8 +12,8 @@ const languageKey = 'language';
/**
* Pass-through function to mark a string for translation extraction.
* Running `npm translations:extract` will include the given string by using this.
* @param {string} s The string to extract for translation.
* @return {string} The same string.
* @param s The string to extract for translation.
* @return The same string.
*/
export function extract(s: string) {
return s;
Expand All @@ -34,8 +34,8 @@ export class I18nService {
/**
* Initializes i18n for the application.
* Loads language from local storage if present, or sets default language.
* @param {!string} defaultLanguage The default language to use.
* @param {Array.<String>} supportedLanguages The list of supported languages.
* @param defaultLanguage The default language to use.
* @param supportedLanguages The list of supported languages.
*/
init(defaultLanguage: string, supportedLanguages: string[]) {
this.defaultLanguage = defaultLanguage;
Expand All @@ -50,7 +50,7 @@ export class I18nService {
* Sets the current language.
* Note: The current language is saved to the local storage.
* If no parameter is specified, the language is loaded from local storage (if present).
* @param {string} language The IETF language code to set.
* @param language The IETF language code to set.
*/
set language(language: string) {
language = language || localStorage.getItem(languageKey) || this.translateService.getBrowserCultureLang();
Expand All @@ -74,7 +74,7 @@ export class I18nService {

/**
* Gets the current language.
* @return {string} The current language code.
* @return The current language code.
*/
get language(): string {
return this.translateService.currentLang;
Expand Down
2 changes: 1 addition & 1 deletion src/app/login/login.component.spec.ts
Expand Up @@ -14,7 +14,7 @@ describe('LoginComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
NgbModule.forRoot(),
NgbModule,
RouterTestingModule,
TranslateModule.forRoot(),
ReactiveFormsModule,
Expand Down
7 changes: 5 additions & 2 deletions src/app/login/login.component.ts
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { finalize } from 'rxjs/operators';

Expand All @@ -21,6 +21,7 @@ export class LoginComponent implements OnInit {
isLoading = false;

constructor(private router: Router,
private route: ActivatedRoute,
private formBuilder: FormBuilder,
private i18nService: I18nService,
private authenticationService: AuthenticationService) {
Expand All @@ -38,7 +39,9 @@ export class LoginComponent implements OnInit {
}))
.subscribe(credentials => {
log.debug(`${credentials.username} successfully logged in`);
this.router.navigate(['/'], { replaceUrl: true });
this.route.queryParams.subscribe(
params => this.router.navigate([ params.redirect || '/'], { replaceUrl: true })
);
}, error => {
log.debug(`Login error: ${error}`);
this.error = error;
Expand Down
2 changes: 1 addition & 1 deletion src/app/shell/header/header.component.spec.ts
Expand Up @@ -14,7 +14,7 @@ describe('HeaderComponent', () => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
NgbModule.forRoot(),
NgbModule,
TranslateModule.forRoot()
],
declarations: [HeaderComponent],
Expand Down
2 changes: 1 addition & 1 deletion src/app/shell/shell.component.spec.ts
Expand Up @@ -17,7 +17,7 @@ describe('ShellComponent', () => {
imports: [
RouterTestingModule,
TranslateModule.forRoot(),
NgbModule.forRoot(),
NgbModule,
CoreModule
],
providers: [
Expand Down

0 comments on commit f7e2d9e

Please sign in to comment.