add ts lint

This commit is contained in:
Quique Fernandez 2016-12-29 18:21:02 +01:00
parent 423cee76b6
commit b36bd97876
23 changed files with 222 additions and 135 deletions

View File

@ -13,11 +13,6 @@ export const routes: Routes = [
{ path: 'orders', component: OrdersComponent },
{ path: 'orders/:id', component: OrdersDetailComponent },
{ path: 'order', component: OrdersNewComponent }
//Lazy async modules (angular-loader-router) and enable a router in each module.
//{
// path: 'basket', loadChildren: '/basket/basket.module' });
// })
//}
];
export const routing = RouterModule.forRoot(routes);

View File

@ -37,10 +37,7 @@ export class BasketComponent implements OnInit {
private calculateTotalPrice() {
this.totalPrice = 0;
this.basket.items.forEach(item => {
this.totalPrice += (item.unitPrice * item.quantity)
this.totalPrice += (item.unitPrice * item.quantity);
});
}
}

View File

@ -9,7 +9,7 @@ import { Header } from '../shared/components/header/header';
@NgModule({
imports: [SharedModule],
declarations: [BasketComponent, BasketStatusComponent],
declarations: [BasketComponent, BasketStatusComponent],
providers: [BasketService],
exports: [BasketStatusComponent]
})

View File

