Skip to content

Commit

Permalink
Merge branch '3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Jun 8, 2022
2 parents 55351d3 + bc9ceb1 commit 3b95b83
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 73 deletions.
4 changes: 4 additions & 0 deletions app/admin/assets/src/scss/components/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
margin-top: 0;
}
}
.modal .form-fields > * {
padding-left: 0;
padding-right: 0;
}
.form-fields {
--bs-gutter-x: 1.45rem;
--bs-gutter-y: 0;
Expand Down
4 changes: 2 additions & 2 deletions app/admin/language/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@
'label_gallery_image_thumbnail' => 'Thumbnail',
'label_gallery_image_name' => 'Filename',
'label_gallery_image_alt' => 'Alt Text',
'label_delivery_condition' => 'Delivery Condition',
'label_delivery_distance' => 'Distance Based Delivery Condition',
'label_delivery_condition' => 'Delivery Charge Condition',
'label_delivery_distance' => 'Distance Based Delivery Charge Condition',

'error_no_zero_total' => 'The %s can not be a value zero on conditions other than \'on all orders\'.',
'alert_delivery_area' => 'Add at least one delivery area to allow your customers find this location.',
Expand Down
53 changes: 37 additions & 16 deletions app/admin/models/LocationOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ class LocationOption extends Model
*/
public $locationContext;

protected $itemsToSaveCache = [];

protected static $cache = [];

public static function onLocation($location = null)
{
$self = new static;
$self->locationContext = $location ?: $self->resolveLocation();
$instance = new static;
$instance->locationContext = $location ?: $instance->resolveLocation();

return $self;
return $instance;
}

public static function findRecord($key, $location = null)
Expand Down Expand Up @@ -76,26 +78,22 @@ public function getAll()

public function setAll($items)
{
if (!$location = $this->locationContext)
if (!$this->locationContext)
return false;

if (!is_array($items))
$items = [];

$records = $this->getAll();
$this->itemsToSaveCache = array_merge($this->itemsToSaveCache, $items);

collect($items)
->filter(function ($value, $key) use ($records) {
return $value != array_get($records, $key);
})
->map(function ($value, $key) use ($location) {
self::updateOrCreate([
'location_id' => $location->location_id,
'item' => $key,
], ['value' => $value]);
if ($this->locationContext->exists) {
$this->updateOptions();
}
elseif ($this->itemsToSaveCache) {
$this->locationContext->bindEventOnce('model.afterSave', function () {
$this->updateOptions();
});

static::$cache[$location->location_id] = $items;
}

return true;
}
Expand Down Expand Up @@ -173,4 +171,27 @@ protected function wrapFieldName($name)

return 'options'.$wrappedName;
}

protected function updateOptions()
{
if (!$location = $this->locationContext)
return false;

$records = $this->getAll();

collect($this->itemsToSaveCache)
->filter(function ($value, $key) use ($records) {
return $value != array_get($records, $key);
})
->each(function ($value, $key) use ($location) {
self::updateOrCreate([
'location_id' => $location->location_id,
'item' => $key,
], ['value' => $value]);
});

static::$cache[$location->location_id] = null;

return true;
}
}
2 changes: 1 addition & 1 deletion app/admin/models/Menu_option_values_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getStockableName()

public function getStockableLocations()
{
return $this->option->locations;
return optional($this->option)->locations;
}

//
Expand Down
2 changes: 2 additions & 0 deletions app/admin/models/Menu_options_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Menu_options_model extends Model
],
],
'morphToMany' => [
'allergens' => ['Admin\Models\Allergens_model', 'name' => 'allergenable'],
'locations' => ['Admin\Models\Locations_model', 'name' => 'locationable'],
],
];
Expand Down Expand Up @@ -95,6 +96,7 @@ protected function afterSave()

protected function beforeDelete()
{
$this->allergens()->detach();
$this->locations()->detach();
}

