Skip to content

Commit 187e4db

Browse files
author
Blueshift Staff
committed
Synced from the Blueshift Repository
1 parent 8138221 commit 187e4db

File tree

16 files changed

+122
-27
lines changed

16 files changed

+122
-27
lines changed

projects/ngx-grid-core/src/lib/controller/grid-controller.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ColumnOperationFactory } from './column-operations/_column-operation.fa
2121
import { GridOperationFactory } from './grid-operations/_grid-operation.factory'
2222
import { RowOperationFactory } from './row-operations/_row-operation.factory'
2323
import { GridSelectionController } from './selection/grid-selection.controller'
24+
import { MatIconRegistry } from '@angular/material/icon'
2425

2526
export const DATA_GRIDS_FOCUSED_TREE: string[] = []
2627

@@ -41,13 +42,17 @@ export class GridControllerService {
4142

4243
private _subs : Set<Subscription> = new Set()
4344

45+
public iconClass = this.iconRegistry.getDefaultFontSetClass().filter((fontSetClass) => fontSetClass.includes('material') || fontSetClass.includes('symbols'))[0]
46+
?? this.iconRegistry.getDefaultFontSetClass()[0];
47+
4448
constructor(
4549
private readonly events : GridEventsService,
4650
public readonly prefs : LocalPreferencesService,
4751
public readonly localize: LocalizationService,
4852
public readonly datePipe: DatePipe,
4953
public readonly dialogs : MatDialog,
5054
public readonly uploads : GridFileUploadService,
55+
private readonly iconRegistry: MatIconRegistry,
5156
icons: IconsService,
5257
) {
5358

projects/ngx-grid-core/src/lib/controller/selection/strategies/multi-row.selection-strategy.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fromEvent, merge, Subject } from 'rxjs'
1+
import { fromEvent, merge, Observable, Subject } from 'rxjs'
22
import { distinctUntilChanged, map, takeUntil } from 'rxjs/operators'
33

44
import {
@@ -19,25 +19,24 @@ export class MultiRowSelectionStrategy implements IGridSelectionStrategy {
1919
constructor(public readonly controller: ISelectionController) { }
2020

2121
public attach(el: HTMLElement): void {
22-
this._keyboardHandling()
2322
this.controller.addSubscription(fromEvent(window.document.documentElement, 'mouseup').subscribe(_ => this._mouseReleased.next(true)))
2423
this.controller.addSubscription(fromEvent<MouseEvent>(el, 'mousedown').subscribe(e => this._startSelection(e)))
24+
this._keyboardHandling()
2525
}
2626

2727
private _startSelection(e: MouseEvent): void {
28-
// button 0 = Left Mouse Button
29-
if (e.button !== 0 || !HasParentOfClass('cell', e.target as HTMLElement)) return
30-
this._gridEvents.CellSelectionStartedEvent.emit(true)
31-
32-
let state = this.controller.CreateSelectionStateFromMouseEvent.run({
33-
ctrlKey: !e.shiftKey && typeof this.controller.state?.previousSelection !== 'undefined',
34-
shiftKey: e.shiftKey,
35-
target: e.target
36-
})
37-
28+
if (!HasParentOfClass('cell', e.target as HTMLElement)) return
29+
let state = this.controller.CreateSelectionStateFromMouseEvent.run(e)
3830
if (!state) return
3931

40-
e.preventDefault() // stops native html element dragging
32+
const lastSelection = this.controller.latestSelection()
33+
// button 2 = Right Mouse Button
34+
if (e.button === 2 && lastSelection?.includes(state.startCellPos) === true) return
35+
36+
this._gridEvents.CellSelectionStartedEvent.emit(true)
37+
38+
// button 0 = Left Mouse Button
39+
if (e.button === 0) e.preventDefault() // stops native html element dragging
4140

4241
this.controller.state = state
4342

@@ -49,7 +48,9 @@ export class MultiRowSelectionStrategy implements IGridSelectionStrategy {
4948
this.controller.CalculateNextSelection.run()
5049

5150
const focusChanged = this.controller.EmitFocusedCell.run()
52-
if (focusChanged) state.previousSelection = state.currentSelection.clone()
51+
if (focusChanged) {
52+
state.previousSelection = state.currentSelection.clone()
53+
}
5354

5455
this._continueSelection()
5556
}
@@ -59,12 +60,20 @@ export class MultiRowSelectionStrategy implements IGridSelectionStrategy {
5960
const state = this.controller.state
6061
if (!state) throw new Error('Selection state is undefined')
6162

62-
this._gridEvents.RowMouseEnteredEvent.on()
63-
.pipe(removeNullish(), takeUntil(merge(this._windowFocusChanged, this._mouseReleased)))
64-
.subscribe(rowComponent => {
63+
const event: Observable<IGridCellCoordinates> = state.isRowSelection ?
64+
this._gridEvents.RowMouseEnteredEvent.onWithInitialValue().pipe(removeNullish(), map(row => row.lastCellPosition)) :
65+
this._gridEvents.CellMouseEnteredEvent.onWithInitialValue().pipe(removeNullish(), map(cell => new GridCellCoordinates( cell.rowComponent.rowKey, cell.column.columnKey )))
66+
67+
event
68+
.pipe(takeUntil(merge(this._windowFocusChanged, this._mouseReleased)))
69+
.subscribe(endCellPos => {
6570
const nextSelection = (state.hasShiftKey && state.previousSelection ? state.previousSelection : state.initialSelection).clone()
66-
this.controller.CalculateNextSelection.run(nextSelection, state.startCellPos, rowComponent.lastCellPosition)
71+
const columns = this.controller.gridController.dataSource.columns
72+
const lastColumnKey = columns[columns.length - 1].columnKey
73+
const firstColumnKey = columns[0].columnKey
74+
this.controller.CalculateNextSelection.run(nextSelection, new GridCellCoordinates(state.startCellPos.rowKey, firstColumnKey), new GridCellCoordinates(endCellPos.rowKey, lastColumnKey))
6775
this._emitSelection(nextSelection)
76+
this.controller.EmitNextSelectionSlice.run()
6877
})
6978
.add(() => {
7079
const finalSelection = this.controller.GetFinalSelection.run()

projects/ngx-grid-core/src/lib/controller/selection/strategies/standard.selection-strategy.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class StandardSelectionStrategy implements IGridSelectionStrategy {
1818
constructor(public readonly controller: ISelectionController) { }
1919

2020
public attach(el: HTMLElement): void {
21-
2221
this.controller.addSubscription(fromEvent(window.document.documentElement, 'mouseup').subscribe(_ => this._mouseReleased.next(true)))
2322
this.controller.addSubscription(fromEvent<MouseEvent>(el, 'mousedown').subscribe(e => this._startSelection(e)))
2423
this._keyboardHandling()

projects/ngx-grid-core/src/lib/events/row/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from "./row-status-changed.event"
55
export * from "./rows-committed.event"
66
export * from "./rows-inserted.event"
77
export * from "./rows-reverted.event"
8+
export * from "./row-double-clicked.event"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { IGridRowComponent } from '../../typings/interfaces'
2+
import { BaseGridEventAbstract } from '../base-grid-event.abstract'
3+
import { GridEventsService } from '../grid-events.service'
4+
5+
export class RowDoubleClickedEvent extends BaseGridEventAbstract<IGridRowComponent> {
6+
public readonly eventName = 'RowDoubleClickedEvent'
7+
constructor(eventService: GridEventsService) { super(eventService) }
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface IIconCellValue {
2+
key: string
3+
size: number
4+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { BehaviorSubject } from 'rxjs'
2+
3+
import { GridControllerService } from '../../../controller/grid-controller.service'
4+
import { GridOverlayService } from '../../../services/grid-overlay-service.service'
5+
import { ECellMode } from '../../../typings/enums/cell-mode.enum'
6+
import { IGridCellComponent } from '../../../typings/interfaces'
7+
import { BaseCellType } from './abstractions/base-cell-type.abstract'
8+
import { IIconCellValue } from '../../../typings/interfaces/icon-cell-value.interface'
9+
10+
export class IconCellType extends BaseCellType {
11+
12+
public mode = new BehaviorSubject<ECellMode>(ECellMode.Readonly)
13+
14+
private _displayNode?: HTMLElement
15+
16+
constructor(
17+
gridController: GridControllerService,
18+
overlayService: GridOverlayService,
19+
parentCell : IGridCellComponent
20+
) { super(overlayService, parentCell, gridController) }
21+
22+
public get displayNode() { return this._displayNode ?? this._generateDisplayNode() }
23+
public get editableNode() { return this.displayNode }
24+
25+
public override receiveValue(value: IIconCellValue | null = this.value): void {
26+
super.receiveValue(value)
27+
if (!this._displayNode) return;
28+
else
29+
{
30+
this._displayNode.innerText = value?.key ?? ''
31+
this._displayNode.style.fontSize = value?.size + 'px'
32+
}
33+
if (!value) this._displayNode.style.display = 'none'
34+
else this._displayNode.style.display = ''
35+
}
36+
37+
private _generateDisplayNode(): HTMLElement {
38+
const node = document.createElement('span')
39+
node.classList.add(this.gridController.iconClass)
40+
this._displayNode = node
41+
this.receiveValue()
42+
return this._displayNode
43+
}
44+
45+
public override measureWidth(): number {
46+
return this.value?.size ?? 0
47+
}
48+
49+
}

projects/ngx-grid-core/src/lib/ui/cell/cell-types/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { NumberCellType as Number } from './number.cell-type'
1010
import { RichTextCellType as RichText } from './rich-text.cell-type'
1111
import { TextCellType as Text } from './text.cell-type'
1212
import { ButtonCellType as Button } from './button.cell-type'
13+
import { IconCellType as Icon } from './icon.cell-type'
1314

1415
/* eslint-disable @typescript-eslint/naming-convention */
1516
const CELL_TYPES = {
@@ -24,7 +25,8 @@ const CELL_TYPES = {
2425
DropdownMultiSelect,
2526
File,
2627
Color,
27-
Button
28+
Button,
29+
Icon
2830
}
2931

3032
export default CELL_TYPES

projects/ngx-grid-core/src/lib/ui/cell/cell-types/value-multi-editing/multi-editors-factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export const CELL_MULTI_EDITORS: {[key in TCellTypeName]: Array<new (cellValue:
1616
File : [ editors.ClearValues ],
1717
Color : [ editors.ClearValues ],
1818
Button : [],
19+
Icon : [],
1920
}

projects/ngx-grid-core/src/lib/ui/cell/cell-types/value-parsing/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export const CELL_VALUE_PARSERS: {[key in TCellTypeName]: ICellValueParser} = {
1818
DateRange : new ValueParser([parsers.Array]),
1919
NumberRange : new ValueParser([parsers.Array]),
2020
Button : new ValueParser([parsers.Button]),
21+
Icon : new ValueParser([parsers.Icon]),
2122
}

0 commit comments

Comments
 (0)