-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Wydder-ListAddressOfAsset' into develop
- Loading branch information
Showing
27 changed files
with
443 additions
and
126 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
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
32 changes: 32 additions & 0 deletions
32
src/app/assets/components/view-address/view-address.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<section class="view-address" *ngIf="address"> | ||
<h2>Adresa</h2> | ||
|
||
<div class="double"> | ||
<app-detailed-text | ||
description="Oras" | ||
[text]="address.city" | ||
></app-detailed-text> | ||
<app-detailed-text | ||
description="Judet" | ||
[text]="address.getCountyName()" | ||
></app-detailed-text> | ||
</div> | ||
|
||
<div class="double"> | ||
<app-detailed-text | ||
description="Strada" | ||
[text]="address.street" | ||
></app-detailed-text> | ||
<app-detailed-text | ||
description="Bloc" | ||
[text]="address.building" | ||
></app-detailed-text> | ||
</div> | ||
|
||
<app-detailed-text | ||
*ngIf="address.description" | ||
description="Detalii" | ||
[text]="address.description" | ||
></app-detailed-text> | ||
</section> | ||
|
22 changes: 22 additions & 0 deletions
22
src/app/assets/components/view-address/view-address.component.scss
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 'mixins'; | ||
|
||
.view-address { | ||
h2 { | ||
@include material-card-title(); | ||
} | ||
|
||
app-detailed-text { | ||
@include flex-column(); | ||
@include flex-grow(); | ||
margin-bottom: 16px; | ||
} | ||
|
||
.double { | ||
display: flex; | ||
flex-direction: row; | ||
|
||
app-detailed-text { | ||
flex-basis: 50%; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/app/assets/components/view-address/view-address.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { Address } from '@app/core'; | ||
|
||
@Component({ | ||
selector: 'app-view-address', | ||
templateUrl: './view-address.component.html', | ||
styleUrls: ['./view-address.component.scss'], | ||
}) | ||
export class ViewAddressComponent { | ||
@Input() address: Address; | ||
} |
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
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
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,16 +1,19 @@ | ||
import { AssetDetailGuard } from './asset-detail.guard'; | ||
import { AssetsGuard } from './assets.guard'; | ||
import { LoadAddressesGuard } from './load-addresses.guard'; | ||
import { LoadCountiesGuard } from './load-counties.guard'; | ||
import { LoadDefendantsGuard } from './load-defendants.guard'; | ||
|
||
export const guards: any[] = [ | ||
AssetsGuard, | ||
AssetDetailGuard, | ||
LoadAddressesGuard, | ||
LoadCountiesGuard, | ||
LoadDefendantsGuard, | ||
]; | ||
|
||
export * from './assets.guard'; | ||
export * from './asset-detail.guard'; | ||
export * from './load-addresses.guard'; | ||
export * from './load-counties.guard'; | ||
export * from './load-defendants.guard'; |
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,36 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, CanActivate } from '@angular/router'; | ||
import { of, Observable } from 'rxjs'; | ||
|
||
import { select, Store } from '@ngrx/store'; | ||
import { catchError, filter, switchMap, take, tap } from 'rxjs/operators'; | ||
import * as fromStore from '../../core/store'; | ||
|
||
@Injectable() | ||
export class LoadAddressesGuard implements CanActivate { | ||
constructor(private store: Store<fromStore.AddressesState>) { | ||
} | ||
|
||
canActivate(route: ActivatedRouteSnapshot): Observable<boolean> { | ||
const theAssetId = parseInt((route.params as any).assetId, 10); | ||
|
||
return this.hasAddressesLoaded(theAssetId) | ||
.pipe( | ||
switchMap(() => of(true)), | ||
catchError(() => of(false)) | ||
); | ||
} | ||
|
||
hasAddressesLoaded(aId: number): Observable<boolean> { | ||
return this.store.pipe(select(fromStore.getAddressesLoadedForAssetId(aId))) | ||
.pipe( | ||
tap((aLoaded: boolean) => { | ||
if (!aLoaded) { | ||
this.store.dispatch(new fromStore.LoadAddresses(aId)); | ||
} | ||
}), | ||
filter((aLoaded: boolean) => aLoaded), | ||
take(1) | ||
); | ||
} | ||
} |
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,34 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { throwError as observableThrowError, Observable } from 'rxjs'; | ||
import { catchError } from 'rxjs/operators'; | ||
|
||
import { environment } from '@env/environment'; | ||
import { AddressRequest, AddressResponse } from '../models'; | ||
|
||
@Injectable() | ||
export class AddressesApiService { | ||
constructor(private http: HttpClient) { | ||
} | ||
|
||
public createAddress(id: number, address: AddressRequest): Observable<AddressResponse> { | ||
return this.http.post<AddressResponse>(`${environment.api_url}/assets/${id}/address`, address) | ||
.pipe( | ||
catchError(aError => observableThrowError(aError.error.errors)) | ||
); | ||
} | ||
|
||
public updateAddress(id: number, address: AddressRequest): Observable<AddressResponse> { | ||
return this.http.put<AddressResponse>(`${environment.api_url}/assets/${id}/address`, address) | ||
.pipe( | ||
catchError(aError => observableThrowError(aError.error.errors)) | ||
); | ||
} | ||
|
||
public getAddress$(aAssetId: number): Observable<AddressResponse> { | ||
return this.http.get<AddressResponse>(`${environment.api_url}/assets/${aAssetId}/address`) | ||
.pipe( | ||
catchError(aError => observableThrowError(aError)) | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.