Our state of the art Gantt chart


Post by kenken9301680 »

Hello friends,

Before I used gantt version 4.0.8, I had to install the source base of the library and then import it into my project in the form

"bryntum-angular-shared": "file:../bryntum-gantt-4.0.8/gantt-4.0.8/examples/angular/_shared",
    "bryntum-gantt": "file:../bryntum-gantt-4.0.8/gantt-4.0.8/build",

Now i want to use gantt 4.1.5 using npm install

 "@bryntum/gantt": "4.1.5", // ex bryntum-gantt
    "@bryntum/gantt-angular": "4.1.5", // ex bryntum-angular-shared

But some previous features when using 4.0.8 version are now faulty, can you tell me how to fix the above errors. Here is my code:

import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
import ganttConfig from './../ganttConfig';
// import { allData } from '../../assets/data/all-data';
// import { GanttComponent } from 'bryntum-angular-shared';
import { BryntumGanttComponent } from '@bryntum/gantt-angular';

import {
  Panel,
  ProjectModel,
  EventModel,
  EventStore,
  LocaleManager,
  TaskStore,
  Gantt,
} from '@bryntum/gantt/gantt.lite.umd.js';
import { NgForm, FormGroup, FormControl, FormBuilder } from '@angular/forms';

import '../custom.locale.Ja.js';
import { CommonService } from '../services/common.service';

declare global {
  interface Window {
    ReactNativeWebView: any;
  }
}

@Component({
  selector: 'gantt-chart-work-all',
  templateUrl: 'gantt-chart-work-all.component.html',
  styleUrls: ['gantt-chart-work-all.component.scss'],
})
export class GanttChartWorkAllComponent implements OnInit, AfterViewInit {
  data;
  editedTask: boolean;

  testAll: any;
  typeFilter: any;

  constructor(private fb: FormBuilder, private _commonService: CommonService) {}

  title = 'gantt-chart-project';
  ganttConfig = ganttConfig;

  type = 0;
  name = '';

  // @ViewChild(GanttComponent, {
  //   static: false,
  // })
  // gantt: GanttComponent;

  listDataChange = [];

  @ViewChild(BryntumGanttComponent, { static: false })
  ganttComponent: BryntumGanttComponent;

  // private gantt : Gantt;

  ngOnInit(): void {
    this.getData();
    this.getTaskFilter();

this.getEdited();

this.onExportPDF();

LocaleManager.applyLocale('Ja');
  }

  ngAfterViewInit(): void {
    // console.log(this.gantt.ganttInstance);
    // store Gantt isntance
    // this.gantt = this.ganttComponent.instance;
    console.log(this.ganttComponent.instance);
  }

  getData() {
    this._commonService.allData$.subscribe(async (data) => {
      if (data) {
        this.data = await this._commonService.prepareAllData(data);
        const dataAllStore =
          await this._commonService.convertDataToTaskStoreAllData(this.data);

    this.testAll = dataAllStore;
    this._commonService.updateDataChart(this.ganttComponent, dataAllStore);
  }
});
  }

  async onGanttEvents(event: any) {
    if (event.type && event.type == 'taskresizeend') {
      await this.ganttComponent.instance.project.commitAsync();
      const updateData = {
        originalData: event?.taskRecord?.originalData,

    startDate: event?.taskRecord?.startDate,
    endDate: event?.taskRecord?.endDate,
    eventType: event?.type,
  };
  this.listDataChange = await this.listDataChange.filter(
    (data) => data?.originalData?.id != updateData?.originalData?.id
  );
  this.listDataChange.push(updateData);

  window.ReactNativeWebView.postMessage(
    JSON.stringify({
      action: 'pushDataChange',
      listDataChange: this.listDataChange,
    })
  );
} else if (event?.type && event?.type == 'aftertaskdrop') {
  await this.ganttComponent.instance.project.commitAsync();
  const updateDataDrag = {
    originalData: event?.taskRecords[0]?.originalData,
    startDate: event?.context?.startDate,
    endDate: event?.context?.endDate,
    eventType: event?.type,
  };
  this.listDataChange = await this.listDataChange.filter(
    (data) => data?.originalData?.id != updateDataDrag?.originalData?.id
  );
  this.listDataChange.push(updateDataDrag);
  window.ReactNativeWebView.postMessage(
    JSON.stringify({
      action: 'pushDataChange',
      listDataChange: this.listDataChange,
    })
  );
}
  }