Expand Down
95 changes: 48 additions & 47 deletions app/admin/models/config/location_areas_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,54 @@
'data-toggle' => 'area-default',
],
],
'type' => [
'label' => 'lang:admin::lang.locations.label_area_type',
'type' => 'radiotoggle',
'default' => 'address',
'options' => [
'address' => 'lang:admin::lang.locations.text_custom',
'polygon' => 'lang:admin::lang.locations.text_shape',
'circle' => 'lang:admin::lang.locations.text_circle',
],
'attributes' => [
'data-toggle' => 'map-shape',
],
],
'boundaries[components]' => [
'label' => 'lang:admin::lang.locations.label_address_component',
'type' => 'repeater',
'sortable' => true,
'commentAbove' => 'lang:admin::lang.locations.help_delivery_components',
'trigger' => [
'action' => 'show',
'field' => 'type',
'condition' => 'value[address]',
],
'form' => [
'fields' => [
'priority' => [
'type' => 'hidden',
],
'type' => [
'label' => 'lang:admin::lang.locations.label_address_component_type',
'type' => 'select',
'default' => 'region',
'options' => [
'street' => 'lang:admin::lang.locations.text_address_component_street',
'sub_locality' => 'lang:admin::lang.locations.text_address_component_town',
'locality' => 'lang:admin::lang.locations.text_address_component_city',
'admin_level_2' => 'lang:admin::lang.locations.text_address_component_region',
'admin_level_1' => 'lang:admin::lang.locations.text_address_component_state',
'postal_code' => 'lang:admin::lang.locations.text_address_component_postal_code',
],
],
'value' => [
'label' => 'lang:admin::lang.locations.label_address_component_value',
'type' => 'text',
],
],
],
],
'conditions' => [
'label' => 'lang:admin::lang.locations.label_delivery_condition',
'type' => 'repeater',
Expand Down Expand Up @@ -87,53 +135,6 @@
],
],
],
'type' => [
'label' => 'lang:admin::lang.locations.label_area_type',
'type' => 'radiotoggle',
'default' => 'address',
'options' => [
'address' => 'lang:admin::lang.locations.text_custom',
'polygon' => 'lang:admin::lang.locations.text_shape',
'circle' => 'lang:admin::lang.locations.text_circle',
],
'attributes' => [
'data-toggle' => 'map-shape',
],
],
'boundaries[components]' => [
'type' => 'repeater',
'sortable' => true,
'commentAbove' => 'lang:admin::lang.locations.help_delivery_components',
'trigger' => [
'action' => 'show',
'field' => 'type',
'condition' => 'value[address]',
],
'form' => [
'fields' => [
'priority' => [
'type' => 'hidden',
],
'type' => [
'label' => 'lang:admin::lang.locations.label_address_component_type',
'type' => 'select',
'default' => 'region',
'options' => [
'street' => 'lang:admin::lang.locations.text_address_component_street',
'sub_locality' => 'lang:admin::lang.locations.text_address_component_town',
'locality' => 'lang:admin::lang.locations.text_address_component_city',
'admin_level_2' => 'lang:admin::lang.locations.text_address_component_region',
'admin_level_1' => 'lang:admin::lang.locations.text_address_component_state',
'postal_code' => 'lang:admin::lang.locations.text_address_component_postal_code',
],
],
'value' => [
'label' => 'lang:admin::lang.locations.label_address_component_value',
'type' => 'text',
],
],
],
],
'_mapview' => [
'type' => 'mapview',
'zoom' => 14,
Expand Down
1 change: 1 addition & 0 deletions app/admin/models/config/menu_options_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'values' => [
'label' => 'lang:admin::lang.menu_options.text_tab_values',
'type' => 'repeater',
'valueFrom' => 'option_values',
'form' => 'menu_option_values_model',
'sortable' => true,
],
Expand Down
1 change: 1 addition & 0 deletions app/admin/models/config/orders_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'label' => 'lang:admin::lang.button_delete',
'class' => 'btn btn-light text-danger',
'data-request-confirm' => 'lang:admin::lang.alert_warning_confirm',
'permissions' => 'Admin.DeleteOrders',
],
];

Expand Down
1 change: 1 addition & 0 deletions app/admin/models/config/reservations_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'label' => 'lang:admin::lang.button_delete',
'class' => 'btn btn-light text-danger',
'data-request-confirm' => 'lang:admin::lang.alert_warning_confirm',
'permissions' => 'Admin.DeleteOrders',
],
];

Expand Down
2 changes: 1 addition & 1 deletion app/admin/requests/Allergen.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function attributes()
public function rules()
{
return [
'name' => ['required', 'between:2,128', 'unique:allergens'],
'name' => ['required', 'between:2,128'],
'description' => ['min:2'],
'status' => ['boolean'],
];
Expand Down
2 changes: 1 addition & 1 deletion app/admin/requests/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function attributes()
public function rules()
{
return [
'name' => ['required', 'between:2,128', 'unique:categories'],
'name' => ['required', 'between:2,128'],
'description' => ['min:2'],
'permalink_slug' => ['alpha_dash', 'max:255'],
'parent_id' => ['nullable', 'integer'],
Expand Down
2 changes: 1 addition & 1 deletion app/admin/requests/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function attributes()
public function rules()
{
return [
'location_name' => ['required', 'between:2,32', 'unique:locations'],
'location_name' => ['required', 'between:2,32'],
'location_email' => ['required', 'email:filter', 'max:96'],
'location_telephone' => ['sometimes'],
'location_address_1' => ['required', 'between:2,128'],
Expand Down
2 changes: 1 addition & 1 deletion app/admin/requests/Mealtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function attributes()
public function rules()
{
return [
'mealtime_name' => ['required', 'between:2,128', 'unique:mealtimes'],
'mealtime_name' => ['required', 'between:2,128'],
'start_time' => ['required', 'valid_time'],
'end_time' => ['required', 'valid_time'],
'mealtime_status' => ['required', 'boolean'],
Expand Down
2 changes: 1 addition & 1 deletion app/admin/requests/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function attributes()
public function rules()
{
return [
'menu_name' => ['required', 'between:2,255', 'unique:menus'],
'menu_name' => ['required', 'between:2,255'],
'menu_description' => ['between:2,1028'],
'menu_price' => ['required', 'numeric', 'min:0'],
'categories.*' => ['sometimes', 'required', 'integer'],
Expand Down
2 changes: 1 addition & 1 deletion app/admin/requests/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function attributes()
public function rules()
{
return [
'table_name' => ['required', 'min:2', 'max:255', 'unique:tables'],
'table_name' => ['required', 'min:2', 'max:255'],
'min_capacity' => ['required', 'integer', 'min:1', 'lte:max_capacity'],
'max_capacity' => ['required', 'integer', 'min:1', 'gte:min_capacity'],
'extra_capacity' => ['required', 'integer'],
Expand Down
2 changes: 1 addition & 1 deletion app/system/requests/MailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function rules()
];

if (optional($this->getForm())->context == 'create') {
$rules['code'] = ['required', 'min:2', 'max:32'];
$rules['code'] = ['required', 'min:2', 'max:128'];
}

return $rules;
Expand Down

0 comments on commit 3b95b83

Please sign in to comment.