edofre/laravel-fullcalendar-scheduler

Laravel组件,用于fullcalendar调度模块

V1.2.3 2018-01-06 13:59 UTC

README

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock Build Status

安装

安装此扩展的首选方法是通过 Composer

要安装,请运行

$ php composer.phar require edofre/laravel-fullcalendar-scheduler "v1.2.3"

或添加

"edofre/laravel-fullcalendar-scheduler": "v1.2.3"

到你的 composer.json 文件的 require 部分。

注意

此包需要fxp/composer-asset插件才能正确安装。此插件允许您通过Composer下载Bower包。

您可以使用以下命令安装它

composer global require "fxp/composer-asset-plugin:^1.3.0”

这将添加fxp composer-asset-plugin,并且您的Composer将能够找到并下载所需的bower-asset/fullcalendar-scheduler包。您可以在以下页面找到更多信息: https://packagist.org.cn/packages/fxp/composer-asset-plugin

配置

将ServiceProvider添加到config/app.php

'providers' => [
        ...
        Edofre\FullcalendarScheduler\FullcalendarSchedulerServiceProvider::class,
    ],

并添加facade

'aliases' => [
        ...
        'Fullcalendar' => Edofre\FullcalendarScheduler\Facades\FullcalendarScheduler::class,
    ],

发布资源和配置文件

php artisan vendor:publish --tag=config
php artisan vendor:publish --tag=fullcalendar-scheduler

手动加载脚本文件

通过在config/.env文件中将include_scripts选项设置为false,脚本在生成日历时将不会包含。如果您想手动包含脚本,可以在header/footer等地方调用以下静态函数。

    \Edofre\FullcalendarScheduler\FullcalendarScheduler::renderScriptFiles();

示例

使用以下作为您的控制器操作

/**
 * @return \Illuminate\Http\Response
 */
public function index()
{
    // Generate a new fullcalendar instance
    $calendar = new \Edofre\FullcalendarScheduler\FullcalendarScheduler();

    // Set events and resources, commented lines shows how to add them via ajax
    // $calendar->setEvents(route('fullcalendar-scheduler-ajax-events'));
    $calendar->setEvents([
        ['id' => '1', 'resourceId' => 'b', 'start' => '2016-05-07T02:00:00', 'end' => '2016-05-07T07:00:00', 'title' => 'event 1'],
        ['id' => '2', 'resourceId' => 'c', 'start' => '2016-05-07T05:00:00', 'end' => '2016-05-07T22:00:00', 'title' => 'event 2'],
        ['id' => '3', 'resourceId' => 'd', 'start' => '2016-05-06', 'end' => '2016-05-08', 'title' => 'event 3'],
        ['id' => '4', 'resourceId' => 'e', 'start' => '2016-05-07T03:00:00', 'end' => '2016-05-07T08:00:00', 'title' => 'event 4'],
        ['id' => '5', 'resourceId' => 'f', 'start' => '2016-05-07T00:30:00', 'end' => '2016-05-07T02:30:00', 'title' => 'event 5'],
    ]);
    
    // $calendar->setResources(route('fullcalendar-scheduler-ajax-resources'));
    $calendar->setResources([
        ['id' => 'a', 'title' => 'Auditorium A'],
        ['id' => 'b', 'title' => 'Auditorium B', 'eventColor' => 'green'],
		['id' => 'c', 'title' => 'Auditorium C', 'eventColor' => 'orange'],
        [
            'id'       => 'd',
            'title'    => 'Auditorium D',
            'children' => [
                ['id' => 'd1', 'title' => 'Room D1'],
                ['id' => 'd2', 'title' => 'Room D2'],
            ],
        ],
        ['id' => 'e', 'title' => 'Auditorium E'],
        ['id' => 'f', 'title' => 'Auditorium F', 'eventColor' => 'red'],
        ['id' => 'g', 'title' => 'Auditorium G'],
        ['id' => 'h', 'title' => 'Auditorium H'],
        ['id' => 'i', 'title' => 'Auditorium I'],
        ['id' => 'j', 'title' => 'Auditorium J'],
        ['id' => 'k', 'title' => 'Auditorium K'],
        ['id' => 'l', 'title' => 'Auditorium L'],
        ['id' => 'm', 'title' => 'Auditorium M'],
        ['id' => 'n', 'title' => 'Auditorium N'],
        ['id' => 'o', 'title' => 'Auditorium O'],
        ['id' => 'p', 'title' => 'Auditorium P'],
        ['id' => 'q', 'title' => 'Auditorium Q'],
        ['id' => 'r', 'title' => 'Auditorium R'],
        ['id' => 's', 'title' => 'Auditorium S'],
        ['id' => 't', 'title' => 'Auditorium T'],
        ['id' => 'u', 'title' => 'Auditorium U'],
        ['id' => 'v', 'title' => 'Auditorium V'],
        ['id' => 'w', 'title' => 'Auditorium W'],
        ['id' => 'x', 'title' => 'Auditorium X'],
        ['id' => 'y', 'title' => 'Auditorium Y'],
        ['id' => 'z', 'title' => 'Auditorium Z'],
    ]);

    // Set options
    $calendar->setOptions([
        'now'               => '2016-05-07',
        'editable'          => true, // enable draggable events
        'aspectRatio'       => 1.8,
        'scrollTime'        => '00:00', // undo default 6am scrollTime
        'defaultView'       => 'timelineDay',
        'views'             => [
            'timelineThreeDays' => [
                'type'     => 'timeline',
                'duration' => [
                    'days' => 3,
                ],
            ],
        ],
        'resourceLabelText' => 'Rooms',
        'eventClick' => new \Edofre\FullcalendarScheduler\JsExpression("
                    function(event, jsEvent, view) {
                        console.log(event);
                    }
                "),
                'viewRender' => new \Edofre\FullcalendarScheduler\JsExpression("
                    function( view, element ) {
                        console.log(\"View \"+view.name+\" rendered\");
                    }
                "),
    ]);

    return view('fullcalendar-scheduler.index', [
        'calendar' => $calendar,
    ]);
}

然后添加以下到您的视图

{!! $calendar->generate() !!}

测试

通过执行以下命令运行测试

composer test