@visactor/vtable-gantt
Version:
canvas table width high performance
76 lines (72 loc) • 6.42 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.DataSource = void 0;
const util_1 = require("../tools/util"), gantt_engine_1 = require("../ts-types/gantt-engine"), vutils_1 = require("@visactor/vutils");
class DataSource {
constructor(_gantt) {
this._gantt = _gantt, this.records = _gantt.records, this.processRecords();
}
processRecords() {
const needMinDate = !this._gantt.options.minDate, needMaxDate = !this._gantt.options.maxDate;
let minDate = Number.MAX_SAFE_INTEGER, maxDate = Number.MIN_SAFE_INTEGER;
if ((needMinDate || needMaxDate || this._gantt.parsedOptions.tasksShowMode === gantt_engine_1.TasksShowMode.Sub_Tasks_Inline || this._gantt.parsedOptions.tasksShowMode === gantt_engine_1.TasksShowMode.Sub_Tasks_Compact) && this.records.length) {
for (let i = 0; i < this.records.length; i++) {
const record = this.records[i];
if (needMinDate && record[this._gantt.parsedOptions.startDateField]) {
const recordMinDate = (0, util_1.createDateAtMidnight)(record[this._gantt.parsedOptions.startDateField]);
minDate = Math.min(minDate, recordMinDate.getTime());
}
if (needMaxDate && record[this._gantt.parsedOptions.endDateField]) {
const recordMaxDate = (0, util_1.createDateAtMidnight)(record[this._gantt.parsedOptions.endDateField]);
maxDate = Math.max(maxDate, recordMaxDate.getTime());
}
this._gantt.parsedOptions.tasksShowMode !== gantt_engine_1.TasksShowMode.Sub_Tasks_Inline && this._gantt.parsedOptions.tasksShowMode !== gantt_engine_1.TasksShowMode.Sub_Tasks_Compact || record.children && record.children.sort(((a, b) => (0,
util_1.createDateAtMidnight)(a[this._gantt.parsedOptions.startDateField]).getTime() - (0,
util_1.createDateAtMidnight)(b[this._gantt.parsedOptions.startDateField]).getTime()));
}
const {unit: minTimeUnit, startOfWeek: startOfWeek, step: step} = this._gantt.parsedOptions.reverseSortedTimelineScales[0];
needMinDate && (this._gantt.parsedOptions.minDate = (0, util_1.getStartDateByTimeUnit)(new Date(minDate), minTimeUnit, startOfWeek),
this._gantt.parsedOptions._minDateTime = this._gantt.parsedOptions.minDate.getTime()),
needMinDate && !needMaxDate && (this._gantt.parsedOptions.maxDate = (0, util_1.getEndDateByTimeUnit)(this._gantt.parsedOptions.minDate, new Date(this._gantt.options.maxDate), minTimeUnit, step),
this._gantt.parsedOptions._maxDateTime = this._gantt.parsedOptions.maxDate.getTime()),
needMaxDate && (this._gantt.parsedOptions.maxDate = (0, util_1.getEndDateByTimeUnit)(this._gantt.parsedOptions.minDate, new Date(maxDate), minTimeUnit, step),
this._gantt.parsedOptions._maxDateTime = this._gantt.parsedOptions.maxDate.getTime());
}
}
adjustOrder(source_index, source_sub_task_index, target_index, target_sub_task_index) {
var _a, _b, _c, _d;
if (this._gantt.parsedOptions.tasksShowMode !== gantt_engine_1.TasksShowMode.Sub_Tasks_Arrange && this._gantt.parsedOptions.tasksShowMode !== gantt_engine_1.TasksShowMode.Sub_Tasks_Compact || source_index !== target_index) if (this._gantt.parsedOptions.tasksShowMode === gantt_engine_1.TasksShowMode.Sub_Tasks_Inline) {
if ((0, vutils_1.isValid)(source_sub_task_index) && (0, vutils_1.isValid)(target_sub_task_index) && (0,
vutils_1.isValid)(source_index) && (0, vutils_1.isValid)(target_index)) {
const sub_task_record = this.records[source_index].children[source_sub_task_index];
this.records[source_index].children.splice(source_sub_task_index, 1), this.records[target_index].children || (this.records[target_index].children = []),
this.records[target_index].children.splice(target_sub_task_index, 0, sub_task_record);
}
null === (_b = null === (_a = this.records[target_index]) || void 0 === _a ? void 0 : _a.children) || void 0 === _b || _b.sort(((a, b) => (0,
util_1.createDateAtMidnight)(a[this._gantt.parsedOptions.startDateField]).getTime() - (0,
util_1.createDateAtMidnight)(b[this._gantt.parsedOptions.startDateField]).getTime()));
} else if (this._gantt.parsedOptions.tasksShowMode === gantt_engine_1.TasksShowMode.Project_Sub_Tasks_Inline) {
if ((0, vutils_1.isValid)(source_sub_task_index) && (0, vutils_1.isValid)(target_sub_task_index) && (0,
vutils_1.isValid)(source_index) && (0, vutils_1.isValid)(target_index)) {
this.records[source_index].type, gantt_engine_1.TaskType.PROJECT;
const targetIsProject = this.records[target_index].type === gantt_engine_1.TaskType.PROJECT, sub_task_record = this.records[source_index].children[source_sub_task_index];
this.records[source_index].children.splice(source_sub_task_index, 1), this.records[target_index].children || (this.records[target_index].children = []),
this.records[target_index].children.splice(target_sub_task_index, 0, sub_task_record),
targetIsProject && (null === (_d = null === (_c = this.records[target_index]) || void 0 === _c ? void 0 : _c.children) || void 0 === _d || _d.sort(((a, b) => (0,
util_1.createDateAtMidnight)(a[this._gantt.parsedOptions.startDateField]).getTime() - (0,
util_1.createDateAtMidnight)(b[this._gantt.parsedOptions.startDateField]).getTime())));
}
} else if ((0, vutils_1.isValid)(source_sub_task_index) && (0, vutils_1.isValid)(target_sub_task_index) && (0,
vutils_1.isValid)(source_index) && (0, vutils_1.isValid)(target_index)) {
const sub_task_record = this.records[source_index].children[source_sub_task_index];
this.records[source_index].children.splice(source_sub_task_index, 1), this.records[target_index].children || (this.records[target_index].children = []),
this.records[target_index].children.splice(target_sub_task_index, 0, sub_task_record);
}
}
setRecords(records) {
this.records = records, this.processRecords();
}
}
exports.DataSource = DataSource;
//# sourceMappingURL=DataSource.js.map