Base event handler registry

pull/7547/head
Oliver Günther 5 years ago
parent ad41b21eb6
commit c8b3f8b1ce
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 2
      frontend/src/app/components/op-context-menu/op-context-menu-handler.ts
  2. 4
      frontend/src/app/components/op-context-menu/op-context-menu.service.ts
  3. 3
      frontend/src/app/components/op-context-menu/wp-context-menu/wp-table-context-menu.directive.ts
  4. 34
      frontend/src/app/components/wp-card-view/event-handler/card-view-handler-registry.ts
  5. 2
      frontend/src/app/components/wp-card-view/event-handler/click-handler.ts
  6. 2
      frontend/src/app/components/wp-card-view/event-handler/double-click-handler.ts
  7. 2
      frontend/src/app/components/wp-card-view/event-handler/right-click-handler.ts
  8. 2
      frontend/src/app/components/wp-fast-table/handlers/context-menu/context-menu-handler.ts
  9. 4
      frontend/src/app/components/wp-fast-table/handlers/row/hierarchy-click-handler.ts
  10. 40
      frontend/src/app/components/wp-fast-table/handlers/table-handler-registry.ts
  11. 41
      frontend/src/app/modules/work_packages/routing/wp-view-base/event-handling/event-handler-registry.ts

@ -28,7 +28,7 @@ export abstract class OpContextMenuHandler {
*
* @param {Event} openerEvent
*/
public positionArgs(openerEvent:JQueryEventObject):any {
public positionArgs(openerEvent:JQueryEventObject|JQuery.Event):any {
return {
my: 'left top',
at: 'right bottom',

@ -60,7 +60,7 @@ export class OPContextMenuService {
* Open a ContextMenu reference and append it to the portal
* @param contextMenu A reference to a context menu handler
*/
public show(menu:OpContextMenuHandler, event:JQueryEventObject, component:any = OPContextMenuComponent) {
public show(menu:OpContextMenuHandler, event:JQueryEventObject|JQuery.Event, component:any = OPContextMenuComponent) {
this.close();
// Create a portal for the given component class and render it
@ -97,7 +97,7 @@ export class OPContextMenuService {
this.active = null;
}
public reposition(event:JQueryEventObject) {
public reposition(event:JQueryEventObject|JQuery.Event) {
if (!this.active) {
return;
}

@ -9,9 +9,8 @@ export class WorkPackageTableContextMenu extends WorkPackageViewContextMenu {
protected workPackageId:string,
protected $element:JQuery,
protected additionalPositionArgs:any = {},
protected allowSplitScreenActions:boolean = true,
protected table:WorkPackageTable) {
super(injector, workPackageId, $element, additionalPositionArgs, allowSplitScreenActions);
super(injector, workPackageId, $element, additionalPositionArgs, true);
}
public triggerContextMenuAction(action:WorkPackageAction) {

@ -1,24 +1,17 @@
import {Injector} from '@angular/core';
import {WorkPackageCardViewComponent} from "core-components/wp-card-view/wp-card-view.component";
import {CardClickHandler} from "core-components/wp-card-view/event-handler/click-handler";
import {CardDblClickHandler} from "core-components/wp-card-view/event-handler/double-click-handler";
import {CardRightClickHandler} from "core-components/wp-card-view/event-handler/right-click-handler";
import {
WorkPackageViewEventHandler,
WorkPackageViewHandlerRegistry
} from "core-app/modules/work_packages/event-handling/event-handler-registry";
export interface CardEventHandler {
EVENT:string;
SELECTOR:string;
export type CardEventHandler = WorkPackageViewEventHandler<WorkPackageCardViewComponent>;
handleEvent(card:WorkPackageCardViewComponent, evt:JQueryEventObject):void;
export class CardViewHandlerRegistry extends WorkPackageViewHandlerRegistry<WorkPackageCardViewComponent> {
eventScope(card:WorkPackageCardViewComponent):JQuery;
}
export class CardViewHandlerRegistry {
constructor(public readonly injector:Injector) {
}
private eventHandlers:((c:WorkPackageCardViewComponent) => CardEventHandler)[] = [
protected eventHandlers:((c:WorkPackageCardViewComponent) => CardEventHandler)[] = [
// Clicking on the card (not within a cell)
c => new CardClickHandler(this.injector, c),
// Double Clicking on the row (not within a cell)
@ -26,17 +19,4 @@ export class CardViewHandlerRegistry {
// Right clicking on cards
t => new CardRightClickHandler(this.injector, t),
];
attachTo(card:WorkPackageCardViewComponent) {
this.eventHandlers.map(factory => {
let handler = factory(card);
let target = handler.eventScope(card);
target.on(handler.EVENT, handler.SELECTOR, (evt:JQueryEventObject) => {
handler.handleEvent(card, evt);
});
return handler;
});
}
}

@ -28,7 +28,7 @@ export class CardClickHandler implements CardEventHandler {
return jQuery(card.container.nativeElement);
}
public handleEvent(card:WorkPackageCardViewComponent, evt:JQueryEventObject) {
public handleEvent(card:WorkPackageCardViewComponent, evt:JQuery.Event) {
let target = jQuery(evt.target);
// Ignore links

@ -26,7 +26,7 @@ export class CardDblClickHandler implements CardEventHandler {
return jQuery(card.container.nativeElement);
}
public handleEvent(card:WorkPackageCardViewComponent, evt:JQueryEventObject) {
public handleEvent(card:WorkPackageCardViewComponent, evt:JQuery.Event) {
let target = jQuery(evt.target);
// Ignore links

@ -31,7 +31,7 @@ export class CardRightClickHandler implements CardEventHandler {
return jQuery(card.container.nativeElement);
}
public handleEvent(card:WorkPackageCardViewComponent, evt:JQueryEventObject) {
public handleEvent(card:WorkPackageCardViewComponent, evt:JQuery.Event) {
let target = jQuery(evt.target);
// We want to keep the original context menu on hrefs

@ -27,7 +27,7 @@ export abstract class ContextMenuHandler implements TableEventHandler {
public abstract handleEvent(table:WorkPackageTable, evt:JQueryEventObject):boolean;
protected openContextMenu(evt:JQueryEventObject, workPackageId:string, positionArgs?:any):void {
protected openContextMenu(evt:JQuery.Event, workPackageId:string, positionArgs?:any):void {
const handler = new WorkPackageTableContextMenu(this.injector, workPackageId, jQuery(evt.target) as JQuery, positionArgs, this.table);
this.opContextMenu.show(handler, evt);
}

@ -4,7 +4,7 @@ import {tableRowClassName} from '../../builders/rows/single-row-builder';
import {WorkPackageTableHierarchiesService} from '../../state/wp-table-hierarchy.service';
import {WorkPackageTable} from '../../wp-fast-table';
import {ClickOrEnterHandler} from '../click-or-enter-handler';
import {TableEventHandler} from '../table-handler-registry';
import {TableEventHandler} from "core-components/wp-fast-table/handlers/table-handler-registry";
export class HierarchyClickHandler extends ClickOrEnterHandler implements TableEventHandler {
// Injections
@ -27,7 +27,7 @@ export class HierarchyClickHandler extends ClickOrEnterHandler implements TableE
return jQuery(table.tbody);
}
public processEvent(table:WorkPackageTable, evt:JQueryEventObject):boolean {
public processEvent(table:WorkPackageTable, evt:JQuery.Event):boolean {
let target = jQuery(evt.target);
// Locate the row from event

@ -18,27 +18,21 @@ import {SelectionTransformer} from './state/selection-transformer';
import {TimelineTransformer} from './state/timeline-transformer';
import {HighlightingTransformer} from "core-components/wp-fast-table/handlers/state/highlighting-transformer";
import {DragAndDropTransformer} from "core-components/wp-fast-table/handlers/state/drag-and-drop-transformer";
export interface TableEventHandler {
EVENT:string;
SELECTOR:string;
handleEvent(table:WorkPackageTable, evt:JQueryEventObject):void;
eventScope(table:WorkPackageTable):JQuery;
}
import {
WorkPackageViewEventHandler,
WorkPackageViewHandlerRegistry
} from "core-app/modules/work_packages/event-handling/event-handler-registry";
type StateTransformers = {
// noinspection JSUnusedLocalSymbols
new(injector:Injector, table:WorkPackageTable):any;
};
export class TableHandlerRegistry {
export type TableEventHandler = WorkPackageViewEventHandler<WorkPackageTable>;
constructor(public readonly injector:Injector) {
}
export class TableHandlerRegistry extends WorkPackageViewHandlerRegistry<WorkPackageTable> {
private eventHandlers:((t:WorkPackageTable) => TableEventHandler)[] = [
protected eventHandlers:((t:WorkPackageTable) => WorkPackageViewEventHandler<WorkPackageTable>)[] = [
// Hierarchy expansion/collapsing
t => new HierarchyClickHandler(this.injector, t),
// Clicking or pressing Enter on a single cell, editable or not
@ -61,7 +55,7 @@ export class TableHandlerRegistry {
t => new RelationsCellHandler(this.injector, t)
];
private readonly stateTransformers:StateTransformers[] = [
protected readonly stateTransformers:StateTransformers[] = [
SelectionTransformer,
RowsTransformer,
ColumnsTransformer,
@ -71,22 +65,4 @@ export class TableHandlerRegistry {
HighlightingTransformer,
DragAndDropTransformer
];
attachTo(table:WorkPackageTable) {
this.stateTransformers.map((cls) => {
return new cls(this.injector, table);
});
this.eventHandlers.map(factory => {
let handler = factory(table);
let target = handler.eventScope(table);
target.on(handler.EVENT, handler.SELECTOR, (evt:JQueryEventObject) => {
handler.handleEvent(table, evt);
});
return handler;
});
}
}

@ -0,0 +1,41 @@
import {Injector} from '@angular/core';
export interface WorkPackageViewEventHandler<T> {
/** Event name to register **/
EVENT:string;
/** Event context CSS selector */
SELECTOR:string;
/** Event callback handler */
handleEvent(view:T, evt:JQuery.Event):void;
/** Event scope method */
eventScope(view:T):JQuery;
}
/**
* Abstract view handler registry for globally handling arbitrary event on the
* view container. Used e.g., for table to register single event callbacks for the entirety
* of the table.
*/
export abstract class WorkPackageViewHandlerRegistry<T> {
constructor(public readonly injector:Injector) {
}
protected abstract eventHandlers:((view:T) => WorkPackageViewEventHandler<T>)[];
attachTo(viewRef:T) {
this.eventHandlers.map(factory => {
let handler = factory(viewRef);
let target = handler.eventScope(viewRef);
target.on(handler.EVENT, handler.SELECTOR, (evt:JQuery.Event) => {
handler.handleEvent(viewRef, evt);
});
return handler;
});
}
}
Loading…
Cancel
Save