Block Data Filtering

Hi

I I am using a schedule control with enable-load-on-demand enabled.

I then have two data managers, one for the appointments and the other for the blocked appointments.

When the appointments action is called i receive some additional data about the view (current view, current date, action etc). This additional data then allows me to filter the request and return only the data that is needed for the current view.

However when the blocked data action is called there is no such additional data. Because of this i am then unable to filter the blocked data results and have to return the entire list. This may work in development, but in production there will be a number of resources/appointment types/categories/blocked data. Returning all the data all the time will create additional database calls and slow down the application.

How am i able to replicate the filtering data for the blocked appointments?

Here is my view

                    <e-appointment-settings apply-time-offset="false"
                                            id="AppointmentId"
                                            subject='"Subject"'
                                            start-time='"StartTime"'
                                            end-time='"EndTime"'
                                            all-day='"AllDay"'
                                            recurrence='"Recurrence"'
                                            recurrence-rule='"RecurrenceRule"'
                                            resource-fields='"OwnerId"'
                                             categorize='"Categorize"'>

                        <e-datamanager url="/UserSchedule/GetData"
                                       insert-url="/UserSchedule/Save"
                                       batch-url="/UserSchedule/ProcessBatch"
                                       remove-url="/UserSchedule/Delete"
                                       adaptor="UrlAdaptor"></e-datamanager>
                    </e-appointment-settings>


                    <e-blockout-settings enable="true"
                                         id="Id"
                                         subject="Subject"
                                         start-time="StartTime"
                                         end-time="EndTime"
                                         resource-id="OwnerId"
                                         is-block-appointment="IsBlockAppointment">
                        <e-datamanager url="/UserSchedule/GetBlockedData"
                                       adaptor="UrlAdaptor"></e-datamanager>

                    </e-blockout-settings>

here is my appointment controller

       public IActionResult GetData([FromBody] ViewModels.MyPostModel post)
        {
            var userId = User.Identity.GetUserId();
            var userProfile = _context.UserProfiles.Where(x => x.UserId == userId).FirstOrDefault();

            var data = FilterAppointment(post.CurrentDate, post.CurrentAction, post.CurrentView, userId);

            ViewModels.BatchDataResult result = new ViewModels.BatchDataResult();
            result.result = data;
            result.count = data.Count;
            return Json(result, new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver()
            });
        }


8 Replies

VS Velmurugan S Syncfusion Team April 27, 2018 03:49 AM UTC

Hi Alex, 
  
Thank you for contacting Syncfusion Support.  
  
We have prepared a workaround to achieve Blockout appointments filtering, which can be downloaded from the below location.  
  
  
<Code>  
<script type="text/javascript">  
    function BlockAppointment(args) {  
        if (args.requestType == "viewNavigate" || args.requestType == "dateNavigate" || args.requestType == "dataBound") {  
            var proxy = $("#Schedule1").data("ejSchedule");  
            var dataManager = ej.DataManager({  
                url: '@Url.Action("GetBlockData""Home")',  
                adaptor: new ej.UrlAdaptor(),  
                crossDomain: true  
            });  
            var query = ej.Query().addParams("CurrentView", proxy.currentView()).addParams("CurrentDate", proxy.currentDate());  
            var promise = dataManager.executeQuery(query);  
            promise.done(function (result) {  
                proxy.model.blockoutSettings.dataSource = result.result;  
                proxy._renderBlockAppointments();  
            });  
        }  
    }  
</script>  
</code>  
  
Controller Page: 
  
