Skip to content
6 changes: 3 additions & 3 deletions packages/qgrid-core/src/format/format.service.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export declare class FormatService {
static number(x: number, format: string): string;
static date(x: Date, format: string): string;
static currency(x: number, format: string): string;
static number(x: number, format: string): string | null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets discuss to use Nullable instead of string | null

static date(x: Date, format: string): string | null;
static currency(x: number, format: string): string | null;
}
10 changes: 5 additions & 5 deletions packages/qgrid-core/src/plugin/grid.plugin.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Model } from '../model/model';
import { Table } from '../dom/table';
import { GridLet } from '../grid/grid.let';
import { ObservableLike } from '../rx/rx';
import { Event } from '../event/event';
import { GridLet } from '../grid/grid.let';
import { GridService } from '../grid/grid.service';
import { Model } from '../model/model';
import { ObservableEvent, ObservableReplyEvent } from '../rx/rx';

export interface GridPlugin {
readonly model: Model;
readonly table: Table;
readonly view: GridLet;
readonly service: GridService;

observe<TState>(event: Event<TState>): ObservableLike<TState>;
observeReply<TState>(event: Event<TState>): ObservableLike<TState>;
observe<TState>(event: Event<TState>): ObservableEvent<TState>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we change it to ObservableEvent? it should return the minimal required interface

observeReply<TState>(event: Event<TState>): ObservableReplyEvent<TState>;
}
2 changes: 1 addition & 1 deletion packages/qgrid-core/src/scene/render/render.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RenderStrategy } from './render.strategy';

export declare class Renderer {
defaultStrategy: RenderStrategy;
readonly rows: { left: any[]; right: any[]; mid: any[] };
readonly rows: Record<string, any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd create an interface for left, right, mid object and use it here.

export interface RowsPosition {
  left: any[];
  mid: any[];
  right: any[];
}
....
readonly rows: RowsPosition;

Because Record<string, ...> could accept any string as a key;


constructor(plugin: GridPlugin);

Expand Down
14 changes: 7 additions & 7 deletions packages/qgrid-ngx/src/lib/body/body-core.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export class BodyCoreComponent implements OnInit {
scrollSettings,
));

disposable.add(listener.on('wheel', e => host.wheel(e)));
disposable.add(listener.on('mouseleave', e => host.mouseLeave(e)));
disposable.add(listener.on('wheel', (e: WheelEvent) => host.wheel(e)));
disposable.add(listener.on('mouseleave', (e: WheelEvent) => host.mouseLeave(e)));
});

