+
\ No newline at end of file
diff --git a/src/app/search-view/search-view.component.ts b/src/app/search-view/search-view.component.ts
index fdaa680..8b0e073 100644
--- a/src/app/search-view/search-view.component.ts
+++ b/src/app/search-view/search-view.component.ts
@@ -1,10 +1,10 @@
import { Component, OnInit, HostListener } from '@angular/core';
-
+import { Router } from '@angular/router';
import { EmitcomService } from '../_services/emitcom.service';
import { NasdaqSearchService } from '../_services/nasdaq-search.service';
import { StockService } from '../_services/stock.service';
import { WatcherService } from '../_services/watcher.service';
-import { AlertService } from '../_services/alert.service';
+
@Component({
selector: 'app-search-view',
@@ -20,8 +20,8 @@ export class SearchViewComponent implements OnInit {
private emitcomService: EmitcomService,
private nasdaqSearchService: NasdaqSearchService,
private stockService: StockService,
- private alertService: AlertService,
- private watcherService: WatcherService
+ private watcherService: WatcherService,
+ private router: Router
) { }
ngOnInit() {
@@ -31,15 +31,13 @@ export class SearchViewComponent implements OnInit {
searchCompany( searchData ){
/* clear out IPO list at each key press */
this.clearIpoList();
- this.alertService.clear();
-
+
if( searchData.length >= 3 ){
this.nasdaqSearchService.query( searchData )
.subscribe(
data => {
if( Object.keys(data).length === 0 ){
/* We only need this here becasue i'm not great at regular expressions */
- this.alertService.error( "No IPO's Found" );
}else{
if( data.length > 0 ){
/* Data found in mock DB slice out the first six results and call method for logos. */
@@ -48,10 +46,10 @@ export class SearchViewComponent implements OnInit {
}
},
error => {
- /* 404 not found in mock DB send alert to user. */
- this.alertService.error( "No IPO's Found" );
+ /* 404 not found in mock DB. */
});
}else if( searchData.length === 0 ){
+ /* Emit event to clear chart when search bar is empty*/
this.emitcomService.destroyChart();
}
}
@@ -71,11 +69,12 @@ export class SearchViewComponent implements OnInit {
}
},
error => {
- /* in this circumstance we don't care about error as the logo return is static from the service. We will find another way to validate images. */
+ /* in this circumstance we don't care about error as the logo return is static from the service. We have another way to validate images. */
});
}
+ /* Move to helper class? */
imgError( event ){
event.target.src = "http://www.lazypug.net/img/pug.jpg";
}
@@ -89,20 +88,11 @@ export class SearchViewComponent implements OnInit {
this.watcherService.addWatching( symbol )
.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 )
- this.emitcomService.updateWatcher();
- }
+ /* send update to Watching componet to refresh list */
+ this.emitcomService.updateWatcher();
},
error => {
- console.log( error );
- /* in this circumstance we don't care about error as the logo return is static from the service. We will find another way to validate images. */
+ /* We could alert the user something went south but as this is a mock DB it won't fail :/ */
});
}
@@ -110,4 +100,8 @@ export class SearchViewComponent implements OnInit {
this.searchResults = null;
}
+ logout(){
+ this.router.navigate(["login"]);
+ }
+
}
diff --git a/src/app/stock-view/stock-view.component.ts b/src/app/stock-view/stock-view.component.ts
index 265a967..19a9f54 100644
--- a/src/app/stock-view/stock-view.component.ts
+++ b/src/app/stock-view/stock-view.component.ts
@@ -7,69 +7,53 @@ import * as Chart from 'chart.js'
selector: 'app-stock-view',
templateUrl: './stock-view.component.html',
styleUrls: ['./stock-view.component.css'],
-
+
})
export class StockViewComponent implements OnInit {
+
+ /* Grab the eleiment for the chart */
@ViewChild('chartView') private chartRef;
chart: any;
-
+
constructor(
- private emitcomService: EmitcomService,
+ private emitcomService: EmitcomService,
private stockService: StockService
- ) { }
+ ) { }
ngOnInit() {
-
+
this.emitcomService.change.subscribe(data => {
- if( data.type == "action" && data.data == "destroyChart" ){
- if( this.chart !== undefined ){
- this.chart.destroy();
- }
- }else if( data.type == "ipo" ){
- this.getStockByChart( data.data, "1m" );
+ /* check com's sent by other components and apply actions as needed */
+ if (data.type == "action" && data.data == "destroyChart") {
+ if (this.chart !== undefined) {
+ this.chart.destroy();
+ }
+ } else if (data.type == "ipo") {
+ this.getStockByChart(data.data, "1m");
}
-
});
-
-
}
+ getStockByChart(symbol, timeFrame) {
-
- getStockByChart( symbol, timeFrame ){
-
- this.stockService.getCharByTime( symbol, timeFrame )
+ this.stockService.getCharByTime(symbol, timeFrame)
.subscribe(
data => {
- if( Object.keys(data).length === 0 ){
- //this.alertService.error( "Bad username or password" );
- }else{
- //console.log(data[0].userName);
- //localStorage.setItem('currentUser', JSON.stringify(data[0]));
- //this.router.navigate(["home"]);
-
- //console.log( data );
- //this.searchResults = data;
- if( data.length > 0 ){
- console.log( data );
- //[n].close
- //[n].date
+ if (data.length > 0) {
+
let date = data.map(data => data.date);
let close = data.map(data => data.close);
- // console.log(date);
- // console.log(close);
-
- if( this.chart !== undefined ){
- this.chart.destroy();
+ if (this.chart !== undefined) {
+ this.chart.destroy();
}
-
+
this.chart = new Chart(this.chartRef.nativeElement, {
type: 'line',
- data:{
+ data: {
labels: date,
datasets: [{
data: close,
@@ -77,40 +61,28 @@ export class StockViewComponent implements OnInit {
fill: false
}]
},
- options:{
- legend:{
+ options: {
+ legend: {
display: false
},
- scales:{
- xAxes:[{
+ scales: {
+ xAxes: [{
display: true
}],
- yAxes:[{
+ yAxes: [{
display: true
}]
}
}
});
-
- /*
- let dates = [];
- dates.forEach((res) =>{
- let jsdate = new Date(res * 1000)
- dates.push( jsdate.toLocalTimeString('en') )
- })
- */
-
-
-
}
- }
+
},
error => {
- //console.log(error)
- //this.alertService.error( "Bad username or password" );
+ /* Something went south send notification */
});
-
+
}