src/app/apps/apps-unregister/apps-unregister.component.ts
Applications Unregister modal
selector | app-apps-unregister |
templateUrl | ./apps-unregister.component.html |
Properties |
Methods |
Outputs |
constructor(modalRef: BsModalRef, appsService: AppsService, loggerService: LoggerService, blockerService: BlockerService, notificationService: NotificationService)
|
||||||||||||||||||||||||
Initialize component
Parameters :
|
event
|
Emit on changes $event type: EventEmitter
|
close |
close()
|
Close the modal
Returns :
void
|
open | ||||||||
open(applications: AppRegistration[])
|
||||||||
Initialize context
Parameters :
Returns :
EventEmitter<any>
|
unregister |
unregister()
|
Complete the unregistration AppRegistrations. Emit confirm event if success and close the open modal dialog.
Returns :
void
|
applications |
applications:
|
Type : AppRegistration[]
|
Applications |
import { Component, EventEmitter, Output } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap';
import { AppRegistration } from '../../shared/model';
import { AppsService } from '../apps.service';
import { NotificationService } from '../../shared/services/notification.service';
import { LoggerService } from '../../shared/services/logger.service';
import { AppError } from '../../shared/model/error.model';
import { BlockerService } from '../../shared/components/blocker/blocker.service';
import { finalize } from 'rxjs/operators';
/**
* Applications Unregister modal
*
* @author Gunnar Hillert
* @author Damien Vitrac
*/
@Component({
selector: 'app-apps-unregister',
templateUrl: './apps-unregister.component.html'
})
export class AppsUnregisterComponent {
/**
* Applications
*/
applications: AppRegistration[];
/**
* Emit on changes
* @type {EventEmitter<any>}
*/
@Output() event = new EventEmitter();
/**
* Initialize component
*
* @param {BsModalRef} modalRef used to control the current modal
* @param {AppsService} appsService
* @param {LoggerService} loggerService
* @param {BlockerService} blockerService
* @param {NotificationService} notificationService
*/
constructor(private modalRef: BsModalRef,
private appsService: AppsService,
private loggerService: LoggerService,
private blockerService: BlockerService,
private notificationService: NotificationService) {
}
/**
* Initialize context
* @param {AppRegistration[]} applications
* @returns {EventEmitter<any>}
*/
open(applications: AppRegistration[]): EventEmitter<any> {
this.applications = applications;
return this.event;
}
/**
* Complete the unregistration {@link AppRegistration}s.
* Emit confirm event if success and close the open modal dialog.
*/
unregister() {
this.loggerService.log(`Proceeding to unregister ${this.applications.length} application(s).`, this.applications);
this.blockerService.lock();
this.appsService.unregisterApps(this.applications).pipe(finalize(() => this.blockerService.unlock())).subscribe(
data => {
if (data.length === 1) {
this.notificationService.success('Successfully removed app "'
+ this.applications[0].name + '" of type "' + this.applications[0].type.toString() + '".');
} else {
this.notificationService.success(`${data.length} app(s) unregistered.`);
}
this.event.emit(data);
this.close();
}, error => {
this.notificationService.error(AppError.is(error) ? error.getMessage() : error);
this.close();
});
}
/**
* Close the modal
*/
close() {
this.modalRef.hide();
}
}
<div class="modal-content" *ngIf="applications">
<div class="modal-header">
<h4 *ngIf="applications.length == 1" class="modal-title pull-left">Confirm Unregister Application</h4>
<h4 *ngIf="applications.length > 1" class="modal-title pull-left">Confirm Unregister Applications</h4>
<button type="button" class="close pull-right" aria-label="Close" (click)="close()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" *ngIf="applications.length == 1">
<p>This action will unregister and delete application
<u><strong>{{ applications[0].name }}</strong></u>
of type <app-type [application]="applications[0]"></app-type>.
Are you sure?</p>
</div>
<div class="modal-body" *ngIf="applications.length > 1">
<p>
This action will unregister and delete the <u><strong>{{ applications.length }}
application{{ applications.length > 1 ? 's' : '' }}</strong></u> listed below.<br />Are you sure?
</p>
<br/>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of applications">
<td>{{ item.name }}</td>
<td><app-type [application]="item"></app-type></td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" (click)="close()">Cancel</button>
<button name="app-unregister" type="button" class="btn btn-primary" (click)="unregister()">
<span *ngIf="applications.length == 1">Unregister the application</span>
<span *ngIf="applications.length > 1">Unregister the applications</span>
</button>
</div>
</div>