<Code>  
        public BatchDataResult GetBlockData([FromBody] MyPostModel post) 
        { 
            var data = FilterBlockAppointment(post.CurrentDate.ToLocalTime(), post.CurrentView); 
            BatchDataResult result = new BatchDataResult(); 
            result.result = data; 
            result.blockAppCount = new ScheduleData().GetBlockData().ToList().Count > 0 ? new ScheduleData().GetBlockData().ToList().Max(p => p.Id) : 1; 
            return result; 
        } 
  
        public static List<BlockoutData> FilterBlockAppointment(DateTime CurrentDate, String CurrentView) 
        { 
            DateTime CurrDate = Convert.ToDateTime(CurrentDate); 
            DateTime StartDate = FirstWeekDate(CurrDate.Date); 
            DateTime EndDate = FirstWeekDate(CurrDate.Date); 
            switch (CurrentView) 
            { 
                case "day": 
                    StartDate = CurrentDate; 
                    EndDate = CurrentDate.AddHours(24); 
                    break; 
                case "week": 
                    EndDate = EndDate.AddDays(7); 
                    break; 
                case "workweek": 
                    EndDate = EndDate.AddDays(5); 
                    break; 
                case "month": 
                    StartDate = CurrDate.Date.AddDays(-CurrDate.Day + 1); 
                    EndDate = StartDate.AddMonths(1); 
                    break; 
            } 
            List<BlockoutData> BlockOutList = new ScheduleData().GetBlockData().ToList().Where(app => app.StartTime >= StartDate && app.StartTime <= EndDate).ToList(); 
            return BlockOutList; 
        }  
</Code>  
  
Regards, 
Velmurugan


AP Alex Power May 16, 2018 09:24 PM UTC

Having implemented this is my live project the

            proxy._renderBlockAppointments();

does not refresh the grid

I can confirm that the data source is set correctly, and that there are records contained within

I have also ensured that i have set the isBlockedAppointment flag to true

here is the view of the object in my chrome console




VS Velmurugan S Syncfusion Team May 17, 2018 05:10 PM UTC

Hi Alex,

 

We tried with the same scenario and also with the same fields, but we were unable to get your reported issue. Could you please confirm whether you are facing issue in displaying any of the data back to the schedule such as both the normal and blockout appointments or only facing problem in displaying blocked appointments alone? We have checked the rendering of both the appointments at our end and it is  getting displayed properly in Schedule and for the same, we have prepared the working video demo, which can be downloaded from the following location.

 

Video demo: http://www.syncfusion.com/downloads/support/forum/137205/ze/ScheduleBlockOutRendering-1546422417

 

Ensured Sample: http://www.syncfusion.com/downloads/support/forum/137205/ze/ScheduleSampleBlockAppLOD-199364829

 

Kindly check with the above sample once and if you still facing the same issue, kindly revert back to us with some more details about the complete control rendering code or other reproducing steps of this issue in the above sample. The information provided by you will be more helpful for us to analyze your reported scenario and provide you back with the possible solution.

 

Regards,

Velmurugan



AP Alex Power May 21, 2018 04:49 PM UTC

Velmurugan,

Thanks for your reply


i can confirm that the issue is just related to the blocked appointments. Live ones render as expected.

My razor view

<ej-schedule id="Schedule1"
                             width="100%"
                             height="525px"
                             enable-load-on-demand="true"
                             current-date="DateTime.Now"
                             drag-stop="onDragStop"
                             resize-stop="onResizeStop"
                             start-hour="9"
                             end-hour="18"
                             show-weekend="false"
                             allow-drag-and-drop="false"
                             enable-appointment-resize="false"
                             time-zone="UTC +01:00" is-dst="false"
                             action-complete="BlockAppointment"
                             create="BlockAppointment">

                    <e-categorize-settings enable="true" datasource="@ViewBag.categorizeData" allow-multiple="false" id="id" color="color" font-color="fontColor" text="text"></e-categorize-settings>

                    <e-time-scale enable="true"
                                  major-slot="60"
                                  minor-slot-count="1"></e-time-scale>
                    <e-group resources="@ViewBag.Grouping"></e-group>
                    <e-resources>
                        <e-resource field="OwnerId" title="Owner" name="Owners" allow-multiple=false>
                            <e-resource-settings datasource="@ViewBag.OwnerData"
                                                 text="Text" id="SIP3ResourceId"
                                                 group-id="GroupId" color="Color">
                            </e-resource-settings>
                        </e-resource>
                    </e-resources>

                    <e-appointment-settings apply-time-offset="true"
                                            id="AppointmentId"
                                            subject='"Subject"'
                                            start-time='"StartTime"'
                                            end-time='"EndTime"'
                                            all-day='"AllDay"'
                                            recurrence='"Recurrence"'
                                            recurrence-rule='"RecurrenceRule"'
                                            resource-fields='"OwnerId"'
                                            categorize='"Categorize"'>

                        <e-datamanager url="/SIP3/GetData"
                                       insert-url="/SIP3/Save"
                                       batch-url="/SIP3/ProcessBatch"
                                       remove-url="/SIP3/Delete"
                                       adaptor="UrlAdaptor"
                                       headers='new List<Dictionary<string, object>> { new Dictionary<string, object>() { { "contactId", ViewBag.contactId } } }'></e-datamanager>
                    </e-appointment-settings>

                    <e-blockout-settings enable="true"
                                         id="AppointmentId"
                                         subject="Subject"
                                         start-time="StartTime"
                                         end-time="EndTime"
                                         resource-id="OwnerId"
                                         is-all-day="IsAllDay"
                                         group-id="GroupId"
                                         is-block-appointment="IsBlockAppointment">
                    </e-blockout-settings>
                </ej-schedule>

