platform icon indicating copy to clipboard operation
platform copied to clipboard

Screen

Open tabuna opened this issue 9 years ago • 7 comments

Screen is an application screen that displays data. Screens are based on predefined templates (Layouts) and all you need to do is to bind the data.

Layouts is a layout, the best explanation is what it is:

  • Table
  • Columns
  • Row
  • Graphs, etc.

2017-10-31 12-59-19

In this case, each layout can include another layout, that is, nesting. For example, the screen is divided into two columns, in the left margin for filling, on the right is a reference table and a graph. You can come up with your own examples of attachments. Fields are specified exactly as in existing "Behaviors". The screens provide built-in commands (Screen Command Bar), allowing users to perform methods of various methods.

2017-11-01 15-05-31

Example

namespace App\Core\Screens;
use App\Core\Layout\TestColums;
use Illuminate\Http\Request;
use Orchid\Platform\Screen\Screen;
class Demo extends Screen
{
    /**
     * Display header name
     *
     * @var string
     */
    public $name = 'Demo Screen';
    /**
     * Display header description
     *
     * @var string
     */
    public $description = 'Testing Screen Capabilities';
    /**
     * Query data
     *
     * @return array
     */
    public function query(): array
    {
        return [
            'content' => [
                'en' => [
                    'name' => 'Test',
                ],
            ]
        ];
    }
    /**
     * Button commands
     *
     * @return array
     */
    public function commandBar() : array
    {
        return [
            'create' => [
                'displayName' => 'New Records',
                'description' => 'Description event to click',
                'method'      => 'create',
            ],
            'create2' => [
                'displayName' => 'Print',
                'description' => 'Description event to click',
                'method'      => 'create',
            ],
            'create3' => [
                'displayName' => 'Function 1',
                'description' => 'Description event to click',
                'method'      => 'create',
            ],
            'create4' => [
                'displayName' => 'Function 2',
                'description' => 'Description event to click',
                'method'      => 'create',
            ],
            'create5' => [
                'displayName' => 'Function 3',
                'description' => 'Description event to click',
                'method'      => 'create',
            ],
        ];
    }
    /**
     * Views
     *
     * @return array
     */
    public function layout() : array
    {
        return [
            TestColums::class,
        ];
    }
    /**
     * @param Request $request
     *
     * @return null
     */
    public function create(Request $request)
    {
        return response(200);
    }
}

TODO:

  • [x] Colums
  • [x] Rows (Fields)
  • [x] Tabs
  • [x] Table
  • [x] Graphs

tabuna avatar Nov 01 '17 21:11 tabuna

Need add

  • [ ] You need to think about how to filter data in tables

Need fix it

  • [ ] Tables must accept an array, not just a paginator

You need to think about adding a new layout in the form of a modal window, the problem is, where to get it from?

tabuna avatar Dec 06 '17 08:12 tabuna

Added Link class for method commandBar

    /**
     * Button commands
     *
     * @return array
     */
    public function commandBar() : array
    {
        return [
            Link::name('Новая ссылка')->link('https://google.com/'),
            Link::name('Новая функция 1')->method('create'),
            Link::name('Новая функция 2')->method('create'),
            Link::name('Новая функция 3')->method('create'),
        ];
    }

tabuna avatar Dec 06 '17 12:12 tabuna

Сделал волевое решение по поводу записи Layouts которые могут быть родительскими.

Было:

    /**
     * Views
     *
     * @return array
     */
    public function layout() : array
    {
        return [
            TestColums::class,
        ];
    }

И этот TestColums содержал лишь 1 метод, который мог включать в себя ещё и ещё таких. Получалось, что в каталоге очень много файлов содержащих мало данных. Мне конечно нравится кратность, но создав с десяток таких, явно надоедает.

