...
 
Commits (25)
stages:
- test
- analysis
- build
variables:
GIT_SUBMODULE_STRATEGY: normal
......@@ -9,26 +11,93 @@ variables:
image: skuld.netshadow.net:5000/lemi-frontend-tester:latest
job_test:
#
# Test Stage
#
job_lint:
stage: test
except:
- master
script:
- npm config get registry
- echo "$(date) Changing to directory ${CI_PROJECT_DIR}"
- cd $CI_PROJECT_DIR
- echo "$(date) Copying /build_cache/lemi-frontend/node_modules to $(pwd)"
- cp -a /build_cache/lemi-frontend/node_modules .
- echo "$(date) Performing npm-update"
- npm update --no-save
- echo "$(date) Performing npm-install"
- npm install --no-save
- echo "$(date) Cleaning up /dist directory"
- rm -rf dist/
- echo "$(date) Performing npm-install"
- npm install --no-save
- echo "$(date) Performing ng-update"
- node_modules/@angular/cli/bin/ng update
- echo "$(date) Angular CLI is linting now"
- node_modules/@angular/cli/bin/ng lint
job_test_build:
stage: test
except:
- master
script:
- echo "$(date) Changing to directory ${CI_PROJECT_DIR}"
- cd $CI_PROJECT_DIR
- echo "$(date) Cleaning up /dist directory"
- rm -rf dist/
- echo "$(date) Performing npm-install"
- npm install --no-save
- npm install typescript@'>=2.7.0 <2.8.0'
- echo "$(date) Performing np-update"
- node_modules/@angular/cli/bin/ng update
- echo "$(date) Angular CLI is building now"
- node_modules/@angular/cli/bin/ng build --verbose false --progress false --build-optimizer false
#
# Analyse Stage
#
job_sq_preview:
image: skuld.netshadow.net:5000/gitlab-sonar-scanner:nodejs
stage: analysis
except:
- master
variables:
SONAR_URL: https://sonar.netshadow.net
SONAR_GITLAB_PROJECT_ID: 24
SONAR_ANALYSIS_MODE: preview
NODE_PATH: /usr/lib/node_modules
script:
- gitlab-sonar-scanner
job_sq_report:
image: skuld.netshadow.net:5000/gitlab-sonar-scanner:nodejs
stage: analysis
except:
- master
variables:
SONAR_URL: https://sonar.netshadow.net
SONAR_GITLAB_PROJECT_ID: 24
SONAR_ANALYSIS_MODE: publish
NODE_PATH: /usr/lib/node_modules
script:
- gitlab-sonar-scanner
#
# Build Stage
#
job_final_build:
only:
- master
script:
- echo "$(date) Changing to directory ${CI_PROJECT_DIR}"
- cd $CI_PROJECT_DIR
- echo "$(date) Cleaning up /dist directory"
- rm -rf dist/
- echo "$(date) Performing npm-install"
- npm install --no-save
- npm install typescript@'>=2.7.0 <2.8.0'
- echo "$(date) Performing ng-update"
- node_modules/@angular/cli/bin/ng update
- echo "$(date) Angular CLI is building now"
- node_modules/@angular/cli/bin/ng build --prod --verbose false --progress false --build-optimizer true
- echo "$(date) All done"
artifacts:
name: "frontend-test-build"
name: "frontend-build"
paths:
- dist/
expire_in: 1 week
when: on_success
This diff is collapsed.
sonar.projectKey=lemi-frontend
sonar.exclusions=node_modules/**,src/assets/**,src/favicon.ico
sonar.sources=./src/app/
sonar.gitlab.project_id=24
......@@ -22,9 +22,7 @@ import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { HttpClientXsrfModule } from '@angular/common/http';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientModule, HttpClientXsrfModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { MatSortModule } from '@angular/material';
import { MatCheckboxModule } from '@angular/material';
......
/**
* This file is part of the Lightweight Extendable Machine Inventory.
*
* Lightweight Extendable Machine Inventory, a free and extendable software
* and hardware inventory.
*
* Copyright (C) <2017-2018> <Andreas Unterkircher>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*/
export class Errors {
static notLoggedIn = 'Unable to proceed - you are not logged in!';
static modelNotInitialized = 'model is not initialized';
static operationInProgress = 'an operation already in progress';
static noneItemsModel = 'Can not set items data for a non-items model';
static noneFieldsModel = 'Can not set items data for a non-fields model';
}
// vim: set filetype=typescript expandtab softtabstop=4 tabstop=4 shiftwidth=4 smartindent:
......@@ -97,22 +97,6 @@ export class AboutComponent extends DefaultComponent implements OnInit {
}));
this.refreshToken = of('unparsable!');
/*this.refreshToken = this.tokenStorageService
.getRefreshToken()
.switchMap((token: string) => {
const tokenInfo = this.parseToken(token);
if (!tokenInfo) {
throw new Error('Failed to parse refresh-token!');
}
tokenInfo.iat = new Date(tokenInfo.iat * 1000);
tokenInfo.nbf = new Date(tokenInfo.nbf * 1000);
tokenInfo.exp = new Date(tokenInfo.exp * 1000);
return of(JSON.stringify(tokenInfo));
});*/
this.username = this.loginService.getUsername();
this.user = this.loginService.getUser();
this.spinnerService.hide();
......
......@@ -36,15 +36,7 @@ export class PageFooterComponent implements OnInit {
}
debugging(): boolean {
if (!this.showDebugging) {
this.showDebugging = true;
} else {
this.showDebugging = false;
}
// console.log(this.element.nativeElement.querySelector('#debugwnd'));
// this.element.nativeElement.querySelector('#debugwnd').sidebar('toggle');
return this.showDebugging;
return !this.showDebugging;
}
}
......
......@@ -25,9 +25,10 @@
<sui-search placeholder="Quick Search..."
optionsField="name"
[maxResults]=5
[optionsLookup]="search"
[optionsLookup]="performSearch"
[resultTemplate]="resultTemplate"
[retainSelectedResult]="false"
(resultSelected)="select($event)"></sui-search>
(resultSelected)="selectResult($event)">
</sui-search>
<!-- vim: set filetype=html expandtab softtabstop=4 tabstop=4 shiftwidth=4 smartindent: -->
......@@ -27,6 +27,13 @@ import { ApiService } from '../../providers/api.service';
import { catchError, tap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
class SearchResult {
guid: string;
name: string;
link: string;
icon: string;
}
@Component({
selector: 'lemi-quick-search',
templateUrl: './quick-search.component.html',
......@@ -34,7 +41,6 @@ import { Observable, of } from 'rxjs';
})
export class QuickSearchComponent implements OnInit {
pattern: string;
searching = false;
constructor(
......@@ -49,11 +55,11 @@ export class QuickSearchComponent implements OnInit {
ngOnInit() { }
search = async (query: string) => {
performSearch = async (query: string) => {
return this.apiService.quickSearch(query);
}
select (selectEvent) {
selectResult (selectEvent: SearchResult) {
this.router.navigateByUrl(selectEvent.link);
}
}
......
......@@ -33,6 +33,12 @@ import { SearchResult } from '../../classes/search-result';
import { catchError, tap, takeUntil } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
interface ModelInfo {
link: string;
model: string;
icon: string;
}
@Component({
selector: 'lemi-search',
templateUrl: './search.component.html',
......@@ -113,90 +119,16 @@ export class SearchComponent extends DefaultComponent implements OnInit, AfterVi
const searchResult = new Array<SearchResult>();
result.result.forEach(function (value) {
let link: string;
let model: string;
let icon: string;
switch (value.model) {
case 'architectures':
link = '/architecture';
model = 'Architecture';
icon = 'architecture';
break;
case 'hosts':
link = '/host';
model = 'Host';
icon = 'host';
break;
case 'hardware_facts':
link = '/hardware';
model = 'Hardware Fact';
icon = 'hardware';
break;
case 'hardware_processors':
link = '/hardware-processor';
model = 'Processor';
icon = 'cpu';
break;
case 'kernels':
link = '/kernel';
model = 'Kernel';
icon = 'kernel';
break;
case 'network_interfaces':
link = '/network-interface';
model = 'Network Interface';
icon = 'interface';
break;
case 'ip_addresses':
link = '/ip-address';
model = 'IP Address';
icon = 'ipaddress';
break;
case 'operating_system_releases':
link = '/operating-system';
if (!value.hasOwnProperty('parent_guid')) {
throw new Error('OS guid is not known!');
}
link += '/' + value.parent_guid;
link += '/release';
model = 'OS Release';
icon = 'os';
break;
case 'operating_systems':
link = '/operating-system';
model = 'OS';
icon = 'os';
break;
case 'software_packages':
link = '/software-package';
model = 'Package';
icon = 'packages';
break;
case 'software_package_versions':
link = '/software-package';
model = 'Package Version';
icon = 'packages';
break;
case 'user':
link = '/user';
model = 'User';
icon = 'user';
break;
default:
console.log('Unknown result!');
console.log(value);
return;
}
link += '/' + value.guid;
const info = this.getModelInfo(value);
info.link += '/' + value.guid;
const dou: SearchResult = {
guid: value.guid,
name: value.name,
type: model,
link: link,
icon: icon,
type: info.model,
link: info.link,
icon: info.icon,
};
searchResult.push(dou);
......@@ -235,6 +167,94 @@ export class SearchComponent extends DefaultComponent implements OnInit, AfterVi
this.searchInput.nativeElement.focus();
this.searchFocused = true;
}
getModelInfo(info): ModelInfo {
if (!info.hasOwnProperty('model')) {
return;
}
let link: string;
let model: string;
let icon: string;
switch (info.model) {
case 'architectures':
link = '/architecture';
model = 'architecture';
icon = 'architecture';
break;
case 'hosts':
link = '/host';
model = 'host';
icon = 'host';
break;
case 'hardware_facts':
link = '/hardware';
model = 'hardware fact';
icon = 'hardware';
break;
case 'hardware_processors':
link = '/hardware-processor';
model = 'processor';
icon = 'cpu';
break;
case 'kernels':
link = '/kernel';
model = 'kernel';
icon = 'kernel';
break;
case 'network_interfaces':
link = '/network-interface';
model = 'network interface';
icon = 'interface';
break;
case 'ip_addresses':
link = '/ip-address';
model = 'ip address';
icon = 'ipaddress';
break;
case 'operating_system_releases':
link = '/operating-system';
if (!info.hasOwnProperty('parent_guid')) {
throw new Error('os guid is not known!');
}
link += '/' + info.parent_guid;
link += '/release';
model = 'os release';
icon = 'os';
break;
case 'operating_systems':
link = '/operating-system';
model = 'os';
icon = 'os';
break;
case 'software_packages':
link = '/software-package';
model = 'package';
icon = 'packages';
break;
case 'software_package_versions':
link = '/software-package';
model = 'package version';
icon = 'packages';
break;
case 'user':
link = '/user';
model = 'user';
icon = 'user';
break;
default:
console.log(model);
throw new Error('unknown result!');
}
return {
link: link,
model: model,
icon: icon,
};
}
}
// vim: set filetype=typescript expandtab softtabstop=4 tabstop=4 shiftwidth=4 smartindent:
......@@ -114,6 +114,7 @@ export class UserComponent extends DefaultComponent implements OnInit {
errorQueue$: Observable<string[]>;
tokens$: Observable<string[]>;
/* tslint:disable */
constructor(
protected route: ActivatedRoute,
protected apiService: ApiService,
......@@ -124,6 +125,7 @@ export class UserComponent extends DefaultComponent implements OnInit {
protected config: AppConfigService,
@Inject(DocumentService) protected document: any,
) {
/* tslint:enable */
super();
if (!this.loginService.isAdmin()) {
......@@ -284,13 +286,13 @@ export class UserComponent extends DefaultComponent implements OnInit {
this.saveText = '';
const privFlags = new PrivilegeFlags;
privFlags.admin = (this.userForm.value.privAdmin === true) ? true : false;
privFlags.admin = !!this.userForm.value.privAdmin;
this.user.setValues = {
username: this.userForm.value.username,
password: this.userForm.value.password1,
email: this.userForm.value.email,
active: (this.userForm.value.active === true) ? true : false,
active: !!this.userForm.value.active,
privileges: privFlags,
};
......
......@@ -21,6 +21,8 @@ import { Observable, of, throwError } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { ApiService } from '../providers/api.service';
import { Errors } from '../classes/errors';
import { ModelFlags } from '../classes/model-flags';
import { ItemsStore } from '../classes/items-store';
import { ItemsConfig } from '../classes/items-config';
......@@ -84,11 +86,11 @@ export class DefaultModel {
*/
load(itemsConfig?: ItemsConfig): Observable<any> {
if (!this.isInitialized) {
return throwError('model is not initialized!');
return throwError(Errors.modelNotInitialized);
}
if (this.inProgress) {
return throwError('an operation already in progress!');
return throwError(Errors.operationInProgress);
}
// nothing to load, if it is a new model being created
......@@ -174,17 +176,14 @@ export class DefaultModel {
get isInitialized(): boolean {
if (!this.modelName || this.modelName === 'default') {
// console.error('no name');
return false;
}
if ((this.mType !== 'items') && (this.mType !== 'fields')) {
// console.error('no type');
return false;
}
if (this.isFieldsModel && !this.mFields) {
// console.error('no fields');
return false;
}
......@@ -194,7 +193,6 @@ export class DefaultModel {
|| !this.mItemsStore.data.items
|| typeof this.mItemsStore.data.items === 'undefined')
) {
// console.error('no items');
return false;
}
......@@ -349,7 +347,7 @@ export class DefaultModel {
*/
set setValues(values: object) {
if (!this.isFieldsModel) {
throw new Error('Can not set values for a non-fields model!');
throw new Error(Errors.noneFieldsModel);
}
this.setFieldValues(values);
......@@ -362,7 +360,7 @@ export class DefaultModel {
*/
set setInitValues(values: object) {
if (!this.isFieldsModel) {
throw new Error('Can not set fields for a non-fields model!');
throw new Error(Errors.noneFieldsModel);
}
this.setFieldValues(values, 'init');
......@@ -376,7 +374,7 @@ export class DefaultModel {
*/
set setItems(data) {
if (!this.isItemsModel) {
throw new Error('Can not set items data for a non-items model!');
throw new Error(Errors.noneItemsModel);
}
if (!Array.isArray(data)) {
......@@ -404,7 +402,7 @@ export class DefaultModel {
*/
set setTotalItems(total: number) {
if (!this.isItemsModel) {
throw new Error('Can not set items data for a non-items model!');
throw new Error(Errors.noneItemsModel);
}
this.mItemsStore.total = total;
......@@ -417,7 +415,7 @@ export class DefaultModel {
*/
get getValues() {
if (!this.isFieldsModel) {
throw new Error('Can not get field values for a non-fields model!');
throw new Error(Errors.noneFieldsModel);
}
return this.mFields;
......@@ -430,7 +428,7 @@ export class DefaultModel {
*/
get getItems(): Observable<any> {
if (!this.isItemsModel) {
throw new Error('Can not get items data for a non-items model!');
throw new Error(Errors.noneItemsModel);
}
if (!this.mItemsStore.data.items) {
......@@ -447,7 +445,7 @@ export class DefaultModel {
*/
get getItemsCount(): number {
if (!this.isItemsModel) {
throw new Error('Can not get items data for a non-items model!');
throw new Error(Errors.noneItemsModel);
}
if (!this.mItemsStore.data.items) {
......@@ -464,7 +462,7 @@ export class DefaultModel {
*/
get getItemsTotal(): number {
if (!this.isItemsModel) {
throw new Error('Can not get items data for a non-items model!');
throw new Error(Errors.noneItemsModel);
}
if (!this.mItemsStore.total) {
......@@ -482,7 +480,7 @@ export class DefaultModel {
*/
get getValuesForSave() {
if (!this.isFieldsModel) {
throw new Error('Can not get field values for a non-fields model!');
throw new Error(Errors.noneFieldsModel);
}
const fields = this.getValues;
......@@ -499,11 +497,11 @@ export class DefaultModel {
*/
save(fields: object): Observable<any> {
if (!this.isInitialized) {
return throwError('model is not initialized!');
return throwError(Errors.modelNotInitialized);
}
if (this.inProgress) {
return throwError('an operation already in progress!');
return throwError(Errors.operationInProgress);
}
this.isSaving = true;
......@@ -541,11 +539,11 @@ export class DefaultModel {
*/
delete(model?: string, guid?: string): Observable<any> {
if (!this.isInitialized) {
return throwError('model is not initialized!');
return throwError(Errors.modelNotInitialized);
}
if (this.inProgress) {
return throwError('an operation already in progress!');
return throwError(Errors.operationInProgress);
}
let delModel;
......@@ -598,7 +596,7 @@ export class DefaultModel {
*/
setFieldValues (values: object, where?: string) {
if (!this.isFieldsModel) {
throw new Error('Can not set fields for a non-fields model!');
throw new Error(Errors.noneFieldsModel);
}
if (!values) {
......@@ -610,7 +608,7 @@ export class DefaultModel {
}
if (!this.mFields) {
throw new Error('model is not initialized!');
return throwError(Errors.modelNotInitialized);
}
Object.keys(values).forEach(function (key) {
......@@ -633,7 +631,7 @@ export class DefaultModel {
* @return boolean
*/
get isFieldsModel(): boolean {
return (!this.mType || this.mType !== 'fields') ? false : true;
return (this.mType !== 'fields');
}
/**
......@@ -642,7 +640,7 @@ export class DefaultModel {
* @return boolean
*/
get isItemsModel(): boolean {
return (!this.mType || this.mType !== 'items') ? false : true;
return (this.mType !== 'items');
}
/**
......@@ -659,7 +657,7 @@ export class DefaultModel {
}
if (this.isFieldsModel) {
throw new Error('Can not set items data for a non-items model!');
throw new Error(Errors.noneItemsModel);
}
this.mItemsType = itemsType;
......@@ -690,7 +688,7 @@ export class DefaultModel {
// this.log(`${operation} failed: ${error.message}`);
// Let the app keep running by returning an empty result.
return of(result as T);
return of(result);
};
}
}
......
This diff is collapsed.
......@@ -56,7 +56,7 @@ export class AppConfigService {
this.http.get('assets/config/' + confName)
.pipe(
map(res => res as any),
map(res => res),
catchError((error: any): any => {
reject(true);
return throwError('Server error, failed to load configuration!');
......
......@@ -30,6 +30,7 @@ import { TokenStorageService } from './token-storage.service';
import { AppConfigService } from './app-config.service';
import { ModalService } from './modal.service';
import { Errors } from '../classes/errors';
import { LoginData } from '../classes/login-data';
import { TokenData } from '../classes/token-data';
import { PersonalTokenData } from '../classes/personal-token-data';
......@@ -112,9 +113,8 @@ export class AuthService implements NgxAuthService, OnDestroy {
scope: '',
};
const options = { headers: new HttpHeaders()
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
const options = {
headers: this.httpHeaders(),
};
return this.http.post<any>(url, payload, options);
......@@ -148,8 +148,6 @@ export class AuthService implements NgxAuthService, OnDestroy {
trace: JSON.stringify(err),
}).afterClosed()
.pipe(switchMap(() => {
// this.logout();
// location.reload();
return throwError(err);
}));
}
......@@ -164,8 +162,6 @@ export class AuthService implements NgxAuthService, OnDestroy {
})
.afterClosed()
.pipe(switchMap(() => {
// this.logout();
// location.reload();
return throwError(err);
}));
}
......@@ -234,9 +230,8 @@ export class AuthService implements NgxAuthService, OnDestroy {
const url = this.config.apiBaseUrl + this.oauthEndpoint;
const options = { headers: new HttpHeaders()
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
const options = {
headers: this.httpHeaders(),
};
const payload = {
......@@ -286,9 +281,7 @@ export class AuthService implements NgxAuthService, OnDestroy {
*/
logout(): void {
const url = this.config.apiBaseUrl + this.logoutEndpoint;
const headers = new HttpHeaders()
.set('Content-Type', 'application/json')
.set('Accept', 'application/json');
const headers = this.httpHeaders();
this.loginState = false;
......@@ -347,15 +340,13 @@ export class AuthService implements NgxAuthService, OnDestroy {
*/
getPersonalAccessTokens(): Observable<any> {
if (!this.isLoggedIn()) {
throwError('not logged in!');
throwError(Errors.notLoggedIn);
return;
}
const url = this.config.apiBaseUrl + this.patEndpoint;
const headers = new HttpHeaders()
.set('Content-Type', 'application/json')
.set('Accept', 'application/json');
const headers = this.httpHeaders();
return this.http.get<any>(url, { headers: headers });
}
......@@ -365,7 +356,7 @@ export class AuthService implements NgxAuthService, OnDestroy {
*/
newPersonalAccessToken(token: PersonalTokenData): Observable<any> {
if (!this.isLoggedIn()) {
throwError('not logged in!');
throwError(Errors.notLoggedIn);
return;
}
......@@ -380,9 +371,7 @@ export class AuthService implements NgxAuthService, OnDestroy {
const url = this.config.apiBaseUrl + this.patEndpoint;
const headers = new HttpHeaders()
.set('Content-Type', 'application/json')
.set('Accept', 'application/json');
const headers = this.httpHeaders();
return this.http.post<any>(url, httpPayload, { headers: headers });
}
......@@ -394,7 +383,7 @@ export class AuthService implements NgxAuthService, OnDestroy {
*/
delPersonalAccessToken(token: PersonalTokenData): Observable<any> {
if (!this.isLoggedIn()) {
throwError('not logged in!');
throwError(Errors.notLoggedIn);
return;
}
......@@ -407,9 +396,7 @@ export class AuthService implements NgxAuthService, OnDestroy {
url += '/';
url += token.id;
const headers = new HttpHeaders()
.set('Content-Type', 'application/json')
.set('Accept', 'application/json');
const headers = this.httpHeaders();
return this.http.delete<any>(url, { headers: headers });
}
......@@ -419,7 +406,7 @@ export class AuthService implements NgxAuthService, OnDestroy {
*/
updatePersonalAccessToken(token: PersonalTokenData): Observable<any> {
if (!this.isLoggedIn()) {
throwError('not logged in!');
throwError(Errors.notLoggedIn);
return;
}
......@@ -446,13 +433,16 @@ export class AuthService implements NgxAuthService, OnDestroy {
url += '/';
url += token.id;
const headers = new HttpHeaders()
.set('Content-Type', 'application/json')
.set('Accept', 'application/json');
const headers = this.httpHeaders();
return this.http.put<any>(url, httpPayload, { headers: headers });
}
public httpHeaders(): HttpHeaders {
return new HttpHeaders()
.set('Content-Type', 'application/json')
.set('Accept', 'application/json');
}
}
// vim: set filetype=typescript expandtab softtabstop=4 tabstop=4 shiftwidth=4 smartindent:
......@@ -29,6 +29,7 @@ import { DebugMessageService } from './debug-message.service';
import { ModalService } from './modal.service';
import { ItemsConfig } from '../classes/items-config';
import { Errors } from '../classes/errors';
class ItemConfig {
metricEndpoint: string;
......@@ -65,7 +66,7 @@ export class MetricService {
*/
getItems(itemsConfig: ItemsConfig): Observable<any> {
if (!this.authSerivce.isLoggedIn()) {
return throwError('not-logged-in');
return throwError(Errors.notLoggedIn);
}
let url = this.config.apiBaseUrl + this.metricUrl;
......@@ -112,7 +113,7 @@ export class MetricService {
*/
getItem(itemConfig: ItemConfig): Observable<any> {
if (!this.authSerivce.isLoggedIn()) {
return throwError('not-logged-in');
return throwError(Errors.notLoggedIn);
}
let url = this.config.apiBaseUrl + this.metricUrl;
......@@ -153,7 +154,7 @@ export class MetricService {
*/
getStats(statsConfig: StatsConfig): Observable<any> {
if (!this.authSerivce.isLoggedIn()) {
return throwError('not-logged-in');
return throwError(Errors.notLoggedIn);
}
let url = this.config.apiBaseUrl + this.metricUrl;
......
......@@ -29,7 +29,7 @@ export class TokenStorageService {
* @returns {Observable<string>}
*/
public getAccessToken(): Observable<string> {
const token: string = <string>localStorage.getItem('accessToken');
const token = localStorage.getItem('accessToken');
return of(token);
}
......@@ -39,7 +39,7 @@ export class TokenStorageService {
* @returns {Observable<string>}
*/
public getRefreshToken(): Observable<string> {
const token: string = <string>localStorage.getItem('refreshToken');
const token = localStorage.getItem('refreshToken');
return of(token);
}
......@@ -50,7 +50,6 @@ export class TokenStorageService {
*/
public setAccessToken(token: string): TokenStorageService {
localStorage.setItem('accessToken', token);
return this;
}
......@@ -61,7 +60,6 @@ export class TokenStorageService {
*/
public setRefreshToken(token: string): TokenStorageService {
localStorage.setItem('refreshToken', token);
return this;
}
......@@ -79,11 +77,9 @@ export class TokenStorageService {
* return true if a accessToken is present
*/
public hasAccessToken() {
let token: string;
const token = localStorage.getItem('accessToken');
if ((token = localStorage.getItem('accessToken')) === null
|| token.length < 1
) {
if (!token || token.length < 1) {
return false;
}
......@@ -111,8 +107,7 @@ export class TokenStorageService {
return;
}
const result = JSON.parse(user);
return result;
return JSON.parse(user);
}
/**
......
......@@ -141,5 +141,8 @@
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true
}
},
"extends": [
"tslint-sonarts"
]
}