TimeRanges on "duplicated" resource
Posted: Mon Dec 09, 2019 12:55 pm
Hello! Currently I have a button than let's you select a resource (driver in our case) and duplicate it with another vehicle assigned, this works great, the thing is I also want to duplicate the timeRanges of this resource so they have the same timeRanges, the code below creates the new resource but with empty timeRanges, I don't know what I'm missing or doing wrong
Thanks!
addResource() {
const scheduler = this.$refs.scheduler.schedulerEngine;
if(!this.newLineModalDriver || !this.newLineModalVehicle) return;
console.log('Add resource', this.newLineModalDriver, this.newLineModalVehicle);
const driverId = this.newLineModalDriver.driverId
//
var driver = {
id: `${driverId}--${this.newLineModalVehicle.id}`,
name: this.newLineModalDriver.name,
vehicleName: this.newLineModalVehicle.name,
vehicleType: this.newLineModalVehicle.vehicleType,
vehicleId: this.newLineModalVehicle.id,
cls: 'b-grid-row--driver',
urlPicture: this.newLineModalDriver.urlPicture,
vehicleLicensePlate: this.newLineModalVehicle.licensePlate,
latitude: this.newLineModalDriver.latitude,
longitude: this.newLineModalDriver.longitude
}
scheduler.resourceStore.add(driver)
// Add resourceTimeRange
var newTimeRanges = []
// Search for this driver timeRanges and "duplicate"
var timeRanges = scheduler.resourceTimeRangeStore.forEach(function (timeRange) {
var timeRangeIds = timeRange.resourceId.split('--')
//console.log(timeRangeIds[0], driverId, timeRangeIds[0] == driverId)
if(timeRangeIds[0] == driverId) {
var newTimeRange = Object.assign({}, timeRange);
newTimeRange.id = Math.random().toString(36).substr(2, 9)
newTimeRange.resourceId = driver.id
newTimeRanges.push(newTimeRange)
//
}
})
// Add timeRanges to storage
newTimeRanges.forEach(function(timeRange) {
scheduler.resourceTimeRangeStore.add(timeRange)
})
this.newLineModal = false
this.$toast.success('Driver added to scheduler')
},