Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions modules/backend/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ServiceProvider extends ModuleServiceProvider
*/
public function register()
{
$this->registerConsole();
$this->registerMailer();
$this->registerAssetBundles();

Expand All @@ -45,6 +46,16 @@ public function boot()
parent::boot('backend');
}

/**
* Register console commands
*/
protected function registerConsole()
{
$this->registerConsoleCommand('create.controller', \Backend\Console\CreateController::class);
$this->registerConsoleCommand('create.formwidget', \Backend\Console\CreateFormWidget::class);
$this->registerConsoleCommand('create.reportwidget', \Backend\Console\CreateReportWidget::class);
}

/**
* Register mail templates
*/
Expand Down
87 changes: 87 additions & 0 deletions modules/backend/console/CreateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php namespace Backend\Console;

use Winter\Storm\Scaffold\GeneratorCommand;
use Winter\Storm\Support\Str;

class CreateController extends GeneratorCommand
{
/**
* The default command name for lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'create:controller';

/**
* The name and signature of this command.
*
* @var string
*/
protected $signature = 'create:controller
{plugin : The name of the plugin. <info>(eg: Winter.Blog)</info>}
{controller : The name of the controller to generate. <info>(eg: Posts)</info>}
{--force : Overwrite existing files with generated files.}
{--model= : Defines the model name to use. If not provided, the singular name of the controller is used.}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates a new controller.';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Controller';

/**
* A mapping of stub to generated file.
*
* @var array
*/
protected $stubs = [
'scaffold/controller/_list_toolbar.stub' => 'controllers/{{lower_name}}/_list_toolbar.htm',
'scaffold/controller/config_form.stub' => 'controllers/{{lower_name}}/config_form.yaml',
'scaffold/controller/config_list.stub' => 'controllers/{{lower_name}}/config_list.yaml',
'scaffold/controller/create.stub' => 'controllers/{{lower_name}}/create.htm',
'scaffold/controller/index.stub' => 'controllers/{{lower_name}}/index.htm',
'scaffold/controller/preview.stub' => 'controllers/{{lower_name}}/preview.htm',
'scaffold/controller/update.stub' => 'controllers/{{lower_name}}/update.htm',
'scaffold/controller/controller.stub' => 'controllers/{{studly_name}}.php',
];

/**
* Prepare variables for stubs.
*
* return @array
*/
protected function prepareVars()
{
$pluginCode = $this->argument('plugin');

$parts = explode('.', $pluginCode);
$plugin = array_pop($parts);
$author = array_pop($parts);

$controller = $this->argument('controller');

/*
* Determine the model name to use,
* either supplied or singular from the controller name.
*/
$model = $this->option('model');
if (!$model) {
$model = Str::singular($controller);
}

return [
'name' => $controller,
'model' => $model,
'author' => $author,
'plugin' => $plugin
];
}
}
71 changes: 71 additions & 0 deletions modules/backend/console/CreateFormWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php namespace Backend\Console;

use Winter\Storm\Scaffold\GeneratorCommand;

class CreateFormWidget extends GeneratorCommand
{
/**
* The default command name for lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'create:formwidget';

/**
* The name and signature of this command.
*
* @var string
*/
protected $signature = 'create:formwidget
{plugin : The name of the plugin. <info>(eg: Winter.Blog)</info>}
{widget : The name of the form widget to generate. <info>(eg: PostList)</info>}
{--force : Overwrite existing files with generated files.}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates a new form widget.';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'FormWidget';

/**
* A mapping of stub to generated file.
*
* @var array
*/
protected $stubs = [
'scaffold/formwidget/formwidget.stub' => 'formwidgets/{{studly_name}}.php',
'scaffold/formwidget/partial.stub' => 'formwidgets/{{lower_name}}/partials/_{{lower_name}}.htm',
'scaffold/formwidget/stylesheet.stub' => 'formwidgets/{{lower_name}}/assets/css/{{lower_name}}.css',
'scaffold/formwidget/javascript.stub' => 'formwidgets/{{lower_name}}/assets/js/{{lower_name}}.js',
];

/**
* Prepare variables for stubs.
*
* return @array
*/
protected function prepareVars()
{
$pluginCode = $this->argument('plugin');

$parts = explode('.', $pluginCode);
$plugin = array_pop($parts);
$author = array_pop($parts);

$widget = $this->argument('widget');

return [
'name' => $widget,
'author' => $author,
'plugin' => $plugin
];
}
}
69 changes: 69 additions & 0 deletions modules/backend/console/CreateReportWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php namespace Backend\Console;

use Winter\Storm\Scaffold\GeneratorCommand;

