UNPKG

@memberjunction/ng-action-gallery

Version:

MemberJunction Action Gallery - A beautiful, filterable gallery component for browsing and selecting actions

149 lines 5.88 kB
import { Injectable } from '@angular/core'; import { ActionGalleryComponent } from './action-gallery.component'; import { Subject } from 'rxjs'; import * as i0 from "@angular/core"; import * as i1 from "@progress/kendo-angular-dialog"; export class ActionGalleryDialogService { constructor(dialogService) { this.dialogService = dialogService; this.dialogRef = null; } /** * Opens the Action Gallery in a dialog for single selection * @param config Configuration for the gallery * @param viewContainerRef Optional ViewContainerRef for proper positioning * @returns Observable that emits the selected action when confirmed */ openForSingleSelection(config = {}, viewContainerRef) { const resultSubject = new Subject(); // Configure for single selection const galleryConfig = { ...config, selectionMode: true, multiSelect: false }; this.openDialog(galleryConfig, viewContainerRef, (component) => { // Handle dialog result this.dialogRef.result.subscribe((result) => { if (result && result.action === 'submit') { const selectedActions = component.getSelectedActions(); resultSubject.next(selectedActions[0] || null); } else { resultSubject.next(null); } resultSubject.complete(); this.dialogRef = null; }); }); return resultSubject.asObservable(); } /** * Opens the Action Gallery in a dialog for multiple selection * @param config Configuration for the gallery * @param viewContainerRef Optional ViewContainerRef for proper positioning * @returns Observable that emits the selected actions when confirmed */ openForMultiSelection(config = {}, viewContainerRef) { const resultSubject = new Subject(); // Configure for multi selection const galleryConfig = { ...config, selectionMode: true, multiSelect: true }; this.openDialog(galleryConfig, viewContainerRef, (component) => { // Handle dialog result this.dialogRef.result.subscribe((result) => { if (result && result.action === 'submit') { const selectedActions = component.getSelectedActions(); resultSubject.next(selectedActions); } else { resultSubject.next([]); } resultSubject.complete(); this.dialogRef = null; }); }); return resultSubject.asObservable(); } /** * Opens the Action Gallery in a dialog for browsing only (no selection) * @param config Configuration for the gallery * @param viewContainerRef Optional ViewContainerRef for proper positioning */ openForBrowsing(config = {}, viewContainerRef) { const galleryConfig = { ...config, selectionMode: false, enableQuickTest: true }; const dialogSettings = { title: config.title || 'Action Gallery', width: config.width || 1200, height: config.height || 800, minWidth: config.minWidth || 800, minHeight: config.minHeight || 600, content: ActionGalleryComponent, actions: [ { text: 'Close', themeColor: 'base' } ], preventAction: () => false }; this.dialogRef = this.dialogService.open(dialogSettings); // Configure the component const component = this.dialogRef.content.instance; component.config = galleryConfig; // Handle dialog close this.dialogRef.result.subscribe(() => { this.dialogRef = null; }); } /** * Closes the currently open dialog */ close() { if (this.dialogRef) { this.dialogRef.close(); this.dialogRef = null; } } /** * Checks if a dialog is currently open */ isOpen() { return this.dialogRef !== null; } openDialog(config, viewContainerRef, resultHandler) { const dialogSettings = { title: config.title || 'Select Actions', width: config.width || 1200, height: config.height || 800, minWidth: config.minWidth || 800, minHeight: config.minHeight || 600, content: ActionGalleryComponent, actions: [ { text: config.cancelButtonText || 'Cancel' }, { text: config.submitButtonText || 'Select', themeColor: 'primary', action: 'submit' } ], preventAction: () => false }; this.dialogRef = this.dialogService.open(dialogSettings); // Configure the component const component = this.dialogRef.content.instance; component.config = config; component.preSelectedActions = config.preSelectedActions || []; // Handle result resultHandler(component); } static { this.ɵfac = function ActionGalleryDialogService_Factory(t) { return new (t || ActionGalleryDialogService)(i0.ɵɵinject(i1.DialogService)); }; } static { this.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: ActionGalleryDialogService, factory: ActionGalleryDialogService.ɵfac, providedIn: 'root' }); } } (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ActionGalleryDialogService, [{ type: Injectable, args: [{ providedIn: 'root' }] }], () => [{ type: i1.DialogService }], null); })(); //# sourceMappingURL=action-gallery-dialog.service.js.map