more clean up
This commit is contained in:
@@ -1,6 +0,0 @@
|
|||||||
import { AlertType } from '../_classes/alertType';
|
|
||||||
|
|
||||||
export class Alert {
|
|
||||||
type: AlertType;
|
|
||||||
message: string;
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
export enum AlertType {
|
|
||||||
Success,
|
|
||||||
Error,
|
|
||||||
Info,
|
|
||||||
Warning
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
export class Stock {
|
|
||||||
Symbol: string;
|
|
||||||
Name: string;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
//import { stock } from './stock';
|
|
||||||
|
|
||||||
export class stockPortfolio{
|
|
||||||
bought: number;
|
|
||||||
sold: number;
|
|
||||||
shares: number;
|
|
||||||
}
|
|
||||||
@@ -6,11 +6,16 @@ export class AuthGuard implements CanActivate {
|
|||||||
|
|
||||||
constructor(private router: Router) { }
|
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) {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||||
if (localStorage.getItem('currentUser')) {
|
if (localStorage.getItem('currentUser')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If not then kick them back to the login page */
|
||||||
this.router.navigate( ['login'] );
|
this.router.navigate( ['login'] );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,28 +5,28 @@ export class EmitcomService {
|
|||||||
|
|
||||||
@Output() change: EventEmitter<any> = new EventEmitter();
|
@Output() change: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
sendData( data: string ) {
|
sendData(data: string) {
|
||||||
let sendData ={
|
let sendData = {
|
||||||
type: "ipo",
|
type: "ipo",
|
||||||
data: data
|
data: data
|
||||||
};
|
};
|
||||||
this.change.emit( sendData );
|
this.change.emit(sendData);
|
||||||
}
|
}
|
||||||
|
|
||||||
destroyChart() {
|
destroyChart() {
|
||||||
let sendData ={
|
let sendData = {
|
||||||
type: "action",
|
type: "action",
|
||||||
data: "destroyChart"
|
data: "destroyChart"
|
||||||
};
|
};
|
||||||
this.change.emit( sendData );
|
this.change.emit(sendData);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateWatcher( ){
|
updateWatcher() {
|
||||||
let sendData ={
|
let sendData = {
|
||||||
type: "action",
|
type: "action",
|
||||||
data: "updateWatcher"
|
data: "updateWatcher"
|
||||||
};
|
};
|
||||||
this.change.emit( sendData );
|
this.change.emit(sendData);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ export class LoginService {
|
|||||||
private http: HttpClient
|
private http: HttpClient
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
login(userData : any) {
|
login(userData: any) {
|
||||||
/* Look at that god like RegEX... We got a ^ AND a ?. /s */
|
/* 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 */
|
/* Run the request expecting a user class back */
|
||||||
return this.http.get<User>(url)
|
return this.http.get<User>(url)
|
||||||
.map(user => {
|
.map(user => {
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
import 'rxjs/add/operator/map'
|
import 'rxjs/add/operator/map'
|
||||||
|
|
||||||
//import { Stock } from '../_classes/stock';
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import {JsonpModule, Jsonp, Response} from '@angular/http';
|
import { Jsonp } from '@angular/http';
|
||||||
|
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
import 'rxjs/add/operator/map'
|
import 'rxjs/add/operator/map'
|
||||||
|
|
||||||
const httpOptions = {
|
const httpOptions = {
|
||||||
@@ -20,13 +17,13 @@ export class StockService {
|
|||||||
private jsonp: Jsonp
|
private jsonp: Jsonp
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
getLogos( symbols ) {
|
getLogos(symbols) {
|
||||||
|
|
||||||
var symbolsComma = "";
|
var symbolsComma = "";
|
||||||
var commaCheck = false;
|
var commaCheck = false;
|
||||||
|
|
||||||
for( var symbol in symbols ){
|
for (var symbol in symbols) {
|
||||||
if( commaCheck ){
|
if (commaCheck) {
|
||||||
symbolsComma += ",";
|
symbolsComma += ",";
|
||||||
}
|
}
|
||||||
commaCheck = true;
|
commaCheck = true;
|
||||||
@@ -42,7 +39,7 @@ export class StockService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCharByTime( symbol, timeFrame ){
|
getCharByTime(symbol, timeFrame) {
|
||||||
const url2 = "https://api.iextrading.com/1.0/stock/" + symbol + "/chart/1m?callback=JSONP_CALLBACK";
|
const url2 = "https://api.iextrading.com/1.0/stock/" + symbol + "/chart/1m?callback=JSONP_CALLBACK";
|
||||||
return this.jsonp.request(url2)
|
return this.jsonp.request(url2)
|
||||||
.map(chartData => {
|
.map(chartData => {
|
||||||
@@ -50,12 +47,12 @@ export class StockService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getIpoBulkData( symbols ){
|
getIpoBulkData(symbols) {
|
||||||
var symbolsComma = "";
|
var symbolsComma = "";
|
||||||
var commaCheck = false;
|
var commaCheck = false;
|
||||||
|
|
||||||
for( var symbol in symbols ){
|
for (var symbol in symbols) {
|
||||||
if( commaCheck ){
|
if (commaCheck) {
|
||||||
symbolsComma += ",";
|
symbolsComma += ",";
|
||||||
}
|
}
|
||||||
commaCheck = true;
|
commaCheck = true;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
@@ -27,7 +27,7 @@ export class WatcherService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addWatching( symbol ){
|
addWatching(symbol) {
|
||||||
let newWatchingSymbol = {
|
let newWatchingSymbol = {
|
||||||
symbol: symbol
|
symbol: symbol
|
||||||
}
|
}
|
||||||
@@ -36,20 +36,20 @@ export class WatcherService {
|
|||||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.http.post<any>(this.apiUrl, newWatchingSymbol, httpOptions )
|
return this.http.post<any>(this.apiUrl, newWatchingSymbol, httpOptions)
|
||||||
.map(data => {
|
.map(data => {
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeFromWatching( id ){
|
removeFromWatching(id) {
|
||||||
let apiUrl = "api/watching/" + id;
|
let apiUrl = "api/watching/" + id;
|
||||||
const httpOptions = {
|
const httpOptions = {
|
||||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.http.delete<any>(apiUrl, httpOptions )
|
return this.http.delete<any>(apiUrl, httpOptions)
|
||||||
.map(data => {
|
.map(data => {
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ export class StockViewComponent implements OnInit {
|
|||||||
this.emitcomService.change.subscribe(data => {
|
this.emitcomService.change.subscribe(data => {
|
||||||
/* check com's sent by other components and apply actions as needed */
|
/* check com's sent by other components and apply actions as needed */
|
||||||
if (data.type == "action" && data.data == "destroyChart") {
|
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) {
|
if (this.chart !== undefined) {
|
||||||
this.chart.destroy();
|
this.chart.destroy();
|
||||||
}
|
}
|
||||||
} else if (data.type == "ipo") {
|
} 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");
|
this.getStockByChart(data.data, "1m");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -38,19 +40,21 @@ export class StockViewComponent implements OnInit {
|
|||||||
|
|
||||||
getStockByChart(symbol, timeFrame) {
|
getStockByChart(symbol, timeFrame) {
|
||||||
|
|
||||||
|
/* As called above this is just the service call for the IEX API*/
|
||||||
this.stockService.getCharByTime(symbol, timeFrame)
|
this.stockService.getCharByTime(symbol, timeFrame)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
data => {
|
data => {
|
||||||
if (data.length > 0) {
|
|
||||||
|
|
||||||
|
/* map out arrays for the x and y axis ( day closing date and IPO value ) */
|
||||||
let date = data.map(data => data.date);
|
let date = data.map(data => data.date);
|
||||||
let close = data.map(data => data.close);
|
let close = data.map(data => data.close);
|
||||||
|
|
||||||
|
/* just to be on the save side check the status of the chart and destory as needed. */
|
||||||
if (this.chart !== undefined) {
|
if (this.chart !== undefined) {
|
||||||
this.chart.destroy();
|
this.chart.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create new chart with basic configuration passing the chart reference defind above */
|
||||||
this.chart = new Chart(this.chartRef.nativeElement, {
|
this.chart = new Chart(this.chartRef.nativeElement, {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: {
|
data: {
|
||||||
@@ -76,11 +80,11 @@ export class StockViewComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
/* Something went south send notification */
|
/* Something went south, send notification? maybe modal or snack bar */
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,30 +5,24 @@
|
|||||||
<h2>Watch List</h2>
|
<h2>Watch List</h2>
|
||||||
</mat-card-title>
|
</mat-card-title>
|
||||||
</mat-card-header>
|
</mat-card-header>
|
||||||
<div>
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 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-nav-list>
|
||||||
<mat-list-item *ngFor="let symbol of watchingSymbols">
|
<mat-list-item *ngFor="let symbol of watchingSymbols">
|
||||||
<div class="watchingContainer">
|
<div class="watchingContainer">
|
||||||
<img class="ipoMiniLogo" src="{{watchingIpos[symbol.symbol].logo.url}}" (error)="imgError($event)">
|
<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" (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">Symbol:<br />{{watchingIpos[symbol.symbol].quote.symbol}}</span>
|
||||||
<span class="mockTable" >Updated:<br />{{watchingIpos[symbol.symbol].quote.latestTime}}</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 High:<br />{{watchingIpos[symbol.symbol].quote.high | currency }}</span>
|
||||||
<span class="mockTable" >Day Low:<br />{{watchingIpos[symbol.symbol].quote.low | 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>
|
<mat-icon (click)="removeFromWatching(symbol.id)" class="removeFromWatchListIcon" fontSet="fa" fontIcon="fa-minus-circle"></mat-icon>
|
||||||
</div>
|
</div>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</mat-nav-list>
|
</mat-nav-list>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</mat-card>
|
</mat-card>
|
||||||
</div>
|
</div>
|
||||||
@@ -23,83 +23,66 @@ export class WatcherViewComponent implements OnInit {
|
|||||||
|
|
||||||
this.getwatcherList();
|
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 => {
|
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();
|
this.getwatcherList();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getwatcherList( ){
|
getwatcherList() {
|
||||||
|
|
||||||
this.watcherService.getWatching( )
|
this.watcherService.getWatching()
|
||||||
.subscribe(
|
.subscribe(
|
||||||
data => {
|
data => {
|
||||||
if( Object.keys(data).length === 0 ){
|
/* 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 */
|
||||||
/* 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);
|
let symbols = data.map(data => data.symbol);
|
||||||
this.getIpoBulkData(symbols, data);
|
this.getIpoBulkData(symbols, data);
|
||||||
console.log( symbols )
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log( "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 ){
|
getIpoBulkData(symbols, rawData) {
|
||||||
this.stockService.getIpoBulkData( symbols )
|
this.stockService.getIpoBulkData(symbols)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
data => {
|
data => {
|
||||||
if( Object.keys(data).length === 0 ){
|
/* Now that we have data we can pass the rest to the template and do done! */
|
||||||
/* 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 )
|
|
||||||
this.watchingIpos = data;
|
this.watchingIpos = data;
|
||||||
this.watchingSymbols = rawData;
|
this.watchingSymbols = rawData;
|
||||||
console.log( symbols )
|
|
||||||
//let symbols = data.map(data => data.symbol);
|
|
||||||
//this.ipoBulkData(symbols);
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log( "error" );
|
/* Something went wrong with the API, alert user and do something or notrhing? */
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
imgError( event ){
|
/* 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";
|
event.target.src = "http://www.lazypug.net/img/pug.jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
removeFromWatching( id ){
|
removeFromWatching(id) {
|
||||||
|
|
||||||
this.watcherService.removeFromWatching( id )
|
/* Does an out of the box http delete call on the mock DB */
|
||||||
|
this.watcherService.removeFromWatching(id)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
data => {
|
data => {
|
||||||
|
/* Once complete rebuild the list */
|
||||||
this.getwatcherList();
|
this.getwatcherList();
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log( "error" );
|
/* Something went wrong, alert user and do something or notrhing? */
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelect( 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 */
|
/* 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 );
|
this.emitcomService.sendData(selectedSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user