class CreateReportWidget extends GeneratorCommand
{
/**
* The default command name for lazy loading.
*
* @var string|null
*/
protected static $defaultName = 'create:reportwidget';

/**
* The name and signature of this command.
*
* @var string
*/
protected $signature = 'create:reportwidget
{plugin : The name of the plugin. <info>(eg: Winter.Blog)</info>}
{widget : The name of the report widget to generate. <info>(eg: PostViews)</info>}
{--force : Overwrite existing files with generated files.}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates a new report widget.';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'ReportWidget';

/**
* A mapping of stub to generated file.
*
* @var array
*/
protected $stubs = [
'scaffold/reportwidget/reportwidget.stub' => 'reportwidgets/{{studly_name}}.php',
'scaffold/reportwidget/widget.stub' => 'reportwidgets/{{lower_name}}/partials/_{{lower_name}}.htm',
];

/**
* Prepare variables for stubs.
*
* return @array
*/
protected function prepareVars()
{
$pluginCode = $this->argument('plugin');

$parts = explode('.', $pluginCode);
$plugin = array_pop($parts);
$author = array_pop($parts);

$widget = $this->argument('widget');

return [
'name' => $widget,
'author' => $author,
'plugin' => $plugin
];
}
}
21 changes: 21 additions & 0 deletions modules/backend/console/scaffold/controller/_list_toolbar.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div data-control="toolbar">
<a
href="<?= Backend::url('{{lower_author}}/{{lower_plugin}}/{{lower_name}}/create') ?>"
class="btn btn-primary wn-icon-plus">
New {{title_singular_name}}
</a>

<button
class="btn btn-danger wn-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', { checked: $('.control-list').listWidget('getChecked') })"
data-request="onDelete"
data-request-confirm="Are you sure you want to delete the selected {{title_plural_name}}?"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', 'disabled')"
data-stripe-load-indicator>
Delete selected
</button>
</div>
31 changes: 31 additions & 0 deletions modules/backend/console/scaffold/controller/config_form.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ===================================
# Form Behavior Config
# ===================================

# Record name
name: {{title_singular_name}}

# Model Form Field configuration
form: $/{{lower_author}}/{{lower_plugin}}/models/{{lower_model}}/fields.yaml

# Model Class name
modelClass: {{studly_author}}\{{studly_plugin}}\Models\{{studly_model}}

# Default redirect location
defaultRedirect: {{lower_author}}/{{lower_plugin}}/{{lower_name}}

# Create page
create:
title: backend::lang.form.create_title
redirect: {{lower_author}}/{{lower_plugin}}/{{lower_name}}/update/:id
redirectClose: {{lower_author}}/{{lower_plugin}}/{{lower_name}}

# Update page
update:
title: backend::lang.form.update_title
redirect: {{lower_author}}/{{lower_plugin}}/{{lower_name}}
redirectClose: {{lower_author}}/{{lower_plugin}}/{{lower_name}}

# Preview page
preview:
title: backend::lang.form.preview_title
50 changes: 50 additions & 0 deletions modules/backend/console/scaffold/controller/config_list.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ===================================
# List Behavior Config
# ===================================

# Model List Column configuration
list: $/{{lower_author}}/{{lower_plugin}}/models/{{lower_model}}/columns.yaml

# Model Class name
modelClass: {{studly_author}}\{{studly_plugin}}\Models\{{studly_model}}

# List Title
title: Manage {{title_plural_name}}

# Link URL for each record
recordUrl: {{lower_author}}/{{lower_plugin}}/{{lower_name}}/update/:id

# Message to display if the list is empty
noRecordsMessage: backend::lang.list.no_records

# Records to display per page
recordsPerPage: 20

# Options to provide the user when selecting how many records to display per page
perPageOptions: [20, 40, 80, 100, 120]

# Display page numbers with pagination, disable to improve performance
showPageNumbers: true

# Displays the list column set up button
showSetup: true

# Displays the sorting link on each column
showSorting: true

# Default sorting column
# defaultSort:
# column: created_at
# direction: desc

# Display checkboxes next to each record
showCheckboxes: true

# Toolbar widget configuration
toolbar:
# Partial for toolbar buttons
buttons: list_toolbar

# Search widget configuration
search:
prompt: backend::lang.list.search_prompt
25 changes: 25 additions & 0 deletions modules/backend/console/scaffold/controller/controller.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php namespace {{studly_author}}\{{studly_plugin}}\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

/**
* {{title_name}} Back-end Controller
*/
class {{studly_name}} extends Controller
{
/**
* @var array Behaviors that are implemented by this controller.
*/
public $implement = [
\Backend\Behaviors\FormController::class,
\Backend\Behaviors\ListController::class,
];

public function __construct()
{
parent::__construct();

BackendMenu::setContext('{{studly_author}}.{{studly_plugin}}', '{{lower_plugin}}', '{{lower_name}}');
}
}
Loading