more clean up

This commit is contained in:
2018-09-11 08:20:53 -04:00
parent 5262b6e2b4
commit d7f47d245e
13 changed files with 158 additions and 201 deletions

View File

@@ -1,6 +0,0 @@
import { AlertType } from '../_classes/alertType';
export class Alert {
type: AlertType;
message: string;
}

View File

@@ -1,6 +0,0 @@
export enum AlertType {
Success,
Error,
Info,
Warning
}

View File

@@ -1,4 +0,0 @@
export class Stock {
Symbol: string;
Name: string;
}

View File

@@ -1,7 +0,0 @@
//import { stock } from './stock';
export class stockPortfolio{
bought: number;
sold: number;
shares: number;
}

View File

@@ -6,11 +6,16 @@ export class AuthGuard implements CanActivate {
constructor(private router: Router) { }
/*
Using CanActivate as route guard and simply checking if the currentUser object is inplace.
This can and should be expanded to validating the token via a service to ensure validity
*/
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (localStorage.getItem('currentUser')) {
return true;
}
/* If not then kick them back to the login page */
this.router.navigate( ['login'] );
return false;
}

View File

@@ -5,28 +5,28 @@ export class EmitcomService {
@Output() change: EventEmitter<any> = new EventEmitter();
sendData( data: string ) {
let sendData ={
sendData(data: string) {
let sendData = {
type: "ipo",
data: data
};
this.change.emit( sendData );
this.change.emit(sendData);
}
destroyChart() {
let sendData ={
let sendData = {
type: "action",
data: "destroyChart"
};
this.change.emit( sendData );
this.change.emit(sendData);
}
updateWatcher( ){
let sendData ={
updateWatcher() {
let sendData = {
type: "action",
data: "updateWatcher"
};
this.change.emit( sendData );
this.change.emit(sendData);
}
constructor() { }

View File

@@ -4,7 +4,7 @@ import 'rxjs/add/operator/map'
import { User } from '../_classes/user';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class LoginService {
@@ -16,14 +16,14 @@ export class LoginService {
private http: HttpClient
) { }
login(userData : any) {
login(userData: any) {
/* Look at that god like RegEX... We got a ^ AND a ?. /s */
const url = this.loginUrl + '/?userName=^' + userData.userName + '$&password=^' + userData.password + '$' ;
const url = this.loginUrl + '/?userName=^' + userData.userName + '$&password=^' + userData.password + '$';
/* Run the request expecting a user class back */
return this.http.get<User>(url)
.map(user => {
.map(user => {
return user;
});
});
}
logout() {

View File

@@ -1,27 +1,24 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'
//import { Stock } from '../_classes/stock';
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class NasdaqSearchService {
private loginUrl = "api/nasdaq";
constructor(
private http: HttpClient
private http: HttpClient
) { }
query(companyName: string) {
const url = this.loginUrl + '/?Name=^' + companyName;
return this.http.get<any>(url)
.map(stock => {
.map(stock => {
return stock;
});
});
}

View File

@@ -1,17 +1,14 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import {JsonpModule, Jsonp, Response} from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Jsonp } from '@angular/http';
import 'rxjs/add/operator/map'
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'text/html' })
headers: new HttpHeaders({ 'Content-Type': 'text/html' })
}
@Injectable({
providedIn: 'root'
providedIn: 'root'
})
export class StockService {
@@ -20,13 +17,13 @@ export class StockService {
private jsonp: Jsonp
) { }
getLogos( symbols ) {
getLogos(symbols) {
var symbolsComma = "";
var commaCheck = false;
for( var symbol in symbols ){
if( commaCheck ){
for (var symbol in symbols) {
if (commaCheck) {
symbolsComma += ",";
}
commaCheck = true;
@@ -36,13 +33,13 @@ export class StockService {
const url = "https://api.iextrading.com/1.0/stock/market/batch?symbols=" + symbolsComma + "&types=logo&callback=JSONP_CALLBACK";
return this.jsonp.request(url)
.map(logos => {
.map(logos => {
return logos["_body"];
});
});
}
getCharByTime( symbol, timeFrame ){
getCharByTime(symbol, timeFrame) {
const url2 = "https://api.iextrading.com/1.0/stock/" + symbol + "/chart/1m?callback=JSONP_CALLBACK";
return this.jsonp.request(url2)
.map(chartData => {
@@ -50,12 +47,12 @@ export class StockService {
});
}
getIpoBulkData( symbols ){
getIpoBulkData(symbols) {
var symbolsComma = "";
var commaCheck = false;
for( var symbol in symbols ){
if( commaCheck ){
for (var symbol in symbols) {
if (commaCheck) {
symbolsComma += ",";
}
commaCheck = true;
@@ -65,8 +62,8 @@ export class StockService {
const url = "https://api.iextrading.com/1.0/stock/market/batch?symbols=" + symbolsComma + "&types=quote,logo&callback=JSONP_CALLBACK";
return this.jsonp.request(url)
.map(logos => {
.map(logos => {
return logos["_body"];
});
});
}
}

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable({
@@ -20,14 +20,14 @@ export class WatcherService {
getWatching() {
const url = this.apiUrl
return this.http.get<any>(url)
.map(data => {
return data;
});
const url = this.apiUrl
return this.http.get<any>(url)
.map(data => {
return data;
});
}
addWatching( symbol ){
addWatching(symbol) {
let newWatchingSymbol = {
symbol: symbol
}
@@ -36,23 +36,23 @@ export class WatcherService {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
return this.http.post<any>(this.apiUrl, newWatchingSymbol, httpOptions )
.map(data => {
return data;
});
return this.http.post<any>(this.apiUrl, newWatchingSymbol, httpOptions)
.map(data => {
return data;
});
}
removeFromWatching( id ){
removeFromWatching(id) {
let apiUrl = "api/watching/" + id;
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
return this.http.delete<any>(apiUrl, httpOptions )
.map(data => {
return data;
});
return this.http.delete<any>(apiUrl, httpOptions)
.map(data => {
return data;
});
}

View File

@@ -26,10 +26,12 @@ export class StockViewComponent implements OnInit {
this.emitcomService.change.subscribe(data => {
/* check com's sent by other components and apply actions as needed */
if (data.type == "action" && data.data == "destroyChart") {
/* destory the chart, could update maybe i'll change it when the time comes up */
if (this.chart !== undefined) {
this.chart.destroy();
}
} else if (data.type == "ipo") {
/* local method for service call for the IEX API passing the symbol and time frame (one month for now) */
this.getStockByChart(data.data, "1m");
}
});
@@ -38,49 +40,51 @@ export class StockViewComponent implements OnInit {
getStockByChart(symbol, timeFrame) {
/* As called above this is just the service call for the IEX API*/
this.stockService.getCharByTime(symbol, timeFrame)
.subscribe(
data => {
if (data.length > 0) {
let date = data.map(data => data.date);
let close = data.map(data => data.close);
/* map out arrays for the x and y axis ( day closing date and IPO value ) */
let date = data.map(data => data.date);
let close = data.map(data => data.close);
if (this.chart !== undefined) {
this.chart.destroy();
/* just to be on the save side check the status of the chart and destory as needed. */
if (this.chart !== undefined) {
this.chart.destroy();
}
/* Create new chart with basic configuration passing the chart reference defind above */
this.chart = new Chart(this.chartRef.nativeElement, {
type: 'line',
data: {
labels: date,
datasets: [{
data: close,
borderColor: '#0097A7',
fill: false
}]
},
options: {
legend: {
display: false
},
scales: {
xAxes: [{
display: true
}],
yAxes: [{
display: true
}]
}
this.chart = new Chart(this.chartRef.nativeElement, {
type: 'line',
data: {
labels: date,
datasets: [{
data: close,
borderColor: '#0097A7',
fill: false
}]
},
options: {
legend: {
display: false
},
scales: {
xAxes: [{
display: true
}],
yAxes: [{
display: true
}]
}
}
});
}
});
},
error => {
/* Something went south send notification */
/* Something went south, send notification? maybe modal or snack bar */
});
}

View File

@@ -5,28 +5,22 @@
<h2>Watch List</h2>
</mat-card-title>
</mat-card-header>
<!-- For the love that is all good and holy take the time to reconstruct the data and switch this to a table! -->
<div>
<div>
<mat-nav-list>
<mat-list-item *ngFor="let symbol of watchingSymbols">
<div class="watchingContainer">
<img class="ipoMiniLogo" src="{{watchingIpos[symbol.symbol].logo.url}}" (error)="imgError($event)">
<span class="mockTable" (click)="onSelect(watchingIpos[symbol.symbol].quote.symbol)" >{{watchingIpos[symbol.symbol].quote.companyName}}</span>
<span class="mockTable" >Symbol:<br />{{watchingIpos[symbol.symbol].quote.symbol}}</span>
<span class="mockTable" >Updated:<br />{{watchingIpos[symbol.symbol].quote.latestTime}}</span>
<span class="mockTable" >Day High:<br />{{watchingIpos[symbol.symbol].quote.high | currency }}</span>
<span class="mockTable" >Day Low:<br />{{watchingIpos[symbol.symbol].quote.low | currency }}</span>
<mat-icon (click)="removeFromWatching(symbol.id)" class="removeFromWatchListIcon" fontSet="fa" fontIcon="fa-minus-circle" ></mat-icon>
</div>
</mat-list-item>
</mat-nav-list>
</div>
<mat-list-item *ngFor="let symbol of watchingSymbols">
<div class="watchingContainer">
<img class="ipoMiniLogo" src="{{watchingIpos[symbol.symbol].logo.url}}" (error)="imgError($event)">
<span class="mockTable" (click)="onSelect(watchingIpos[symbol.symbol].quote.symbol)">{{watchingIpos[symbol.symbol].quote.companyName}}</span>
<span class="mockTable">Symbol:<br />{{watchingIpos[symbol.symbol].quote.symbol}}</span>
<span class="mockTable">Updated:<br />{{watchingIpos[symbol.symbol].quote.latestTime}}</span>
<span class="mockTable">Day High:<br />{{watchingIpos[symbol.symbol].quote.high | currency }}</span>
<span class="mockTable">Day Low:<br />{{watchingIpos[symbol.symbol].quote.low | currency }}</span>
<mat-icon (click)="removeFromWatching(symbol.id)" class="removeFromWatchListIcon" fontSet="fa" fontIcon="fa-minus-circle"></mat-icon>
</div>
</mat-list-item>
</mat-nav-list>
</div>

View File

@@ -23,83 +23,66 @@ export class WatcherViewComponent implements OnInit {
this.getwatcherList();
/* Just like in the other component we are going to subscribe to the same service and listen for events. */
this.emitcomService.change.subscribe(data => {
if( data.type == "action" && data.data == "updateWatcher" ){
/* This will update the watch list */
if (data.type == "action" && data.data == "updateWatcher") {
this.getwatcherList();
}
});
}
getwatcherList( ){
getwatcherList() {
this.watcherService.getWatching( )
.subscribe(
data => {
if( Object.keys(data).length === 0 ){
/* We only have to check for the object key becasue i'm not great with regex... */
/* If nothing is found do nothing */
}else{
/* Now that we have the search results and company IPO logos to match we can set the data and let the template take over. */
//this.searchResults = companySearchResults;
//this.searchResultLogos = data;
console.log( data )
let symbols = data.map(data => data.symbol);
this.getIpoBulkData(symbols, data);
console.log( symbols )
}
},
error => {
console.log( "error" );
});
this.watcherService.getWatching()
.subscribe(
data => {
/* We are going to map out the symbols for the next service call but still pass the raw return so we can use the ID'd later for remvoing items from the DB */
let symbols = data.map(data => data.symbol);
this.getIpoBulkData(symbols, data);
},
error => {
/* A 404 can happen if nothing is returned and thats ok, it would be possible that the watcher DB is empty */
});
}
getIpoBulkData( symbols, rawData ){
this.stockService.getIpoBulkData( symbols )
.subscribe(
data => {
if( Object.keys(data).length === 0 ){
/* We only have to check for the object key becasue i'm not great with regex... */
/* If nothing is found do nothing */
}else{
/* Now that we have the search results and company IPO logos to match we can set the data and let the template take over. */
//this.searchResults = companySearchResults;
//this.searchResultLogos = data;
console.log( data )
getIpoBulkData(symbols, rawData) {
this.stockService.getIpoBulkData(symbols)
.subscribe(
data => {
/* Now that we have data we can pass the rest to the template and do done! */
this.watchingIpos = data;
this.watchingSymbols = rawData;
console.log( symbols )
//let symbols = data.map(data => data.symbol);
//this.ipoBulkData(symbols);
}
},
error => {
console.log( "error" );
});
},
error => {
/* Something went wrong with the API, alert user and do something or notrhing? */
});
}
imgError( event ){
event.target.src = "http://www.lazypug.net/img/pug.jpg";
/* Now I need to move this to a helper class as it's used more than once */
imgError(event) {
event.target.src = "http://www.lazypug.net/img/pug.jpg";
}
removeFromWatching( id ){
removeFromWatching(id) {
this.watcherService.removeFromWatching( id )
.subscribe(
data => {
this.getwatcherList();
},
error => {
console.log( "error" );
});
/* Does an out of the box http delete call on the mock DB */
this.watcherService.removeFromWatching(id)
.subscribe(
data => {
/* Once complete rebuild the list */
this.getwatcherList();
},
error => {
/* Something went wrong, alert user and do something or notrhing? */
});
}
onSelect( selectedSymbol ){
/* On user click call sendData method on the service to emit an event to be picked up on the stock-view componet */
this.emitcomService.sendData( selectedSymbol );
}
onSelect(selectedSymbol) {
/* On user click call sendData method on the service to emit an event to be picked up on the stock-view componet for the chart */
this.emitcomService.sendData(selectedSymbol);
}
}