Skip to content

Commit

Permalink
SHIBUI-823 Implemented notification for failed preview
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Sep 4, 2018
1 parent dcdac35 commit bdf79b9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
33 changes: 24 additions & 9 deletions ui/src/app/metadata/domain/effect/entity.effect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { Store } from '@ngrx/store';

import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';
Expand All @@ -12,6 +13,10 @@ import { MetadataTypes } from '../domain.type';
import { EntityIdService } from '../service/entity-id.service';
import * as entityActions from '../action/entity.action';

import * as fromRoot from '../../../app.reducer';

import { AddNotification } from '../../../notification/action/notification.action';
import { Notification, NotificationType } from '../../../notification/model/notification';

@Injectable()
export class EntityEffects {
Expand All @@ -27,20 +32,30 @@ export class EntityEffects {
private actions$: Actions,
private modalService: NgbModal,
private providerService: ResolverService,
private entityService: EntityIdService
private entityService: EntityIdService,
private store: Store<fromRoot.State>
) { }

openModal(prev: { id: string, entity: MetadataEntity }): void {
let { id, entity } = prev,
request: Observable<string> = entity.kind === MetadataTypes.FILTER ?
this.entityService.preview(id) : this.providerService.preview(id);
request.subscribe(xml => {
let modal = this.modalService.open(PreviewDialogComponent, {
size: 'lg',
windowClass: 'modal-xl'
});
modal.componentInstance.entity = entity;
modal.componentInstance.xml = xml;
});
request.subscribe(
xml => {
let modal = this.modalService.open(PreviewDialogComponent, {
size: 'lg',
windowClass: 'modal-xl'
});
modal.componentInstance.entity = entity;
modal.componentInstance.xml = xml;
},
err => {
this.store.dispatch(new AddNotification(new Notification(
NotificationType.Danger,
`Unable to preview entity.`,
8000
)));
}
);
}
} /* istanbul ignore next */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<button class="btn btn-link text-right" [ngSwitch]="button.id" (click)="this.action($event)">
<button class="btn btn-link text-right" [ngSwitch]="button.id" (click)="this.action($event)" *ngIf="this.visible">
<i class="fa fa-eye fa-lg text-success" *ngSwitchCase="'preview'"></i>
<i class="fa fa-floppy-o fa-lg text-info" *ngSwitchDefault></i>
</button>
15 changes: 12 additions & 3 deletions ui/src/app/schema-form/widget/button/icon-button.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import {
Component, AfterViewInit,
Component, AfterViewInit, ChangeDetectorRef
} from '@angular/core';
import { ButtonWidget } from 'ngx-schema-form';
import { ɵb as ActionRegistry } from 'ngx-schema-form';
import { interval } from 'rxjs';

@Component({
selector: 'icon-button',
templateUrl: `./icon-button.component.html`
})
export class IconButtonComponent extends ButtonWidget implements AfterViewInit {

action = ($event) => {};
visible = false;

constructor(private actionRegistry: ActionRegistry) {
action = (e) => {};

constructor(
private actionRegistry: ActionRegistry,
private changeDetector: ChangeDetectorRef
) {
super();
}

Expand All @@ -24,5 +30,8 @@ export class IconButtonComponent extends ButtonWidget implements AfterViewInit {
}
e.preventDefault();
};

this.visible = !!this.actionRegistry.get(this.button.id);
this.changeDetector.detectChanges();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@
<li class="list-group-item d-flex justify-content-between align-items-center" *ngFor="let id of targets">
{{ id }}
<span>
<sf-form-element-action *ngFor="let button of getButtonConfig(id)" [button]="button" [formProperty]="formProperty"></sf-form-element-action>
<sf-form-element-action
*ngFor="let button of getButtonConfig(id)"
[button]="button"
[formProperty]="formProperty">
</sf-form-element-action>
<button class="btn btn-link text-right" (click)="removeId(id)">
<i class="fa fa-trash fa-lg text-danger"></i>
</button>
Expand Down

0 comments on commit bdf79b9

Please sign in to comment.