Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeWindow in Config - can't configure #32

Open
renatomenon opened this issue Sep 1, 2021 · 25 comments
Open

TimeWindow in Config - can't configure #32

renatomenon opened this issue Sep 1, 2021 · 25 comments

Comments

@renatomenon
Copy link

Hello,

I am trying to configure TimeWindow property to my Gantt, but I can't get this working...

Using this code:

`
var timewindows = {
windowStart: 1598979874000,
windowEnd: 1662051874000,
};

var config = {
    data: {
        resources: {
            data: dataLoaded,
            // Activities of the resources are provided along with the 'activities' property of resource objects.
            // Alternatively, they could be listed from the 'data.activities' configuration.
            activities: 'activities',
            name: 'name', // The name of the resource is provided with the name property of the resource object.
            id: 'id', // The id of the resource is provided with the id property of the resource object.
        },
        // As activities are provided along with the resources, this section only describes how to create
        // activity Gantt properties from the activity model objects.
        activities: {
            start: 'start', // The start of the activity is provided with the start property of the model object
            end: 'end', // The end of the activity is provided with the end property of the model object
            name: 'name', // The name of the activity is provided with the name property of the model object
        },
        timeWindow: {
            // Fetch the time window returned as an object with the format
            start: 'windowStart', // The start of the time window is provided with the 'windowStart' property of the returned time window object
            end: 'windowEnd', // The end of the time window is provided with the 'windowStart' property of the returned time window object
            url: timewindows,
        },
    },
    toolbar: [
        'title',
        'search',
        'separator',
        {
            type: 'button',
            text: 'Refresh',
            fontIcon: 'fa fa-refresh fa-lg',
            onclick: function (ctx) {
                ctx.gantt.draw();
            },
        },
        'fitToContent',
        'zoomIn',
        'zoomOut',
    ],
    title: '@Resources.Planning',
};

new Gantt('gantt', config);`

I tried differents formats of date in object, but the same error.

Could anyone help me? Thanks.

Error:
Error initializing the Gantt : Could not configure data for timeWindow. Probably a configuration issue with key(s) start,end checkFetcher@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:4074:17 setConfiguration@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:4201:21 GanttModel@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:750:14 GanttModel@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:4060:125 createModel@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:7946:19 setConfiguration@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:7914:27 GanttPanel/_this.initPromise<@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:7716:20

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

can you use directly

timeWindow: {
start: '1598979874000',
end: 1662051874000
}

?

@renatomenon
Copy link
Author

Hello @delhoume !

