2

我正在尝试以角度 1 使用完整的日历,并且我完成了显示事件,

当我尝试在下一个和上一个按钮单击时添加事件时,我也收到了来自服务器的响应,但是当事件被分配给 FullCalendar 事件时,它会返回默认视图或任何议程,例如,如果视图是日视图并且当我单击上一个按钮,它会转到前一天,当事件来自服务器时,它会返回到今天的视图。以下是可以让您清楚地了解我在做什么的代码。

HTML

<div id="demoCalender" fc fc-options="calendarOptions">

$scope.defaultViewAgenda = "agendaDay";

$scope.calendarOptions = {
    height: get_calendar_height(100),        
    header: {
        left: 'title',
        center: 'today',
        right: 'prev,agendaDay,agendaWeek,month,next'
    },
    buttonText: {
        today: 'Today',
        month: 'Month',
        week: 'Week',
        day: 'Day',
        list: 'List'
    },
    defaultTimedEventDuration: '00:45:00',
    forceEventDuration: false,        
    defaultView: $scope.defaultViewAgenda,
    firstHour: 09,        
    themeSystem: 'standard',
    windowResize: function (view) {            
        $('#demoCalender').fullCalendar('option', 'height', get_calendar_height(117));
        $('#demoCalender').fullCalendar('rerenderEvents');
    },
    viewRender: function (view) {
        console.log(view);
    },
    events: [],
    viewDisplay: function (element) {
        console.log(element);
    }
};

FullCalendar 选项。并且事件默认为空,当服务器响应来自我的以下函数的服务器方法调用时,事件显示在日历中

$scope.getAgendaReschedules = function (agenda, startTime, endTime, isAgendaNextOrPrevious) {
    demoReschedules.getRescheduls($scope.assignedAgentId, "RESCHEDULED", startTime, endTime).then(function (response) {
        if (response.status == 200) {
            if (response.data.length > 0) {
                var groupByScheduledContacts = response.data.reduce(function (result, current) {
                    result[current.scheduled] = result[current.scheduled] || [];
                    result[current.scheduled].push(current);
                    return result;
                }, {});

                $scope.events = [{}];

                for (key in groupByScheduledContacts) {
                    var eventTime = moment(key, "DD/MM/YYYY HH:mm:ss");
                    $scope.events.push({
                        title: 'No. of rescheduled call : ' + groupByScheduledContacts[key].length,
                        start: eventTime,
                        end: eventTime,
                        description: 'This is a cool event',
                        color: $scope.getColorForReschedules(eventTime)
                    });
                }

                $scope.calendarOptions.events = $scope.events;

                if (isAgendaNextOrPrevious == false) {
                    $scope.calendarOptions.defaultView = agenda;
                }                    
            }
            else {
                $scope.calendarOptions.events.push({});
                $scope.calendarOptions.defaultView = agenda;                    
            }
        }            
    }, function err() { });

};  

并单击诸如周、月和日之类的议程按钮,我在上面调用相同的方法,当我对下一个和上一个按钮执行相同操作时,它会进入今天的视图。如果议程是一天,或者如果议程视图是周,那么它就是本周,月份也是如此。

下面是下一个和上一个按钮单击的代码。

在此$scope.tempViewAgenda是我在日、周或月议程按钮单击时设置的临时变量值。

$('#demoCalender').fullCalendar().on('click', '.fc-prev-button', function () {
    switch ($scope.tempViewAgenda) {
        case "agendaDay":
            //alert("Prev Day");                
            $scope.getPreviousAgendaReschedules('d');
            break;

        case "agendaWeek":
            $scope.getPreviousAgendaReschedules('w');
            //alert("Prev Week");
            break;

        case "month":
            $scope.getPreviousAgendaReschedules('m');
            //alert("Prev Month");
            break;
    }
});

$('#demoCalender').fullCalendar().on('click', '.fc-next-button', function () {
    switch ($scope.tempViewAgenda) {
        case "agendaDay":
            $scope.getNextAgendaReschedules('d');
            break;

        case "agendaWeek":
            $scope.getNextAgendaReschedules('w');
            //alert("Next Week");
            break;

        case "month":
            $scope.getNextAgendaReschedules('m');
            //alert("Next Month");
            break;
    }
});


//previous agenda reschedules
$scope.getPreviousAgendaReschedules = function (agendaStartCharacterToSubtract) {
    $scope.startDate = moment($scope.startDate).subtract(1, agendaStartCharacterToSubtract).format('YYYY-MM-DD HH:mm:ss');
    $scope.endDate = moment($scope.endDate).subtract(1, agendaStartCharacterToSubtract).format('YYYY-MM-DD HH:mm:ss');
    console.log("Previous : start date : " + $scope.startDate + " End date : " + $scope.endDate);
    $scope.getAgendaReschedules($scope.tempViewAgenda, $scope.startDate, $scope.endDate, true);
};

//next agenda reschedules
$scope.getNextAgendaReschedules = function (agendaStartCharacterToAdd) {
    $scope.startDate = moment($scope.startDate).add(1, agendaStartCharacterToAdd).format('YYYY-MM-DD HH:mm:ss');
    $scope.endDate = moment($scope.endDate).add(1, agendaStartCharacterToAdd).format('YYYY-MM-DD HH:mm:ss');
    console.log("Next : start date : " + $scope.startDate + " End date : " + $scope.endDate);
    $scope.getAgendaReschedules($scope.tempViewAgenda, $scope.startDate, $scope.endDate, true);
};

有没有人来解决这个问题?

4

1 回答 1

1

我得到了这个问题的答案,每当我要分配事件时,它都会重新初始化,所以我需要设置默认日期和议程视图以显示获取的事件,例如

$scope.getAgendaReschedules = function (agenda, startTime, endTime, isAgendaNextOrPrevious) {
    demoReschedules.getRescheduls($scope.assignedAgentId, "RESCHEDULED", startTime, endTime).then(function (response) {
        if (response.status == 200) {
            if (response.data.length > 0) {
                var groupByScheduledContacts = response.data.reduce(function (result, current) {
                    result[current.scheduled] = result[current.scheduled] || [];
                    result[current.scheduled].push(current);
                    return result;
                }, {});

                $scope.events = [{}];

                for (key in groupByScheduledContacts) {
                    var eventTime = moment(key, "DD/MM/YYYY HH:mm:ss");
                    $scope.events.push({
                        title: 'No. of rescheduled call : ' + groupByScheduledContacts[key].length,
                        start: eventTime,
                        end: eventTime,
                        description: 'This is a cool event',
                        color: $scope.getColorForReschedules(eventTime)
                    });
                }

                $scope.calendarOptions.events = $scope.events;

                if (isAgendaNextOrPrevious) {
                    $scope.calendarOptions.defaultDate = moment(startTime);
                    $scope.calendarOptions.defaultView = agenda;
                }
                else {
                    $scope.calendarOptions.defaultDate = moment(startTime);
                    $scope.calendarOptions.defaultView = agenda;
                }
            }
            else {
                $scope.calendarOptions.events.push({});                    
                $scope.calendarOptions.defaultDate = moment(startTime);
                $scope.calendarOptions.defaultView = agenda;
            }
        }            
    }, function err() { });

};  
于 2018-07-31T13:45:13.737 回答