@ -54,7 +54,7 @@ export class CatalogComponent implements OnInit {
this.basketService.addItemToBasket(item);
}
getCatalog(pageSize:number, pageIndex: number, brand?: number, type?: number) {
getCatalog(pageSize: number, pageIndex: number, brand?: number, type?: number) {
this.service.getCatalog(pageIndex, pageSize, brand, type).subscribe(catalog => {
this.catalog = catalog;

View File

@ -22,7 +22,7 @@ export class CatalogService {
}
getCatalog(pageIndex: number, pageSize: number, brand: number, type: number): Observable<ICatalog> {
var url = this.catalogUrl;
let url = this.catalogUrl;
if (brand || type) {
url = this.catalogUrl + '/type/' + ((type) ? type.toString() : 'null') + '/brand/' + ((brand) ? brand.toString() : 'null');
}

View File

@ -12,11 +12,11 @@ import { Router } from '@angular/router';
templateUrl: './orders-new.component.html'
})
export class OrdersNewComponent implements OnInit {
private newOrderForm : FormGroup; // new order form
private newOrderForm: FormGroup; // new order form
private order: IOrder;
constructor(private service: OrdersService, fb: FormBuilder, private router: Router, private basketEvents: BasketWrapperService) {
//Obtener información del perfil de usuario.
// Obtener información del perfil de usuario.
this.order = service.mapBasketAndIdentityInfoNewOrder();
this.newOrderForm = fb.group({
'street': [this.order.street, Validators.required],
@ -31,7 +31,6 @@ export class OrdersNewComponent implements OnInit {
}
ngOnInit() {
}
submitForm(value: any) {
@ -45,7 +44,7 @@ export class OrdersNewComponent implements OnInit {
this.order.cardsecuritynumber = this.newOrderForm.controls['securitycode'].value;
this.service.postOrder(this.order).subscribe(res => {
//this will emit an observable. Basket service is subscribed to this observable, and will react deleting the basket for the current user.
// this will emit an observable. Basket service is subscribed to this observable, and will react deleting the basket for the current user.
this.basketEvents.orderCreated();
this.router.navigate(['orders']);

View File

@ -36,7 +36,7 @@ export class OrdersService {
return response.json();
});
}
postOrder(item): Observable<boolean> {
return this.service.post(this.ordersUrl + '/new', item).map((response: Response) => {
return true;
@ -51,7 +51,7 @@ export class OrdersService {
console.log(basket);
console.log(identityInfo);
//Identity data mapping:
// Identity data mapping:
order.street = identityInfo.address_street;
order.city = identityInfo.address_city;
order.country = identityInfo.address_country;
@ -65,10 +65,9 @@ export class OrdersService {
order.total = 0;
order.expiration = identityInfo.card_expiration;
//basket data mapping:
// basket data mapping:
order.orderItems = new Array<IOrderItem>();
basket.items.forEach(x =>
{
basket.items.forEach(x => {
let item: IOrderItem = <IOrderItem>{};
item.pictureurl = x.pictureUrl;
item.productId = +x.productId;

View File

@ -12,15 +12,14 @@ import { SecurityService } from '../../services/security.service';
export class Identity implements OnInit {
private authenticated: boolean = false;
private subscription: Subscription;
private userName: string = "";
private userName: string = '';
constructor(private service: SecurityService) {
}
ngOnInit() {
this.subscription = this.service.authenticationChallenge$.subscribe(res =>
{
this.subscription = this.service.authenticationChallenge$.subscribe(res => {
this.authenticated = res;
this.userName = this.service.UserData.email;
});

View File

@ -18,10 +18,9 @@ export class Pager implements OnInit, OnChanges {
buttonStates: any = {
nextDisabled: true,
previousDisabled: true,
}
};
ngOnInit() {
//console.log(this.model);
}
ngOnChanges() {

View File

@ -1,6 +1,6 @@
import { IBasketItem } from './basketItem.model';
export interface IBasket {
items: IBasketItem[]
buyerId: string
}
items: IBasketItem[];
buyerId: string;
}

View File

@ -1,9 +1,8 @@
export interface IBasketItem {
id: string
productId: string
productName: string
unitPrice: number,
quantity: number,
pictureUrl: string
id: string;
productId: string;
productName: string;
unitPrice: number;
quantity: number;
pictureUrl: string;
}

View File

@ -1,8 +1,8 @@
import {ICatalogItem} from './catalogItem.model';
export interface ICatalog {
pageIndex: number
data: ICatalogItem[]
pageSize: number
count: number
pageIndex: number;
data: ICatalogItem[];
pageSize: number;
count: number;
}

View File

@ -1,4 +1,4 @@
export interface ICatalogBrand {
id: number
brand: string
id: number;
brand: string;
}

View File

@ -1,4 +1,4 @@
export interface ICatalogType {
id: number
type: string
id: number;
type: string;
}

View File

@ -13,7 +13,7 @@ export interface IOrder {
cardholdername: string;
cardtypeid: number;
buyer: string;
ordernumber: string,
total: number,
ordernumber: string;
total: number;
orderItems: IOrderItem[];
}

View File

@ -3,5 +3,5 @@ export interface IOrderItem {
productname: string;
unitprice: number;
units: number;
productId: number
productId: number;
}

View File

@ -1,7 +1,7 @@
export interface IPager {
itemsPage: number,
totalItems: number,
actualPage: number,
totalPages: number,
items: number,
}
itemsPage: number;
totalItems: number;
actualPage: number;
totalPages: number;
items: number;
}

View File

@ -8,17 +8,17 @@ import { SecurityService } from '../services/security.service';
@Injectable()
export class BasketWrapperService {
public basket: IBasket
public basket: IBasket;
constructor(private identityService: SecurityService) { }
//observable that is fired when a product is added to the cart
// observable that is fired when a product is added to the cart
private addItemToBasketSource = new Subject<IBasketItem>();
addItemToBasket$ = this.addItemToBasketSource.asObservable();
private orderCreatedSource = new Subject();
orderCreated$ = this.orderCreatedSource.asObservable();
addItemToBasket(item: ICatalogItem) {
if (this.identityService.IsAuthorized) {
let basket: IBasketItem = {
@ -28,7 +28,8 @@ export class BasketWrapperService {
quantity: 1,
unitPrice: item.price,
id: ''
}
};
this.addItemToBasketSource.next(basket);
} else {
this.identityService.Authorize();

View File

@ -19,9 +19,9 @@ export class DataService {
if (this.securityService) {
options.headers = new Headers();
options.headers.append("Authorization", "Bearer " + this.securityService.GetToken());
options.headers.append('Authorization', 'Bearer ' + this.securityService.GetToken());
}
return this.http.get(url, options).map(
(res: Response) => {
return res;
@ -33,7 +33,7 @@ export class DataService {
if (this.securityService) {
options.headers = new Headers();
options.headers.append("Authorization", "Bearer " + this.securityService.GetToken());
options.headers.append('Authorization', 'Bearer ' + this.securityService.GetToken());
}
return this.http.post(url, data, options).map(
@ -47,7 +47,7 @@ export class DataService {
if (this.securityService) {
options.headers = new Headers();
options.headers.append("Authorization", "Bearer " + this.securityService.GetToken());
options.headers.append('Authorization', 'Bearer ' + this.securityService.GetToken());
}
console.log('data.service deleting');

View File

@ -3,7 +3,6 @@ import { Http, Response, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
//import { Configuration } from '../app.constants';
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
@ -20,45 +19,45 @@ export class SecurityService {
this.headers = new Headers();
this.headers.append('Content-Type', 'application/json');
this.headers.append('Accept', 'application/json');
this.storage = sessionStorage; //localStorage;
this.storage = sessionStorage; // localStorage;
if (this.retrieve("IsAuthorized") !== "") {
this.IsAuthorized = this.retrieve("IsAuthorized");
if (this.retrieve('IsAuthorized') !== '') {
this.IsAuthorized = this.retrieve('IsAuthorized');
this.authenticationSource.next(true);
this.UserData = this.retrieve("userData");
this.UserData = this.retrieve('userData');
}
}
public IsAuthorized: boolean;
public GetToken(): any {
return this.retrieve("authorizationData");
return this.retrieve('authorizationData');
}
public ResetAuthorizationData() {
this.store("authorizationData", "");
this.store("authorizationDataIdToken", "");
this.store('authorizationData', '');
this.store('authorizationDataIdToken', '');
this.IsAuthorized = false;
this.store("IsAuthorized", false);
this.store('IsAuthorized', false);
}
public UserData: any;
public SetAuthorizationData(token: any, id_token:any) {
if (this.retrieve("authorizationData") !== "") {
this.store("authorizationData", "");
public SetAuthorizationData(token: any, id_token: any) {
if (this.retrieve('authorizationData') !== '') {
this.store('authorizationData', '');
}
this.store("authorizationData", token);
this.store("authorizationDataIdToken", id_token);
this.store('authorizationData', token);
this.store('authorizationDataIdToken', id_token);
this.IsAuthorized = true;
this.store("IsAuthorized", true);
this.store('IsAuthorized', true);
this.getUserData()
.subscribe(data => {
this.UserData = data;
this.store("userData", data);
//emit observable
this.store('userData', data);
// emit observable
this.authenticationSource.next(true);
window.location.href = 'http://localhost:5104';
},
@ -71,25 +70,25 @@ export class SecurityService {
public Authorize() {
this.ResetAuthorizationData();
var authorizationUrl = 'http://localhost:5105/connect/authorize';
var client_id = 'js';
var redirect_uri = 'http://localhost:5104/';
var response_type = "id_token token";
var scope = "openid profile orders basket";
var nonce = "N" + Math.random() + "" + Date.now();
var state = Date.now() + "" + Math.random();
let authorizationUrl = 'http://localhost:5105/connect/authorize';
let client_id = 'js';
let redirect_uri = 'http://localhost:5104/';
let response_type = 'id_token token';
let scope = 'openid profile orders basket';
let nonce = 'N' + Math.random() + '' + Date.now();
let state = Date.now() + '' + Math.random();
this.store("authStateControl", state);
this.store("authNonce", nonce);
this.store('authStateControl', state);
this.store('authNonce', nonce);
var url =
authorizationUrl + "?" +
"response_type=" + encodeURI(response_type) + "&" +
"client_id=" + encodeURI(client_id) + "&" +
"redirect_uri=" + encodeURI(redirect_uri) + "&" +
"scope=" + encodeURI(scope) + "&" +
"nonce=" + encodeURI(nonce) + "&" +
"state=" + encodeURI(state);
let url =
authorizationUrl + '?' +
'response_type=' + encodeURI(response_type) + '&' +
'client_id=' + encodeURI(client_id) + '&' +
'redirect_uri=' + encodeURI(redirect_uri) + '&' +
'scope=' + encodeURI(scope) + '&' +
'nonce=' + encodeURI(nonce) + '&' +
'state=' + encodeURI(state);
window.location.href = url;
}
@ -97,41 +96,41 @@ export class SecurityService {
public AuthorizedCallback() {
this.ResetAuthorizationData();
var hash = window.location.hash.substr(1);
let hash = window.location.hash.substr(1);
var result: any = hash.split('&').reduce(function (result : any, item: string) {
var parts = item.split('=');
let result: any = hash.split('&').reduce(function (result: any, item: string) {
let parts = item.split('=');
result[parts[0]] = parts[1];
return result;
}, {});
console.log(result);
var token = "";
var id_token = "";
var authResponseIsValid = false;
let token = '';
let id_token = '';
let authResponseIsValid = false;
if (!result.error) {
if (result.state !== this.retrieve("authStateControl")) {
console.log("AuthorizedCallback incorrect state");
if (result.state !== this.retrieve('authStateControl')) {
console.log('AuthorizedCallback incorrect state');
} else {
token = result.access_token;
id_token = result.id_token
id_token = result.id_token;
var dataIdToken: any = this.getDataFromToken(id_token);
let dataIdToken: any = this.getDataFromToken(id_token);
console.log(dataIdToken);
// validate nonce
if (dataIdToken.nonce !== this.retrieve("authNonce")) {
console.log("AuthorizedCallback incorrect nonce");
if (dataIdToken.nonce !== this.retrieve('authNonce')) {
console.log('AuthorizedCallback incorrect nonce');
} else {
this.store("authNonce", "");
this.store("authStateControl", "");
this.store('authNonce', '');
this.store('authStateControl', '');
authResponseIsValid = true;
console.log("AuthorizedCallback state and nonce validated, returning access token");
console.log('AuthorizedCallback state and nonce validated, returning access token');
}
}
}
@ -143,18 +142,18 @@ export class SecurityService {
}
public Logoff() {
var authorizationUrl = 'http://localhost:5105/connect/endsession';
var id_token_hint = this.retrieve("authorizationDataIdToken");
var post_logout_redirect_uri = 'http://localhost:5104/';
let authorizationUrl = 'http://localhost:5105/connect/endsession';
let id_token_hint = this.retrieve('authorizationDataIdToken');
let post_logout_redirect_uri = 'http://localhost:5104/';
var url =
authorizationUrl + "?" +
"id_token_hint=" + encodeURI(id_token_hint) + "&" +
"post_logout_redirect_uri=" + encodeURI(post_logout_redirect_uri);
let url =
authorizationUrl + '?' +
'id_token_hint=' + encodeURI(id_token_hint) + '&' +
'post_logout_redirect_uri=' + encodeURI(post_logout_redirect_uri);
this.ResetAuthorizationData();
//emit observable
// emit observable
this.authenticationSource.next(false);
window.location.href = url;
}
@ -162,16 +161,16 @@ export class SecurityService {
public HandleError(error: any) {
console.log(error);
if (error.status == 403) {
this._router.navigate(['/Forbidden'])
this._router.navigate(['/Forbidden']);
}
else if (error.status == 401) {
//this.ResetAuthorizationData();
this._router.navigate(['/Unauthorized'])
// this.ResetAuthorizationData();
this._router.navigate(['/Unauthorized']);
}
}
private urlBase64Decode(str: string) {
var output = str.replace('-', '+').replace('_', '/');
let output = str.replace('-', '+').replace('_', '/');
switch (output.length % 4) {
case 0:
break;
@ -189,9 +188,9 @@ export class SecurityService {
}
private getDataFromToken(token: any) {
var data = {};
let data = {};
if (typeof token !== 'undefined') {
var encoded = token.split('.')[1];
let encoded = token.split('.')[1];
data = JSON.parse(this.urlBase64Decode(encoded));
}
@ -199,7 +198,7 @@ export class SecurityService {
}
private retrieve(key: string): any {
var item = this.storage.getItem(key);
let item = this.storage.getItem(key);
if (item && item !== 'undefined') {
return JSON.parse(this.storage.getItem(key));
@ -225,9 +224,9 @@ export class SecurityService {
this.headers.append('Content-Type', 'application/json');
this.headers.append('Accept', 'application/json');
var token = this.GetToken();
let token = this.GetToken();
if (token !== "") {
if (token !== '') {
this.headers.append('Authorization', 'Bearer ' + token);
}
}

View File

@ -19,7 +19,7 @@ import { UppercasePipe } from './pipes/uppercase.pipe';
import { BasketWrapperService} from './services/basket.wrapper.service';
import { SecurityService } from './services/security.service';
//Components:
// Components:
import { Pager } from './components/pager/pager';
import { Header } from './components/header/header';
import { Identity } from './components/identity/identity';
@ -58,8 +58,6 @@ import { Identity } from './components/identity/identity';
DynamicFormControlComponent,
ErrorSummaryComponent,
ErrorMessageComponent,
//FooterComponent,
//HeaderComponent,
PageHeadingComponent,
UppercasePipe,
Pager,
@ -76,7 +74,7 @@ export class SharedModule {
DataService,
FormControlService,
UtilityService,
BasketWrapperService,
BasketWrapperService,
SecurityService
]
};

View File

@ -29,10 +29,11 @@
"build:main": "node node_modules/webpack/bin/webpack.js --config config/webpack.config.js",
"setdev": "set ASPNETCORE_ENVIRONMENT=Development",
"setprod": "set ASPNETCORE_ENVIRONMENT=Production",
"build:dev": "npm run lint:sass && npm run setdev && npm run clean:dist && npm run build:vendor && npm run build:main",
"build:dev": "npm run setdev && npm run clean:dist && npm run build:vendor && npm run build:main",
"build:prod": "npm run setprod && npm run clean:dist && npm run build:vendor && npm run build:main",
"version": "npm run build",
"lint:sass": "sass-lint -c .sass-lint.yml Client/**/*.scss --verbose"
"lint:sass": "sass-lint -c .sass-lint.yml Client/**/*.scss --verbose",
"lint:ts": "tslint -c tslint.json Client/**/*.ts"
},
"dependencies": {
"@angular/common": "2.1.2",
@ -92,9 +93,9 @@
"sass-loader": "4.0.2",
"ts-helpers": "1.1.1",
"ts-node": "1.4.3",
"tslint": "3.15.1",
"tslint": "^3.15.1",
"typedoc": "0.5.0",
"typescript": "2.0.6",
"typescript": "^2.0.6",
"url-loader": "^0.5.7",
"webpack": "2.1.0-beta.25",
"webpack-externals-plugin": "1.0.0",

View File

@ -0,0 +1,101 @@
{
"jsRules": {
"class-name": true,
"comment-format": [
true,
"check-space"
],
"indent": [
true,
"spaces"
],
"no-duplicate-variable": true,
"no-eval": true,
"no-trailing-whitespace": true,
"no-unsafe-finally": true,
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"quotemark": [
true,
"single"
],
"semicolon": [
true,
"always"
],
"triple-equals": [
false,
"allow-null-check"
],
"variable-name": [
true,
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
},
"rules": {
"class-name": true,
"comment-format": [
true,
"check-space"
],
"indent": [
true,
"spaces"
],
"no-eval": true,
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-unsafe-finally": true,
"no-var-keyword": true,
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"quotemark": [
true,
"single"
],
"semicolon": [
true,
"always"
],
"triple-equals": [
false,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"variable-name": [
true,
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}
}