I have been banging my head against a wall trying to get something working that I thought would be basic functionality without any luck.
I have a vue-2/nuxt implementation of scheduler-pro trial. Data is retrieved directly from a SQL backend, and we have this working successfully. What I was hoping would be easy to do is to periodically refresh the data from our database but this is frustratingly more complicated than I would like it to be. Is this not a common scenario in any of the reactive frameworks? Or perhaps I am missing the page that explains this?
Here is how I am attempting to get the data to refresh.
In the component VUE page, in the mounted lifecycle hook I have the following code:
async mounted() {
this.thisProject = this.$refs.schedulerpro.project
setInterval(() => {
if (this.thisProject) {
console.log('timer initiated')
this.thisProject.sync()
}
}, 10000)
}
In the config file:
const project = (window.project = new ProjectModel({
autoLoad: true,
syncDataOnLoad: true,
eventStore : {
syncDataOnLoad : true
},
transport: {
load: {
url: '/api/train-schedule'
},
sync: {
url: '/api/train-schedule',
method: 'post'
}
}
}))
const schedulerproConfig = {
project,
...
I don't think this is the problem (see below) but here is the api to call the data. I am mainly including this to show the "got to sync" console message that I reference below. If there is confusion on what we are doing here we call a service that calls SPs from our DB that return our data, we have one SP for each type of data (event, resource, dependency, assignment):
router.post('/train-schedule/:type?', async (req, res) => {
console.log('got to sync')
const url = 'redacted'
const body = {
queryTimeout: 100,
inputParameters: [],
outputParameters: []
}
const type = req.params?.type?.toLowerCase()
const sps = {
resources: 'TimelineResources_SelectData',
events: 'TimelineEvents_SelectData',
assignments: 'TimelineAssignments_SelectData',
dependencies: 'TimelineDependencies_SelectData'
}
if (type && sps[type]) {
const { data } = await axios.post(url, {
...body,
storedProcedureName: sps[type]
})
return res.json(data.ResultSets.Table1)
}
const resources = axios.post(url, {
...body,
storedProcedureName: 'TimelineResources_SelectData'
})
const dependencies = axios.post(url, {
...body,
storedProcedureName: 'TimelineDependencies_SelectData'
})
const assignments = axios.post(url, {
...body,
storedProcedureName: 'TimelineAssignments_SelectData'
})
const events = axios.post(url, {
...body,
storedProcedureName: 'TimelineEvents_SelectData'
})
const response = await Promise.all([
resources,
dependencies,
assignments,
events
]).catch()
const [Resources, Dependencies, Assignments, Events] = response.map(
item => item.data
)
res.json({
resources: {
rows: Resources.ResultSets.Table1
},
dependencies: {
rows: Dependencies.ResultSets.Table1
},
assignments: {
rows: Assignments.ResultSets.Table1
},
events: {
rows: Events.ResultSets.Table1
}
})
})
This initially loads the data properly when component is mounted, I get one instance of the API message "Got To Sync" and when the interval timer fires I do see the console.message "timer initiated". But there is no network call to get the data via sync() and the console.message "got to sync" does not fire again (which leads me to believe that sync isn't actually being called when the timer fires). If I do nothing I continue to see the "timer initiated" message fire at every interval - so timer is still working. But no changes in the UI when I make changes on the backend, no network calls are kicked off and sync is never called...
UNTIL I manually adjust the length of any event, or presumably make any change to an event. Then the sync API fires at the given timer interval, I see "got to sync" message and the data starts to flow as expected. I can make changes in my database and the next time the timer fires I see the update values reflected in the UI - everything is working how I would expect. That is until I refresh the page, then the problem starts over again.
Is there something I am missing? How do I kick start the sync to work right off the bat? I have syncDataOnLoad set to true which is what I hoped would fix the issue but no luck.
Thanks for any help here.