This commit is contained in:
crusader 2018-05-31 15:48:49 +09:00
parent ef9e3d7d78
commit 5628f7a6c4
5 changed files with 128 additions and 19 deletions

View File

@ -1,9 +1,10 @@
<of-error-message [error]="error" [closable]="false"></of-error-message>
<of-block-progressbar [target]="content" [pending]="pending"></of-block-progressbar>
<h1>Unauthorized</h1>
<of-error-message [error]="error$ | async" [closable]="false"></of-error-message>
<of-block-progressbar [target]="content" [pending]="pending$ | async"></of-block-progressbar>
<p-panel #content [showHeader]="false" class="block-panel">
<h1>Unauthorized</h1>
<p-table #dt [value]="noauthProbes" selectionMode="single" dataKey="id">
<p-table #dt [value]="noauthProbes$ | async" selectionMode="single" dataKey="id">
<ng-template pTemplate="header">
<tr>
<th style="width: 3.25em" pResizableColumn></th>

View File

@ -1,25 +1,82 @@
import { Component, Input, Output, EventEmitter, AfterContentInit } from '@angular/core';
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { Component, Input, Output, EventEmitter, AfterContentInit, OnInit } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable, of } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { ConfirmationService, Message } from 'primeng/primeng';
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { AuthContainerSelector } from '@overflow/shared/auth/store';
import { DomainMember } from '@overflow/commons-typescript/model/domain';
import { NoAuthProbeService } from '../service/noauth-probe.service';
@Component({
selector: 'of-noauth-probe-list',
templateUrl: './noauth-probe-list.component.html',
providers: [ConfirmationService]
})
export class NoAuthProbeListComponent {
@Input() noauthProbes: NoAuthProbe[];
@Input() pending: boolean;
@Input() error: any;
@Output() accept = new EventEmitter<NoAuthProbe>();
@Output() deny = new EventEmitter<NoAuthProbe>();
export class NoAuthProbeListComponent implements OnInit {
noauthProbes$: Observable<NoAuthProbe[]>;
pending$: Observable<boolean>;
error$: Observable<any>;
constructor(
private confirmationService: ConfirmationService,
private store: Store<any>,
private noAuthProbeService: NoAuthProbeService,
) {
}
ngOnInit() {
this.store.pipe(
tap(() => {
this.pending$ = of(true);
}),
select(AuthContainerSelector.selectDomainMember),
exhaustMap((domainMember: DomainMember) =>
this.noAuthProbeService.readAllByDomainID(domainMember.domain.id)
.pipe(
map((noauthProbes: NoAuthProbe[]) => {
this.setNoauthProbes$(noauthProbes);
}),
catchError(error => {
this.setError$(error);
return of();
})
)
),
tap(() => {
this.pending$ = of(false);
}),
).take(1).subscribe();
// this.noauthProbes$ = this.store.pipe(
// select(AuthContainerSelector.selectDomainMember),
// exhaustMap((domainMember: DomainMember) =>
// this.noAuthProbeService.readAllByDomainID(domainMember.domain.id)
// .pipe(
// map((noauthProbes: NoAuthProbe[]) => {
// this.pending$ = of(false);
// if (null === noauthProbes) {
// return null;
// }
// noauthProbes.forEach(noauthProbe => {
// noauthProbe.descriptions = JSON.parse(noauthProbe.description);
// });
// return noauthProbes;
// }),
// catchError(error => {
// this.pending$ = of(false);
// this.error$ = of(error);
// return of(null);
// })
// )
// )
// );
}
onAcceptOrDeny(isAccept: boolean, selected: NoAuthProbe) {
const title = isAccept ?
'Are you sure to accept this Probe?' : 'Are you sure to deny this Probe';
@ -31,10 +88,60 @@ export class NoAuthProbeListComponent {
message: message,
icon: isAccept ? 'fa-check' : 'fa fa-trash',
accept: () => {
isAccept ? this.accept.emit(selected) : this.deny.emit(selected);
if (isAccept) {
this.noAuthProbeService.acceptNoAuthProbe(selected.id)
.pipe(
tap(() => {
this.pending$ = of(true);
}),
map((noauthProbes: NoAuthProbe[]) => {
this.setNoauthProbes$(noauthProbes);
}),
catchError(error => {
this.setError$(error);
return of();
}),
tap(() => {
this.pending$ = of(false);
}),
).take(1).subscribe();
} else {
this.noAuthProbeService.denyNoauthProbe(selected.id)
.pipe(
tap(() => {
this.pending$ = of(true);
}),
map((noauthProbes: NoAuthProbe[]) => {
this.setNoauthProbes$(noauthProbes);
}),
catchError(error => {
this.setError$(error);
return of();
}),
tap(() => {
this.pending$ = of(false);
}),
).take(1).subscribe();
}
},
reject: () => {
}
});
}
private setNoauthProbes$(noauthProbes: NoAuthProbe[]): void {
if (null === noauthProbes) {
return;
}
noauthProbes.forEach(noauthProbe => {
noauthProbe.descriptions = JSON.parse(noauthProbe.description);
});
this.noauthProbes$ = of(noauthProbes);
}
private setError$(error: any): void {
this.error$ = of(error);
}
}

View File

@ -1,7 +1,7 @@
<of-noauth-probe-list
<!-- <of-noauth-probe-list
[noauthProbes]="noauthProbes$ | async"
[pending]="pending$ | async"
[error]="error$ | async"
(accept)="accept($event)"
(deny)="deny($event)">
</of-noauth-probe-list>
</of-noauth-probe-list> -->

View File

@ -7,11 +7,12 @@ export class UITemplateDirective {
@Input() type: string;
@Input('ofUITemplate') ofUITemplate: string;
// tslint:disable-next-line:no-input-rename
@Input('ofUITemplate') name: string;
constructor(public template: TemplateRef<any>) { }
getType(): string {
return this.ofUITemplate;
return this.name;
}
}

View File

@ -1 +1 @@
<of-noauth-probe-list-container></of-noauth-probe-list-container>
<of-noauth-probe-list></of-noauth-probe-list>