Hello,
I have discovered issue of how to manage resources in ejSchedule during runtime using AngularJS. In future I would like to have select box control of different groups of vehicles and when user changes the group then I want to display right data to ejSchedule. As shown bellow after initialization I call function to bind vehicles as resource of schedule. When it is finished rides are displayed and there are all the needed data in the property ("#RidesSchedule").data("ejSchedule").model.resources[0] as you can see in attached images, but I do not see those vehicles in schedule. The strange thing is if I call $("#RidesSchedule").data("ejSchedule").refresh() in console then all vehicles show up and times of rides are moved one hour forwards. Could you please give me any advice of what I am doing wrong? Thank you very much in advance.
Inicialization of ejSchedule in view.html:
<ej-schedule id="RidesSchedule"
e-orientation="horizontal"
e-currentdate="vm.viewDate"
e-views="vm.views"
e-currentview="vm.calendarView"
e-group="vm.group"
e-appointmentsettings-datasource="vm.rides"
e-appointmentsettings-id="rideId"
e-appointmentsettings-subject="subject"
e-appointmentsettings-starttime="startsAt"
e-appointmentsettings-endtime="endsAt"
e-appointmentsettings-description="description"
e-appointmentsettings-allday="allDay"
e-appointmentsettings-recurrence="recurrence"
e-appointmentsettings-recurrencerule="recurrenceRule">
<e-resources>
<e-resource e-allowmultiple="false" e-field="vehicleId" e-title="Vehicle" e-name="Vehicles" e-resourcesettings="vm.vehicleResourcedata"></e-resource>
</e-resources>
</ej-schedule>
Angular controller:
angular
.module("app-rides")
.controller("scheduleController", scheduleController);
function scheduleController($http) {
var vm = this;
vm.calendarView = "day";
vm.viewDate = new Date(); //date for schedule
vm.views = [];
vm.rides = [];
vm.group = {
resources: ["Vehicles"]
};
vm.vehicleResourcedata = {
dataSource: [],
text: "text", id: "id"
}; //resource for scheduler
getVehicles(); //load vehicles to scheduler as resource
//get vehicles as resource
function getVehicles() {
$http.get("/api/cars")
.then(function (response) {
//success
for (var i = 0; i < response.data.length; i++) {
var car = {
text: response.data[i].plateNumber,
id: response.data[i].carId
};
vm.vehicleResourcedata.dataSource.push(car);
}
getActualRides(); //get actual rides for displayed cars
},
function (error) {
//failure
})
.finally(function () {
});
}
//get data
function getActualRides() {
$http.get("/api/rides")
.then(function (response) {
//success
bindRidesToSchedule(response.data);
},
function (error) {
//failure
})
.finally(function () {
});
}
//bind data from db to schedule
function bindRidesToSchedule(responseData) {
for (var i = 0; i < responseData.length; i++) {
var ride = {
rideId: responseData[i].rideId, //id of ride which gonna be send to process this ride
subject: responseData[i].customer.name + ": " + responseData[i].placeFrom + " - " + responseData[i].placeTo,
description: responseData[i].placeFrom + " - " + responseData[i].placeTo,
startsAt: moment(responseData[i].timeFrom).toDate(),
endsAt: moment(responseData[i].timeTo).toDate(),
vehicleId: responseData[i].car.carId
}
vm.rides.push(ride);
}
}
}
Attachment:
screens_f02944b.rar