Our pure JavaScript Scheduler component


Post by William »

When auto sync, all operations (CRUD) are sent back to the background together, rather than the latest operations. How to solve this?

Post by pmiklashevich »

autoSync performs a request only after autoSyncTimeout is over. So it grabs all changes and send them together. If records are still dirty after sync request is completed, please make sure your server response is correct. if "success" not equal to "true", request is considered to be failed.

Pavlo Miklashevych
Sr. Frontend Developer


Post by William »

I'm sure "success" equal to "true".But after 'autoSync', the last synchronized data will be sent to the background together with the latest data. Is there any way to just send the latest data?
crudManager : {
                autoLoad  : true,
                autoSync  : true,
                autoSyncTimeout : 100,
                transport : {
                    load: {
                        url : conf.schedulerLoad
                    },
                    sync : {
                        url : conf.schedulerSync,
                        method : 'POST',
                        paramName : 'dat',
                        params : {
                            taskId     : 1
                        }
                    }
                },
                writeAllFields: true
           }

Post by pmiklashevich »

Hello,

While was checking your issue I found a bug that writeAllFields on crudManager doesn't work. Need to set writeAllFields to stores explicitly. Ticket here: https://app.assembla.com/spaces/bryntum/tickets/9094-crudmanager-writeallfields-is-not-taken-into-account/details

