mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-28 02:53:11 +00:00
Updated various other libraries to their latest versions Updated various project files for better Angular 8 support
111 lines
3.2 KiB
TypeScript
111 lines
3.2 KiB
TypeScript
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
|
|
import { Subject } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { FuseConfirmDialogComponent } from '@fuse/components/confirm-dialog/confirm-dialog.component';
|
|
|
|
import { ContactsService } from 'app/main/apps/contacts/contacts.service';
|
|
|
|
@Component({
|
|
selector : 'selected-bar',
|
|
templateUrl: './selected-bar.component.html',
|
|
styleUrls : ['./selected-bar.component.scss']
|
|
})
|
|
export class ContactsSelectedBarComponent implements OnInit, OnDestroy
|
|
{
|
|
confirmDialogRef: MatDialogRef<FuseConfirmDialogComponent>;
|
|
hasSelectedContacts: boolean;
|
|
isIndeterminate: boolean;
|
|
selectedContacts: string[];
|
|
|
|
// Private
|
|
private _unsubscribeAll: Subject<any>;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param {ContactsService} _contactsService
|
|
* @param {MatDialog} _matDialog
|
|
*/
|
|
constructor(
|
|
private _contactsService: ContactsService,
|
|
public _matDialog: MatDialog
|
|
)
|
|
{
|
|
// Set the private defaults
|
|
this._unsubscribeAll = new Subject();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Lifecycle hooks
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* On init
|
|
*/
|
|
ngOnInit(): void
|
|
{
|
|
this._contactsService.onSelectedContactsChanged
|
|
.pipe(takeUntil(this._unsubscribeAll))
|
|
.subscribe(selectedContacts => {
|
|
this.selectedContacts = selectedContacts;
|
|
setTimeout(() => {
|
|
this.hasSelectedContacts = selectedContacts.length > 0;
|
|
this.isIndeterminate = (selectedContacts.length !== this._contactsService.contacts.length && selectedContacts.length > 0);
|
|
}, 0);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* On destroy
|
|
*/
|
|
ngOnDestroy(): void
|
|
{
|
|
// Unsubscribe from all subscriptions
|
|
this._unsubscribeAll.next();
|
|
this._unsubscribeAll.complete();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Public methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Select all
|
|
*/
|
|
selectAll(): void
|
|
{
|
|
this._contactsService.selectContacts();
|
|
}
|
|
|
|
/**
|
|
* Deselect all
|
|
*/
|
|
deselectAll(): void
|
|
{
|
|
this._contactsService.deselectContacts();
|
|
}
|
|
|
|
/**
|
|
* Delete selected contacts
|
|
*/
|
|
deleteSelectedContacts(): void
|
|
{
|
|
this.confirmDialogRef = this._matDialog.open(FuseConfirmDialogComponent, {
|
|
disableClose: false
|
|
});
|
|
|
|
this.confirmDialogRef.componentInstance.confirmMessage = 'Are you sure you want to delete all selected contacts?';
|
|
|
|
this.confirmDialogRef.afterClosed()
|
|
.subscribe(result => {
|
|
if ( result )
|
|
{
|
|
this._contactsService.deleteSelectedContacts();
|
|
}
|
|
this.confirmDialogRef = null;
|
|
});
|
|
}
|
|
}
|