Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

[WIP] Add beverage property management #14

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions controllers/Beverages.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Backend\Behaviors\FormController;
use Backend\Behaviors\ListController;
use Backend\Behaviors\RelationController;
use Backend\Classes\NavigationManager;
use Backend\Classes\Controller;

Expand All @@ -17,15 +18,17 @@
* Beverages Back-end Controller.
*
* @package Adrenth\CoffeeManager\Controllers
* @mixin ListController
* @mixin FormController
* @mixin ListController
* @mixin RelationController
*/
class Beverages extends Controller
{
/** {@inheritdoc} */
public $implement = [
FormController::class,
ListController::class,
RelationController::class,
];

/** @var string */
Expand All @@ -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'];

/**
Expand Down
1 change: 1 addition & 0 deletions controllers/beverages/_properties.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= $this->relationRender('properties') ?>
13 changes: 13 additions & 0 deletions controllers/beverages/config_relation.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions models/Beverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @package Adrenth\CoffeeManager\Models
* @mixin Eloquent
* @property BeverageProperty[] properties
*/
class Beverage extends Model
{
Expand All @@ -28,6 +29,17 @@ class Beverage extends Model
*/
protected $guarded = [];

/**
* {@inheritdoc}
*/
public $hasMany = [
'properties' => [
BeverageProperty::class,
'key' => 'beverage_id',
'order' => 'name',
],
];

/**
* {@inheritdoc}
*/
Expand Down
38 changes: 38 additions & 0 deletions models/BeverageProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Adrenth\CoffeeManager\Models;

use Eloquent;
use October\Rain\Database\Model;

/**
* Class BeverageProperty
*
* @package Adrenth\CoffeeManager\Models
* @mixin Eloquent
* @property Beverage beverage
*/
class BeverageProperty extends Model
{
/**
* {@inheritdoc}
*/
public $table = 'adrenth_coffeemanager_beverage_properties';

/**
* {@inheritdoc}
*/
protected $guarded = [];

/**
* {@inheritdoc}
*/
public $belongsTo = [
'beverage' => [
Beverage::class,
'key' => 'beverage_id',
],
];
}
7 changes: 7 additions & 0 deletions models/beverage/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ fields:
label: Group
type: relation
span: left

tabs:
fields:
properties:
type: partial
tab: Properties
context: update
12 changes: 12 additions & 0 deletions models/beverageproperty/columns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ===================================
# List Column Definitions
# ===================================

columns:
name:
label: Name
searchable: true
id:
label: ID
searchable: true
width: '100px'
8 changes: 8 additions & 0 deletions models/beverageproperty/fields.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ===================================
# Form Field Definitions
# ===================================

fields:
name:
label: Name
span: left
14 changes: 14 additions & 0 deletions updates/20190126_0001_create_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down