承接 asantibanez/livewire-resource-time-grid 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

asantibanez/livewire-resource-time-grid

Composer 安装命令:

composer require asantibanez/livewire-resource-time-grid

包简介

Laravel Livewire resource time grid component

README 文档

README

This package allows you to build resource/time grid to show events in a "calendar" way. You can define resources as anything that owns an event, eg. a particular day, a user, a client, etc. Events loaded with the component will be then rendered in columns according to the resource it belongs to and the starting date of the event.

Preview

preview

Installation

You can install the package via composer:

composer require asantibanez/livewire-resource-time-grid

Requirements

This package uses livewire/livewire (https://laravel-livewire.com/) under the hood.

It also uses TailwindCSS (https://tailwindcss.com/) for base styling.

Please make sure you include both of this dependencies before using this component.

Usage

In order to use this component, you must create a new Livewire component that extends from LivewireResourceTimeGrid

You can use make:livewire to create a new component. For example.

php artisan make:livewire AppointmentsGrid

In the AppointmentsGrid class, instead of extending from the base Component Livewire class, extend from LivewireResourceTimeGrid. Also, remove the render method. You'll have a class similar to this snippet.

class AppointmentsGrid extends LivewireResourceTimeGrid
{
    //
}

In this class, you must override the following methods

public function resources()
{
    // must return a Laravel collection
}

public function events()
{
    // must return a Laravel collection
}

In resources() method, return a collection holding the "resources" that own the events that are going to be listed in the grid. These "resources" must be arrays with key => value pairs and must include an id and a title. You can add any other keys to each "resource as needed"

Example

public function resources()
{
    return collect([
        ['id' => 'andres', 'title' => 'Andres'],
        ['id' => 'pamela', 'title' => 'Pamela'],
        ['id' => 'sara', 'title' => 'Sara'],
        ['id' => 'bruno', 'title' => 'Bruno'],
    ]);
}

In the events() method, return a collection holding the events that belong to each of the "resources" returned in the resources() method. Events must also be keyed arrays holding at least the following keys: id, title, starts_at, ends_at, resource_id.

Also, the following conditions are expected for each returned event:

  • For each event resource_id must match an id in the resources() returned collection.
  • starts_at must be a Carbon\Carbon instance
  • ends_at must be a Carbon\Carbon instance

Example

public function events()
{
    return collect([
        [
            'id' => 1,
            'title' => 'Breakfast',
            'starts_at' => Carbon::today()->setTime(10, 0),
            'ends_at' => Carbon::today()->setTime(12, 0),
            'resource_id' => 'andres',
        ],
        [
            'id' => 2,
            'title' => 'Lunch',
            'starts_at' => Carbon::today()->setTime(13, 0),
            'ends_at' => Carbon::today()->setTime(15, 0),
            'resource_id' => 'pamela',
        ],
    ]);
}

Now, we can include our component in any view. You must specify 3 parameters, starting-hour, ending-hour and interval. These parameters represent the times of a day the grid will render and how many divisions per hour it will display. (interval must be in minutes and less than 60)

Example

<livewire:appointments-grid
    starting-hour="8"
    ending-hour="19"
    interval="15"
/>

You should include scripts with @livewireResourceTimeGrid to enable drag and drop which is turned on by default. You must include them after @livewireScripts

@livewireScripts
@livewireResourceTimeGridScripts

This will render a grid starting from 8am til 7pm inclusive with time slots of 15 minutes.

example

By default, the component uses all the available width and height. You can constrain it to use a specific set of dimensions with a wrapper element.

Advanced Usage

UI customization

You can customize the behavior of the component with the following properties when rendering on a view:

  • resource-column-header-view which can be any blade.php view that renders information of a resource. This view will be injected with a $resource variable holding its data.
  • event-view which can be any blade.php view that will be used to render the event card. This view will be injected with a $event variable holding its data.
  • resource-column-header-height-in-rems and hour-height-in-rems can be used to customize the height of each resource view or time slot respectively. Defaults used are 4 and 8 respectively. These will be used as rem values.
  • before-grid-view and after-grid-view can be any blade.php views that can be rendered before or after the grid itself. These can be used to add extra features to your component using Livewire.

Example

<livewire:appointments-grid
    starting-hour="8"
    ending-hour="19"
    interval="15"
    resource-column-header-view="path/to/view/staring/from/views/folder"
    event-view="path/to/view/staring/from/views/folder"
    resource-column-header-height-in-rems="4"
    hour-height-in-rems="8"
    before-grid-view="path/to/view/staring/from/views/folder"
    after-grid-view="path/to/view/staring/from/views/folder"
/>

Interaction customization

You can override the following methods to add interactivity to your component

public function hourSlotClick($resourceId, $hour, $slot)
{
    // This event is triggered when a time slot is clicked.// 
    // You'll get the resource id as well as the hour and minute
    // clicked by the user
}

public function onEventClick($event)
{
    // This event will fire when an event is clicked. You will get the event that was
    // clicked by the user
}

public function onEventDropped($eventId, $resourceId, $hour, $slot)
{
    // This event will fire when an event is dragged and dropped into another time slot
    // You will get the event id, the new resource id + hour + minute where it was
    // dragged to
}

You can also override how events and resources are matched instead of using a resource_id and id respectively. To do this, you must override the following method

public function isEventForResource($event, $resource)
{
    // Must return true or false depending if the $resource is the owner of the $event
}

The base implementation for this method is

return $event['resource_id'] == $resource['id'];

You can customize it as you need. 👍

Testing

composer test

Todo

Add more tests 💪

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email santibanez.andres@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

asantibanez/livewire-resource-time-grid 适用场景与选型建议

asantibanez/livewire-resource-time-grid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.16k 次下载、GitHub Stars 达 229, 最近一次更新时间为 2020 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「asantibanez」 「livewire-resource-time-grid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 asantibanez/livewire-resource-time-grid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 asantibanez/livewire-resource-time-grid 我们能提供哪些服务?
定制开发 / 二次开发

基于 asantibanez/livewire-resource-time-grid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 231
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 229
  • Watchers: 7
  • Forks: 47
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-14