This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sidebar): Show 'Entity not found' message if id in query params …
…is invalid Fixes #374
- Loading branch information
wowshakhov
authored
Aug 28, 2017
1 parent
1aa83f5
commit 324eed6
Showing
24 changed files
with
322 additions
and
242 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div class="no-results"> | ||
{{ 'COMMON.NO_RESULTS' | translate }} | ||
{{ text | translate }} | ||
</div> |
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,8 +1,11 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, Input } from '@angular/core'; | ||
|
||
|
||
@Component({ | ||
selector: 'cs-no-results', | ||
templateUrl: 'no-results.component.html', | ||
styleUrls: ['no-results.component.scss'] | ||
}) | ||
export class NoResultsComponent {} | ||
export class NoResultsComponent { | ||
@Input() public text = 'COMMON.NO_RESULTS'; | ||
} |
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 +1 @@ | ||
export * from './sidebar.component'; | ||
export * from './sidebar-container/sidebar-container.component'; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...components/sidebar/sidebar.component.scss → ...ontainer/sidebar-container.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@import '../../../../style/__variables'; | ||
@import '../../../../../style/_variables'; | ||
|
||
.sidebar { | ||
height: 100%; | ||
|
23 changes: 23 additions & 0 deletions
23
src/app/shared/components/sidebar/sidebar-container/sidebar-container.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,23 @@ | ||
import { Component, HostBinding, Input, } from '@angular/core'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
|
||
|
||
@Component({ | ||
selector: 'cs-sidebar', | ||
templateUrl: 'sidebar-container.component.html', | ||
styleUrls: ['sidebar-container.component.scss'] | ||
}) | ||
export class SidebarContainerComponent { | ||
@Input() @HostBinding('class.open') public isOpen; | ||
|
||
constructor( | ||
private route: ActivatedRoute, | ||
private router: Router | ||
) {} | ||
|
||
public onDetailsHide(): void { | ||
this.router.navigate([this.route.parent.snapshot.url], { | ||
queryParamsHandling: 'preserve' | ||
}); | ||
} | ||
} |
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,38 +1,50 @@ | ||
import { | ||
Component, Input | ||
} from '@angular/core'; | ||
import { DialogService } from '../../../dialog/dialog-module/dialog.service'; | ||
import { OnInit } from '@angular/core'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { BaseModel } from '../../models/base.model'; | ||
import { BaseBackendService } from '../../services/base-backend.service'; | ||
import { NotificationService } from '../../services/notification.service'; | ||
|
||
|
||
@Component({ | ||
selector: 'cs-sidebar', | ||
templateUrl: 'sidebar.component.html', | ||
styleUrls: ['sidebar.component.scss'] | ||
}) | ||
export class SidebarComponent { | ||
@Input() public isOpen = false; | ||
|
||
private dialogsOpen: boolean; // true if any mdl dialog is open | ||
private dialogWasOpen: boolean; // true if last dialog was closed | ||
export abstract class SidebarComponent<M extends BaseModel> implements OnInit { | ||
public entity: M; | ||
public notFound: boolean; | ||
|
||
constructor( | ||
private router: Router, | ||
private route: ActivatedRoute, | ||
private dialogService: DialogService | ||
) { | ||
this.dialogService.onDialogsOpenChanged | ||
.subscribe(dialogsOpen => { | ||
this.dialogsOpen = dialogsOpen; | ||
if (dialogsOpen) { | ||
this.dialogWasOpen = true; | ||
protected entityService: BaseBackendService<M>, | ||
protected notificationService: NotificationService, | ||
protected route: ActivatedRoute, | ||
protected router: Router | ||
) {} | ||
|
||
public ngOnInit(): void { | ||
this.pluckId() | ||
.switchMap(id => this.loadEntity(id)) | ||
.subscribe( | ||
entity => this.entity = entity, | ||
error => { | ||
if (error === 'ENTITY_DOES_NOT_EXIST') { | ||
this.onEntityDoesNotExist(); | ||
} else { | ||
this.onError(error); | ||
} | ||
} | ||
}); | ||
); | ||
} | ||
|
||
private pluckId(): Observable<string> { | ||
return this.route.params.pluck('id').filter(id => !!id) as Observable<string>; | ||
} | ||
|
||
protected loadEntity(id: string): Observable<M> { | ||
return this.entityService.get(id); | ||
} | ||
|
||
private onEntityDoesNotExist(): void { | ||
this.notFound = true; | ||
} | ||
|
||
public onDetailsHide(): void { | ||
this.router.navigate([this.route.parent.snapshot.url], { | ||
queryParamsHandling: 'preserve' | ||
}); | ||
private onError(error: any): void { | ||
this.notificationService.error(error.message); | ||
} | ||
} |
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
70 changes: 37 additions & 33 deletions
70
src/app/spare-drive/spare-drive-sidebar/spare-drive-sidebar.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,57 +1,61 @@ | ||
import { Component, HostBinding, Input } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { Component, HostBinding } from '@angular/core'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { SidebarComponent } from '../../shared/components/sidebar/sidebar.component'; | ||
import { Volume } from '../../shared/models'; | ||
import { VolumeType } from '../../shared/models/volume.model'; | ||
import { DateTimeFormatterService } from '../../shared/services/date-time-formatter.service'; | ||
import { DiskOfferingService } from '../../shared/services/disk-offering.service'; | ||
import { VolumeTagService } from '../../shared/services/tags/volume-tag.service'; | ||
import { NotificationService } from '../../shared/services/notification.service'; | ||
import { VolumeService } from '../../shared/services/volume.service'; | ||
import { VolumeTagService } from '../../shared/services/tags/volume-tag.service'; | ||
|
||
|
||
@Component({ | ||
selector: 'cs-spare-drive-sidebar', | ||
templateUrl: 'spare-drive-sidebar.component.html' | ||
}) | ||
export class SpareDriveSidebarComponent { | ||
public description: string; | ||
|
||
@Input() public volume: Volume; | ||
export class SpareDriveSidebarComponent extends SidebarComponent<Volume> { | ||
@HostBinding('class.grid') public grid = true; | ||
|
||
constructor( | ||
public dateTimeFormatterService: DateTimeFormatterService, | ||
private diskOfferingService: DiskOfferingService, | ||
private route: ActivatedRoute, | ||
private volumeService: VolumeService, | ||
private volumeTagService: VolumeTagService, | ||
protected notificationService: NotificationService, | ||
protected route: ActivatedRoute, | ||
protected router: Router, | ||
protected volumeService: VolumeService, | ||
protected volumeTagService: VolumeTagService, | ||
private diskOfferingService: DiskOfferingService | ||
) { | ||
this.route.params.pluck('id') | ||
.subscribe((id: string) => { | ||
if (!id) { | ||
return; | ||
} | ||
|
||
Observable.forkJoin( | ||
this.diskOfferingService.getList({ type: VolumeType.DATADISK }), | ||
this.volumeService.get(id) | ||
) | ||
.subscribe(([diskOfferings, volume]) => { | ||
this.volumeTagService.getDescription(volume) | ||
.subscribe(description => { | ||
volume.diskOffering = diskOfferings.find( | ||
offering => offering.id === volume.diskOfferingId | ||
); | ||
this.volume = volume; | ||
this.description = description; | ||
}); | ||
}); | ||
}); | ||
super(volumeService, notificationService, route, router); | ||
} | ||
|
||
public changeDescription(newDescription: string): void { | ||
this.volumeTagService.setDescription(this.volume, newDescription) | ||
this.volumeTagService.setDescription(this.entity, newDescription) | ||
.onErrorResumeNext() | ||
.subscribe(); | ||
} | ||
|
||
protected loadEntity(id: string): Observable<Volume> { | ||
return this.volumeService.get(id) | ||
.switchMap(volume => { | ||
if (volume) { | ||
return Observable.of(volume); | ||
} else { | ||
return Observable.throw('ENTITY_DOES_NOT_EXIST'); | ||
} | ||
}) | ||
.switchMap(volume => { | ||
return Observable.forkJoin( | ||
Observable.of(volume), | ||
this.diskOfferingService.getList({ type: VolumeType.DATADISK }), | ||
this.volumeTagService.getDescription(volume) | ||
); | ||
}) | ||
.map(([volume, diskOfferings, description]) => { | ||
volume.diskOffering = diskOfferings.find(_ => _.id === volume.diskOfferingId); | ||
volume.description = description; | ||
return volume; | ||
}); | ||
} | ||
} |
Oops, something went wrong.