Skip to content

Commit

Permalink
fix: rename some function
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankWang117 committed Feb 15, 2022
1 parent 61dabd6 commit cd2f74d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
10 changes: 7 additions & 3 deletions example/src/app/gantt/gantt.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
GanttItem,
GanttPrintService,
NgxGanttComponent,
GanttItemInternal
GanttItemInternal,
GanttSelectedEvent
} from 'ngx-gantt';
import { of } from 'rxjs';
import { delay } from 'rxjs/operators';
Expand Down Expand Up @@ -117,8 +118,11 @@ export class AppGanttExampleComponent implements OnInit {
this.items = [...this.items];
}

selectedChange(selectedItem: GanttItemInternal[]) {
this.thyNotify.info('Event: selectedChange', `当前选中的 item 的 id 为 ${selectedItem.map((item) => item.id).join('、')}`);
selectedChange(event: GanttSelectedEvent) {
this.thyNotify.info(
'Event: selectedChange',
`当前选中的 item 的 id 为 ${(event.selectedValue as GanttItem[]).map((item) => item.id).join('、')}`
);
}

linkDragEnded(event: GanttLinkDragEvent) {
Expand Down
5 changes: 5 additions & 0 deletions packages/gantt/src/class/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ export class GanttBarClickEvent<T = unknown> {
event: Event;
item: GanttItem<T>;
}

export class GanttSelectedEvent<T = unknown> {
event: Event;
selectedValue: GanttItem<T> | GanttItem<T>[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<ng-template #ganttItems let-group="group" let-items="items" let-level="level">
<ng-container *ngFor="let item of items; trackBy: trackBy">
<div
(click)="selectItem(item)"
(click)="itemClick.emit({ event: $event, selectedValue: this.item.origin })"
class="gantt-table-item gantt-table-row"
[class.gantt-table-item-first-level-group]="level === 0 && (item.type | isGanttRangeItem)"
[class.gantt-table-item-with-group]="group"
Expand Down
9 changes: 2 additions & 7 deletions packages/gantt/src/components/table/gantt-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import {
Output,
EventEmitter
} from '@angular/core';
import { GanttItemInternal, GanttGroupInternal } from '../../class';
import { GanttItemInternal, GanttGroupInternal, GanttSelectedEvent } from '../../class';
import { NgxGanttTableColumnComponent } from '../../table/gantt-column.component';
// import { defaultColumnWidth, minColumnWidth } from '../../gantt.component';
import { CdkDragEnd, CdkDragMove, CdkDragStart } from '@angular/cdk/drag-drop';
import { coerceCssPixelValue } from '@angular/cdk/coercion';
import { GanttAbstractComponent, GANTT_ABSTRACT_TOKEN } from '../../gantt-abstract';
import { SelectionModel } from '@angular/cdk/collections';
import { GanttUpper, GANTT_UPPER_TOKEN } from 'ngx-gantt';

export const defaultColumnWidth = 100;
Expand Down Expand Up @@ -62,7 +61,7 @@ export class GanttTableComponent implements OnInit, OnChanges {

@Input() rowAfterTemplate: TemplateRef<any>;

@Output() selectedChange = new EventEmitter<GanttItemInternal>();
@Output() itemClick = new EventEmitter<GanttSelectedEvent>();

@ViewChild('dragLine', { static: true }) draglineElementRef: ElementRef<HTMLElement>;

Expand Down Expand Up @@ -167,10 +166,6 @@ export class GanttTableComponent implements OnInit, OnChanges {
event.source.reset();
}

selectItem(item: GanttItemInternal) {
this.selectedChange.emit(item);
}

private showAuxiliaryLine(event: CdkDragMove) {
const tableRect = this.elementRef.nativeElement.getBoundingClientRect();
const targetRect = event.source.element.nativeElement.getBoundingClientRect();
Expand Down
2 changes: 1 addition & 1 deletion packages/gantt/src/gantt.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[emptyTemplate]="tableEmptyTemplate"
[rowBeforeTemplate]="table?.rowBeforeTemplate"
[rowAfterTemplate]="table?.rowAfterTemplate"
(selectedChange)="selectedItemChange($event)"
(itemClick)="selectItem($event)"
></gantt-table>
</ng-template>
<ng-template #mainTemplate>
Expand Down
17 changes: 9 additions & 8 deletions packages/gantt/src/gantt.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { startWith, takeUntil, take, finalize } from 'rxjs/operators';
import { Subject, Observable } from 'rxjs';
import { GanttUpper, GANTT_UPPER_TOKEN } from './gantt-upper';
import { GanttLinkDragEvent, GanttLineClickEvent, GanttItemInternal, GanttItem } from './class';
import { GanttLinkDragEvent, GanttLineClickEvent, GanttItemInternal, GanttItem, GanttSelectedEvent } from './class';
import { NgxGanttTableColumnComponent } from './table/gantt-column.component';
import { sideWidth } from './gantt.styles';
import { coerceCssPixelValue } from '@angular/cdk/coercion';
Expand Down Expand Up @@ -60,7 +60,7 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, AfterViewIn

@Output() lineClick = new EventEmitter<GanttLineClickEvent>();

@Output() selectedChange = new EventEmitter<GanttItemInternal | GanttItemInternal[]>();
@Output() selectedChange = new EventEmitter<GanttSelectedEvent>();

@ContentChild(NgxGanttTableComponent) table: NgxGanttTableComponent;

Expand Down Expand Up @@ -137,19 +137,20 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, AfterViewIn
}
}

selectedItemChange(item: GanttItemInternal) {
selectItem(selectEvent: GanttSelectedEvent) {
if (!this.selectable) {
return;
}
this.selectionModel.toggle(item.id);
const { event, selectedValue } = selectEvent;
this.selectionModel.toggle((selectedValue as GanttItem).id);

const selectedIds = this.selectionModel.selected;
if (this.multiple) {
const selectedItems = this.getGanttItems(selectedIds);
this.selectedChange.emit(selectedItems);
const selectedValue = this.getGanttItems(selectedIds).map((item) => item.origin);
this.selectedChange.emit({ event, selectedValue });
} else {
const selectedItem = this.getGanttItem(selectedIds[0]);
this.selectedChange.emit(selectedItem);
const selectedValue = this.getGanttItem(selectedIds[0])?.origin;
this.selectedChange.emit({ event, selectedValue });
}
}

Expand Down

0 comments on commit cd2f74d

Please sign in to comment.