Skip to content

Commit

Permalink
feat(table): add gantt side table
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeButterball authored and walkerkay committed May 27, 2020
1 parent a25d7b8 commit 89a7db9
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .angulardoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"repoId": "e269ef2e-9a71-4aa1-8085-f4a738a9cfef",
"lastSync": 0
}
11 changes: 10 additions & 1 deletion example/src/app/examples/examples.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
<ngx-gantt [start]="1514736000" end="1609430400" [items]="items" [groups]="groups"></ngx-gantt>
<ngx-gantt start="1514736000" end="1609430400" [items]="items" [groups]="groups">
<ngx-gantt-column name="标题">
<ng-template #cell let-row>
{{ row.origin.title }}
</ng-template>
</ngx-gantt-column>
<ng-template #group let-group>
{{ group.title }}
</ng-template>
</ngx-gantt>
19 changes: 16 additions & 3 deletions packages/gantt/src/gantt-upper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { Input, TemplateRef, Output, EventEmitter, ContentChild, ElementRef, HostBinding } from '@angular/core';
import {
Input,
TemplateRef,
Output,
EventEmitter,
ContentChild,
ElementRef,
HostBinding,
ContentChildren,
QueryList,
} from '@angular/core';
import {
GanttItem,
GanttGroup,
Expand All @@ -12,6 +22,7 @@ import { GanttView, GanttViewOptions } from './views/view';
import { createViewFactory } from './views/factory';
import { GanttDate } from './utils/date';
import { Subject, fromEvent } from 'rxjs';
import { GanttTableColumnComponent } from './table/column/column.component';

const defaultStyles = {
lineHeight: 55,
Expand Down Expand Up @@ -45,9 +56,11 @@ export abstract class GanttUpper {

@Output() dragEnded = new EventEmitter<GanttDragEvent>();

@ContentChild('barTemplate', { static: true }) barTemplate: TemplateRef<any>;
@ContentChild('bar', { static: true }) barTemplate: TemplateRef<any>;

@ContentChild('group', { static: true }) groupTemplate: TemplateRef<any>;

@ContentChild('groupTemplate', { static: true }) groupTemplate: TemplateRef<any>;
@ContentChildren(GanttTableColumnComponent) columns: QueryList<GanttTableColumnComponent>;

public view: GanttView;

Expand Down
8 changes: 7 additions & 1 deletion packages/gantt/src/gantt.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import { GanttContainerComponent } from './layout/gantt-container.component';
import { GanttSideComponent } from './layout/gantt-side.component';
import { GanttFlatComponent } from './flat/gantt-flat.component';
import { GanttBarComponent } from './bar/bar.component';
import { GanttTableColumnComponent } from './table/column/column.component';
import { GanttTableGroupComponent } from './table/group/group.component';
import { GanttTableItemsComponent } from './table/items/items.component';

@NgModule({
imports: [CommonModule],
exports: [GanttTableComponent, GanttFlatComponent],
exports: [GanttTableComponent, GanttFlatComponent, GanttTableColumnComponent],
declarations: [
GanttTableComponent,
GanttFlatComponent,
GanttSideComponent,
GanttContainerComponent,
GanttCalendarComponent,
GanttBarComponent,
GanttTableColumnComponent,
GanttTableGroupComponent,
GanttTableItemsComponent,
],
providers: [],
})
Expand Down
1 change: 1 addition & 0 deletions packages/gantt/src/table/column/column.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ng-content></ng-content>
10 changes: 7 additions & 3 deletions packages/gantt/src/table/column/column.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ContentChild, TemplateRef, Input } from '@angular/core';

@Component({
selector: 'gantt-table-column',
template: '',
selector: 'ngx-gantt-column',
templateUrl: './column.component.html',
})
export class GanttTableColumnComponent implements OnInit {
@Input() name: string;

@ContentChild('cell', { static: true }) templateRef: TemplateRef<any>;

constructor() {}

ngOnInit() {}
Expand Down
28 changes: 26 additions & 2 deletions packages/gantt/src/table/gantt-table.component.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
<gantt-side> </gantt-side>
<gantt-side>
<div class="gantt-items-header" *ngIf="columns?.length">
<table>
<thead>
<th *ngFor="let column of columns" [title]="column.name">
{{ column.name }}
</th>
</thead>
</table>
</div>
<div class="gantt-items-container">
<ng-container *ngIf="groups.length; else itemsTemplate">
<gantt-table-group *ngFor="let group of groups" [group]="group" [groupHeader]="groupTemplate">
<gantt-table-items [items]="group.items" [columns]="columns"></gantt-table-items>
</gantt-table-group>
</ng-container>
<ng-template #itemsTemplate
><gantt-table-items [items]="items" [columns]="columns"></gantt-table-items
></ng-template>
</div>
</gantt-side>
<gantt-container>
<gantt-calendar-overlay *ngIf="view"></gantt-calendar-overlay>
<div class="gantt-viewer-container">
<!-- groups -->
<div class="gantt-viewer-groups" *ngIf="groups && groups.length > 0; else itemsTemplate" [style.width.px]="view.width">
<div
class="gantt-viewer-groups"
*ngIf="groups && groups.length > 0; else itemsTemplate"
[style.width.px]="view.width"
>
<ng-container *ngFor="let group of groups; trackBy: trackBy">
<div class="gantt-group"></div>
<div class="gantt-items">
Expand Down
12 changes: 2 additions & 10 deletions packages/gantt/src/table/gantt-table.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import {
Component,
OnInit,
ElementRef,
ChangeDetectionStrategy,
Input,
EventEmitter,
Output,
HostBinding,
} from '@angular/core';
import { Component, OnInit, ElementRef, ChangeDetectionStrategy, Input, EventEmitter, Output } from '@angular/core';
import { GanttUpper } from '../gantt-upper';
import { GanttRef, GANTT_REF_TOKEN } from '../gantt-ref';
import { GanttDependencyDragEvent, GanttDependencyEvent, GanttItemInternal } from '../class';

@Component({
selector: 'ngx-gantt',
templateUrl: './gantt-table.component.html',
Expand Down
7 changes: 7 additions & 0 deletions packages/gantt/src/table/group/group.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="gantt-table-group-header">
<ng-template
[ngTemplateOutlet]="groupHeader"
[ngTemplateOutletContext]="{ $implicit: group, group: group }"
></ng-template>
</div>
<ng-content></ng-content>
18 changes: 18 additions & 0 deletions packages/gantt/src/table/group/group.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, OnInit, TemplateRef, Input, ViewChild, ElementRef, HostBinding } from '@angular/core';
import { GanttGroup } from '../../class/group';

@Component({
selector: 'gantt-table-group',
templateUrl: './group.component.html',
})
export class GanttTableGroupComponent implements OnInit {
@Input() group: GanttGroup;

@Input() groupHeader: TemplateRef<any>;

@HostBinding('class.gantt-table-group') ganttTableGroupClass = true;

constructor(public elementRef: ElementRef<HTMLDivElement>) {}

ngOnInit() {}
}
34 changes: 34 additions & 0 deletions packages/gantt/src/table/items/items.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<table>
<tbody>
<ng-container *ngFor="let row of items; let i = index">
<ng-template
[ngTemplateOutlet]="trTemplate"
[ngTemplateOutletContext]="{ row: row, index: i, level: 0 }"
></ng-template>
</ng-container>
</tbody>
</table>

<ng-template #trTemplate let-row="row" let-i="index" let-level="level">
<tr>
<td *ngFor="let column of columns">
<div [class.text-truncate]="true">
<ng-template
[ngTemplateOutlet]="tdTemplate"
[ngTemplateOutletContext]="{
column: column,
row: row,
index: i
}"
></ng-template>
</div>
</td>
</tr>
</ng-template>

<ng-template #tdTemplate let-column="column" let-row="row" let-index="index">
<ng-template
[ngTemplateOutlet]="column.templateRef"
[ngTemplateOutletContext]="{ $implicit: row, row: row, index: index }"
></ng-template>
</ng-template>
19 changes: 19 additions & 0 deletions packages/gantt/src/table/items/items.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, OnInit, Input, HostBinding, QueryList } from '@angular/core';
import { GanttItem } from '../../class/item';
import { GanttTableColumnComponent } from '../column/column.component';

@Component({
selector: 'gantt-table-items',
templateUrl: './items.component.html',
})
export class GanttTableItemsComponent implements OnInit {
@Input() items: GanttItem[] = [];

@Input() columns: QueryList<GanttTableColumnComponent>;

@HostBinding('class.gantt-table-items') ganttTableItemsClass = true;

constructor() {}

ngOnInit() {}
}

0 comments on commit 89a7db9

Please sign in to comment.