Skip to content

Commit

Permalink
date & date time, wave 2 2021 support
Browse files Browse the repository at this point in the history
  • Loading branch information
MaTeMaTuK committed Oct 24, 2021
1 parent 18d4c48 commit 0fda08e
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 330 deletions.
22 changes: 13 additions & 9 deletions UniversalGanttChartComponent/ControlManifest.Input.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<manifest>
<control namespace="UniversalGanttGridComponent" constructor="UniversalGanttChartComponent" version="0.1.4" display-name-key="Universal Gantt Chart Component" description-key="Component shows tasks on a timeline. You can move them on the chart." control-type="standard" >
<control namespace="UniversalGanttGridComponent" constructor="UniversalGanttChartComponent" version="0.1.5" display-name-key="Universal Gantt Chart Component" description-key="Component shows tasks on a timeline. You can move them on the chart." control-type="standard" >
<!--external-service-usage node declares whether this 3rd party PCF control is using external service or not, if yes, this control will be considered as premium and please also add the external domain it is using.
If it is not using any external service, please set the enabled="false" and DO NOT add any domain below. The "enabled" will be false by default.
Example1:
Expand All @@ -17,21 +17,25 @@
<domain></domain>
-->
</external-service-usage>
<type-group name="Date.All">
<type>DateAndTime.DateAndTime</type>
<type>DateAndTime.DateOnly</type>
</type-group>
<!-- dataset node represents a set of entity records on CDS; allow more than one datasets -->
<data-set name="entityDataSet" display-name-key="Entity-Grid" cds-data-set-options="displayCommandBar:true;displayViewSelector:true;displayQuickFind:true">
<property-set name="title" display-name-key="Title" description-key="Record Name for displaying on grid" of-type="SingleLine.Text" usage="bound" required="true" />
<property-set name="startTime" display-name-key="Start" description-key="Scheduled start date and time" of-type="DateAndTime.DateAndTime" usage="bound" required="true" />
<property-set name="endTime" display-name-key="End" description-key="Scheduled end date and time" of-type="DateAndTime.DateAndTime" usage="bound" required="true" />
<property-set name="progress" display-name-key="Progress" description-key="From 0 to 100. Whole Number" of-type="Whole.None" usage="bound" required="false" />
<property-set name="parentRecord" display-name-key="Parent Record" description-key="Parent record reference" of-type="Lookup.Simple" usage="bound" required="false" />
<property-set name="title" display-name-key="Title" description-key="Record Name for displaying on grid" of-type="SingleLine.Text" usage="input" required="true" />
<property-set name="startTime" display-name-key="Start" description-key="Scheduled start date and time" of-type-group="Date.All" usage="input" required="true" />
<property-set name="endTime" display-name-key="End" description-key="Scheduled end date and time" of-type-group="Date.All" usage="input" required="true" />
<property-set name="progress" display-name-key="Progress" description-key="From 0 to 100. Whole Number" of-type="Whole.None" usage="input" required="false" />
<property-set name="parentRecord" display-name-key="Parent Record" description-key="Parent record reference" of-type="Lookup.Simple" usage="input" required="false" />
<property-set name="taskTypeOption" display-name-key="Task Type(Option)"
description-key="Specifies record type. Task, milestone, project. You are able to configure option-text mapping in Task Type Mapping parameter." of-type="OptionSet"
usage="bound" required="false"
usage="input" required="false"
/>
<property-set name="displayColorOption"
display-name-key="Display Color(Option)" description-key="Specifies record color by option value(hex code)" of-type="OptionSet" usage="bound" required="false" />
display-name-key="Display Color(Option)" description-key="Specifies record color by option value(hex code)" of-type="OptionSet" usage="input" required="false" />
<property-set name="displayColorText"
display-name-key="Display Color(Text)" description-key="Specifies record color by text value(hex code)" of-type="SingleLine.Text" usage="bound" required="false" />
display-name-key="Display Color(Text)" description-key="Specifies record color by text value(hex code)" of-type="SingleLine.Text" usage="input" required="false" />
</data-set>

<property name="displayMode" display-name-key="Display Mode" description-key="Parameter enables or disables progress and datetime controls" of-type="Enum" usage="input" required="true" default-value="editable">
Expand Down
38 changes: 0 additions & 38 deletions UniversalGanttChartComponent/components/gantt-footer.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { Task } from "gantt-task-react";

