devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
349 lines (348 loc) • 12.5 kB
JavaScript
/**
* DevExtreme (esm/ui/gantt/ui.gantt.view.js)
* Version: 21.1.4
* Build date: Mon Jun 21 2021
*
* Copyright (c) 2012 - 2021 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import $ from "../../core/renderer";
import Widget from "../widget/ui.widget";
import {
getGanttViewCore
} from "./gantt_importer";
import {
TaskAreaContainer
} from "./ui.gantt.task.area.container";
import dateLocalization from "../../localization/date";
import {
isDefined
} from "../../core/utils/type";
import messageLocalization from "../../localization/message";
import {
format
} from "../../core/utils/string";
export class GanttView extends Widget {
_init() {
super._init();
this._onSelectionChanged = this._createActionByOption("onSelectionChanged");
this._onScroll = this._createActionByOption("onScroll");
this._onDialogShowing = this._createActionByOption("onDialogShowing");
this._onPopupMenuShowing = this._createActionByOption("onPopupMenuShowing");
this._expandAll = this._createActionByOption("onExpandAll");
this._collapseAll = this._createActionByOption("onCollapseAll");
this._taskClick = this._createActionByOption("onTaskClick");
this._taskDblClick = this._createActionByOption("onTaskDblClick");
this._onAdjustControl = this._createActionByOption("onAdjustControl")
}
_initMarkup() {
var GanttView = getGanttViewCore();
this._ganttViewCore = new GanttView(this.$element().get(0), this, {
showResources: this.option("showResources"),
taskTitlePosition: this._getTaskTitlePosition(this.option("taskTitlePosition")),
firstDayOfWeek: this._getFirstDayOfWeek(this.option("firstDayOfWeek")),
allowSelectTask: this.option("allowSelection"),
editing: this._parseEditingSettings(this.option("editing")),
validation: this.option("validation"),
stripLines: {
stripLines: this.option("stripLines")
},
areHorizontalBordersEnabled: this.option("showRowLines"),
areAlternateRowsEnabled: false,
viewType: this._getViewTypeByScaleType(this.option("scaleType")),
cultureInfo: this._getCultureInfo(),
taskTooltipContentTemplate: this.option("taskTooltipContentTemplate"),
taskProgressTooltipContentTemplate: this.option("taskProgressTooltipContentTemplate"),
taskTimeTooltipContentTemplate: this.option("taskTimeTooltipContentTemplate"),
taskContentTemplate: this.option("taskContentTemplate")
});
this._selectTask(this.option("selectedRowKey"));
this.updateBarItemsState()
}
_getFirstDayOfWeek(value) {
return isDefined(value) ? value : dateLocalization.firstDayOfWeekIndex()
}
getTaskAreaContainer() {
return this._ganttViewCore.taskAreaContainer
}
getBarManager() {
return this._ganttViewCore.barManager
}
executeCoreCommand(id) {
var command = this._ganttViewCore.getCommandByKey(id);
if (command) {
command.execute()
}
}
changeTaskExpanded(id, value) {
this._ganttViewCore.changeTaskExpanded(id, value)
}
updateView() {
this._ganttViewCore.updateView()
}
updateBarItemsState() {
this._ganttViewCore.barManager.updateItemsState([])
}
setWidth(value) {
this._ganttViewCore.setWidth(value)
}
_selectTask(id) {
this._ganttViewCore.selectTaskById(id)
}
_update(keepExpandState) {
var core = this._ganttViewCore;
var state = keepExpandState && core.getTasksExpandedState();
core.loadOptionsFromGanttOwner();
if (keepExpandState) {
core.applyTasksExpandedState(state)
} else {
core.resetAndUpdate()
}
}
_getCultureInfo() {
return {
monthNames: dateLocalization.getMonthNames("wide"),
dayNames: dateLocalization.getDayNames("wide"),
abbrMonthNames: dateLocalization.getMonthNames("abbreviated"),
abbrDayNames: dateLocalization.getDayNames("abbreviated"),
quarterNames: this._getQuarterNames(),
amText: dateLocalization.getPeriodNames()[0],
pmText: dateLocalization.getPeriodNames()[1]
}
}
_getQuarterNames() {
var quarterFormat = messageLocalization.format("dxGantt-quarter");
if (!quarterFormat) {
return dateLocalization.getQuarterNames()
}
return [format(quarterFormat, 1), format(quarterFormat, 2), format(quarterFormat, 3), format(quarterFormat, 4)]
}
_getTaskTitlePosition(value) {
switch (value) {
case "outside":
return 1;
case "none":
return 2;
default:
return 0
}
}
_getViewTypeByScaleType(scaleType) {
switch (scaleType) {
case "minutes":
return 0;
case "hours":
return 1;
case "days":
return 3;
case "weeks":
return 4;
case "months":
return 5;
case "quarters":
return 6;
case "years":
return 7;
default:
return
}
}
_parseEditingSettings(value) {
return {
enabled: value.enabled,
allowDependencyDelete: value.allowDependencyDeleting,
allowDependencyInsert: value.allowDependencyAdding,
allowTaskDelete: value.allowTaskDeleting,
allowTaskInsert: value.allowTaskAdding,
allowTaskUpdate: value.allowTaskUpdating,
allowResourceDelete: value.allowResourceDeleting,
allowResourceInsert: value.allowResourceAdding,
allowResourceUpdate: value.allowResourceUpdating,
allowTaskResourceUpdate: value.allowTaskResourceUpdating
}
}
_optionChanged(args) {
switch (args.name) {
case "width":
super._optionChanged(args);
this._ganttViewCore.setWidth(args.value);
break;
case "height":
this._ganttViewCore.setHeight(args.value);
break;
case "tasks":
case "dependencies":
case "resources":
case "resourceAssignments":
this._update();
break;
case "showResources":
this._ganttViewCore.setShowResources(args.value);
break;
case "taskTitlePosition":
this._ganttViewCore.setTaskTitlePosition(this._getTaskTitlePosition(args.value));
break;
case "firstDayOfWeek":
this._ganttViewCore.setFirstDayOfWeek(this._getFirstDayOfWeek(args.value));
break;
case "allowSelection":
this._ganttViewCore.setAllowSelection(args.value);
break;
case "selectedRowKey":
this._selectTask(args.value);
break;
case "editing":
this._ganttViewCore.setEditingSettings(this._parseEditingSettings(args.value));
break;
case "validation":
this._ganttViewCore.setValidationSettings(args.value);
this._update(true);
break;
case "showRowLines":
this._ganttViewCore.setRowLinesVisible(args.value);
break;
case "scaleType":
this._ganttViewCore.setViewType(this._getViewTypeByScaleType(args.value));
break;
case "stripLines":
this._ganttViewCore.setStripLines({
stripLines: args.value
});
break;
case "taskTooltipContentTemplate":
this._ganttViewCore.setTaskTooltipContentTemplate(args.value);
break;
case "taskProgressTooltipContentTemplate":
this._ganttViewCore.setTaskProgressTooltipContentTemplate(args.value);
break;
case "taskTimeTooltipContentTemplate":
this._ganttViewCore.setTaskTimeTooltipContentTemplate(args.value);
break;
case "taskContentTemplate":
this._ganttViewCore.setTaskContentTemplate(args.value);
break;
default:
super._optionChanged(args)
}
}
get bars() {
return this.option("bars")
}
getRowHeight() {
return this.option("rowHeight")
}
getHeaderHeight() {
return this.option("headerHeight")
}
getGanttTasksData() {
return this.option("tasks")
}
getGanttDependenciesData() {
return this.option("dependencies")
}
getGanttResourcesData() {
return this.option("resources")
}
getGanttResourceAssignmentsData() {
return this.option("resourceAssignments")
}
getGanttWorkTimeRules() {
return {}
}
getExternalTaskAreaContainer(element) {
if (!this._taskAreaContainer) {
this._taskAreaContainer = new TaskAreaContainer(element, this)
}
return this._taskAreaContainer
}
changeGanttTaskSelection(id, selected) {
this._onSelectionChanged({
id: id,
selected: selected
})
}
onGanttScroll(scrollTop) {
this._onScroll({
scrollTop: scrollTop
})
}
showDialog(name, parameters, callback, afterClosing) {
this._onDialogShowing({
name: name,
parameters: parameters,
callback: callback,
afterClosing: afterClosing
})
}
getModelChangesListener() {
return this.option("modelChangesListener")
}
getExportInfo() {
return this.option("exportInfo")
}
showPopupMenu(info) {
this._onPopupMenuShowing(info)
}
getMainElement() {
return this.option("mainElement").get(0)
}
adjustControl() {
this._onAdjustControl()
}
getRequireFirstLoadParentAutoCalc() {
return this.option("validation.autoUpdateParentTasks")
}
collapseAll() {
this._collapseAll()
}
expandAll() {
this._expandAll()
}
onTaskClick(key, event) {
this._taskClick({
key: key,
event: event
});
return true
}
onTaskDblClick(key, event) {
return this._taskDblClick({
key: key,
event: event
})
}
onGanttViewContextMenu(event, key, type) {
return true
}
getFormattedDateText(date) {
var result = "";
if (date) {
var datePart = dateLocalization.format(date, "shortDate");
var timePart = dateLocalization.format(date, "hh:mm");
result = datePart + " " + timePart
}
return result
}
destroyTemplate(container) {
$(container).empty()
}
getTreeListTableStyle() {
return this.callExportHelperMethod("getTreeListTableStyle")
}
getTreeListColCount() {
return this.callExportHelperMethod("getTreeListColCount")
}
getTreeListHeaderInfo(colIndex) {
return this.callExportHelperMethod("getTreeListHeaderInfo", colIndex)
}
getTreeListCellInfo(rowIndex, colIndex) {
return this.callExportHelperMethod("getTreeListCellInfo", rowIndex, colIndex)
}
callExportHelperMethod(methodName) {
var helper = this.option("exportHelper");
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key]
}
return helper[methodName](...args)
}
}