  onExportPDF() {
    this._commonService.exportPdf$.subscribe(async (exportPdf) => {
      if (exportPdf?.isExportPdf && exportPdf?.isExportPdf == 0) {
        this.ganttComponent.instance.features.pdfExport.export().then(
          (res: any) => {
            if (res?.response?.parsedJson?.url) {
              window.ReactNativeWebView.postMessage(
                JSON.stringify({
                  action: 'pushAttachmentUrl',
                  url: res?.response?.parsedJson?.url,
                })
              );
            }
          },
          (err) => {
            console.log('err', err);
          }
        );
      }
    });
  }

  getTaskFilter() {
    this._commonService.taskFilter$.subscribe(async (data) => {
      if (data) {
        this.onTaskChanged(data);
      }
    });
  }

  getEdited() {
    this._commonService.edited$.subscribe(async (edited) => {
      if (edited == 1) {
        this.ganttComponent.features.taskResize.disabled = false;
        this.ganttComponent.features.taskDrag.disabled = false;
        // @ts-ignore: Unreachable code error
        this.ganttComponent.instance.subGrids.locked.collapsed = true;
      }
    });
  }

  async onTaskChanged(value) {
    const type = value;
    if (type.length > 0) {
      const filterAllData = await this._commonService.filterAllDataByType(
        this.data,
        type
      );
      const taskStoreAllData =
        await this._commonService.convertDataToTaskStoreAllData(filterAllData);
      this._commonService.updateDataChart(
        this.ganttComponent,
        taskStoreAllData
      );
    }
  }
}
Attachments
13.png
13.png (104.97 KiB) Viewed 394 times

Post by saki »

The errors are due to the missing detailed typings for features config option. I have created a ticket to add them: https://github.com/bryntum/support/issues/3023

As a workaround, until it is fixed, you can use:

this.ganttComponent.instance.features['pdfExport'].export().then( ...
// ...
this.ganttComponent.instance.features['taskResize'] ...
this.ganttComponent.instance.features['taskDrag'] ...

Or you can prefix the offending lines with // @ts-ignore.


Post by kenken9301680 »

Thank you for your help,

So I'm using generic gantt events into a function like this:

 async onGanttEvents(event: any) {
    if (event.type && event.type == 'taskresizeend') {
      await this.ganttComponent.instance.project.commitAsync();
      const updateData = {
        originalData: event?.taskRecord?.originalData,

    startDate: event?.taskRecord?.startDate,
    endDate: event?.taskRecord?.endDate,
    eventType: event?.type,
  };
  this.listDataChange = await this.listDataChange.filter(
    (data) => data?.originalData?.id != updateData?.originalData?.id
  );
  this.listDataChange.push(updateData);

  window.ReactNativeWebView.postMessage(
    JSON.stringify({
      action: 'pushDataChange',
      listDataChange: this.listDataChange,
    })
  );
} else if (event?.type && event?.type == 'aftertaskdrop') {
  await this.ganttComponent.instance.project.commitAsync();
  const updateDataDrag = {
    originalData: event?.taskRecords[0]?.originalData,
    startDate: event?.context?.startDate,
    endDate: event?.context?.endDate,
    eventType: event?.type,
  };
  this.listDataChange = await this.listDataChange.filter(
    (data) => data?.originalData?.id != updateDataDrag?.originalData?.id
  );
  this.listDataChange.push(updateDataDrag);
  window.ReactNativeWebView.postMessage(
    JSON.stringify({
      action: 'pushDataChange',
      listDataChange: this.listDataChange,
    })
  );
}
  }

But in the file bryntum-gantt.component.d.ts is split into separate events, for example onTaskDrag, onTaskResizeEnd, ...

So I also have to separate events when handling?


Post by saki »

Both approaches work. If you want to have one handler for all events then you need

(onCatchAll) = "onGanttEvents($event)"

in your template file and if you want per-event handlers, you need:

(onTaskDrag) = "taskDragHandler($event);
(onTaskResize) = "taskResizeHandler($event);

It's a matter of preference but the latter makes the code more granular and readable.

Note: Your second question should have been posted as a new topic.


Post Reply