327 lines
13 KiB
PHP
327 lines
13 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Requests\DemoCatalogsRequest;
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController;
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
|
|
|
|
use Backpack\CRUD\app\Library\Widget;
|
|
|
|
/**
|
|
* Class DemoCatalogsCrudController
|
|
* @package App\Http\Controllers\Admin
|
|
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
|
|
*/
|
|
class DemoCatalogsCrudController extends CrudController
|
|
{
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
|
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\InlineCreateOperation;
|
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
|
|
//use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ReorderOperation;
|
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation;
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\BulkCloneOperation;
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
|
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
|
|
|
|
|
|
|
|
/**
|
|
* Configure the CrudPanel object. Apply settings to all operations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function setup()
|
|
{
|
|
CRUD::setModel(\App\Models\DemoCatalogs::class);
|
|
CRUD::setRoute(config('backpack.base.route_prefix') . '/demo-catalogs');
|
|
CRUD::setEntityNameStrings('demo catalogs', 'demo catalogs');
|
|
|
|
CRUD::enableDetailsRow();
|
|
|
|
$this->crud->set('clone.redirect_after_clone', true);
|
|
}
|
|
|
|
protected function setupReorderOperation()
|
|
{
|
|
CRUD::set('reorder.label', 'name');
|
|
CRUD::set('reorder.max_level', 1);
|
|
}
|
|
|
|
protected function showDetailsRow($id)
|
|
{
|
|
|
|
$this->data['entry'] = $this->crud->getEntry($id);
|
|
$this->data['crud'] = $this->crud;
|
|
Widget::add()->to('crud-details-row')->type('progress')->value(135)->description('Progress')->progress(50);
|
|
$userCount = 300;
|
|
Widget::add()->to('crud-details-row')->type('div')->class('row')->content([
|
|
//widget made using fluent syntax
|
|
Widget::make()
|
|
->type('progress')
|
|
->class('card border-0 text-white bg-primary')
|
|
->progressClass('progress-bar')
|
|
->value($userCount)
|
|
->description('Registered users.')
|
|
->progress(100 * (int)$userCount / 1000)
|
|
->hint(1000 - $userCount . ' more until next milestone.'),
|
|
|
|
//widget made using the array definition
|
|
Widget::make(
|
|
[
|
|
'type' => 'card',
|
|
'class' => 'card bg-dark text-white',
|
|
'wrapper' => ['class' => 'col-sm-3 col-md-3'],
|
|
'content' => [
|
|
'header' => 'Example Widget',
|
|
'body' => 'Widget placed at "before_content" secion in same row',
|
|
]
|
|
]
|
|
),
|
|
]);
|
|
|
|
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
|
|
return view('crud::details_row', $this->data);
|
|
}
|
|
|
|
/**
|
|
* Define what happens when the List operation is loaded.
|
|
*
|
|
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
|
|
* @return void
|
|
*/
|
|
protected function setupListOperation()
|
|
{
|
|
if (! $this->crud->getRequest()->has('order')){
|
|
$this->crud->orderBy('lft', 'asc')->orderBy('id', 'desc');
|
|
}
|
|
|
|
|
|
CRUD::addColumn('#');
|
|
CRUD::column('name')->label('名稱')->type('textarea_nl2br')->escaped(false)->searchLogic('text');
|
|
$this->crud->addColumns([
|
|
[
|
|
'value' => '111,222,333',
|
|
'label' => 'ttt',
|
|
'type' => 'text_split',
|
|
'wrapper' => [
|
|
'href' => function ($crud, $column, $entry, $related_key, $current_value) {
|
|
$query = "";
|
|
$query .= 'date_range='.$current_value;
|
|
return backpack_url('logs/view-by-cloud-id-days-r?'.$query);
|
|
},
|
|
],
|
|
],
|
|
// [
|
|
// 'name' => 'text9',
|
|
// 'type' => 'image',
|
|
// ],
|
|
// [
|
|
// 'name' => 'text9',
|
|
// 'type' => 'table',
|
|
// 'entity_singular' => '梯度價格', // used on the "Add X" button
|
|
// 'columns' => [
|
|
// 'name' => 'Name',
|
|
// 'desc' => 'Description',
|
|
// 'price' => 'Price'
|
|
// ],
|
|
// ],
|
|
[
|
|
'name' => 'text9', // The db column name
|
|
'label' => 'Video1', // Table column heading
|
|
'type' => 'video',
|
|
],
|
|
[
|
|
'name' => 'text10', // The db column name
|
|
'label' => 'Video2', // Table column heading
|
|
'type' => 'video',
|
|
],
|
|
]);
|
|
|
|
|
|
|
|
//CRUD::setFromDb(); // set columns from db columns.
|
|
|
|
/**
|
|
* Columns can be defined using the fluent syntax:
|
|
* - CRUD::column('price')->type('number');
|
|
*/
|
|
}
|
|
|
|
protected function fetchNewsCatalog()
|
|
{
|
|
return $this->fetch(\App\Models\NewsCatalog::class);
|
|
}
|
|
|
|
/**
|
|
* Define what happens when the Create operation is loaded.
|
|
*
|
|
* @see https://backpackforlaravel.com/docs/crud-operation-create
|
|
* @return void
|
|
*/
|
|
protected function setupCreateOperation()
|
|
{
|
|
CRUD::setValidation(DemoCatalogsRequest::class);
|
|
//CRUD::setFromDb(); // set fields from db columns.
|
|
|
|
/**
|
|
* Fields can be defined using the fluent syntax:
|
|
* - CRUD::field('price')->type('number');
|
|
*/
|
|
//CRUD::field('name')->label('名稱(必填)')->type('textarea');
|
|
|
|
CRUD::addFields([
|
|
[
|
|
'name' => 'name',
|
|
'lable' => 'Name',
|
|
],
|
|
[
|
|
'name' => 'photos',
|
|
'label' => '圖片',
|
|
'type' => 'upload_img_multiple',
|
|
'upload' => true,
|
|
'disk' => 'public',
|
|
'hint' => '',
|
|
'qty' => 3, // 0=no limit, >0=limit
|
|
'showSingleChoise' => '0', // 0=hidden, 1=show(default)
|
|
'showComment' => '0', // 0=hidden, 1=show(default)
|
|
],
|
|
[
|
|
'name' => 'text1',
|
|
'lable' => 'Text1',
|
|
'type' => 'select2_from_array',
|
|
'options' => ['one' => 'One', 'two' => 'Two'],
|
|
],
|
|
[
|
|
'name' => 'text2',
|
|
'lable' => 'Text2',
|
|
'type' => 'browse',
|
|
],
|
|
[
|
|
'name' => 'text3',
|
|
'lable' => 'Text3',
|
|
'type' => 'browse_multiple',
|
|
'sortable' => true,
|
|
// app/models/modelxxx.php add "protected $casts = ['text3' => 'array'];"
|
|
],
|
|
[ // date_range
|
|
'name' => 'text4,text5', // db columns for start_date & end_date
|
|
'label' => 'Text4,5',
|
|
'type' => 'date_range',
|
|
// app/models/modelxxx.php add "protected $casts = ['text4' => 'datetime', 'text5' => 'datetime'];"
|
|
|
|
// OPTIONALS
|
|
// default values for start_date & end_date
|
|
//'default' => ['2019-03-28 01:01', '2019-04-05 02:00'],
|
|
// options sent to daterangepicker.js
|
|
'date_range_options' => [
|
|
'drops' => 'down', // can be one of [down/up/auto]
|
|
'timePicker' => true,
|
|
'locale' => ['format' => 'YYYY/MM/DD HH:mm']
|
|
],
|
|
],
|
|
[
|
|
'name' => 'text6',
|
|
'lable' => 'Text6',
|
|
'type' => 'date_picker',
|
|
// app/models/modelxxx.php add "protected $casts = ['text6' => 'datetime'];"
|
|
'date_picker_options' => [
|
|
'todayBtn' => 'linked',
|
|
'format' => 'yyyy-mm-dd',
|
|
'language' => str_replace('_', '-', app()->getLocale()),
|
|
],
|
|
],
|
|
[
|
|
'name' => 'text7',
|
|
'lable' => 'Text7',
|
|
'type' => 'datetime_picker',
|
|
// app/models/modelxxx.php add "protected $casts = ['text7' => 'datetime'];"
|
|
'datetime_picker_options' => [
|
|
'format' => 'YYYY/MM/DD HH:mm',
|
|
//'language' => 'en',
|
|
'tooltips' => [ //use this to translate the tooltips in the field
|
|
'today' => 'Hoje',
|
|
'selectDate' => 'Selecione a data',
|
|
// available tooltips: today, clear, close, selectMonth, prevMonth, nextMonth, selectYear, prevYear, nextYear, selectDecade, prevDecade, nextDecade, prevCentury, nextCentury, pickHour, incrementHour, decrementHour, pickMinute, incrementMinute, decrementMinute, pickSecond, incrementSecond, decrementSecond, togglePeriod, selectTime, selectDate
|
|
]
|
|
],
|
|
'allows_null' => true,
|
|
// 'default' => '2017-05-12 11:59:59',
|
|
],
|
|
[
|
|
'name' => 'text8',
|
|
'lable' => 'Text8',
|
|
'type' => 'tinymce',
|
|
// optional overwrite of the configuration array
|
|
'options' => [
|
|
//'selector' => 'textarea.tinymce',
|
|
//'skin' => 'dick-light',
|
|
'plugins' => 'lists advlist image link media anchor table hr imagetools importcss insertdatetime paste searchreplace textcolor textpattern help',
|
|
'menubar' => 'edit insert view format help',
|
|
'toolbar' => 'undo redo bold italic alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image media link',
|
|
'language' => str_replace('-', '_', app()->getLocale()),
|
|
'height' => '500px',
|
|
],
|
|
],
|
|
// [
|
|
// 'name' => 'text9',
|
|
// 'lable' => 'Text9',
|
|
// 'type' => 'base64_image',
|
|
// 'filename' => null, // set to null if not needed
|
|
// 'aspect_ratio' => 1, // set to 0 to allow any aspect ratio
|
|
// 'crop' => true, // set to true to allow cropping, false to disable
|
|
// 'src' => NULL, // null to read straight from DB, otherwise set to model accessor function
|
|
// ],
|
|
// [
|
|
// 'name' => 'text9',
|
|
// 'label' => 'Text9',
|
|
// 'type' => 'table',
|
|
// 'entity_singular' => '梯度價格', // used on the "Add X" button
|
|
// 'columns' => [
|
|
// 'name' => 'Name',
|
|
// 'desc' => 'Description',
|
|
// 'price' => 'Price'
|
|
// ],
|
|
// 'max' => 5, // maximum rows allowed in the table
|
|
// 'min' => 0, // minimum rows allowed in the table
|
|
// ],
|
|
[ // URL
|
|
'name' => 'text9',
|
|
'label' => 'text9 Link to video file on YouTube or Vimeo',
|
|
'type' => 'video',
|
|
'youtube_api_key' => 'AIzaSyDXyjzIho2thtYafQ_ofKOPEkj63Dprj58',
|
|
],
|
|
[ // URL
|
|
'name' => 'text10',
|
|
'label' => 'text10 Link to video file on YouTube or Vimeo',
|
|
'type' => 'video',
|
|
'youtube_api_key' => 'AIzaSyDXyjzIho2thtYafQ_ofKOPEkj63Dprj58',
|
|
],
|
|
[
|
|
'type' => "relationship",
|
|
'name' => 'NewsCatalog', // the method on your model that defines the relationship
|
|
'ajax' => true,
|
|
'inline_create' => true, // assumes the URL will be "/admin/category/inline/create"
|
|
]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Define what happens when the Update operation is loaded.
|
|
*
|
|
* @see https://backpackforlaravel.com/docs/crud-operation-update
|
|
* @return void
|
|
*/
|
|
protected function setupUpdateOperation()
|
|
{
|
|
$this->setupCreateOperation();
|
|
}
|
|
}
|