Our pure JavaScript Scheduler component


Post by Exigo »

Hello,

I am trying to remap my event start and end date fields, however all the examples I have found on the forum have not worked for me.. So far this is the best attempt without any luck.

After I sent the scheduler the dates like date_start instead of startDate they no longer appear and does not understand the dates I send them. What am I missing to make this work?

2020-11-06_10h35_45.png
2020-11-06_10h35_45.png (13.96 KiB) Viewed 635 times

(It doesn't work if date_start and date_end are defined as strings either)

The scheduler receives the data like this

{
    "success": true,
    "resources": {
        "rows": [
            {
                "id": 172,
                "schedule_id": 1,
                "parent_id": null,
                "parent_schedule_id": null,
                "name": "Block A",
                "location_level_id": 1,
                "location_level_name": "Blocks",
                "children": [
                    {
                        "id": 179,
                        "schedule_id": 1,
                        "parent_id": 172,
                        "parent_schedule_id": 1,
                        "name": "Building 1",
                        "location_level_id": 2,
                        "location_level_name": "Building",
                        "children": [
                            {
                                "id": 180,
                                "schedule_id": 1,
                                "parent_id": 179,
                                "parent_schedule_id": 1,
                                "name": "Level 1",
                                "location_level_id": 3,
                                "location_level_name": "Level",
                                "children": [
                                    {
                                        "id": 181,
                                        "schedule_id": 1,
                                        "parent_id": 180,
                                        "parent_schedule_id": 1,
                                        "name": "Apartment 2",
                                        "location_level_id": 57,
                                        "location_level_name": "Apartment",
                                        "children": [],
                                        "expanded": true
                                    }
                                ],
                                "expanded": true
                            }
                        ],
                        "expanded": true
                    }
                ],
                "expanded": true
            }
        ]
    },
    "events": {
        "rows": [
            {
                "id": 15,
                "schedule_id": 1,
                "parent_id": null,
                "parent_schedule_id": null,
                "code": "001",
                "name": "Test Name",
                "color": "000000",
                "object": "sum_task",
                "children": [
                    {
                        "id": 16,
                        "schedule_id": 1,
                        "parent_id": 15,
                        "parent_schedule_id": 1,
                        "code": "001",
                        "name": "Test Name",
                        "color": "000000",
                        "object": "sum_task",
                        "children": [
                            {
                                "id": 17,
                                "schedule_id": 1,
                                "parent_id": 16,
                                "parent_schedule_id": 1,
                                "code": "001",
                                "name": "Test Name",
                                "color": "000000",
                                "object": "sum_task",
                                "children": [
                                    {
                                        "id": 20,
                                        "schedule_id": 1,
                                        "parent_id": 17,
                                        "parent_schedule_id": 1,
                                        "code": "001",
                                        "name": "Test Name",
                                        "color": "000000",
                                        "object": "sum_task",
                                        "children": []
                                    },
                                    {
                                        "id": 386,
                                        "schedule_id": 1,
                                        "code": "dd78",
                                        "name": "Task 1",
                                        "location_precision": 57,
                                        "user_id": null,
                                        "supplier_id": null,
                                        "sum_task_id": 17,
                                        "object": "task",
                                        "children": [
                                            {
                                                "id": 362,
                                                "schedule_id": 1,
                                                "name": "Subtask 1",
                                                "paced": false,
                                                "as_soon_as_possible": false,
                                                "order": 1,
                                                "color": "red",
                                                "calendar_id": 1,
                                                "task_id": 386,
                                                "object": "subtask",
                                                "children": [
                                                    {
                                                        "id": 622,
                                                        "schedule_id": 1,
                                                        "location_id": 181,
                                                        "date_start": "2020-10-01T00:00:00",
                                                        "date_end": "2020-10-07T00:00:00",
                                                        "duration": 6.0,
                                                        "order": 1,
                                                        "subtask_id": 362,
                                                        "name": "Subtask 1",
                                                        "object": "location_task"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": 18,
                        "schedule_id": 1,
                        "parent_id": 15,
                        "parent_schedule_id": 1,
                        "code": "001",
                        "name": "Test Name",
                        "color": "000000",
                        "object": "sum_task",
                        "children": []
                    }
                ]
            },
            {
                "id": 387,
                "schedule_id": 1,
                "code": "555",
                "name": "Task 2",
                "location_precision": 57,
                "user_id": null,
                "supplier_id": null,
                "sum_task_id": null,
                "object": "task",
                "children": [
                    {
                        "id": 363,
                        "schedule_id": 1,
                        "name": "Subtask 2",
                        "paced": false,
                        "as_soon_as_possible": false,
                        "order": 1,
                        "color": "red",
                        "calendar_id": 1,
                        "task_id": 387,
                        "object": "subtask",
                        "children": [
                            {
                                "id": 623,
                                "schedule_id": 1,
                                "location_id": 181,
                                "date_start": "2020-10-07T00:00:00",
                                "date_end": "2020-10-12T09:00:00",
                                "duration": 5.375,
                                "order": 1,
                                "subtask_id": 363,
                                "name": "Subtask 2",
                                "object": "location_task"
                            }
                        ]
                    }
                ]
            },
            {
                "id": 388,
                "schedule_id": 1,
                "code": "dd",
                "name": "Task 3",
                "location_precision": 57,
                "user_id": null,
                "supplier_id": null,
                "sum_task_id": null,
                "object": "task",
                "children": [
                    {
                        "id": 364,
                        "schedule_id": 1,
                        "name": "Subtask 3",
                        "paced": false,
                        "as_soon_as_possible": false,
                        "order": 1,
                        "color": "red",
                        "calendar_id": 1,
                        "task_id": 388,
                        "object": "subtask",
                        "children": [
                            {
                                "id": 624,
                                "schedule_id": 1,
                                "location_id": 181,
                                "date_start": "2020-11-16T00:00:00",
                                "date_end": "2020-11-19T00:00:00",
                                "duration": 3.0,
                                "order": 1,
                                "subtask_id": 364,
                                "name": "Subtask 3",
                                "object": "location_task"
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "dependencies": {
        "rows": [
            {
                "id": 318,
                "schedule_id": 1,
                "fromEvent": 622,
                "toEvent": 623
            }
        ]
    },
    "assignments": {
        "rows": [
            {
                "id": 622,
                "schedule_id": 1,
                "resource": 181,
                "event": 622
            },
            {
                "id": 623,
                "schedule_id": 1,
                "resource": 181,
                "event": 623
            },
            {
                "id": 624,
                "schedule_id": 1,
                "resource": 181,
                "event": 624
            }
        ]
    }
}

Post by arcady »

Try using field mapping approach:

export class MyEvent extends EventModel {
    static get fields() {
        return [
            { name : 'startDate', dataSource : 'date_start' },
            { name : 'endDate', dataSource : 'date_end' }
        ];
    }
}

Post by Exigo »

Thanks! This works great.. I totally missed that part of the Event model docs.


Post Reply