Стало:

    /**
     * Views
     *
     * @return array
     */
    public function layout() : array
    {
        return [
            Layouts::columns([
                'Колонка 1'  => [
                    TestRows::class,
                ],
                'Колонка 2' => [
                    TestRows2::class,
                ],
                'Колонка 3' => [
                    Layouts::tabs([
                        'tab-1' => [
                            TestRows::class,
                        ],
                        'tab-2' => [
                            TestRows::class,
                        ],
                    ]),
                ]
            ]),
        ];
    }

Конечно такая запись намного сложнее читается и нагромождена на мой взгляд, но в конечном счёте думаю так будет лучше.

tabuna avatar Dec 06 '17 22:12 tabuna

Сейчас класс Screen должен выглядеть так:


class Demo extends Screen
{
    /**
     * Display header name
     *
     * @var string
     */
    public $name = 'Demo Screen';

    /**
     * Display header description
     *
     * @var string
     */
    public $description = 'Testing Screen Capabilities';

    /**
     * Query data
     *
     * @return array
     */
    public function query() : array
    {
        return [
            'user'  => User::find(1),
            'users' => User::paginate(),
        ];
    }

    /**
     * Button commands
     *
     * @return array
     */
    public function commandBar() : array
    {
        return [
            Link::name('Сохранить')->method('save'),
            Link::name('Вывести на печать')->method('create'),
            Link::name('Новая функция 1')->method('create'),
            Link::name('Новая функция 2')->method('create'),
            Link::name('Новая функция 3')->method('create'),
        ];
    }

    /**
     * Views
     *
     * @return array
     */
    public function layout() : array
    {
        return [
            Layouts::columns([
                'Колонка 1'  => [
                    TestRows::class,
                ],
                'Колонка 2' => [
                    TestRows2::class,
                ],
                'Колонка 3' => [
                    Layouts::tabs([
                        'tab-1' => [
                            TestRows::class,
                        ],
                        'tab-2' => [
                            TestRows::class,
                        ],
                    ]),
                ]
            ]),
        ];
    }

    /**
     * @param Request $request
     *
     * @return null
     */
    public function create(Request $request)
    {
        return response(200);
    }

    /**
     * @param Request $request
     */
    public function save(Request $request)
    {
        return response(200);
    }

}

tabuna avatar Dec 06 '17 22:12 tabuna

Хочу протестировать.

  1. в пакете создал папку src/Http/Screens
  2. в неё добавил файл Demo.php с вышеуказанным кодом, плюс вверху namespace and use как в документации
  3. в файле route.php добавил строку
Route::screen('dashboard/news', 'Demo','dashboard.screens.demo.list');

перехожу по адресу dashboard/news - ошибка "Class Demo does not exist" что делать?

PSalador avatar Dec 17 '17 16:12 PSalador

Сейчас немного иначе идёт, проблема в том, что файл route.php определяет наймспейс как контроллер, то есть app/Http/Controllers + твой класс.

Вручную можно не создавать, есть же команды artisan:

php artisan make:screen Test

Посмотри https://github.com/tabuna/Vision-Clinic

tabuna avatar Dec 17 '17 16:12 tabuna

Получилось.

Вручную можно не создавать, есть же команды artisan:

Я в пакете делаю там artisan не создает.

  1. в файле route.php добавил строку
Route::middleware(config('uslugi.middleware.private'))
            ->namespace('Salador\Uslugi\Http\Screens\Demo')
            ->prefix('dashboard/screen')
            ->group(function($route){
				$route->screen('demo', 'Demo','dashboard.screens.demo.list');
			});
  1. Создал файл src\Http\Layouts\Demo\TestRows.php с содержимым
<?php
namespace Salador\Uslugi\Http\Layouts\Demo;
use Orchid\Platform\Layouts\Rows;
class TestRows extends Rows
{
    public function fields() : array
    {
        return [
            'first_name' => [
                'tag'      => 'input',
                'type'     => 'text',
                'name'     => 'user.name',
                'max'      => 255,
                'required' => true,
                'title'    => 'First name',
            ],
        ];
    }
}

работает по адресу dashboard/screen/demo

PSalador avatar Dec 17 '17 18:12 PSalador