I tried to use this example (https://github.com/IBM/gantt-chart/blob/60cca5558c20ea818dc512e0d60ea65c7adb6b5f/packages/ibm-gantt-chart-docs/src/docs/data_time_window.md), but I don't have sure about a date format declaration in my object.

I declared an object like this example:

var timewindows = {
windowStart: 1598979874000,
windowEnd: 1662051874000,
};

But doesn't worked.

Using value directing in configuration, like bellow, doesn't work too.

timeWindow: {
start: '1598979874000',
end: 1662051874000
}

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

The code that shows an error is in

const checkFetcher = (fetcher, type) => {

and is called at

if ((fetchConfig = config.timeWindow)) {

I do not know exactly why this fails and what should be the correct arguments, it seems that url should contain a path to a json object that should contains keys described in the start and end parts of the timeWindow object, so maybe defining an external file as shown in the doc works.
The url is fetched then its windowStart and windowEnd keys are queried I think

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

it seems that url is mandatory and it must be an external file, or you will have an error.

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

I found that fetchers can have inline data (not urls), see
https://github.com/IBM/gantt-chart/blob/60cca5558c20ea818dc512e0d60ea65c7adb6b5f/packages/ibm-gantt-chart-docs/src/docs/data_fetchers.md
so you may try

timeWindow : {
data: timewindows,
start : 'windowStart',
end : 'windowEnd'
}

with timewindows beeing an array or a fonction returning an array.

@renatomenon
Copy link
Author

Unfortunately I also tried differents ways... Using a separated json file or using a array like that bellow.

Also tried different types of date (linux epoch, ust etc) and changing the property names of start and end...

const timeWindows = {
        "windowStart": 1598979874000,
        "windowEnd": 1662051874000
    };
    var config = {
        data: {
            timeWindow: {
                start: 'windowStart',
                end: 'windowEnd',
                data: timeWindows,
            },
            resources: {
                data: dataLoaded,
                activities: 'activities',
                name: 'name', 
                id: 'id', 
            },
            activities: {
                start: 'start', 
                end: 'end', 
                name: 'name', 
            },
        },
        toolbar: [
            'title',
            'search',
            'separator',
            {
                type: 'button',
                text: 'Refresh',
                fontIcon: 'fa fa-refresh fa-lg',
                onclick: function (ctx) {
                    ctx.gantt.draw();
                },
            },
            'fitToContent',
            'zoomIn',
            'zoomOut',
        ],
        title: '@Resources.Planning',
    };

The same error is showed:

Error initializing the Gantt : Could not configure data for timeWindow. Probably a configuration issue with key(s) start,end checkFetcher@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:4074:17 setConfiguration@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:4201:21 GanttModel@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:750:14 GanttModel@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:4060:125 createModel@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:7946:19 setConfiguration@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:7914:27 GanttPanel/_this.initPromise<@http://localhost:50863/Scripts/ibm-gantt-chart-jquery.js:7716:20

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

your
const timeWindows = {
"windowStart": 1598979874000,
"windowEnd": 1662051874000
};

is not an array, can you try

const timeWindows = [ {
"windowStart": 1598979874000,
"windowEnd": 1662051874000
} ];

as described in doc for fetchers with the resources field ?

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

Maybe also the values need to be strings

const timeWindows = [ {
"windowStart": "1598979874000",
"windowEnd": "1662051874000"
} ];

@renatomenon
Copy link
Author

I tried using these ways but got same error

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

I am running out of ideas, I will try to trace source code to see what happens

@renatomenon
Copy link
Author

renatomenon commented Sep 2, 2021

In JS, this is line:

image

fetcher.get is undefined

@delhoume
Copy link
Member

delhoume commented Sep 2, 2021

I do not see why timeWindow fetcher is different from other fetchers (activities or resources)...
Maybe you can try to create a function that returns the array, that would be another code path

@renatomenon
Copy link
Author

Thank you very much @delhoume

I really don't know why TimeWindow parameter in config do not work correctly here.

Now, I edited other path code in JS to force time window and it worked for me.

image

If you or someone else find where is my problem using timeWindow parameter in config, let me know!

Thank you for your time and help!

@delhoume
Copy link
Member

delhoume commented Sep 3, 2021

You're welcome

@mhogeveen
Copy link

For future users trying to solve this problem, this was the solution that worked for me:

const config = {
    data: {
      ...,
      timeWindow: () => {
        return new Promise((resolve, _) => {
          resolve({
            start: <your start date here>,
            end: <your end date here>,
          });
        });
      },
    },
  };

wndPromise = this.timeWindowFetcher.get(data).then(obj => ({

This line seems to suggest the timeWindowFetcher expects a Promise and does not take any other forms of input into consideration.

Hope that helps!

@delhoume
Copy link
Member

delhoume commented Apr 1, 2022

Thank you for your solution !

@precamp-io
Copy link

precamp-io commented Oct 4, 2022

path code in JS to force

I am struggling with No time window defined - doesn't help but i am quiet new at this

var dataConfig = {
            resources : {
                url : "/api/data3",
                parent : "parent",
                id : "id",
                name : "name",
                activities : "activities", 
            },
            activities : {
                start : function(activities) { return makeDate(activities.start); },
                end : function(activities) { return makeDate(activities.end); },
                name : "name",
                parent : "parent",
                id : "id"
            },
        }

        var config = {
                        // Configure a toolbar associated with the Gantt
            toolbar: [
            'title',
            'search',
            'separator',
            {
                    type: 'button',
                    text: 'Refresh',
                    fontIcon: 'fa fa-refresh fa-lg',
                    onclick: function(ctx) {
                        ctx.gantt.draw();
                    },
            },
            'fitToContent',
            'zoomIn',
            'zoomOut',
            ],
            title: 'Marketing Swimlane',
        };
    //   new Gantt('gantt', config);

    $(document).ready(function() {
        // $('#gantt').Gantt(config);
        new Gantt( 'gantt', { data: dataConfig });
    });`

This is my controller:

    public function getProjectsTaskBusinessUnit(PickList $pickList)
    {

        $resources = PickList::query()->select('id', 'name', 'id as parent')
                        ->with(['activities' => function ($query) {
                            $query->select('projects.id', 'projects.name', 'projects.start_date as start', 'projects.end_date as end');
                        }])
                        ->where('group_by', 'business_units')
                        ->get();

        return response()->json([
            "resources" => $resources,
        ]);
    }
```

@delhoume
Copy link
Member

delhoume commented Oct 4, 2022

It seems there is a solution two posts above

@precamp-io
Copy link

I have tried what is recommended not sure what I am missing

@precamp-io
Copy link

I have this error now Loading error : Invalid start "NaN"

@delhoume
Copy link
Member

delhoume commented Oct 4, 2022

please show your timeWindow() code

@precamp-io
Copy link

precamp-io commented Oct 4, 2022

var dataConfig = {
            resources : {
                url : "/api/data3",
                parent : "parent",
                id : "id",
                name : "name",
                activities : "activities", 
            },
            activities : {
                // start : function(activities) { return makeDate(activities.start); },
                // end : function(activities) { return makeDate(activities.end); },
                name : "name",
                parent : "parent",
                id : "id"
            },
            dateFormat : "yyyy-MM-dd'T'HH:mm:ss.SSSZ", // Format to parse date strings from.
            timeWindow: () => {
                return new Promise((resolve, _) => {
                    resolve({
                        start: function(activities) { return makeDate(activities.start); },
                        end: function(activities) { return makeDate(activities.end); },
                    });
                });
            },
        }

@delhoume
Copy link
Member

delhoume commented Oct 5, 2022

what is your makeDate function ?
It should return a number as in new Date().getTime()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants