Finished all main functions
This commit is contained in:
3420
package-lock.json
generated
3420
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
src/app/_guards/auth.guard.ts
Normal file
17
src/app/_guards/auth.guard.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class AuthGuard implements CanActivate {
|
||||||
|
|
||||||
|
constructor(private router: Router) { }
|
||||||
|
|
||||||
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||||
|
if (localStorage.getItem('currentUser')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.router.navigate( ['login'] );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,9 +38,11 @@ export class InMemoryDataService implements InMemoryDbService {
|
|||||||
|
|
||||||
let watching = [
|
let watching = [
|
||||||
{
|
{
|
||||||
|
id:3,
|
||||||
symbol: "MSFT"
|
symbol: "MSFT"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id:4,
|
||||||
symbol: "GOOGL"
|
symbol: "GOOGL"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ export class EmitcomService {
|
|||||||
this.change.emit( sendData );
|
this.change.emit( sendData );
|
||||||
}
|
}
|
||||||
|
|
||||||
addToWatcher( data: string ){
|
updateWatcher( ){
|
||||||
let sendData ={
|
let sendData ={
|
||||||
type: "watcher",
|
type: "action",
|
||||||
data: data
|
data: "updateWatcher"
|
||||||
};
|
};
|
||||||
this.change.emit( sendData );
|
this.change.emit( sendData );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import 'rxjs/add/operator/map'
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export class WatcherService {
|
export class WatcherService {
|
||||||
|
|
||||||
private apiUrl = "api/watching/";
|
private apiUrl = "api/watching/";
|
||||||
@@ -22,7 +25,36 @@ export class WatcherService {
|
|||||||
.map(data => {
|
.map(data => {
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addWatching( symbol ){
|
||||||
|
let newWatchingSymbol = {
|
||||||
|
symbol: symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
const httpOptions = {
|
||||||
|
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.http.post<any>(this.apiUrl, newWatchingSymbol, httpOptions )
|
||||||
|
.map(data => {
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import { RouterModule, Routes } from '@angular/router';
|
|||||||
import { LoginComponent } from './login/login.component';
|
import { LoginComponent } from './login/login.component';
|
||||||
import { HomeComponent } from './home/home.component';
|
import { HomeComponent } from './home/home.component';
|
||||||
import { UserAdminComponent } from './user-admin/user-admin.component';
|
import { UserAdminComponent } from './user-admin/user-admin.component';
|
||||||
|
import { AuthGuard } from './_guards/auth.guard';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
/* default path sends users to login */
|
/* default path sends users to login */
|
||||||
{ path: '', redirectTo: '/login', pathMatch: 'full' },
|
{ path: '', redirectTo: '/login', pathMatch: 'full' },
|
||||||
/* component paths */
|
/* component paths */
|
||||||
{ path: 'login', component: LoginComponent },
|
{ path: 'login', component: LoginComponent },
|
||||||
{ path: 'home', component: HomeComponent },
|
{ path: 'home', component: HomeComponent, canActivate: [AuthGuard] },
|
||||||
{ path: 'user-admin', component: UserAdminComponent }
|
{ path: 'user-admin', component: UserAdminComponent, canActivate: [AuthGuard] }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { InMemoryDataService } from './_mockdata/mock-data-nasdaq';
|
|||||||
import { AlertComponent } from './_helpers/alert.component';
|
import { AlertComponent } from './_helpers/alert.component';
|
||||||
import { AlertService } from './_services/alert.service';
|
import { AlertService } from './_services/alert.service';
|
||||||
import { EmitcomService } from './_services/emitcom.service';
|
import { EmitcomService } from './_services/emitcom.service';
|
||||||
|
import { AuthGuard } from './_guards/auth.guard';
|
||||||
|
|
||||||
import { AppRoutingModule } from './/app-routing.module';
|
import { AppRoutingModule } from './/app-routing.module';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
@@ -29,6 +30,7 @@ import { MatIconRegistry } from "@angular/material";
|
|||||||
import { MatDividerModule } from '@angular/material/divider';
|
import { MatDividerModule } from '@angular/material/divider';
|
||||||
import { MatListModule } from '@angular/material/list';
|
import { MatListModule } from '@angular/material/list';
|
||||||
import { WatcherViewComponent } from './watcher-view/watcher-view.component';
|
import { WatcherViewComponent } from './watcher-view/watcher-view.component';
|
||||||
|
import {MatMenuModule} from '@angular/material/menu';
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@@ -58,12 +60,14 @@ import { WatcherViewComponent } from './watcher-view/watcher-view.component';
|
|||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatDividerModule,
|
MatDividerModule,
|
||||||
MatListModule,
|
MatListModule,
|
||||||
JsonpModule
|
JsonpModule,
|
||||||
|
MatMenuModule
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
AlertService,
|
AlertService,
|
||||||
EmitcomService,
|
EmitcomService,
|
||||||
MatIconRegistry
|
MatIconRegistry,
|
||||||
|
AuthGuard
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -31,4 +31,13 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items:center;
|
align-items:center;
|
||||||
color: #018786;
|
color: #018786;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header{
|
||||||
|
font-size: 21px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mat-card-title{
|
||||||
|
margin: 0px;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,22 @@
|
|||||||
<div class="cardContainer">
|
<div class="cardContainer">
|
||||||
<mat-card id="searchCard">
|
<mat-card id="searchCard">
|
||||||
<mat-card-header>
|
<mat-card-header class="fullWidth">
|
||||||
<mat-card-title>
|
<div class="ipoContainer">
|
||||||
<h2>Search IPO's</h2>
|
<mat-card-title>
|
||||||
</mat-card-title>
|
<h2>Search IPO's</h2>
|
||||||
|
</mat-card-title>
|
||||||
|
<div class="spacer"></div>
|
||||||
|
|
||||||
|
<button mat-icon-button [matMenuTriggerFor]="menu">
|
||||||
|
<mat-icon class="addWatchListIcon" fontSet="fa" fontIcon="fa-bars" ></mat-icon>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<mat-menu #menu="matMenu">
|
||||||
|
<button mat-menu-item>Item 1</button>
|
||||||
|
<button mat-menu-item>Item 2</button>
|
||||||
|
</mat-menu>
|
||||||
|
</div>
|
||||||
|
|
||||||
</mat-card-header>
|
</mat-card-header>
|
||||||
<mat-form-field class="fullWidth">
|
<mat-form-field class="fullWidth">
|
||||||
<input matInput placeholder="Company"
|
<input matInput placeholder="Company"
|
||||||
@@ -22,7 +35,7 @@
|
|||||||
<img class="ipoMiniLogo" src="{{searchResultLogos[company.Symbol].logo.url}}" (error)="imgError($event)">
|
<img class="ipoMiniLogo" src="{{searchResultLogos[company.Symbol].logo.url}}" (error)="imgError($event)">
|
||||||
<span (click)="onSelect(company.Symbol)" >{{company.Name}}</span>
|
<span (click)="onSelect(company.Symbol)" >{{company.Name}}</span>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
<mat-icon class="addWatchListIcon" fontSet="fa" fontIcon="fa-plus-circle" ></mat-icon>
|
<mat-icon (click)="addToWatching(company.Symbol)" class="addWatchListIcon" fontSet="fa" fontIcon="fa-plus-circle" ></mat-icon>
|
||||||
</div>
|
</div>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</mat-nav-list>
|
</mat-nav-list>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Component, OnInit, HostListener } from '@angular/core';
|
|||||||
import { EmitcomService } from '../_services/emitcom.service';
|
import { EmitcomService } from '../_services/emitcom.service';
|
||||||
import { NasdaqSearchService } from '../_services/nasdaq-search.service';
|
import { NasdaqSearchService } from '../_services/nasdaq-search.service';
|
||||||
import { StockService } from '../_services/stock.service';
|
import { StockService } from '../_services/stock.service';
|
||||||
|
import { WatcherService } from '../_services/watcher.service';
|
||||||
import { AlertService } from '../_services/alert.service';
|
import { AlertService } from '../_services/alert.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -19,7 +20,8 @@ export class SearchViewComponent implements OnInit {
|
|||||||
private emitcomService: EmitcomService,
|
private emitcomService: EmitcomService,
|
||||||
private nasdaqSearchService: NasdaqSearchService,
|
private nasdaqSearchService: NasdaqSearchService,
|
||||||
private stockService: StockService,
|
private stockService: StockService,
|
||||||
private alertService: AlertService
|
private alertService: AlertService,
|
||||||
|
private watcherService: WatcherService
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@@ -83,6 +85,27 @@ export class SearchViewComponent implements OnInit {
|
|||||||
this.emitcomService.sendData( selectedSymbol );
|
this.emitcomService.sendData( selectedSymbol );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addToWatching( symbol ){
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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. */
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
clearIpoList(){
|
clearIpoList(){
|
||||||
this.searchResults = null;
|
this.searchResults = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,6 @@
|
|||||||
@media only screen and (min-width : 600px){
|
@media only screen and (min-width : 600px) and (max-width: 1199px){
|
||||||
#watcherCard{
|
#watcherCard{
|
||||||
width: 400px;
|
display: none;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (min-width : 800px){
|
|
||||||
#watcherCard{
|
|
||||||
width: 600px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (min-width : 1000px) {
|
|
||||||
#watcherCard{
|
|
||||||
width: 900px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,4 +14,35 @@
|
|||||||
#watcherCard{
|
#watcherCard{
|
||||||
width: 1200px;
|
width: 1200px;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.mat-nav-list .mat-list-item {
|
||||||
|
height:45px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.watchingContainer{
|
||||||
|
width:100%;
|
||||||
|
display: flex;
|
||||||
|
align-items:center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ipoMiniLogo{
|
||||||
|
width:35px;
|
||||||
|
height: auto;
|
||||||
|
border-radius: 50%;
|
||||||
|
text-align: right;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mockTable{
|
||||||
|
width:200px;
|
||||||
|
margin: 0px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.removeFromWatchListIcon{
|
||||||
|
width:auto;
|
||||||
|
font-size: 25px;
|
||||||
|
display: flex;
|
||||||
|
align-items:center;
|
||||||
|
color: #018786;
|
||||||
}
|
}
|
||||||
@@ -11,11 +11,14 @@
|
|||||||
<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="ipoContainer">
|
<div class="watchingContainer">
|
||||||
|
<img class="ipoMiniLogo" src="{{watchingIpos[symbol.symbol].logo.url}}" (error)="imgError($event)">
|
||||||
<span>{{watchingIpos[symbol].quote.companyName}}</span>
|
<span class="mockTable" (click)="onSelect(watchingIpos[symbol.symbol].quote.symbol)" >{{watchingIpos[symbol.symbol].quote.companyName}}</span>
|
||||||
<div class="spacer"></div>
|
<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>
|
</div>
|
||||||
</mat-list-item>
|
</mat-list-item>
|
||||||
</mat-nav-list>
|
</mat-nav-list>
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ export class WatcherViewComponent implements OnInit {
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
this.getwatcherList();
|
this.getwatcherList();
|
||||||
|
|
||||||
|
this.emitcomService.change.subscribe(data => {
|
||||||
|
if( data.type == "action" && data.data == "updateWatcher" ){
|
||||||
|
this.getwatcherList();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getwatcherList( ){
|
getwatcherList( ){
|
||||||
@@ -38,7 +45,7 @@ export class WatcherViewComponent implements OnInit {
|
|||||||
//this.searchResultLogos = data;
|
//this.searchResultLogos = data;
|
||||||
console.log( data )
|
console.log( data )
|
||||||
let symbols = data.map(data => data.symbol);
|
let symbols = data.map(data => data.symbol);
|
||||||
this.getIpoBulkData(symbols);
|
this.getIpoBulkData(symbols, data);
|
||||||
console.log( symbols )
|
console.log( symbols )
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -49,7 +56,7 @@ export class WatcherViewComponent implements OnInit {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getIpoBulkData( symbols ){
|
getIpoBulkData( symbols, rawData ){
|
||||||
this.stockService.getIpoBulkData( symbols )
|
this.stockService.getIpoBulkData( symbols )
|
||||||
.subscribe(
|
.subscribe(
|
||||||
data => {
|
data => {
|
||||||
@@ -62,7 +69,8 @@ export class WatcherViewComponent implements OnInit {
|
|||||||
//this.searchResultLogos = data;
|
//this.searchResultLogos = data;
|
||||||
console.log( data )
|
console.log( data )
|
||||||
this.watchingIpos = data;
|
this.watchingIpos = data;
|
||||||
this.watchingSymbols = symbols;
|
this.watchingSymbols = rawData;
|
||||||
|
console.log( symbols )
|
||||||
//let symbols = data.map(data => data.symbol);
|
//let symbols = data.map(data => data.symbol);
|
||||||
//this.ipoBulkData(symbols);
|
//this.ipoBulkData(symbols);
|
||||||
|
|
||||||
@@ -73,4 +81,25 @@ export class WatcherViewComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imgError( event ){
|
||||||
|
event.target.src = "http://www.lazypug.net/img/pug.jpg";
|
||||||
|
}
|
||||||
|
|
||||||
|
removeFromWatching( id ){
|
||||||
|
|
||||||
|
this.watcherService.removeFromWatching( id )
|
||||||
|
.subscribe(
|
||||||
|
data => {
|
||||||
|
this.getwatcherList();
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.log( "error" );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user