observeReply(model.sceneChanged)
.subscribe(e => {
.subscribe((e: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e: GridEventArg<SceneState>

if (model.grid().interactionMode === 'detached') {
if (e.hasChanges('status')) {
switch (e.state.status) {
Expand All @@ -86,22 +86,22 @@ export class BodyCoreComponent implements OnInit {
});

observe(model.sceneChanged)
.subscribe(e => {
.subscribe((e: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e: GridEventArg<SceneState>

if (e.hasChanges('status') && e.state.status === 'push') {
this.cd.markForCheck();
}
});
}

columnId(index: number, item: ColumnView) {
columnId(index: number, item: ColumnView): string | undefined {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorly string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not possible. Have to specify it as a union.
image

return item.model.key;
}

rowId(index: number) {
rowId(index: number): number {
return index;
}

mapToDataIndex(viewIndex: number) {
mapToDataIndex(viewIndex: number): number {
return this.$view.scroll.y.container.position + viewIndex;
}
}
4 changes: 1 addition & 3 deletions packages/qgrid-ngx/src/lib/body/body.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import { RowModule } from '../row/row.module';
VscrollModule,
RowModule,
],
exports: [
BodyCoreComponent,
],
exports: [BodyCoreComponent],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check indentation.
Should be as before

})
export class BodyModule {
}
4 changes: 2 additions & 2 deletions packages/qgrid-ngx/src/lib/body/td-core.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { TrCoreDirective } from '../row/tr-core.directive';
selector: '[q-grid-core-td]',
})
export class TdCoreDirective implements DomTd, OnInit, OnDestroy, OnChanges {
@Input('q-grid-core-value') actualValue: any;
@Input('q-grid-core-label') actualLabel: any;
@Input('q-grid-core-value') actualValue: unknown;
@Input('q-grid-core-label') actualLabel: unknown;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about that


@Input('q-grid-core-td') columnView: ColumnView;

Expand Down
8 changes: 2 additions & 6 deletions packages/qgrid-ngx/src/lib/box/box.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { NgModule } from '@angular/core';
import { BoxComponent } from './box.component';

@NgModule({
declarations: [
BoxComponent,
],
exports: [
BoxComponent,
],
declarations: [BoxComponent],
exports: [BoxComponent],
})
export class BoxModule {
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class CellHandlerComponent implements OnInit, AfterViewInit {
if (e.hasChanges('status')) {
if (e.state.status === 'endBatch' && this.endBatchEdit) {
this.endBatchEdit();
this.endBatchEdit = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this will break something

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be reverted

}
}
});
Expand Down
12 changes: 3 additions & 9 deletions packages/qgrid-ngx/src/lib/cell-handler/cell-handler.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ import { CommonModule } from '@angular/common';
import { CellHandlerComponent } from './cell-handler.component';

@NgModule({
declarations: [
CellHandlerComponent,
],
exports: [
CellHandlerComponent,
],
imports: [
CommonModule,
],
declarations: [CellHandlerComponent],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put back formatting.
It should be autoformatted on save

exports: [CellHandlerComponent],
imports: [CommonModule],
})
export class CellHandlerModule {
}
8 changes: 4 additions & 4 deletions packages/qgrid-ngx/src/lib/cell/cell-template.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { Injectable, ViewContainerRef } from '@angular/core';
import { ColumnModel, GridError, noop } from '@qgrid/core';
import { TemplateService } from '../template/template.service';

function canBuild(column) {
function canBuild(column: ColumnModel) {
return column.type !== 'pad';
}

function buildId(source: string, column: ColumnModel, mode = 'view') {
const { key, type, itemType } = column as any;
const { key, type, itemType } = column;
return `${source}-${mode}-cell-${type}-of-${itemType}-the-${key}.tpl.html`;
}

function buildKeys(source: string, column: ColumnModel, mode = 'view') {
const { key, itemType } = column as any;
let { type } = column as any;
const { key, itemType } = column;
let { type } = column;

switch (mode) {
case 'view': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { NgModule } from '@angular/core';
import { DirtyDirective } from './dirty.directive';

@NgModule({
declarations: [
DirtyDirective,
],
exports: [
DirtyDirective,
],
declarations: [DirtyDirective],
exports: [DirtyDirective],
})
export class ChangeDetectorModule {
}
8 changes: 2 additions & 6 deletions packages/qgrid-ngx/src/lib/column-list/column-list.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { NgModule } from '@angular/core';
import { ColumnListComponent } from './column-list.component';

@NgModule({
declarations: [
ColumnListComponent,
],
exports: [
ColumnListComponent,
],
declarations: [ColumnListComponent],
exports: [ColumnListComponent],
})
export class ColumnListModule {
}
14 changes: 7 additions & 7 deletions packages/qgrid-ngx/src/lib/column-list/column-list.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { GridPlugin } from '../plugin/grid-plugin';
@Injectable()
export class ColumnListService {
private host = new Lazy(() => {
const canCopy = (key: string, source, target) =>
const canCopy = (key: string, source: any, target: any) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source, target - Partial<ColumnModel>

Object.prototype.hasOwnProperty.call(target, key) && !isUndefined(source[key]);

return new ColumnListHost(this.plugin.model, canCopy, parseFactory);
Expand All @@ -20,27 +20,27 @@ export class ColumnListService {
constructor(private plugin: GridPlugin) {
}

add(column: ColumnModel) {
add(column: ColumnModel): void {
this.host.instance.add(column);
}

copy(target, source) {
copy(target: any, source: any): void {
Copy link
Collaborator

@klumba12 klumba12 May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any -> Partial<ColumnModel>

this.host.instance.copy(target, source);
}

generateKey(source) {
generateKey(source: any): string {
Copy link
Collaborator

@klumba12 klumba12 May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any -> Partial<ColumnModel>

return this.host.instance.generateKey(source);
}

extract(key, type): ColumnModel {
extract(key: string, type: string): ColumnModel {
return this.host.instance.extract(key, type);
}

register(column: ColumnModel) {
register(column: ColumnModel): void {
this.host.instance.register(column);
}

delete(key: string) {
delete(key: string): void {
this.host.instance.delete(key);
}
}
20 changes: 13 additions & 7 deletions packages/qgrid-ngx/src/lib/column/column.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ColumnComponent implements OnInit, OnDestroy, OnChanges {
// We want to update model when ngOntInit is triggered and not in afterViewInit
// so we apply dirty hack to understand if column is cohort or not.
const element = this.elementRef.nativeElement as HTMLElement;
if (element.children.length && element.children.item(0).tagName === 'Q-GRID-COLUMN') {
if (element.children.length && element.children.item(0)?.tagName === 'Q-GRID-COLUMN') {
this.type = 'cohort';
if (!withKey) {
this.key = `$cohort-${this.title || guid()}`;
Expand Down Expand Up @@ -142,7 +142,9 @@ export class ColumnComponent implements OnInit, OnDestroy, OnChanges {

if (withKey) {
if (this.parentHost) {
this.parentHost.column.children.push(column);
if (this.parentHost.column.children) {
this.parentHost.column.children.push(column);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually you can replace these lines with
this.parentHost.column.children?.push(column);

}
} else {
this.columnList.add(column);
}
Expand All @@ -152,9 +154,9 @@ export class ColumnComponent implements OnInit, OnDestroy, OnChanges {
const settings =
Object
.keys(this)
.filter(key => !isUndefined(this[key]) && Object.prototype.hasOwnProperty.call(column, key))
.reduce((memo, key) => {
memo[key] = column[key];
.filter(key => !isUndefined(this.key) && Object.prototype.hasOwnProperty.call(column, key))
.reduce((memo: any, key: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memo isn't any.
{ [key: string]: Column } if i got this right

memo[key] = column[key as keyof ColumnModel];
return memo;
}, {}) as ColumnModel;

Expand All @@ -180,8 +182,12 @@ export class ColumnComponent implements OnInit, OnDestroy, OnChanges {

ngOnDestroy() {
const { column } = this.selfHost;
if (column && column.source === 'template') {
this.columnList.delete(column.key);
if (!(column && column.source === 'template')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!column || column.source !== 'template' is more readable, as for me.
If there's no column OR coumn source is not template.
Same thing with column.key.

Btw, why you even need to change this condition?

if (column && column.key && column.source === 'template') {
  this.columnList.delete(column.key);
}

return;
}
if(!column.key) {
return;
}
this.columnList.delete(column.key);
}
}
10 changes: 2 additions & 8 deletions packages/qgrid-ngx/src/lib/dnd/dnd.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ import { DragDirective } from './drag.directive';
import { DropDirective } from './drop.directive';

@NgModule({
declarations: [
DragDirective,
DropDirective,
],
exports: [
DragDirective,
DropDirective,
],
declarations: [DragDirective, DropDirective],
exports: [DragDirective, DropDirective],
})
export class DndModule {
}
13 changes: 7 additions & 6 deletions packages/qgrid-ngx/src/lib/dnd/drag.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class DragDirective {

if (this.drag.canExecute(eventArg) === false) {
e.preventDefault();
transfer.effectAllowed = 'none';
if (transfer) {
transfer.effectAllowed = 'none';
}
return false;
}

Expand All @@ -50,8 +52,10 @@ export class DragDirective {

this.elementRef.nativeElement.classList.add(`${GRID_PREFIX}-drag`);

transfer.setData(DragService.mimeType, DragService.encode(data));
transfer.effectAllowed = this.effect || 'move';
if(transfer) {
transfer.setData(DragService.mimeType, DragService.encode(data));
transfer.effectAllowed = this.effect || 'move';
}

DragService.data = data;
DragService.area = this.area;
Expand All @@ -78,8 +82,5 @@ export class DragDirective {
this.elementRef.nativeElement.classList.remove(`${GRID_PREFIX}-drag`);

DragService.data = null;
DragService.area = null;
DragService.element = null;
DragService.startPosition = null;
}
}
12 changes: 9 additions & 3 deletions packages/qgrid-ngx/src/lib/dnd/drop.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export class DropDirective implements OnInit {
e.preventDefault();

this.elementRef.nativeElement.classList.add(`${GRID_PREFIX}-dragover`);
e.dataTransfer.dropEffect = 'move';
if (e.dataTransfer) {
e.dataTransfer.dropEffect = 'move';
}
return false;
}

Expand All @@ -117,7 +119,9 @@ export class DropDirective implements OnInit {
}

if (this.area !== DragService.area) {
e.dataTransfer.dropEffect = 'none';
if (e.dataTransfer) {
e.dataTransfer.dropEffect = 'none';
}
return false;
}

Expand All @@ -142,7 +146,9 @@ export class DropDirective implements OnInit {
DragService.data = eventArg.dragData;
}

e.dataTransfer.dropEffect = 'move';
if(e.dataTransfer) {
e.dataTransfer.dropEffect = 'move';
}
}

return false;
Expand Down
15 changes: 3 additions & 12 deletions packages/qgrid-ngx/src/lib/foot/foot.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@ import { RowModule } from '../row/row.module';
import { CommonModule } from '@angular/common';

@NgModule({
declarations: [
FootCoreComponent,
TfCoreDirective,
],
exports: [
FootCoreComponent,
TfCoreDirective,
],
imports: [
CommonModule,
RowModule,
],
declarations: [FootCoreComponent, TfCoreDirective],
exports: [FootCoreComponent ,TfCoreDirective],
imports: [CommonModule, RowModule],
})
export class FootModule {
}
Loading