Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: titleCase folders #930

Open
wants to merge 14 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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 59 additions & 0 deletions app/Admin/Controllers/MenuOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Admin\Controllers;

use Admin\Facades\AdminMenu;

class MenuOptions extends \Admin\Classes\AdminController
{
public $implement = [
'Admin\Actions\ListController',
'Admin\Actions\FormController',
'Admin\Actions\LocationAwareController',
];

public $listConfig = [
'list' => [
'model' => 'Admin\Models\Menu_options_model',
'title' => 'lang:admin::lang.menu_options.text_title',
'emptyMessage' => 'lang:admin::lang.menu_options.text_empty',
'defaultSort' => ['option_id', 'DESC'],
'configFile' => 'menu_options_model',
],
];

public $formConfig = [
'name' => 'lang:admin::lang.menu_options.text_form_name',
'model' => 'Admin\Models\Menu_options_model',
'request' => 'Admin\Requests\MenuOption',
'create' => [
'title' => 'lang:admin::lang.form.create_title',
'redirect' => 'menu_options/edit/{option_id}',
'redirectClose' => 'menu_options',
'redirectNew' => 'menu_options/create',
],
'edit' => [
'title' => 'lang:admin::lang.form.edit_title',
'redirect' => 'menu_options/edit/{option_id}',
'redirectClose' => 'menu_options',
'redirectNew' => 'menu_options/create',
],
'preview' => [
'title' => 'lang:admin::default.form.preview_title',
'redirect' => 'menu_options',
],
'delete' => [
'redirect' => 'menu_options',
],
'configFile' => 'menu_options_model',
];

protected $requiredPermissions = 'Admin.Menus';

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

AdminMenu::setContext('menus', 'restaurant');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Admin\Classes\AdminController;
use Admin\Facades\AdminMenu;
use Admin\Models\Menu_options_model;
use Igniter\Flame\Exception\ApplicationException;

class Menus extends AdminController
{
Expand Down Expand Up @@ -59,37 +57,4 @@ public function __construct()

AdminMenu::setContext('menus', 'restaurant');
}

public function edit_onChooseMenuOption($context, $recordId)
{
$menuOptionId = post('Menu._options');
if (!$menuOption = Menu_options_model::find($menuOptionId))
throw new ApplicationException(lang('admin::lang.menus.alert_menu_option_not_attached'));

$model = $this->asExtension('FormController')->formFindModelObject($recordId);

$menuItemOption = $model->menu_options()->create(['option_id' => $menuOptionId]);

$menuOption->option_values()->get()->each(function ($model) use ($menuItemOption) {
$menuItemOption->menu_option_values()->create([
'menu_option_id' => $menuItemOption->menu_option_id,
'option_value_id' => $model->option_value_id,
'new_price' => $model->price,
]);
});

$model->reload();
$this->asExtension('FormController')->initForm($model, $context);

flash()->success(sprintf(lang('admin::lang.alert_success'), 'Menu item option attached'))->now();

$formField = $this->widgets['form']->getField('menu_options');

return [
'#notification' => $this->makePartial('flash'),
'#'.$formField->getId('group') => $this->widgets['form']->renderField($formField, [
'useContainer' => FALSE,
]),
];
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
237 changes: 237 additions & 0 deletions app/Admin/FormWidgets/MenuOptionEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
<?php

namespace Admin\FormWidgets;

use Admin\Classes\BaseFormWidget;
use Admin\Classes\FormField;
use Admin\Models\Menu_options_model;
use Admin\Traits\FormModelWidget;
use Admin\Traits\ValidatesForm;
use Admin\Widgets\Form;
use Exception;
use Igniter\Flame\Exception\ApplicationException;
use Illuminate\Support\Facades\DB;

/**
* Menu Option Editor Widget
*/
class MenuOptionEditor extends BaseFormWidget
{
use FormModelWidget;
use ValidatesForm;

const INDEX_SEARCH = '___index__';

const SORT_PREFIX = '___dragged_';

//
// Object properties
//

protected $defaultAlias = 'menuoptioneditor';

protected $modelClass = Menu_options_model::class;

//
// Configurable properties
//

public $formName = 'Record';

/**
* @var array Form field configuration
*/
public $form;

public $pickerPlaceholder = 'lang:admin::lang.menu_options.help_menu_option';

public $newRecordTitle = 'New %s';

public $editRecordTitle = 'Edit %s';

public $emptyMessage = 'admin::lang.list.text_empty';

public $confirmMessage = 'admin::lang.alert_warning_confirm';

public $popupSize = 'modal-lg';

public function initialize()
{
$this->fillFromConfig([
'form',
'formName',
'pickerPlaceholder',
'emptyMessage',
'confirmMessage',
'popupSize',
]);

if ($this->formField->disabled || $this->formField->readOnly) {
$this->previewMode = TRUE;
}
}

public function render()
{
$this->prepareVars();

return $this->makePartial('menuoptioneditor/menuoptioneditor');
}

public function loadAssets()
{
$this->addJs('../../repeater/assets/vendor/sortablejs/Sortable.min.js', 'sortable-js');
$this->addJs('../../repeater/assets/vendor/sortablejs/jquery-sortable.js', 'jquery-sortable-js');
$this->addJs('../../repeater/assets/js/repeater.js', 'repeater-js');

$this->addJs('../../recordeditor/assets/js/recordeditor.modal.js', 'recordeditor-modal-js');
$this->addJs('../../recordeditor/assets/js/recordeditor.js', 'recordeditor-js');

$this->addJs('js/menuoptioneditor.js', 'menuoptioneditor-js');
}

public function getSaveValue($value)
{
return FormField::NO_SAVE_DATA;
}

/**
* Prepares the view data
*/
public function prepareVars()
{
$this->vars['formField'] = $this->formField;
$this->vars['fieldItems'] = $this->getLoadValue();

$this->vars['pickerPlaceholder'] = $this->pickerPlaceholder;

$this->vars['emptyMessage'] = $this->emptyMessage;
$this->vars['confirmMessage'] = $this->confirmMessage;
}

public function reload()
{
$this->formField->value = null;
$this->model->reloadRelations();

$this->prepareVars();

return [
'#notification' => $this->makePartial('flash'),
'#'.$this->getId('items') => $this->makePartial('menuoptioneditor/items'),
];
}

public function onAssignRecord()
{
$menuOptionId = post('optionId');
if (!$menuOption = Menu_options_model::find($menuOptionId))
throw new ApplicationException(lang('admin::lang.menu_options.alert_menu_option_not_attached'));

if ($this->model->menu_option_values()->where('option_id', $menuOptionId)->exists())
throw new ApplicationException(lang('admin::lang.menu_options.alert_menu_option_already_attached'));

$menuOption->option_values()->get()->each(function ($model) {
$this->model->menu_option_values()->create([
'option_id' => $model->option_id,
'option_value_id' => $model->option_value_id,
'priority' => $model->priority,
]);
});

flash()->success(sprintf(lang('admin::lang.alert_success'), 'Menu item option assigned'))->now();

return $this->reload();
}

public function onLoadRecord()
{
$formTitle = lang($this->editRecordTitle);

if (!strlen($recordId = post('recordId')))
throw new ApplicationException(lang('admin::lang.form.missing_id'));

$model = $this->getLoadValue()->firstWhere('option_id', $recordId);

if (!$model)
throw new Exception(sprintf(lang('admin::lang.form.not_found'), $recordId));

return $this->makePartial('recordeditor/form', [
'formRecordId' => $recordId,
'formTitle' => sprintf($formTitle, lang($this->formName)),
'formWidget' => $this->makeItemFormWidget($model, 'edit'),
]);
}

public function onSaveRecord()
{
if (!strlen($recordId = post('recordId')))
throw new ApplicationException(lang('admin::lang.form.missing_id'));

$model = $this->getLoadValue()->firstWhere('option_id', $recordId);

$form = $this->makeItemFormWidget($model, 'edit');

$saveData = $this->prepareSaveData($model, $form->getSaveData());

DB::transaction(function () use ($saveData) {
$this->model->addMenuOptionValues($saveData);
});

flash()->success(sprintf(lang('admin::lang.alert_success'), 'Item updated'))->now();

return $this->reload();
}

public function onDeleteRecord()
{
if (!strlen($recordId = post('recordId')))
throw new ApplicationException(lang('admin::lang.form.missing_id'));

$this->model->menu_option_values()
->where('option_id', $recordId)
->delete();

flash()->success(sprintf(lang('admin::lang.alert_success'), lang($this->formName).' deleted'))->now();

$this->prepareVars();

return [
'#notification' => $this->makePartial('flash'),
];
}

protected function getPickerOptions()
{
return $this->modelClass::getRecordEditorOptions();
}

protected function makeItemFormWidget($model, $context)
{
$widgetConfig = is_string($this->form) ? $this->loadConfig($this->form, ['form'], 'form') : $this->form;
$widgetConfig['model'] = $model;
$widgetConfig['alias'] = $this->alias.'FormMenuOptionEditor';
$widgetConfig['arrayName'] = $this->formField->arrayName.'[menuOptionEditorData]';
$widgetConfig['context'] = $context;
$widget = $this->makeWidget(Form::class, $widgetConfig);

$widget->bindToController();
$widget->previewMode = $this->previewMode;

return $widget;
}

protected function prepareSaveData($model, $saveData)
{
$optionValues = collect(array_get($saveData, 'menu_option_values'))
->map(function ($optionValue) {
$optionValue['new_price'] = $optionValue['price'];
unset($optionValue['price']);

return $optionValue;
})
->all();

return [$model->getKey() => $optionValues];
}
}
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.