Other than that I don't see any issues and I can't reproduce yours. Please adjust examples/crudmanager/app.js
    crudManager : {
        // writeAllFields : true, // Doesn't work, see https://app.assembla.com/spaces/bryntum/tickets/9094

        resourceStore : {
            writeAllFields : true,
            // Add some custom fields
            fields : ['car', 'dt']
        },

        eventStore : {
            writeAllFields : true,
            // Add a custom field and redefine durationUnit to default to hours
            fields : ['dt', { name : 'durationUnit', defaultValue : 'hour' }]
        },
        ....
        autoLoad : true, // already true in this demo
        autoSync : true, // already true in this demo, timeout is 100 by default
Then go to the browser, drag "Serve engine" one hour ahead, then drag "Paint job" one hour ahead. See 2 sync requests in console. Each request has only one item (events.updated[0]).

Please let me know how to adjust the demo and what to do to see 2 items in the second request. Or provide a runnable testcase which shows the issue.

Best,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by William »

Hello:
https://lh/scheduler/examples/crudmanager/
This link cannot be opened
Here is my example:
App.tsx
import * as React from 'react';
import NewScheduler from './newScheduler';

class App extends React.Component  {
    // public state = {
    //    jsPan: undefined,
    //   gantt: undefined,
    // };

    public componentDidMount() {
        console.log('start App.')
    }

    public render() {
        const marginBottomTop10 = {
            marginBottom: '10px',
            marginTop: '10px'
        };

        const ele = (
            <div className="x_content">
                <div className="row" style={marginBottomTop10}>
                    <div className="col-md-12 col-sm-12 col-xs-12">
                        <NewScheduler />
                    </div>
                </div>
            </div>
        );
        return ele;
    }
}
export default App;
NewScheduler.tsx
import * as React from 'react';
import 'bryntum-scheduler/scheduler.stockholm.css'
import {Scheduler, TimeSpan} from 'bryntum-scheduler';

class NewScheduler extends React.Component {
    public state = {
        timeRanges : null
    };

    public scheduler: any = null;

    public componentDidMount() {
        this.scheduler = new Scheduler({
            appendTo   : 'newscheduler',
            minHeight  : '20em',
            eventStyle : 'border',
            barMargin  : 2,
            autoHeight  : true,
            startDate  : new Date(2019, 7, 7, 6),
            endDate    : new Date(2019, 7, 7, 20),
            viewPreset : 'hourAndDay',
            timeRanges : {
                store: {
                    modelClass: TimeSpan,
                    storeId: 'timeRanges',
                    data: this.state.timeRanges
                }
            },
            columns : [
                {
                    // type      : 'resourceInfo',
                    // imagePath : '../_shared/images/users/',
                    text      : 'Staff',
                    field     : 'name'
                },
                {
                    text   : 'Type',
                    field  : 'role',
                    flex   : 1,
                    editor : {
                        type        : 'combo',
                        items       : ['Sales', 'Manager'],
                        editable    : false,
                        pickerWidth : 140
                    }
                }
            ],
            crudManager : {
                autoLoad  : true,
                autoSync  : true,
                autoSyncTimeout : 100,
                transport : {
                    load: {
                        // url : '/data.json'
                        url : url_scheduler_load
                    },

                    sync: {
                        url : url_scheduler_sync,
                        method: 'POST',
                        paramName: 'data',
                        params      : {
                            taskId     : 1
                        }
                    }
                }
            },
            features : {
                contextMenu: {
                    cellItems: [{
                        text: 'Add rows',
                        icon: 'b-fa b-fa-plus',
                        weight: 140,
                        onItem: () => {
                            this.scheduler.resourceStore.add({name: 'New name', role: 'New'});
                        }
                    }]
                }
            },

        });
    }

    public componentWillUnmount() {
        this.scheduler.destroy();
    }
    
    public render() {
        return <div className={'b-react-scheduler-container'} id='newscheduler' />
    }
}
export default NewScheduler;
The demo in PHP returns the CRUD changes data. Does 'autoSync' return the changes data?
If so, what is the return data structure?
Thanks !

Post by pmiklashevich »

https://lh/scheduler/examples/crudmanager/
This link cannot be opened
"lh" is localhost. "scheduler" is your distributive. "examples/crudmanager" is a path to the demo. The url can be differ depending on your local webserver configuration. The idea is to run demo locally, adjust sources and make sure it works.
The demo in PHP returns the CRUD changes data. Does 'autoSync' return the changes data?
If so, what is the return data structure?
Please see response format in our Gantt guides: https://www.bryntum.com/docs/gantt/#guides/crud_manager.md
We will move it to scheduler in next releases.

The main idea is to return `true` in case of successful saving. Otherwise data will stay dirty and will be sent with next sync request.
{
        "success" : true,
        ....
}
Request:
2019-08-21_17011.png
2019-08-21_17011.png (151.33 KiB) Viewed 2263 times
Response:
2019-08-21_1701.png
2019-08-21_1701.png (84.73 KiB) Viewed 2263 times
Here is my example
We accept only runnable testcases. If you want us to inspect your code, please make sure it's runnable, zip it up and attach here (node_modules should be removed, we have to be able to build and run it on our end).

Best regards,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by William »

Hello,
I think I've found the answer to the question.It's a matter of returning data structures.This article plays a very important role.
https://www.bryntum.com/docs/gantt/#guides/crud_manager.md

In addition, if a newly created resource must be 'resourceId' instead of 'id', it cannot be modified and deleted. Adding an event will result in an error.

Response:
{
            'success': true,
            'requestId': '1122',
            'revision': 2,
            'events': {
                'rows': [
                    {
                        '$PhantomId'      : ‘3344’,
                        // To add a new event, you must use 'id' instead of 'eventId'.
                        'id'                        : 3,
                        'resourceId'        : 4,
                        'name'                 : ‘test’,
                        'startDate'           : '2019-08-22 10:00',
                        'endDate'            : '2019-08-22 12:00',
                        ...
                    }
                ],
                'removed': []
            },
            'resources': {
                'rows': [
                	{
                		 '$PhantomId'      :  ‘5566’,
                		 // To add a new resource, you must use 'resourceId' instead of 'id'.
                		 'resourceId'	      : 5,
                		 'name'		      : 'Jack',
                		 ...
                	}
                ],
                'removed': []
            }
        }
Thanks again!
Best
William
Attachments
1.png
1.png (35.74 KiB) Viewed 2258 times

Post by pmiklashevich »

// To add a new resource, you must use 'resourceId' instead of 'id'
It doesn't sound right. Resource model idField is "id" by default. You can add a new resource in our CrudManager demo and see the response. Please run in console:
scheduler.resourceStore.add({ car : 'ZAZ 968M' })
2019-08-22_1239.png
2019-08-22_1239.png (370.54 KiB) Viewed 2254 times
Adding an event will result in an error
Please provide detailed steps of how I can reproduce the error with one of our samples.

Pavlo Miklashevych
Sr. Frontend Developer


Post by William »

I don't see any of these errors in this demo.
https://www.bryntum.com/examples/scheduler/crudmanager/
But the above error occurred in my example.I'm sure the 'id' will get an error, and I haven't changed anything about it.Does the following code matter?
{ text : 'Id', field : 'id', width : 100, editor : false, hidden : false}

Post by pmiklashevich »

But the above error occurred in my example.
Please zip it up and attach here. We will try to investigate it to find the root cause.

Pavlo Miklashevych
Sr. Frontend Developer


Post Reply