From a99066f062c14778eec2fa3dd526a7d849590718 Mon Sep 17 00:00:00 2001 From: Nathan van der Werf Date: Mon, 28 Jan 2019 21:12:40 +0100 Subject: [PATCH] Add beverage property management --- controllers/Beverages.php | 10 ++++-- controllers/beverages/_properties.htm | 1 + controllers/beverages/config_relation.yaml | 13 ++++++++ models/Beverage.php | 12 +++++++ models/BeverageProperty.php | 38 ++++++++++++++++++++++ models/beverage/fields.yaml | 7 ++++ models/beverageproperty/columns.yaml | 12 +++++++ models/beverageproperty/fields.yaml | 8 +++++ updates/20190126_0001_create_tables.php | 14 ++++++++ 9 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 controllers/beverages/_properties.htm create mode 100644 controllers/beverages/config_relation.yaml create mode 100644 models/BeverageProperty.php create mode 100644 models/beverageproperty/columns.yaml create mode 100644 models/beverageproperty/fields.yaml diff --git a/controllers/Beverages.php b/controllers/Beverages.php index d2fc248..59adc04 100644 --- a/controllers/Beverages.php +++ b/controllers/Beverages.php @@ -6,6 +6,7 @@ use Backend\Behaviors\FormController; use Backend\Behaviors\ListController; +use Backend\Behaviors\RelationController; use Backend\Classes\NavigationManager; use Backend\Classes\Controller; @@ -17,8 +18,9 @@ * Beverages Back-end Controller. * * @package Adrenth\CoffeeManager\Controllers - * @mixin ListController * @mixin FormController + * @mixin ListController + * @mixin RelationController */ class Beverages extends Controller { @@ -26,6 +28,7 @@ class Beverages extends Controller public $implement = [ FormController::class, ListController::class, + RelationController::class, ]; /** @var string */ @@ -34,7 +37,10 @@ class Beverages extends Controller /** @var string */ public $listConfig = 'config_list.yaml'; - /** {@inheritdoc} */ + /** @var string */ + public $relationConfig = 'config_relation.yaml'; + + /** {@inheritdoc} */ public $requiredPermissions = ['adrenth.coffeemanager.access_beverages']; /** diff --git a/controllers/beverages/_properties.htm b/controllers/beverages/_properties.htm new file mode 100644 index 0000000..dcb6145 --- /dev/null +++ b/controllers/beverages/_properties.htm @@ -0,0 +1 @@ +relationRender('properties') ?> diff --git a/controllers/beverages/config_relation.yaml b/controllers/beverages/config_relation.yaml new file mode 100644 index 0000000..c60c336 --- /dev/null +++ b/controllers/beverages/config_relation.yaml @@ -0,0 +1,13 @@ +# =================================== +# Relation Behavior Config +# =================================== + +properties: + label: Properties + view: + list: $/adrenth/coffeemanager/models/beverageproperty/columns.yaml + toolbarButtons: create|delete + manage: + form: $/adrenth/coffeemanager/models/beverageproperty/fields.yaml + recordsPerPage: 10 + emptyMessage: backend::lang.list.no_records diff --git a/models/Beverage.php b/models/Beverage.php index 8360b27..c8ed81e 100644 --- a/models/Beverage.php +++ b/models/Beverage.php @@ -15,6 +15,7 @@ * * @package Adrenth\CoffeeManager\Models * @mixin Eloquent + * @property BeverageProperty[] properties */ class Beverage extends Model { @@ -28,6 +29,17 @@ class Beverage extends Model */ protected $guarded = []; + /** + * {@inheritdoc} + */ + public $hasMany = [ + 'properties' => [ + BeverageProperty::class, + 'key' => 'beverage_id', + 'order' => 'name', + ], + ]; + /** * {@inheritdoc} */ diff --git a/models/BeverageProperty.php b/models/BeverageProperty.php new file mode 100644 index 0000000..0606c80 --- /dev/null +++ b/models/BeverageProperty.php @@ -0,0 +1,38 @@ + [ + Beverage::class, + 'key' => 'beverage_id', + ], + ]; +} diff --git a/models/beverage/fields.yaml b/models/beverage/fields.yaml index 1a10d1f..43833c9 100644 --- a/models/beverage/fields.yaml +++ b/models/beverage/fields.yaml @@ -10,3 +10,10 @@ fields: label: Group type: relation span: left + +tabs: + fields: + properties: + type: partial + tab: Properties + context: update diff --git a/models/beverageproperty/columns.yaml b/models/beverageproperty/columns.yaml new file mode 100644 index 0000000..ad980e9 --- /dev/null +++ b/models/beverageproperty/columns.yaml @@ -0,0 +1,12 @@ +# =================================== +# List Column Definitions +# =================================== + +columns: + name: + label: Name + searchable: true + id: + label: ID + searchable: true + width: '100px' diff --git a/models/beverageproperty/fields.yaml b/models/beverageproperty/fields.yaml new file mode 100644 index 0000000..c6556ef --- /dev/null +++ b/models/beverageproperty/fields.yaml @@ -0,0 +1,8 @@ +# =================================== +# Form Field Definitions +# =================================== + +fields: + name: + label: Name + span: left diff --git a/updates/20190126_0001_create_tables.php b/updates/20190126_0001_create_tables.php index de689e4..8154456 100644 --- a/updates/20190126_0001_create_tables.php +++ b/updates/20190126_0001_create_tables.php @@ -45,6 +45,20 @@ public function up(): void ->onDelete('cascade'); }); + Schema::create('adrenth_coffeemanager_beverage_properties', function (Blueprint $table) { + $table->engine = 'InnoDB'; + $table->increments('id'); + $table->unsignedInteger('beverage_id'); + $table->string('name'); + $table->timestamps(); + + $table->foreign('beverage_id', 'beverage') + ->references('id') + ->on('adrenth_coffeemanager_beverages') + ->onUpdate('cascade') + ->onDelete('cascade'); + }); + Schema::create('adrenth_coffeemanager_groups', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->increments('id');