diff --git a/.npmignore b/.npmignore index 2f6a9716..f229ebbd 100644 --- a/.npmignore +++ b/.npmignore @@ -6,5 +6,4 @@ src/ vite.config.js tsconfig.json eslint.config.js -AGENTS.md CONTRIBUTING.md diff --git a/AGENTS.md b/AGENTS.md index bd8943aa..48ebbd90 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,46 +1,50 @@ # AGENTS.md -Guidance for AI coding agents working in this repository. +Guidance for AI coding agents working with DHTMLX Gantt in this project. ## What this is -DHTMLX Gantt, MIT edition — an open source JavaScript Gantt chart library. The repository ships library sources, samples, and a smoke test suite. It is generated from an internal source tree on each release (see CONTRIBUTING.md), so structural refactors should stay minimal and focused. - -## Layout - -| Path | Content | -|---|---| -| `src/dhtmlxgantt.ts` | library entry point | -| `src/core/` | core: datastores, task data layer, UI (grid, timeline, lightbox), worktime | -| `src/core/plugins/` | always-on plugins (batch update, task types, formatters…) | -| `src/ext/` | opt-in extensions activated via `gantt.plugins({...})` (tooltip, quick_info, keyboard_navigation…) | -| `src/css/` | LESS styles, fonts, skins | -| `src/locale/` | locales | -| `samples/` | runnable demos; served by `npm run start`, and the corpus the smoke test loads | -| `scripts/` | build/dev/test node scripts, sample-data backend | -| `codebase/` | build output (generated; never edit by hand) | - -## Commands - -```bash -npm install -npm run build # vite build -> codebase/ + d.ts -npm run start # watch build + backend (:9200) + vite devserver -npm run test # build + smoke test: every sample loads without console errors -npm run test 07_grid # smoke just one samples folder -npm run lint # eslint over src/ (flat config, intentionally lax) -``` - -## Working on the code - -- The build must stay green: `npm run build` after any `src/` change, and `npm run lint` should pass. -- `npm run test` is a smoke pass: it loads every sample headless and fails on a page error or `console.error`. It is the regression net — keep it green after `src/` changes. -- Sample pages reference `../../codebase/dhtmlxgantt.js` — run a build before opening them. -- `src/types.d.ts` declares the compile-time globals (`VERSION`, `LICENSE`, …) injected by vite `define`. -- Some modules are intentional basic implementations of Pro features (e.g. `src/core/ui/render/dummy_layer.js`, re-export shims like `src/core/ui/grid/resource_grid.js`, and `src/core/worktime/strategy/calendar_strategy.js` which re-exports the disabled `no_work_time` strategy — working-time calendars are out of scope). Do not "complete" them — the Pro feature set is out of scope for this edition (see README). - -## Conventions - -- Match the style of the file you edit (the codebase mixes older ES5-style JS and newer TS — both are fine in their places). -- Tabs for indentation. -- No new runtime dependencies — the library bundle must stay dependency-free. +DHTMLX Gantt, MIT edition (`dhtmlx-gantt` v10+) — an open source JavaScript Gantt chart library. Many Gantt examples online describe the PRO edition, so some APIs you know may be missing here (see Edition limits). + +- Install, import and the first chart: [README.md](README.md), "Quick start". +- Changing the library source code: see `CONTRIBUTING.md` in the [GitHub repository](https://github.com/DHTMLX/gantt). + +## Before you write code + +Use these instead of working from memory: + +- **DHTMLX MCP server** (`https://docs.dhtmlx.com/mcp`): current API and docs. Use it to confirm config, method and event names and signatures. + - Claude Code: `claude mcp add --transport http dhtmlx-mcp https://docs.dhtmlx.com/mcp` + - Codex: `codex mcp add dhtmlx-mcp --url https://docs.dhtmlx.com/mcp` + - Other clients: add the same URL as an HTTP MCP server. +- **Agent skill** `dhtmlx-js-gantt`: integration patterns and known pitfalls. Install: `npx skills add DHTMLX/skills --skill dhtmlx-js-gantt` ([source](https://github.com/DHTMLX/skills/tree/main/dhtmlx-js-gantt)). + +If they are not installed, suggest that the user installs them. Without MCP, use the [docs](https://docs.dhtmlx.com/gantt/). + +## Edition limits + +Some features are kept out of this community build; the PRO edition has them. The list is in [README.md](README.md), "Community vs PRO". + +- These APIs do not throw. They are missing or silent no-ops, so a chart that loads fine can still lack the feature. Enabling a plugin that is not in this build does nothing. +- `codebase/dhtmlxgantt.d.ts` describes the full product. Types and autocomplete do not prove a feature exists here. +- MCP and the docs cover PRO too. Check every feature you use against the list above. +- If a requested feature is not in this edition, tell the user before writing code: name the feature and say it is a PRO feature ([comparison](https://docs.dhtmlx.com/gantt/guides/editions-comparison/), [30-day trial](https://dhtmlx.com/docs/products/dhtmlxGantt/download.shtml)). Then still write the requested code. Do not silently replace or drop it. +- Check the edition at runtime with `gantt.license` (`"mit"` here). +- `ReactGantt`, `VueGantt` and `AngularGantt` are PRO components. For React, Angular and Vue, use the [integration guides](https://docs.dhtmlx.com/gantt/integrations/react/js-gantt-react/) with the core library. + +## Rules that prevent common bugs + +- Give the Gantt container an explicit height, and import `dhtmlx-gantt/codebase/dhtmlxgantt.css`. +- Set config and call `gantt.plugins({...})` before `gantt.init()`. +- Pass dates as `Date` objects or strings that match `gantt.config.date_format`. A mismatch shifts dates by years. +- Template return values are inserted as raw HTML. Escape user-supplied text before it reaches a template. +- For several charts, or a chart inside a component lifecycle, use `Gantt.getGanttInstance()` and call `destructor()` on that instance. Never call `destructor()` on the default `gantt` export, and never use `gantt.detachAllEvents()`. +- `gantt.init()` fires `onGanttReady` every time. Attach handlers and create the DataProcessor once, not inside a repeated `onGanttReady`. +- Apply changes that come from outside (a socket, another user) inside `gantt.silent(...)`, so the DataProcessor does not send them back. +- Use documented API only. Verify unfamiliar names and signatures with MCP. + +## Links + +- [Documentation](https://docs.dhtmlx.com/gantt/) and [API reference](https://docs.dhtmlx.com/gantt/api/) +- [Samples](https://docs.dhtmlx.com/gantt/samples/) (also in `samples/` of the repository) +- [Community forum](https://forum.dhtmlx.com/c/gantt) diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..43c994c2 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +@AGENTS.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d1c4ed13..115dc590 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,9 +2,11 @@ Thank you for your interest in improving DHTMLX Gantt! +This file is for people who change the library code in this repository. If you only use the library in your own project, see [AGENTS.md](AGENTS.md) and [README.md](README.md). + ## How this repository is maintained -This repository is **generated from an internal source tree** on every release. The content of each release replaces the previous content wholesale — pull requests cannot be merged here directly. +This repository is **generated from an internal source tree** on every release. The content of each release replaces the previous content wholesale — pull requests cannot be merged here directly. Because of this, structural refactors should stay minimal and focused. That said, contributions are welcome and are handled like this: @@ -24,15 +26,46 @@ Please include: ## Development +### Repository layout + +| Path | Content | +|---|---| +| `src/dhtmlxgantt.ts` | library entry point | +| `src/core/` | core: datastores, task data layer, UI (grid, timeline, lightbox), worktime | +| `src/core/plugins/` | always-on plugins (batch update, task types, formatters…) | +| `src/ext/` | opt-in extensions activated via `gantt.plugins({...})` (tooltip, quick_info, keyboard_navigation…) | +| `src/css/` | LESS styles, fonts, skins | +| `src/locale/` | locales | +| `samples/` | runnable demos; served by `npm run start`, and the corpus the smoke test loads | +| `scripts/` | build/dev/test node scripts, sample-data backend | +| `codebase/` | build output (generated; never edit by hand) | + +### Commands + ```bash npm install -npm run start # watch build + dev server with samples -npm run test # smoke test: every sample loads without console errors -npm run lint # eslint over src/ +npm run build # vite build -> codebase/ + d.ts +npm run start # watch build + backend (:9200) + vite devserver +npm run test # build + smoke test: every sample loads without console errors +npm run test 07_grid # smoke just one samples folder +npm run lint # eslint over src/ (flat config, intentionally lax) ``` `npm run test` is a smoke pass: it builds the library, then loads every sample headless and fails on a page error or `console.error`. Run it before opening a PR — a red result means your change broke a sample. +### Working on the code + +- The build must stay green: run `npm run build` after any `src/` change, and `npm run lint` should pass. +- Sample pages reference `../../codebase/dhtmlxgantt.js` — run a build before opening them. +- `src/types.d.ts` declares the compile-time globals (`VERSION`, `LICENSE`, …) injected by vite `define`. +- Some modules are intentional basic implementations of Pro features (e.g. `src/core/ui/render/dummy_layer.js`, re-export shims like `src/core/ui/grid/resource_grid.js`, and `src/core/worktime/strategy/calendar_strategy.js` which re-exports the disabled `no_work_time` strategy — working-time calendars are out of scope). Do not "complete" them — the Pro feature set is out of scope for this edition (see Scope below). + +### Conventions + +- Match the style of the file you edit (the codebase mixes older ES5-style JS and newer TS — both are fine in their places). +- Tabs for indentation. +- No new runtime dependencies — the library bundle must stay dependency-free. + ## Scope This edition intentionally excludes the Pro-only features (auto scheduling, critical path, resources, baselines, split tasks, and others) as well as some features kept out of this community build (markers, multiselect, undo/redo, unscheduled tasks, the new-task placeholder) — see README. PRs that re-implement out-of-scope features will be declined. diff --git a/README.md b/README.md index 19b21454..40d36ce4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DHTMLX Gantt - JavaScript Gantt Chart (Community Edition) -[![npm: v.10.0.3](https://img.shields.io/badge/npm-v.10.0.3-blue.svg)](https://www.npmjs.com/package/dhtmlx-gantt) · [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md) · [![made by DHTMLX](https://img.shields.io/badge/made%20by-DHTMLX-blue)](https://dhtmlx.com/) +[![npm: v.10.0.4](https://img.shields.io/badge/npm-v.10.0.4-blue.svg)](https://www.npmjs.com/package/dhtmlx-gantt) · [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md) · [![made by DHTMLX](https://img.shields.io/badge/made%20by-DHTMLX-blue)](https://dhtmlx.com/) ![](dhtmlx_logo.svg) @@ -206,7 +206,7 @@ The Community Edition covers the everyday Gantt feature set, **including project - **Drag-and-drop scheduling** - move task bars to reschedule; resize bars to change duration - **Progress indicators** - completion shown as a filled bar segment, editable in the lightbox - **Lightbox task editor** - configurable modal dialog; add your own controls -- **Smart rendering** - only visible rows/columns are drawn, for large datasets +- **Large-dataset rendering** - row and timeline virtualization renders only visible tasks, links, and timeline cells to reduce rendering overhead - **Multiple chart instances** - render several independent Gantts on one page via the `Gantt` factory - **Templates** - override any rendered element (bars, grid cells, scale cells, tooltips) - **Plugins** - tooltips, quick info, keyboard navigation, fullscreen, drag-timeline, click-drag @@ -220,6 +220,8 @@ The Community Edition covers the everyday Gantt feature set, **including project > **Note:** `codebase/dhtmlxgantt.d.ts` describes the full product API, so it lists some PRO-only methods that are not present in this edition. +**Performance at scale**: Explore [benchmarks with up to 100,000 tasks](https://dhtmlx.com/blog/javascript-gantt-performance-benchmark-handling-up-to-100000-tasks/) and [performance optimization tips](https://docs.dhtmlx.com/gantt/guides/performance/). The benchmarks cover both rendering and scheduling workloads, including PRO-only features. + --- ## Community vs PRO @@ -315,6 +317,8 @@ Building with an AI coding assistant (Claude Code, Cursor, Codex…)? Two free h - [DHTMLX MCP Server](https://docs.dhtmlx.com/gantt/integrations/ai-tools/mcp-server/) - connects your assistant to up-to-date DHTMLX documentation and API reference. - [Agent Skills](https://docs.dhtmlx.com/gantt/integrations/ai-tools/agent-skills/) - teach the assistant correct integration patterns and known pitfalls. +The package also ships [AGENTS.md](AGENTS.md) with rules for AI agents (edition limits, common pitfalls). Point your assistant to `node_modules/dhtmlx-gantt/AGENTS.md`. + ## Useful links - [Export services](https://dhtmlx.com/docs/products/dhtmlxGantt/export.shtml) diff --git a/bower.json b/bower.json index f0d3cb7d..2f7584bb 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "gantt", - "version": "10.0.3", + "version": "10.0.4", "homepage": "https://dhtmlx.com/docs/products/dhtmlxGantt/", "description": "An open source JavaScript Gantt chart that helps you illustrate a project schedule in a nice-looking chart.", "main": [ diff --git a/package-lock.json b/package-lock.json index 38ac4e3a..184b0427 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dhtmlx-gantt", - "version": "10.0.3", + "version": "10.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dhtmlx-gantt", - "version": "10.0.3", + "version": "10.0.4", "license": "MIT", "devDependencies": { "chalk": "^5.3.0", diff --git a/package.json b/package.json index d0915ca2..ce841f81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dhtmlx-gantt", - "version": "10.0.3", + "version": "10.0.4", "description": "DHTMLX Gantt - open source JavaScript Gantt chart (Community edition)", "type": "module", "main": "codebase/dhtmlxgantt.js", @@ -11,7 +11,9 @@ "codebase", "whatsnew.md", "README.md", - "LICENSE.md" + "LICENSE.md", + "AGENTS.md", + "CLAUDE.md" ], "scripts": { "build": "vite build && node scripts/postbuild.js", diff --git a/samples/04_customization/05_tree_template.html b/samples/04_customization/05_tree_template.html index 46658367..d9020a89 100644 --- a/samples/04_customization/05_tree_template.html +++ b/samples/04_customization/05_tree_template.html @@ -1,39 +1,39 @@ - - - - Template for tree nodes - - - - - - - - - -
- - - + + + + Template for tree nodes + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/samples/05_lightbox/04_custom_editor.html b/samples/05_lightbox/04_custom_editor.html index e3af1e89..33562a6d 100644 --- a/samples/05_lightbox/04_custom_editor.html +++ b/samples/05_lightbox/04_custom_editor.html @@ -1,50 +1,50 @@ - - - - Custom control in the lightbox - - - - - - - -
- - + + + + Custom control in the lightbox + + + + + + + +
+ + \ No newline at end of file diff --git a/samples/common/bodyScrollLock.min.js b/samples/common/bodyScrollLock.min.js index 524f0b6f..55541554 100644 --- a/samples/common/bodyScrollLock.min.js +++ b/samples/common/bodyScrollLock.min.js @@ -1 +1 @@ -!function(e,t){if("function"==typeof define&&define.amd)define(["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var o={};t(o),e.bodyScrollLock=o}}(this,function(exports){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,o=Array(e.length);t - + diff --git a/scripts/assets/dhtmlxgantt.d.ts.template b/scripts/assets/dhtmlxgantt.d.ts.template index 96fa6578..fd1e8abd 100644 --- a/scripts/assets/dhtmlxgantt.d.ts.template +++ b/scripts/assets/dhtmlxgantt.d.ts.template @@ -701,7 +701,7 @@ export interface GanttEventCallback { * @param id the id of the double clicked task * @param e a native event object */ - "onTaskDblClick"(id: string, e?: Event): boolean; + "onTaskDblClick"(id: string | number, e?: Event): boolean; /** * fires when the user drags a task @@ -2923,9 +2923,9 @@ export interface GanttStatic { getScrollState(): { x: number, y: number }; /** - * returns the id of the selected task + * returns the id of the selected task, or null if no task is selected */ - getSelectedId(): string; + getSelectedId(): string | number | null; /** * returns an array of the currently selected tasks @@ -4990,7 +4990,7 @@ export interface GanttUIState { /** * the id of a task that the user is currently dragging in the Gantt chart. *undefined* or *null*, if no tasks are being dragged in the Gantt chart. */ - drag_id: string | null | undefined, + drag_id: string | number | null | undefined, /** * the drag mode. Has these values: 'move','resize','progress', 'ignore' when a task is dragged. Otherwise, has *null* or *undefined* value. @@ -5005,7 +5005,7 @@ export interface GanttUIState { /** * the id of a task that is currently opened in the lightbox. *undefined* or *null*, if no tasks are opened in the lightbox. */ - lightbox: string | null | undefined, + lightbox: string | number | null | undefined, /** * the new link creation state, returns *true* when the link is created from the start of the predecessor task. @@ -5055,7 +5055,7 @@ export interface GanttUIState { /** * the id of the currently selected task. *undefined* or *null*, if no tasks are selected in the Gantt chart. */ - selected_task: string | null | undefined + selected_task: string | number | null | undefined } export interface RoundDateConfig { @@ -5685,7 +5685,7 @@ export interface CalendarConfig { [timespan: string]: { from: Date, to: Date, - hours?: Array, + hours?: Array | boolean, days?: WorkDaysTuple | WorkDaysSettings | boolean, }, } @@ -5946,7 +5946,7 @@ export interface Calendar { [timespan: string]: { from: Date, to: Date, - hours?: string[] | number[], + hours?: string[] | number[] | boolean, days?: WorkDaysTuple | boolean, }, }, diff --git a/src/core/common/gantt_types.ts b/src/core/common/gantt_types.ts index 981c8092..e087cbb4 100644 --- a/src/core/common/gantt_types.ts +++ b/src/core/common/gantt_types.ts @@ -691,7 +691,7 @@ export interface GanttEventCallback { * @param id the id of the double clicked task * @param e a native event object */ - "onTaskDblClick"(id: string, e?: Event): boolean; + "onTaskDblClick"(id: string | number, e?: Event): boolean; /** * fires when the user drags a task @@ -2908,9 +2908,9 @@ export interface GanttStatic { getScrollState(): { x: number, y: number }; /** - * returns the id of the selected task + * returns the id of the selected task, or null if no task is selected */ - getSelectedId(): string; + getSelectedId(): string | number | null; /** * returns an array of the currently selected tasks @@ -4969,7 +4969,7 @@ export interface GanttUIState { /** * the id of a task that the user is currently dragging in the Gantt chart. *undefined* or *null*, if no tasks are being dragged in the Gantt chart. */ - drag_id: string | null | undefined, + drag_id: string | number | null | undefined, /** * the drag mode. Has these values: 'move','resize','progress', 'ignore' when a task is dragged. Otherwise, has *null* or *undefined* value. @@ -4984,7 +4984,7 @@ export interface GanttUIState { /** * the id of a task that is currently opened in the lightbox. *undefined* or *null*, if no tasks are opened in the lightbox. */ - lightbox: string | null | undefined, + lightbox: string | number | null | undefined, /** * the new link creation state, returns *true* when the link is created from the start of the predecessor task. @@ -5034,7 +5034,7 @@ export interface GanttUIState { /** * the id of the currently selected task. *undefined* or *null*, if no tasks are selected in the Gantt chart. */ - selected_task: string | null | undefined + selected_task: string | number | null | undefined } export interface RoundDateConfig { @@ -5601,7 +5601,7 @@ export interface CalendarConfig { [timespan: string]: { from: Date, to: Date, - hours?: Array, + hours?: Array | boolean, days?: WorkDaysTuple | WorkDaysSettings | boolean, }, } @@ -5862,7 +5862,7 @@ export interface Calendar { [timespan: string]: { from: Date, to: Date, - hours?: string[] | number[], + hours?: string[] | number[] | boolean, days?: WorkDaysTuple | boolean, }, }, diff --git a/src/core/data.js b/src/core/data.js index bf91ef03..350c025d 100644 --- a/src/core/data.js +++ b/src/core/data.js @@ -620,5 +620,8 @@ export default function(gantt) { gantt._init_task_timing(gantt.getTask(id)); return true; }); + gantt.$data.tasksStore.attachEvent("onAfterSilentMove", function (id) { + gantt._init_task_timing(gantt.getTask(id)); + }); }; \ No newline at end of file diff --git a/src/core/dataprocessor/data_processor.ts b/src/core/dataprocessor/data_processor.ts index cbe39662..b522eb66 100644 --- a/src/core/dataprocessor/data_processor.ts +++ b/src/core/dataprocessor/data_processor.ts @@ -507,25 +507,26 @@ export class DataProcessor { break; case "delete": case "deleted": - if(!this.deleteAfterConfirmation || this._ganttMode !== "task"){ + if (this.deleteAfterConfirmation && this._ganttMode === "task" && this.$gantt.isTaskExists(sid)) { this.$gantt.setUserData(sid, this.action_param, "true_deleted", this._ganttMode); - this.$gantt[this._methods[3]](sid); + const task = this.$gantt.getTask(sid); + this.$gantt.silent(() => { + this.$gantt.deleteTask(sid); + }); + this.$gantt.callEvent("onAfterTaskDelete", [sid, task]); + this.$gantt.render(); delete this._in_progress[marker]; return this.callEvent("onAfterUpdate", [sid, action, tid, btag]); - }else{ - if (this._ganttMode === "task" && this.$gantt.isTaskExists(sid)) { - this.$gantt.setUserData(sid, this.action_param, "true_deleted", this._ganttMode); - const task = this.$gantt.getTask(sid); - this.$gantt.silent(() => { - this.$gantt.deleteTask(sid); - }); - this.$gantt.callEvent("onAfterTaskDelete", [sid, task]); - this.$gantt.render(); - delete this._in_progress[marker]; - } + } + if (this._in_progress[marker] === "wait" && this.getState(sid) === "deleted") { + // a delete of this id queued during the request is already done on the server + this.setUpdated(sid, false); + delete this._in_progress[marker]; return this.callEvent("onAfterUpdate", [sid, action, tid, btag]); } - + // The item left Gantt before this response. End the request like any other, so that + // no state passes to an item that comes back with the same id. + break; } if (this._in_progress[marker] !== "wait") { @@ -680,7 +681,7 @@ export class DataProcessor { clear:"" }; - this._methods=["_row_style","setCellTextStyle","_change_id","_delete_task"]; + this._methods=["_row_style","setCellTextStyle","_change_id"]; extendGantt(this.$gantt, this); const dataProcessorEvents = new DataProcessorEvents(this.$gantt, this); dataProcessorEvents.attach(); @@ -691,7 +692,6 @@ export class DataProcessor { delete this.$gantt._dp; delete this.$gantt._change_id; delete this.$gantt._row_style; - delete this.$gantt._delete_task; delete this.$gantt._sendTaskOrder; delete this.$gantt; diff --git a/src/core/dataprocessor/extend_gantt.ts b/src/core/dataprocessor/extend_gantt.ts index 7f4e0e99..b61c820f 100644 --- a/src/core/dataprocessor/extend_gantt.ts +++ b/src/core/dataprocessor/extend_gantt.ts @@ -54,9 +54,6 @@ export default function extendGantt(gantt: any, dp: any) { gantt.refreshTask(rowId); }; - // fake method for dataprocessor - gantt._delete_task = function(rowId, node) {}; // tslint:disable-line - gantt._sendTaskOrder = function(id, item){ if (item.$drop_target) { this._dp.setGanttMode("task"); diff --git a/src/core/datastore/datastore_hooks.js b/src/core/datastore/datastore_hooks.js index 2d2f8ee8..3b8ddbdf 100644 --- a/src/core/datastore/datastore_hooks.js +++ b/src/core/datastore/datastore_hooks.js @@ -125,17 +125,35 @@ function initDataStores(gantt){ return true; }); - tasksStore.attachEvent("onAfterItemMove", function(sid, parent, tindex){ + // The position of a moved task for the data processor, which sends it as `target` with the next + // save of the task. + function setDropTarget(store, sid){ var source = gantt.getTask(sid); - if(this.getNextSibling(sid) !== null){ - source.$drop_target = this.getNextSibling(sid); - } else if(this.getPrevSibling(sid) !== null){ - source.$drop_target = "next:" + this.getPrevSibling(sid); + if(store.getNextSibling(sid) !== null){ + source.$drop_target = store.getNextSibling(sid); + } else if(store.getPrevSibling(sid) !== null){ + source.$drop_target = "next:" + store.getPrevSibling(sid); }else{ source.$drop_target = "next:null"; } + } + + tasksStore.attachEvent("onAfterItemMove", function(sid, parent, tindex){ + setDropTarget(this, sid); + }); + // A silent move gives a task no position for the data processor. A task that already has one - + // a `$drop_target` that waits for the next save, or the `target` of an earlier reorder, which + // the data processor sends with every later save - gets the position of its new place, as after + // a move outside silent(). The old position no longer describes where the task is, and only the + // task's own move can tell whether it still applies. + tasksStore.attachEvent("onAfterSilentMove", function(sid){ + var task = gantt.getTask(sid); + var target = task.target; + if(task.$drop_target || (target !== undefined && target !== null && target !== "")){ + setDropTarget(this, sid); + } }); tasksStore.attachEvent("onStoreUpdated", function(id, item, action){ diff --git a/src/core/datastore/own_item_id.ts b/src/core/datastore/own_item_id.ts new file mode 100644 index 00000000..0e7a7664 --- /dev/null +++ b/src/core/datastore/own_item_id.ts @@ -0,0 +1,18 @@ +import { DatastoreMethods } from "../common/gantt_types"; +import { checkZeroId } from "../../utils/helpers"; + +/** + * Returns the own id of the item that `rawId` names, so that an id read from a DOM attribute or an + * object key (always a string) gets the type that the application gave the item (GS-3658). + * An id that names no item is returned as is. + * + * The own id `0` is returned as `"0"`: callers test these ids for truthiness, and Gantt already + * refers to a task with the id `0` as `"0"` (see `replaceValidZeroId`). + */ +export function getOwnItemId(store: Pick, rawId: string | number): string | number { + const item = store.getItem(rawId); + if (!item) { + return rawId; + } + return checkZeroId(item.id) ? "0" : item.id; +} diff --git a/src/core/datastore/treedatastore.js b/src/core/datastore/treedatastore.js index b5619004..8a937157 100644 --- a/src/core/datastore/treedatastore.js +++ b/src/core/datastore/treedatastore.js @@ -493,9 +493,17 @@ TreeDataStore.prototype = utils.mixin({ return; } } - - if(this.callEvent("onBeforeItemMove", [sid, parent, tindex]) === false) + + // GS-3389: Silent moves emit no public move events, cannot be vetoed by apps, and create no undo entry. + // Store handlers still guard and update tree state (`onBeforeSilentMove`, `onAfterSilentMove`). + var silent = this.isSilent(); + if(silent){ + // Keep placeholder and extension guards active during silent moves. + if(isPlaceholderTask(sid, null, this, this._ganttConfig) || + this.callEvent("onBeforeSilentMove", [sid, parent, tindex]) === false) + return false; + }else if(this.callEvent("onBeforeItemMove", [sid, parent, tindex]) === false) return false; var placeholderIds = []; @@ -543,7 +551,11 @@ TreeDataStore.prototype = utils.mixin({ this._moveInner(this.getIndexById(sid), this.getIndexById(parent) + tindex); - this.callEvent("onAfterItemMove", [sid, parent, tindex]); + if(silent){ + this.callEvent("onAfterSilentMove", [sid, parent, tindex, source_pid]); + }else{ + this.callEvent("onAfterItemMove", [sid, parent, tindex]); + } this.refresh(); }, diff --git a/src/core/facades/datastore.js b/src/core/facades/datastore.js index 410f7d6d..42f8a6c0 100644 --- a/src/core/facades/datastore.js +++ b/src/core/facades/datastore.js @@ -7,6 +7,7 @@ import createDatastoreSelect from "../datastore/select"; import datastoreRender from "../datastore/datastore_render"; import isHeadless from "../../utils/is_headless"; import {replaceValidZeroId} from "../../utils/helpers"; +import { getOwnItemId } from "../datastore/own_item_id"; function getDatastores(){ var storeNames = this.$services.getService("datastores"); @@ -195,6 +196,9 @@ var createDatastoreFacade = function(){ return false; id = replaceValidZeroId(id, this.config.root_id); if (id){ + // GS-3658. The caller can give the id 12 as "12"; store the own id so that + // getSelectedId() matches the ids from the UI + id = getOwnItemId(store, id); let oldSelectId = this.getSelectedId(); // Don't repaint the resource panel as the data didn't change store._skipResourceRepaint = true; @@ -213,6 +217,10 @@ var createDatastoreFacade = function(){ }, unselectTask: function(id){ var store = this.$data.tasksStore; + if (id) { + // GS-3658. The own id, so that the unselect event gets the same id as the select events + id = getOwnItemId(store, id); + } store.unselect(id); // GS-730. Split task is not included in the tree, // so the datastore renderer will think that the task is not visible diff --git a/src/core/plugins/auto_task_types.js b/src/core/plugins/auto_task_types.js index 670f23f0..c1b06264 100644 --- a/src/core/plugins/auto_task_types.js +++ b/src/core/plugins/auto_task_types.js @@ -161,4 +161,10 @@ export default function(gantt) { updateAfterRemoveChild(originalMoveTaskParent); updateParentTypes(id); })); + + // Silent moves must update both parents; the store supplies the old parent. + gantt.$data.tasksStore.attachEvent("onAfterSilentMove", callIfEnabled(function(id, parent, tindex, oldParent) { + updateAfterRemoveChild(oldParent); + updateParentTypes(id); + })); }; \ No newline at end of file diff --git a/src/core/ui/grid/grid.js b/src/core/ui/grid/grid.js index 80259cb5..9296f85f 100644 --- a/src/core/ui/grid/grid.js +++ b/src/core/ui/grid/grid.js @@ -8,6 +8,7 @@ import rowResize from "./task_grid_row_resize"; import ColumnDnd from "../plugins/column_grid_dnd"; import mouseEventContainer from "../mouse_event_container"; +import { getOwnItemId } from "../../datastore/own_item_id"; var Grid = function (parent, config, factory, gantt) { this.$config = utils.mixin({}, config || {}); @@ -390,13 +391,18 @@ Grid.prototype = { _initEvents: function () { var gantt = this.$gantt; + // GS-3658. The attribute value is always a string; the open and close events get the own id of the row + var getRowId = gantt.bind(function (target) { + return getOwnItemId(this.$config.rowStore, target.getAttribute(this.$config.item_attribute)); + }, this); + this._mouseDelegates.delegate("click", "gantt_close", gantt.bind(function (e, id, trg) { var store = this.$config.rowStore; if (!store) return true; var target = domHelpers.locateAttribute(e, this.$config.item_attribute); if (target) { - store.close(target.getAttribute(this.$config.item_attribute)); + store.close(getRowId(target)); } return false; @@ -408,7 +414,7 @@ Grid.prototype = { var target = domHelpers.locateAttribute(e, this.$config.item_attribute); if (target) { - store.open(target.getAttribute(this.$config.item_attribute)); + store.open(getRowId(target)); } return false; diff --git a/src/core/ui/grid/task_grid_row_resize.js b/src/core/ui/grid/task_grid_row_resize.js index e40972ce..ac774d8d 100644 --- a/src/core/ui/grid/task_grid_row_resize.js +++ b/src/core/ui/grid/task_grid_row_resize.js @@ -1,7 +1,14 @@ import * as domHelpers from "../utils/dom_helpers"; +import { getOwnItemId } from "../../datastore/own_item_id"; function createRowResizer(gantt, grid){ + // GS-3658. `locate` returns the attribute string for this attribute, which tasks and resources share; + // the events get the own id of the row + function locateRowId(e){ + return getOwnItemId(grid.$config.rowStore, gantt.locate(e, grid.$getConfig().task_grid_row_resizer_attribute)); + } + var _task_grid_row_resize = { row_before_start: gantt.bind(function (dnd, obj, e) { var config = grid.$getConfig(); @@ -10,17 +17,14 @@ function createRowResizer(gantt, grid){ var el = domHelpers.locateAttribute(e, config.task_grid_row_resizer_attribute); if (!el) return false; - var row_id = this.locate(e, config.task_grid_row_resizer_attribute), - row = store.getItem(row_id); + var row = store.getItem(locateRowId(e)); if (grid.callEvent("onBeforeRowResize", [row]) === false) return false; }, gantt), row_after_start: gantt.bind(function (dnd, obj, e) { - var config = grid.$getConfig(); - - var row_id = this.locate(e, config.task_grid_row_resizer_attribute); + var row_id = locateRowId(e); dnd.config.marker.innerHTML = ""; dnd.config.marker.className += " gantt_row_grid_resize_area"; diff --git a/src/core/ui/grid/tasks_grid_dnd.js b/src/core/ui/grid/tasks_grid_dnd.js index 5acd1cda..a4b7b59d 100644 --- a/src/core/ui/grid/tasks_grid_dnd.js +++ b/src/core/ui/grid/tasks_grid_dnd.js @@ -1,5 +1,6 @@ import * as domHelpers from "../utils/dom_helpers"; import isPlaceholderTask from "../../../utils/placeholder_task"; +import { getOwnItemId } from "../../datastore/own_item_id"; function _init_dnd(gantt, grid) { var DnD = gantt.$services.getService("dnd"); @@ -16,6 +17,11 @@ function _init_dnd(gantt, grid) { return gantt.getDatastore(grid.$config.bind); } + // GS-3658. The attribute value is always a string; the events get the own id of the row + function getRowId(el){ + return getOwnItemId(getStore(), el.getAttribute(grid.$config.item_attribute)); + } + function checkPlaceholderTask(id){ return isPlaceholderTask(id, gantt, getStore()); } @@ -33,7 +39,7 @@ function _init_dnd(gantt, grid) { return false; } - var id = el.getAttribute(grid.$config.item_attribute); + var id = getRowId(el); if (checkPlaceholderTask(id)) return false; var datastore = getStore(); @@ -58,7 +64,7 @@ function _init_dnd(gantt, grid) { element.style.position = "static"; } - dnd.config.id = el.getAttribute(grid.$config.item_attribute); + dnd.config.id = getRowId(el); var store = getStore(); diff --git a/src/core/ui/grid/tasks_grid_dnd_marker.js b/src/core/ui/grid/tasks_grid_dnd_marker.js index df57f8ff..7049d3f1 100644 --- a/src/core/ui/grid/tasks_grid_dnd_marker.js +++ b/src/core/ui/grid/tasks_grid_dnd_marker.js @@ -4,6 +4,7 @@ import getLockedLevelTarget from "./tasks_grid_dnd_marker_helpers/locked_level"; import getMultiLevelTarget from "./tasks_grid_dnd_marker_helpers/multi_level"; import higlighter from "./tasks_grid_dnd_marker_helpers/highlight"; import isPlaceholderTask from "../../../utils/placeholder_task"; +import { getOwnItemId } from "../../datastore/own_item_id"; function _init_dnd(gantt, grid) { var DnD = gantt.$services.getService("dnd"); @@ -20,6 +21,11 @@ function _init_dnd(gantt, grid) { return gantt.getDatastore(grid.$config.bind); } + // GS-3658. The attribute value is always a string; the events get the own id of the row + function getRowId(el){ + return getOwnItemId(grid.$config.rowStore, el.getAttribute(grid.$config.item_attribute)); + } + function checkPlaceholderTask(id){ return isPlaceholderTask(id, gantt, getStore()); } @@ -36,7 +42,7 @@ function _init_dnd(gantt, grid) { return false; } - var id = el.getAttribute(grid.$config.item_attribute); + var id = getRowId(el); var datastore = grid.$config.rowStore; var task = datastore.getItem(id); @@ -61,7 +67,7 @@ function _init_dnd(gantt, grid) { element.style.pointerEvents = "none"; } - dnd.config.id = el.getAttribute(grid.$config.item_attribute); + dnd.config.id = getRowId(el); var store = grid.$config.rowStore; diff --git a/src/core/ui/lightbox/controls/baseline_control.js b/src/core/ui/lightbox/controls/baseline_control.js index 676d5a32..6b5175d0 100644 --- a/src/core/ui/lightbox/controls/baseline_control.js +++ b/src/core/ui/lightbox/controls/baseline_control.js @@ -77,6 +77,7 @@ export default function(gantt) { var template = gantt.templates.task_end_date || gantt.templates.task_date; endspan.innerHTML = template(end_date); + gantt._waiAria.lightboxDurationInputValueAttr(inps[1], duration, inps[1].value); } function _change_duration(step) { diff --git a/src/core/ui/lightbox/controls/duration_control.js b/src/core/ui/lightbox/controls/duration_control.js index 8813768a..18674462 100644 --- a/src/core/ui/lightbox/controls/duration_control.js +++ b/src/core/ui/lightbox/controls/duration_control.js @@ -67,6 +67,7 @@ export default function(gantt) { var template = gantt.templates.task_end_date || gantt.templates.task_date; endspan.innerHTML = template(end_date); + gantt._waiAria.lightboxDurationInputValueAttr(inps[1], duration, inps[1].value); } function _change_duration(step) { diff --git a/src/core/ui/lightbox/controls/parent_control.js b/src/core/ui/lightbox/controls/parent_control.js index 7cb81b4d..c8f8434a 100644 --- a/src/core/ui/lightbox/controls/parent_control.js +++ b/src/core/ui/lightbox/controls/parent_control.js @@ -36,6 +36,15 @@ export default function(gantt) { return gantt.form_blocks.select.set_value.apply(gantt, [newOptions, value, ev, config]); }; + ParentControl.prototype.get_value = function(node, ev, config) { + const value = gantt.form_blocks.select.get_value.apply(gantt, arguments); + // GS-3658. The select gives the option value as a string; the parent is the option's own key + const option = (config.options || []).find(function(item) { + return String(item.key) === value; + }); + return option ? option.key : value; + }; + function _display(config, item_id) { var tasks = [], options = []; diff --git a/src/core/ui/resource_store_mixin.js b/src/core/ui/resource_store_mixin.js index f8b5b568..30455ffe 100644 --- a/src/core/ui/resource_store_mixin.js +++ b/src/core/ui/resource_store_mixin.js @@ -72,6 +72,16 @@ function createMixin(_super){ } linkedStore._quick_refresh = true; self.relevantResources.forEach(function(id){ + const row = linkedStore.getItem(id); + if (row && row.$role === "task") { + // Quick refresh skips the filter that normally rebuilds fetched copies. + // Keep their display range current without updating assignment data. + const gantt = self.$gantt; + const task = gantt.getTask(row.$task_id); + row.start_date = gantt.copy(task.start_date); + row.end_date = gantt.copy(task.end_date); + row.duration = task.duration; + } linkedStore.refresh(id); }); linkedStore._quick_refresh = false; @@ -174,21 +184,28 @@ function createMixin(_super){ _getIdsFromAssignments: function(id){ const gantt = this.$gantt; + const linkedStore = this.$config.rowStore; const resourceIds = []; + const addAssignmentRows = function(assignment){ + resourceIds.push(assignment.resource_id); + if (linkedStore.$config.fetchTasks) { + // GS-3700. Fetched tasks are separate rows; refreshing their resource does not repaint them. + const rowId = assignment.task_id + "_" + assignment.resource_id; + if (linkedStore.exists(rowId)) { + resourceIds.push(rowId); + } + } + }; const task = gantt.getTask(id); let assignments = gantt.getTaskAssignments(id); - assignments.forEach(function(assignment){ - resourceIds.push(assignment.resource_id); - }); + assignments.forEach(addAssignmentRows); // get child assignments when dragging project task if (gantt.isSummaryTask(task) && gantt.config.drag_project) { gantt.eachTask(function(child){ const childAssignments = gantt.getTaskAssignments(child.id); - childAssignments.forEach(function(assignment){ - resourceIds.push(assignment.resource_id); - }); + childAssignments.forEach(addAssignmentRows); }, id); } @@ -197,9 +214,7 @@ function createMixin(_super){ const selectedIds = gantt.getSelectedTasks(); selectedIds.forEach(function(selectedId){ const selectedAssignments = gantt.getTaskAssignments(selectedId); - selectedAssignments.forEach(function(assignment){ - resourceIds.push(assignment.resource_id); - }); + selectedAssignments.forEach(addAssignmentRows); }); } diff --git a/src/core/ui/timeline/scales.js b/src/core/ui/timeline/scales.js deleted file mode 100644 index a38d88b4..00000000 --- a/src/core/ui/timeline/scales.js +++ /dev/null @@ -1,382 +0,0 @@ -import * as utils from "../../../utils/utils"; - -function ScaleHelper(gantt){ - var dateHelper = gantt.date; - var services = gantt.$services; - - return { - getSum: function (sizes, from, to) { - if (to === undefined) - to = sizes.length - 1; - if (from === undefined) - from = 0; - - var summ = 0; - for (var i = from; i <= to; i++) - summ += sizes[i]; - - return summ; - }, - setSumWidth: function (sum_width, scale, from, to) { - var parts = scale.width; - - if (to === undefined) - to = parts.length - 1; - if (from === undefined) - from = 0; - var length = to - from + 1; - - if (from > parts.length - 1 || length <= 0 || to > parts.length - 1) - return; - - var oldWidth = this.getSum(parts, from, to); - - var diff = sum_width - oldWidth; - - this.adjustSize(diff, parts, from, to); - this.adjustSize(-diff, parts, to + 1); - - scale.full_width = this.getSum(parts); - }, - splitSize: function (width, count) { - var arr = []; - for (var i = 0; i < count; i++) arr[i] = 0; - - this.adjustSize(width, arr); - return arr; - - }, - adjustSize: function (width, parts, from, to) { - if (!from) - from = 0; - if (to === undefined) - to = parts.length - 1; - - var length = to - from + 1; - - var full = this.getSum(parts, from, to); - - for (var i = from; i <= to; i++) { - var share = Math.floor(width * (full ? (parts[i] / full) : (1 / length))); - - full -= parts[i]; - width -= share; - length--; - - parts[i] += share; - } - parts[parts.length - 1] += width; - }, - sortScales: function (scales) { - function cellSize(unit, step) { - var d = new Date(1970, 0, 1); - return dateHelper.add(d, step, unit) - d; - } - - scales.sort(function (a, b) { - if (cellSize(a.unit, a.step) < cellSize(b.unit, b.step)) { - return 1; - } else if (cellSize(a.unit, a.step) > cellSize(b.unit, b.step)) { - return -1; - } else { - return 0; - } - }); - - for (var i = 0; i < scales.length; i++) { - scales[i].index = i; - } - }, - _prepareScaleObject: function(scale){ - var format = scale.format; - if(!format){ - format = scale.template || scale.date || "%d %M"; - } - - if(typeof format === "string"){ - format = gantt.date.date_to_str(format); - } - return { - unit: scale.unit || "day", - step: scale.step || 1, - format: format, - css: scale.css, - projection: scale.projection || null, - column_width: scale.column_width || null - }; - }, - primaryScale: function(config) { - const scaleConfig = config || gantt.config; - - const primaryScale = scaleConfig.scales[0]; - const result = { - unit: primaryScale.unit, - step: primaryScale.step, - template: primaryScale.template, - format: primaryScale.format, - date: primaryScale.date, - css: primaryScale.css || gantt.templates.scale_cell_class, - projection: primaryScale.projection || null, - column_width: primaryScale.column_width || null - }; - - return this._prepareScaleObject(result); - }, - getAdditionalScales: function(config) { - const scaleConfig = config || gantt.config; - const scales = scaleConfig.scales.slice(1); - - return scales.map(function(scale){ - return this._prepareScaleObject(scale); - }.bind(this)); - }, - prepareConfigs: function (scales, min_coll_width, container_width, scale_height, minDate, maxDate, rtl) { - var heights = this.splitSize(scale_height, scales.length); - var full_width = container_width; - - var configs = []; - for (var i = scales.length - 1; i >= 0; i--) { - var main_scale = (i == scales.length - 1); - var cfg = this.initScaleConfig(scales[i], minDate, maxDate); - if (main_scale) { - this.processIgnores(cfg); - } - - if(main_scale && cfg.column_width){ - full_width = cfg.column_width * (cfg.display_count || cfg.count); - } - - this.initColSizes(cfg, min_coll_width, full_width, heights[i]); - this.limitVisibleRange(cfg); - - if (main_scale) { - full_width = cfg.full_width; - } - - configs.unshift(cfg); - } - - - for (var i = 0; i < configs.length - 1; i++) { - this.alineScaleColumns(configs[configs.length - 1], configs[i]); - } - for (var i = 0; i < configs.length; i++) { - - if(rtl){ - this.reverseScale(configs[i]); - } - this.setPosSettings(configs[i]); - } - return configs; - - }, - - reverseScale: function(scale){ - scale.width = scale.width.reverse(); - scale.trace_x = scale.trace_x.reverse(); - - var indexes = scale.trace_indexes; - scale.trace_indexes = {}; - scale.trace_index_transition = {}; - scale.rtl = true; - for(var i = 0; i < scale.trace_x.length; i++){ - scale.trace_indexes[scale.trace_x[i].valueOf()] = i; - scale.trace_index_transition[indexes[scale.trace_x[i].valueOf()]] = i; - } - return scale; - }, - - setPosSettings: function (config) { - for (var i = 0, len = config.trace_x.length; i < len; i++) { - config.left.push((config.width[i - 1] || 0) + (config.left[i - 1] || 0)); - } - }, - - _ignore_time_config: function (date, scale) { - - if (gantt.config.skip_off_time) { - var skip = true; - var probe = date; - - // check dates in case custom scale unit, e.g. {unit: "month", step: 3} - for (var i = 0; i < scale.step; i++) { - if (i) { - probe = dateHelper.add(date, i, scale.unit); - } - - skip = skip && !this.isWorkTime(probe, scale.unit); - } - - return skip; - } - return false; - }, - //defined in an extension - processIgnores: function (config) { - config.ignore_x = {}; - config.display_count = config.count; - }, - initColSizes: function (config, min_col_width, full_width, line_height) { - var cont_width = full_width; - - config.height = line_height; - - var column_count = config.display_count === undefined ? config.count : config.display_count; - - if (!column_count) - column_count = 1; - - const fixedMode = !isNaN(config.column_width*1) && config.column_width*1 > 0; - if (fixedMode) { - const baseCellWidth = config.column_width*1; - config.col_width = baseCellWidth; - cont_width = baseCellWidth * column_count; - } else { - config.col_width = Math.floor(cont_width / column_count); - if (min_col_width) { - if (config.col_width < min_col_width) { - config.col_width = min_col_width; - cont_width = config.col_width * column_count; - } - } - } - - config.width = []; - var ignores = config.ignore_x || {}; - for (var i = 0; i < config.trace_x.length; i++) { - if (ignores[config.trace_x[i].valueOf()] || (config.display_count == config.count)) { - if(fixedMode){ - config.width[i] = config.col_width; - } else { - config.width[i] = 0; - } - } else { - // width of month columns should be proportional month duration - var width = 1; - if (config.unit == "month") { - var days = Math.round((dateHelper.add(config.trace_x[i], config.step, config.unit) - config.trace_x[i]) / (1000 * 60 * 60 * 24)); - width = days; - } - config.width[i] = width; - } - } - - if(!fixedMode){ - this.adjustSize(cont_width - this.getSum(config.width)/* 1 width per column from the code above */, config.width); - } - - config.full_width = this.getSum(config.width); - }, - initScaleConfig: function (config, min_date, max_date) { - var cfg = utils.mixin({ - count: 0, - col_width: 0, - full_width: 0, - height: 0, - width: [], - left: [], - trace_x: [], - trace_indexes: {}, - min_date: new Date(min_date), - max_date: new Date(max_date) - }, config); - - this.eachColumn(config.unit, config.step, min_date, max_date, function (date) { - cfg.count++; - cfg.trace_x.push(new Date(date)); - cfg.trace_indexes[date.valueOf()] = cfg.trace_x.length - 1; - }); - - cfg.trace_x_ascending = cfg.trace_x.slice(); - return cfg; - }, - iterateScales: function (lower_scale, upper_scale, from, to, callback) { - var upper_dates = upper_scale.trace_x; - var lower_dates = lower_scale.trace_x; - - var prev = from || 0; - var end = to || (lower_dates.length - 1); - var prevUpper = 0; - - - for (var up = 1; up < upper_dates.length; up++) { - var target_index = (lower_scale.trace_indexes[+upper_dates[up]]); - if (target_index !== undefined && target_index <= end) { - if (callback) { - callback.apply(this, [prevUpper, up, prev, target_index]); - } - prev = target_index; - prevUpper = up; - continue; - } - } - }, - alineScaleColumns: function (lower_scale, upper_scale, from, to) { - this.iterateScales(lower_scale, upper_scale, from, to, function (upper_start, upper_end, lower_start, lower_end) { - var targetWidth = this.getSum(lower_scale.width, lower_start, lower_end - 1); - var actualWidth = this.getSum(upper_scale.width, upper_start, upper_end - 1); - if (actualWidth != targetWidth) { - this.setSumWidth(targetWidth, upper_scale, upper_start, upper_end - 1); - } - - }); - }, - - eachColumn: function (unit, step, min_date, max_date, callback) { - var start = new Date(min_date), - end = new Date(max_date); - if (dateHelper[unit + "_start"]) { - start = dateHelper[unit + "_start"](start); - } - - var curr = new Date(start); - if (+curr >= +end) { - end = dateHelper.add(curr, step, unit); - } - while (+curr < +end) { - callback.call(this, new Date(curr)); - var tzOffset = curr.getTimezoneOffset(); - curr = dateHelper.add(curr, step, unit); - curr = gantt._correct_dst_change(curr, tzOffset, step, unit); - if (dateHelper[unit + '_start']) - curr = dateHelper[unit + "_start"](curr); - } - }, - limitVisibleRange: function (cfg) { - var dates = cfg.trace_x; - - var left = 0, right = cfg.width.length - 1; - var diff = 0; - if (+dates[0] < +cfg.min_date && left != right) { - var width = Math.floor(cfg.width[0] * ((dates[1] - cfg.min_date) / (dates[1] - dates[0]))); - diff += cfg.width[0] - width; - cfg.width[0] = width; - - dates[0] = new Date(cfg.min_date); - } - - var last = dates.length - 1; - var lastDate = dates[last]; - var outDate = dateHelper.add(lastDate, cfg.step, cfg.unit); - if (+outDate > +cfg.max_date && last > 0) { - var width = cfg.width[last] - Math.floor(cfg.width[last] * ((outDate - cfg.max_date) / (outDate - lastDate))); - diff += cfg.width[last] - width; - cfg.width[last] = width; - } - - if (diff) { - var full = this.getSum(cfg.width); - var shared = 0; - for (var i = 0; i < cfg.width.length; i++) { - var share = Math.floor(diff * (cfg.width[i] / full)); - cfg.width[i] += share; - shared += share; - } - this.adjustSize(diff - shared, cfg.width); - } - - } - }; -} - -export default ScaleHelper; diff --git a/src/core/ui/wai_aria.js b/src/core/ui/wai_aria.js index ff3ad495..7164e970 100644 --- a/src/core/ui/wai_aria.js +++ b/src/core/ui/wai_aria.js @@ -157,6 +157,15 @@ export default function(gantt){ }); }, + lightboxDurationInputValueAttr: function(input, value, text){ + input.setAttribute("aria-valuenow", value); + if(text){ + input.setAttribute("aria-valuetext", text); + }else{ + input.removeAttribute("aria-valuetext"); + } + }, + inlineEditorAttr: function(div){ div.setAttribute("role", "row"); }, diff --git a/src/core/ui_core.js b/src/core/ui_core.js index a6a63c0a..2206ee7c 100644 --- a/src/core/ui_core.js +++ b/src/core/ui_core.js @@ -8,6 +8,7 @@ import messages from "./ui/message"; import ui from "./ui/index"; import createLayoutFacade from "./facades/layout"; import taskLayers from "./data_task_layers"; +import { getOwnItemId } from "./datastore/own_item_id"; import skin from "./ui/skin"; import skyblue from "../css/skins/skyblue"; @@ -25,6 +26,17 @@ import lightbox_optional_time from "./ui/lightbox/lightbox_optional_time"; import wai_aria from "./ui/wai_aria"; +// GS-3658. The task and link attributes hold item ids, so `locate` can return the own id +function getStoreOfIdAttribute(gantt, attribute) { + if (attribute === gantt.config.task_attribute) { + return gantt.$data.tasksStore; + } + if (attribute === gantt.config.link_attribute) { + return gantt.$data.linksStore; + } + return null; +} + export default function(gantt) { if(!env.isNode){ @@ -73,21 +85,23 @@ export default function(gantt) { wai_aria(gantt); gantt.locate = function(e) { - var trg = domHelpers.getTargetNode(e); + const trg = domHelpers.getTargetNode(e); // ignore empty rows/cells of the timeline if(domHelpers.closest(trg, ".gantt_task_row")){ return null; } - var targetAttribute = arguments[1] || this.config.task_attribute; + const targetAttribute = arguments[1] || this.config.task_attribute; - var node = domHelpers.locateAttribute(trg, targetAttribute); - if(node){ - return node.getAttribute(targetAttribute); - }else{ + const node = domHelpers.locateAttribute(trg, targetAttribute); + if(!node){ return null; } + + const id = node.getAttribute(targetAttribute); + const store = getStoreOfIdAttribute(this, targetAttribute); + return store ? getOwnItemId(store, id) : id; }; gantt._locate_css = function(e, classname, strict){ diff --git a/src/css/fonts/OFL.txt b/src/css/fonts/OFL.txt index 63db4fa7..d05ec4b3 100644 --- a/src/css/fonts/OFL.txt +++ b/src/css/fonts/OFL.txt @@ -1,93 +1,93 @@ -Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter) - -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -https://openfontlicense.org - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. +Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/ext/export_api/index.ts b/src/ext/export_api/index.ts index 80cad0cf..0caeecf4 100644 --- a/src/ext/export_api/index.ts +++ b/src/ext/export_api/index.ts @@ -431,16 +431,7 @@ export default function(gantt: any) { if (!gantt.config.work_time) { time = defaultWorkTimes; } else { - const wTime = gantt._working_time_helper; - if (wTime && wTime.get_calendar) { - time = wTime.get_calendar(); - } else if (wTime) { - time = { - hours: wTime.hours, - minutes: null, - dates: wTime.dates - }; - } else if (gantt.config.worktimes && gantt.config.worktimes.global) { + if (gantt.config.worktimes && gantt.config.worktimes.global) { const settings = gantt.config.worktimes.global; if (settings.parsed) { @@ -473,6 +464,37 @@ export default function(gantt: any) { return time; }, + _serializeCustomWeeks(customWeeks: any) { + const formatDate = gantt.date.date_to_str("%Y-%m-%d"); + const result: any = {}; + + for (const name in customWeeks) { + const week = customWeeks[name]; + const copy = gantt.mixin({}, week); + if (copy.from instanceof Date) { + copy.fromDate = formatDate(copy.from); + } + if (copy.to instanceof Date) { + copy.toDate = formatDate(copy.to); + } + result[name] = copy; + } + return result; + }, + + _serializeWorktimes(worktimes: any) { + const result: any = {}; + for (const id in worktimes) { + const calendar = worktimes[id]; + const copy = gantt.mixin({}, calendar); + if (calendar.customWeeks) { + copy.customWeeks = gantt.ext.export_api._serializeCustomWeeks(calendar.customWeeks); + } + + result[id] = copy; + } + return result; + }, _eachTaskTimed(start:any, end:any) { return function(code:any, parent:any, master:any) { @@ -1290,6 +1312,12 @@ export default function(gantt: any) { for (const i in config) { res[i] = config[i]; } + + if (res.config.worktimes) { + res.config = gantt.mixin({}, res.config); + res.config.worktimes = gantt.ext.export_api._serializeWorktimes(res.config.worktimes); + } + return res; }, @@ -1305,6 +1333,7 @@ export default function(gantt: any) { projectProperties: config.projectProperties || undefined, taskProperties: config.taskProperties || undefined, resourceProperties: config.resourceProperties || undefined, + assignmentProperties: config.assignmentProperties || undefined, }; formData.append("type", config.type || "msproject-parse"); diff --git a/src/types.d.ts b/src/types.d.ts index 069f90c9..6507c974 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -40,9 +40,11 @@ interface ICalendarWorktimes { -interface ICalendarCustomWeekSettings extends ICalendarWorktimes{ +interface ICalendarCustomWeekSettings extends Omit{ from: Date; to: Date; + // `false` gives the period no work hours, `true` or an absent value applies the hours of the calendar + hours?: CalendarHoursConfig[] | boolean; } interface ICalendarWorktimeSettings extends ICalendarWorktimes{ diff --git a/whatsnew.md b/whatsnew.md index d6aa7147..2bbefdc8 100644 --- a/whatsnew.md +++ b/whatsnew.md @@ -1,3 +1,27 @@ +### 10.0.4 + +- Add the syncTaskOrder prop to React Gantt, which applies the row order of the tasks array to the chart +- Improve the performance of scrolling the timeline with many split tasks in the viewport - the split task bars that are already rendered stay in place, and only the bars that enter or leave the viewport are added or removed +- Add the assignmentProperties parameter to importFromMSProject(), which imports additional and custom properties of resource assignments from MS Project files (requires version 2.5.0.0 or later of the export module) + +- Fix the issue where React Gantt did not change the order of the rows when only the order of the tasks array changed +- Fix the issue where a task moved to the end of its branch in React Gantt when the task received a new id +- Fix the issue where moving a task inside silent() fired the task move events, added the move to the undo history, and sent it to the server. This also affected React Gantt, Vue Gantt, and Angular Gantt when the application changed the parent of a task in its data +- Fix the issue where React Gantt crashed when the config prop came from frozen state (a Valtio snapshot, or Immer and Redux Toolkit state in development mode), and changed the objects of a mutable config prop - Gantt now gets its own copy of each config value, see the migration notes +- Fix the issue where React Gantt reset a resized column width when the config prop got a new but equal object (for example, a config object written inline in JSX) +- Fix the issue where React Gantt threw an error after the config of a layout cell was changed twice +- Fix the issue where the editors of the inlineEditors prop of React Gantt did not open after editor_types in the config prop was changed +- Fix the issue where every template of React Gantt returned an empty string when the component received a callback ref, and an inline callback ref that stored the instance in the state started an endless update loop +- Fix the issue where tasks and links created from the UI stored string ids in the parent, source, and target properties when the task ids were numbers. locate(), getSelectedId(), and the multiselect methods now also return the ids with the type the tasks have +- Fix the issue where the DataProcessor did not send the delete request for an item that was added back with the id of a deleted item, for example, after undo in React Gantt with a state manager +- Fix the error thrown when a customWeeks period of a calendar had hours: false and the duration_unit config was set to "minute" +- Fix the issue where getClosestWorkTime() with dir: "past" entered a loop and threw an error when a whole month was non-working and its first day was a Sunday +- Fix the issue where the task rows of the expanded resource panel were not repainted while and after a task was dragged +- Fix the issue where screen readers announced 0 for the duration fields of the lightbox, including baseline durations, instead of their current value (thanks to Stepan Kuntso) +- Fix the issue where the dates of the customWeeks periods of calendars were exported to MS Project with a shift that depended on the time zone of the user +- Fix the issue where the export to MS Project returned an error instead of the file when auto scheduling was enabled and a task had progress but no assigned resources (requires version 2.5.0.0 or later of the export module) + + ### 10.0.3 - Improve the performance of loading tasks - parsing large datasets no longer slows down quadratically as the number of tasks on the same level grows, so the gain is largest on flat or wide structures and minimal on deep trees that hold few tasks per level