-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f43a1ad
commit 0b2eab3
Showing
17 changed files
with
165 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
VirtualMind.WebApp/ClientApp/src/app/counter/counter.component.html
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
VirtualMind.WebApp/ClientApp/src/app/counter/counter.component.spec.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
VirtualMind.WebApp/ClientApp/src/app/counter/counter.component.ts
This file was deleted.
Oops, something went wrong.
47 changes: 26 additions & 21 deletions
47
VirtualMind.WebApp/ClientApp/src/app/fetch-data/fetch-data.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
<h1 id="tableLabel">Weather forecast</h1> | ||
<h1 id="tableLabel">Quotes</h1> | ||
|
||
<p>This component demonstrates fetching data from the server.</p> | ||
<p> Look the quotation of the day</p> | ||
|
||
<p *ngIf="!forecasts"><em>Loading...</em></p> | ||
<div *ngIf="dolar"> | ||
<h4>DOLAR (USD)</h4> | ||
<div> | ||
<ul> | ||
<li>Purchase Value: {{ dolar.purchase }}</li> | ||
<li>Sale Value: {{ dolar.sale }}</li> | ||
<li>Last Update: {{ dolar.lastUpdate }}</li> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
|
||
<div *ngIf="real"> | ||
<h4>REAL (BRL)</h4> | ||
<div> | ||
<ul> | ||
<li>Purchase Value: {{ real.purchase }}</li> | ||
<li>Sale Value: {{ real.sale }}</li> | ||
<li>Last Update: {{ real.lastUpdate }}</li> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<button (click)="getAllQuote()">Update Quotation</button> | ||
|
||
<table class='table table-striped' aria-labelledby="tableLabel" *ngIf="forecasts"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Temp. (C)</th> | ||
<th>Temp. (F)</th> | ||
<th>Summary</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr *ngFor="let forecast of forecasts"> | ||
<td>{{ forecast.date }}</td> | ||
<td>{{ forecast.temperatureC }}</td> | ||
<td>{{ forecast.temperatureF }}</td> | ||
<td>{{ forecast.summary }}</td> | ||
</tr> | ||
</tbody> | ||
</table> |
51 changes: 41 additions & 10 deletions
51
VirtualMind.WebApp/ClientApp/src/app/fetch-data/fetch-data.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,54 @@ | ||
import { Component, Inject } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { Store, select } from '@ngrx/store'; | ||
import { quote } from '../models/quote.model'; | ||
import QuoteState from '../store/quote/quoteState'; | ||
import { getDolar, getReal } from '../store/quote/quoteAction'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
@Component({ | ||
selector: 'app-fetch-data', | ||
templateUrl: './fetch-data.component.html' | ||
}) | ||
export class FetchDataComponent { | ||
public forecasts: WeatherForecast[]; | ||
|
||
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) { | ||
http.get<WeatherForecast[]>(baseUrl + 'weatherforecast').subscribe(result => { | ||
this.forecasts = result; | ||
quote$: Observable<QuoteState>; | ||
dolar: quote; | ||
real: quote; | ||
|
||
constructor(private http: HttpClient, | ||
@Inject('BASE_URL') private baseUrl: string, | ||
private store: Store<{ quotes: QuoteState }>) { | ||
this.quote$ = this.store.pipe(select((state: any) => state.quotes)); | ||
this.getAllQuote(); | ||
} | ||
|
||
ngOnInit() { | ||
this.quote$.pipe( | ||
map(x => { | ||
this.dolar = x.dolar; | ||
this.real = x.real; | ||
}) | ||
) | ||
.subscribe(); | ||
} | ||
|
||
getAllQuote() { | ||
console.log('fetching cote'); | ||
this.getDollarQuote(); | ||
this.getRealQuote(); | ||
} | ||
|
||
getDollarQuote() { | ||
this.http.get<quote>(this.baseUrl + 'exchange?currencyType=USD').subscribe(result => { | ||
this.store.dispatch(getDolar({payload: result})); | ||
}, error => console.error(error)); | ||
} | ||
} | ||
|
||
interface WeatherForecast { | ||
date: string; | ||
temperatureC: number; | ||
temperatureF: number; | ||
summary: string; | ||
getRealQuote() { | ||
this.http.get<quote>(this.baseUrl + 'exchange?currencyType=BRL').subscribe(result => { | ||
this.store.dispatch(getReal({payload: result})); | ||
}, error => console.error(error)); | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
VirtualMind.WebApp/ClientApp/src/app/home/home.component.html
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface quote { | ||
purchase: string; | ||
sale: string; | ||
lastUpdate: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
VirtualMind.WebApp/ClientApp/src/app/store/quote/quoteAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Action, createAction, props, createReducer, on } from '@ngrx/store'; | ||
import { quote } from '../../models/quote.model'; | ||
|
||
enum ActionTypes { | ||
GetDolar = 'GetDolar', | ||
GetReal = 'GetReal' | ||
} | ||
|
||
export const getDolar = createAction( | ||
ActionTypes.GetDolar, | ||
props<{payload: quote}>() | ||
) | ||
|
||
export const getReal = createAction( | ||
ActionTypes.GetReal, | ||
props<{payload: quote}>() | ||
) |
22 changes: 22 additions & 0 deletions
22
VirtualMind.WebApp/ClientApp/src/app/store/quote/quoteReducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Action, createReducer, on } from '@ngrx/store'; | ||
import * as QuoteActions from './quoteAction'; | ||
import { quote } from '../../models/quote.model'; | ||
import QuoteState, { initializeState } from './quoteState'; | ||
|
||
export const intialState = initializeState(); | ||
|
||
export const reducer = createReducer( | ||
intialState, | ||
on(QuoteActions.getDolar, (state, action) => ({ | ||
...state, | ||
dolar: action.payload | ||
})), | ||
on(QuoteActions.getReal, (state, action) => ({ | ||
...state, | ||
real: action.payload | ||
})) | ||
) | ||
|
||
export function QuoteReducer(state: QuoteState, action: Action) { | ||
return reducer(state, action); | ||
} |
Oops, something went wrong.