My Controller for live appointments

        public IActionResult GetData([FromBody] ViewModels.MyPostModel post)
        {
            string contactId2 = Request.Headers["contactid"].ToString();

            var contactId = int.Parse(contactId2);

            var data = FilterAppointment(post.CurrentDate, post.CurrentAction, post.CurrentView, contactId);
            ViewModels.BatchDataResult result = new ViewModels.BatchDataResult();
            result.result = data;
            result.count = data.Count;
            return Json(result, new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver()
            });
        }

        public List<ViewModels.Appointment> FilterAppointment(DateTime CurrentDate, String CurrentAction, String CurrentView, int ContactId)
        {
            DateTime CurrDate = Convert.ToDateTime(CurrentDate);
            DateTime StartDate = FirstWeekDate(CurrDate.Date);
            DateTime EndDate = FirstWeekDate(CurrDate.Date);
            //List<Appointment> DefaultScheduleList = _context.SIP3Appointment.ProjectTo<Appointment>().ToList();
            switch (CurrentView)
            {
                case "day":
                    StartDate = CurrentDate;
                    EndDate = CurrentDate.AddHours(24);
                    break;
                case "week":
                    EndDate = EndDate.AddDays(7);
                    break;
                case "workweek":
                    EndDate = EndDate.AddDays(5);
                    break;
                case "month":
                    StartDate = CurrDate.Date.AddDays(-CurrDate.Day + 1);
                    EndDate = StartDate.AddMonths(1);
                    break;
                case "agenda":
                    EndDate = EndDate.AddDays(7);
                    break;
            }


            var queryEndDate = EndDate.AddDays(1);

            //DefaultScheduleList = _context.DefaultSchedule.ToList().Where(app => app.StartTime >= StartDate && app.StartTime <= EndDate || app.Recurrence == true).ToList();// here particular date DefaultSchedule is filtered
            var DefaultScheduleList = _context.Appointments
                .Where(x => x.ContactId == ContactId)
                .Where(x => x.AppointmentType == AppointmentTypes.SIP3Appointment)
                .Where(x => x.StartTime >= StartDate && x.EndTime <= queryEndDate)
                .ProjectTo<ViewModels.Appointment>()
                .ToList();

            return DefaultScheduleList;
        }






AP Alex Power May 21, 2018 04:50 PM UTC

