scheduler.component.ts:
lastAppointment;
onActionComplete(args: ActionEventArgs): void {
this.eventService.getLastAppointment().subscribe((data : any) => {
this.lastAppointment = data.appointment;
});
console.log('last appointment: ', this.lastAppointment[0].Client);
}
This is on the Nodejs backend to retrieve the last document in the :
events.js:
router.get("/getLastAppointment", authRequired, (req, res) => {
// console.log(req.decoded.userId);
User.findOne({_id: req.decoded.userId}).select('username email').exec((err, user) =>{
if(err){
res.json({success: false, message: err});
} else {
if(!user){
res.json({success: false, message: 'Not found'});
} else {
user= user;
connection.db.collection('ScheduleData').find().sort( { _id : -1 } ).limit(1).toArray((err, cus) => {
res.json({appointment: cus});
console.log(req.body.params);
});;
console.log(user.username);
}
}
});
});However, when I save an appointment, it does not take the Client of the newly created appointment , but the last one before the user clicked on save, if that makes sense.
So if I make a new event and chose Bob , i want that lastAppointment; gets assigned to 'Bob'.How do I get the 'Client' of the last created event?
onPopupOpen() method:
onPopupOpen(args: PopupOpenEventArgs): void {
let clientsDrop = [{text:'Hans', value:'Hans'}, {text:'Bob', value:'Bob'} ]
if (args.type === 'Editor') {
// Create required custom elements in initial time
if (!args.element.querySelector('.custom-field-row')) {
let row: HTMLElement = createElement('div', {className: 'custom-field-row'});
let formElement: HTMLElement = args.element.querySelector('.e-schedule-form');
formElement.firstChild.insertBefore(row, args.element.querySelector('.e-title-location-row'));
let container: HTMLElement = createElement('div', {className: 'custom-field-container'});
let inputEle: HTMLInputElement = createElement('input', {
className: 'e-field', attrs: {name: 'Client'}
}) as HTMLInputElement;
container.appendChild(inputEle);
let row2: HTMLElement = createElement('div', {className: 'custom-field-row'});
let formElement2: HTMLElement = args.element.querySelector('.e-schedule-form');
formElement2.firstChild.insertBefore(row, args.element.querySelector('.e-title-location-row'));
let container2: HTMLElement = createElement('div', {className: 'custom-field-container'});
row.appendChild(container);
row2.appendChild(container2);
let dropDownList: DropDownList = new DropDownList({
dataSource: clientsDrop,
fields: {text: 'text', value: 'value'},
value: (<{ [key: string]: Object }>(args.data)).Client as string,
floatLabelType: 'Always', placeholder: 'Client'
});
dropDownList.appendTo(inputEle);
inputEle.setAttribute('name', 'Client');
}
}
}
Thanks in advance.
ngOnInit(): void {
this.selectedDate = new Date(2018, 1, 14);
this.eventSettings = { dataSource: this.dataManager };
this.dropDownDataSource = [
{ company: 'Public Event', companyValue: 'public-event' },
{ company: 'Maintenance', companyValue: 'maintenance' },
{ company: 'Commercial Event', companyValue: 'commercial-event' },
{ company: 'Family Event', companyValue: 'family-event' }
];
}
onPopupOpen(args: PopupOpenEventArgs): void {
if (args.type === 'Editor') {
// Create required custom elements in initial time
if (!args.element.querySelector('.custom-field-row')) {
let row: HTMLElement = createElement('div', { className: 'custom-field-row' });
let formElement: HTMLElement = <HTMLElement>args.element.querySelector('.e-schedule-form');
formElement.firstChild.insertBefore(row, args.element.querySelector('.e-title-location-row'));
let container: HTMLElement = createElement('div', { className: 'custom-field-container' });
let inputEle: HTMLInputElement = createElement('input', {
className: 'e-field', attrs: { name: 'EventType' }
}) as HTMLInputElement;
container.appendChild(inputEle);
row.appendChild(container);
let drowDownList: DropDownList = new DropDownList({
dataSource: this.dropDownDataSource,
fields: { text: 'company', value: 'companyValue' },
value: (args.data as { [key: string]: Object }).EventType as string,
floatLabelType: 'Always', placeholder: 'Event Type'
});
drowDownList.appendTo(inputEle);
inputEle.setAttribute('name', 'EventType');
}
}
} |