angular-ui / ui-calendar

A complete AngularJS directive for the Arshaw FullCalendar.
http://angular-ui.github.io/ui-calendar/
MIT License
1.49k stars 729 forks source link

Events disappearing when other eventSource is changed #442

Closed rossjcooper closed 6 years ago

rossjcooper commented 7 years ago

I am finding that when an eventSource in my eventSources array is changing some events from other eventSources are disappearing from the calendar, it doesn't appear to be deleting the actual data because if I trigger a render by going back and forward a month in the view they reappear.

It appears to happen in the $scope.dayClick() function, once this has been triggered 3+ times the $scope.projects events disappear one at a time.

angular.module('calendarController', []).controller('calendarController', function($scope, $http, uiCalendarConfig, Calendar) {
    //Hide task pane by default
    $scope.task_toggle = false;
    //Initalise scope variables
    $scope.task = {};
    $scope.projects = {
        url : "/api/calendar/projects"
    };
    $scope.tasks = [];
    $scope.eventSources = [];

    //Triggered when a day is clicked on calendar
    $scope.dayClick = function(date, jsEvent, view) {
       // $scope.tasks.splice($scope.tasks.length-1);
            //Setup new task
            $scope.task = {
                title: "New task",
                start: date,
                end: date,
            };
            //Show task pane
            $scope.task_toggle = true;
            //Push new task to array for calendar
            $scope.tasks.push($scope.task);
        }
        //Triggered when task pane is cancelled
    $scope.cancelTask = function() {
        //Hide pane
        $scope.task_toggle = false;
        //Reset task object
        $scope.task = {};
    }
    $scope.eventClick = function(calEvent, jsEvent, view) {
            $scope.task = calEvent;
            $scope.task_toggle = true;
        }
        //Config settings for calendar
    $scope.uiConfig = {
        calendar: {
            height: 450,
            editable: true,
            header: {
                left: 'month basicWeek basicDay agendaWeek agendaDay',
                center: 'title',
                right: 'today prev,next'
            },
            eventClick: $scope.eventClick,
            eventDrop: $scope.alertOnDrop,
            eventResize: $scope.alertOnResize,
            dayClick: $scope.dayClick
        }
    };
    $scope.eventSources = [$scope.projects, $scope.tasks];
});
rossjcooper commented 7 years ago

I have tried adding a refetchEvents call on the $scope.dayClick() function which has stopped the other events disappearing but now I get an obvious flicker while the events are being refetched and rendered, this is clearly not a permanent fix but it does clarify it may be more to do with ui-calendar not handling eventSources correctly as opposed to Angular binding going wrong somewhere.

$scope.dayClick = function(date, jsEvent, view) {
        ...
            $('#myCalendar').fullCalendar('refetchEvents');
        }
daniel42na commented 7 years ago

Try to add stick=true to each event

danielraban commented 7 years ago

stick:true,

rossjcooper commented 7 years ago

I'll give it a try but surely if the events are from event sources anyway surely they wouldn't disappear on rerendering

Hasan-Mainul commented 3 years ago

$scope.getAllTimelineByPOID = function (PurchaseOrderID) { timelineService.getAllTimelineByPOID(PurchaseOrderID).then(function (res) { if (res.data.length > 0) { $scope.timelineList = formatDate(res.data, '', ["PlannedDate", 'ActualDate', 'LastModified']);
var calenderval = res.data; //Cache= true; angular.forEach(calenderval, /stick,/ function (value) {
$scope.events.push({ title: value.Description, start: value.ActualDate //Cache: true //stick: true //end: value.ActualDate, //allDay: false

                });
            });
            $scope.eventSources = [$scope.events];
            console.log($scope.eventSources);

            for (var i = 0; i < $scope.timelineList.length; i++) {
                $scope.timelineList[i].ActualDate = new Date($scope.timelineList[i].ActualDate);
                $scope.timelineList[i].LastModified = new Date($scope.timelineList[i].LastModified);
            }
        }
        else {
            $scope.timelineList.push($scope.timeline);
        }
    });
};

i'm facing same problem , help me out