Controller for blocked appointments
        public JsonResult GetBlockData([FromBody] MyPostModel post)
        {
            var data = FilterBlockAppointment(post.CurrentDate.ToLocalTime(), post.CurrentView);
            BatchDataResult result = new BatchDataResult();
            result.result = data;
            result.count = data.Count;

            var returnobj = new JsonResult(result, new JsonSerializerSettings());
            return returnobj;
        }

        public List<BlockData> FilterBlockAppointment(DateTime CurrentDate, String CurrentView)
        {
            DateTime CurrDate = Convert.ToDateTime(CurrentDate);
            DateTime StartDate = FirstWeekDate(CurrDate.Date);
            DateTime EndDate = FirstWeekDate(CurrDate.Date);
            switch (CurrentView)
            {
                case "day":
                    StartDate = CurrentDate;
                    EndDate = CurrentDate.AddHours(24);
                    break;
                case "week":
                    EndDate = EndDate.AddDays(7);
                    break;
                case "workweek":
                    EndDate = EndDate.AddDays(5);
                    break;
                case "month":
                    StartDate = CurrDate.Date.AddDays(-CurrDate.Day + 1);
                    EndDate = StartDate.AddMonths(1);
                    break;
            }

            List<BlockData> BlockOutList = _context.Appointments
                .Where(app => app.StartTime >= StartDate
                            && app.StartTime <= EndDate)
                            .ProjectTo<BlockData>()
                            .ToList();

            foreach(var appointment in BlockOutList)
            {
                appointment.IsBlockAppointment = true;
                appointment.GroupId = "1";
            }

            return BlockOutList;
        }

JS for blocked appointments

function BlockAppointment(args) {
    var url = $("#BlockDataURL").attr("data-ph-block-data-url");

    if (args.requestType == "viewNavigate" || args.requestType == "dateNavigate" || args.requestType == "dataBound") {
        var proxy = $("#Schedule1").data("ejSchedule");
        var dataManager = ej.DataManager({
            url: url,
            adaptor: new ej.UrlAdaptor(),
            crossDomain: true
        });
        var query = ej.Query().addParams("CurrentView", proxy.currentView()).addParams("CurrentDate", proxy.currentDate());
        var promise = dataManager.executeQuery(query);
        promise.done(function (result) {
            proxy.model.blockoutSettings.dataSource = result.result;
            proxy._renderBlockAppointments();
        });
    }
}  


VS Velmurugan S Syncfusion Team May 22, 2018 04:22 PM UTC

Hi Alex,

 

Thanks for your update.

 

We have analyzed our given code example and suspecting that the reason for the issue is passing the blockout settings data source value wrongly (passing blockout model settings values instead of blockout data source alone to the blockoutSettings.dataSource). Therefore, we request you to change the code example of passing the blockout settings dataSource value. Please refer to the following code example to overcome this issue.

 

<Code>

function BlockAppointment(args) {

        if (args.requestType == "viewNavigate" || args.requestType == "dateNavigate" || args.requestType == "dataBound") {

            var proxy = $("#Schedule1").data("ejSchedule");

            var dataManager = ej.DataManager({

                url: '@Url.Action("GetBlockData", "Home")',

                adaptor: new ej.UrlAdaptor(),

                crossDomain: true

            });

            var query = ej.Query().addParams("CurrentView", proxy.currentView()).addParams("CurrentDate", proxy.currentDate());

            var promise = dataManager.executeQuery(query);

            promise.done(function (result) {

                proxy.model.blockoutSettings.dataSource = result.result.result; // Here need to pass the datasource value alone instead of blockoutSettings model values

                proxy._renderBlockAppointments();

            });

        }

    }

</Code>

 

We regret for the inconvenience caused as we have provided the sample with the above highlighted line on 26th April, 2018 update, but while mentioning the code example in that reply, along with this sample wrongly mentioned as “proxy.model.blockoutSettings.dataSource = result.result” instead of “proxy.model.blockoutSettings.dataSource = result.result.result” and this may misguided you to get the above reported issue.

 

Kindly try with the above changes and let us know if it resolves the reported problem as well as if you need any further assistance on this.

 

Regards,

Velmurugan


AP Alex Power June 7, 2018 02:27 PM UTC

thanks for all the help with this

The answer did indeed fix the problem


VS Velmurugan S Syncfusion Team June 8, 2018 05:02 AM UTC

Hi Alex,   
You are most welcome.   
We are glad that our given solution helped you to resolve your problem. Please let us know if you need any further assistance on this.    
Regards,  
Velmurugan  


Loader.
Up arrow icon