export const creatTaskListLocal = (
export const createTaskListLocal = (
includeTime: boolean,
onClick: (task: Task) => void,
formatDateShort: (value: Date, includeTime?: boolean) => string
Expand Down
22 changes: 15 additions & 7 deletions UniversalGanttChartComponent/components/universal-gantt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { createHeaderLocal } from "./task-list-header";
import { ViewSwitcher } from "./view-switcher";
import { IInputs } from "../generated/ManifestTypes";
import { createTooltip } from "./gantt-tooltip";
import { creatTaskListLocal } from "./task-list-table";
import { createTaskListLocal } from "./task-list-table";
import { isErrorDialogOptions } from "../helper";

export type UniversalGanttProps = {
context: ComponentFramework.Context<IInputs>;
Expand Down Expand Up @@ -40,14 +41,14 @@ export type UniversalGanttProps = {
columnWidthMonth: number;
onViewChange: (viewMode: ViewMode) => void;
onExpanderStateChange: (itemId: string, expanderState: boolean) => void;
setUpdateEvent: (updateEvent: boolean) => void;
} & EventOption &
DisplayOption;
export const UniversalGantt: React.FunctionComponent<UniversalGanttProps> = (
props
) => {
debugger;
const [view, setView] = React.useState(props.viewMode);
const { context, setUpdateEvent } = props;
const { context } = props;
// Events
const handleDateChange = async (task: Task) => {
const recordRef =
Expand All @@ -65,7 +66,11 @@ export const UniversalGantt: React.FunctionComponent<UniversalGanttProps> = (
),
});
} catch (e) {
context.navigation.openErrorDialog(e);
if (isErrorDialogOptions(e)) {
context.navigation.openErrorDialog(e);
} else {
console.error(e);
}
resultState = false;
}
context.parameters.entityDataSet.refresh();
Expand All @@ -83,7 +88,11 @@ export const UniversalGantt: React.FunctionComponent<UniversalGanttProps> = (
[props.progressFieldName]: task.progress,
});
} catch (e) {
context.navigation.openErrorDialog(e);
if (isErrorDialogOptions(e)) {
context.navigation.openErrorDialog(e);
} else {
console.error(e);
}
resultState = false;
}
context.parameters.entityDataSet.refresh();
Expand All @@ -105,7 +114,6 @@ export const UniversalGantt: React.FunctionComponent<UniversalGanttProps> = (
};

const handleExpanderClick = (task: Task) => {
setUpdateEvent(true);
props.onExpanderStateChange(task.id, !!task.hideChildren);
};

Expand Down Expand Up @@ -135,7 +143,7 @@ export const UniversalGantt: React.FunctionComponent<UniversalGanttProps> = (
props.includeTime,
formatDateShort
),
TaskListTable: creatTaskListLocal(
TaskListTable: createTaskListLocal(
props.includeTime,
handleOpenRecord,
formatDateShort
Expand Down
8 changes: 8 additions & 0 deletions UniversalGanttChartComponent/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const isErrorDialogOptions = (
error: ComponentFramework.NavigationApi.ErrorDialogOptions | any
): error is ComponentFramework.NavigationApi.ErrorDialogOptions => {
return (
(error as ComponentFramework.NavigationApi.ErrorDialogOptions).errorCode !==
undefined
);
};
33 changes: 12 additions & 21 deletions UniversalGanttChartComponent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Task, ViewMode } from "gantt-task-react";
import { UniversalGantt } from "./components/universal-gantt";
import { generate } from "@ant-design/colors";
import { TaskType } from "gantt-task-react/dist/types/public-types";
import { isErrorDialogOptions } from "./helper";

type DataSet = ComponentFramework.PropertyTypes.DataSet;

Expand All @@ -28,18 +29,15 @@ export class UniversalGanttChartComponent
private _crmUserTimeOffset: number;
private _dataSet: DataSet;
private _locale: string;
private _tasks: Task[];
private _taskTypeMap: any;
private _projects: {
[index: string]: boolean;
};
private _updateEvent: boolean;

constructor() {
this.handleViewModeChange = this.handleViewModeChange.bind(this);
this.handleExpanderStateChange = this.handleExpanderStateChange.bind(this);
this.generateColorTheme = this.generateColorTheme.bind(this);
this.setUpdateEvent = this.setUpdateEvent.bind(this);
}

public init(
Expand Down Expand Up @@ -83,18 +81,11 @@ export class UniversalGanttChartComponent
return;

try {
if (
context.updatedProperties.indexOf(this._dataSetName) !== -1 ||
this._updateEvent
) {
this._tasks = await this.generateTasks(
context,
this._dataSet,
!!progressField
);
this._updateEvent = false;
}
const tasks = this._tasks;
const tasks = await this.generateTasks(
context,
this._dataSet,
!!progressField
);

if (!this._locale) {
this._locale = await this.getLocalCode(context);
Expand Down Expand Up @@ -140,6 +131,7 @@ export class UniversalGanttChartComponent
context.parameters.displayDateFormat.raw === "datetime";

const fontSize = context.parameters.fontSize.raw || "14px";
debugger;
//create gantt
const gantt = React.createElement(UniversalGantt, {
context,
Expand Down Expand Up @@ -170,7 +162,6 @@ export class UniversalGanttChartComponent
columnWidthMonth,
onViewChange: this.handleViewModeChange,
onExpanderStateChange: this.handleExpanderStateChange,
setUpdateEvent: this.setUpdateEvent,
});

ReactDOM.render(gantt, this._container);
Expand Down Expand Up @@ -371,15 +362,15 @@ export class UniversalGanttChartComponent
return code;
}
} catch (e) {
context.navigation.openErrorDialog(e);
if (isErrorDialogOptions(e)) {
context.navigation.openErrorDialog(e);
} else {
console.error(e);
}
}

return "en"; // English
}

private setUpdateEvent(updateEvent: boolean) {
this._updateEvent = updateEvent;
}
/**
* It is called by the framework prior to a control receiving new data.
* @returns an object based on nomenclature defined in manifest, expecting object[s] for property marked as “bound” or “output”
Expand Down
2 changes: 1 addition & 1 deletion UniversalGanttChartSolution/src/Other/Solution.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<LocalizedName description="UniversalGanttChartSolution" languagecode="1033" />
</LocalizedNames>
<Descriptions />
<Version>1.4</Version>
<Version>1.5</Version>
<!-- Solution Package Type: Unmanaged(0)/Managed(1)/Both(2)-->
<Managed>2</Managed>
<Publisher>
Expand Down
Loading

0 comments on commit 0fda08e

Please sign in to comment.