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

@@ -1,11 +1,8 @@
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'
})

View File

@@ -1,9 +1,6 @@
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 = {

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({

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,19 +40,21 @@ 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) {
/* 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);
/* 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: {
@@ -76,11 +80,11 @@ export class StockViewComponent implements OnInit {
}
});
}
},
error => {
/* Something went south send notification */
/* Something went south, send notification? maybe modal or snack bar */
});
}

View File

@@ -5,9 +5,8 @@
<h2>Watch List</h2>
</mat-card-title>
</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>
<mat-nav-list>
<mat-list-item *ngFor="let symbol of watchingSymbols">
@@ -25,10 +24,5 @@
</div>
</div>
</mat-card>
</div>

View File

@@ -23,7 +23,9 @@ 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 => {
/* This will update the watch list */
if (data.type == "action" && data.data == "updateWatcher") {
this.getwatcherList();
}
@@ -36,22 +38,12 @@ export class WatcherViewComponent implements OnInit {
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 )
/* 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);
console.log( symbols )
}
},
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 */
});
}
@@ -60,45 +52,36 @@ export class WatcherViewComponent implements OnInit {
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 )
/* 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" );
/* Something went wrong with the API, alert user and do something or notrhing? */
});
}
/* 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) {
/* 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 => {
console.log( "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 */
/* 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);
}