Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sampoyigi committed Jan 4, 2019
1 parent 934b4b0 commit 6394902
Show file tree
Hide file tree
Showing 62 changed files with 676 additions and 421 deletions.
9 changes: 9 additions & 0 deletions app/admin/classes/Navigation.php
Expand Up @@ -170,6 +170,15 @@ public function filterPermittedNavItems($items)
if (!$permission = array_get($item, 'permission'))
return TRUE;

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

$permission = array_map(function ($value) {
$permArray = explode('.', $value);
$name = array_slice($permArray, 0, 2);
return implode('.', $name).'.Access';
}, $permission);

return AdminAuth::user()->hasPermission($permission);
})->toArray();
}
Expand Down
2 changes: 1 addition & 1 deletion app/admin/classes/User.php
Expand Up @@ -90,7 +90,7 @@ public function getStaffGroupId()

public function canAccessCustomerAccount()
{
return $this->fromModel('customer_account_access', 'group');
return $this->isSuperUser() OR $this->fromModel('customer_account_access', 'group');
}

public function isStrictLocation()
Expand Down
57 changes: 42 additions & 15 deletions app/admin/controllers/CustomerGroups.php
@@ -1,5 +1,6 @@
<?php namespace Admin\Controllers;

use Admin\Models\Customer_groups_model;
use AdminMenu;

class CustomerGroups extends \Admin\Classes\AdminController
Expand All @@ -11,32 +12,32 @@ class CustomerGroups extends \Admin\Classes\AdminController

public $listConfig = [
'list' => [
'model' => 'Admin\Models\Customer_groups_model',
'title' => 'lang:admin::lang.customer_groups.text_title',
'model' => 'Admin\Models\Customer_groups_model',
'title' => 'lang:admin::lang.customer_groups.text_title',
'emptyMessage' => 'lang:admin::lang.customer_groups.text_empty',
'defaultSort' => ['country_name', 'ASC'],
'configFile' => 'customer_groups_model',
'defaultSort' => ['country_name', 'ASC'],
'configFile' => 'customer_groups_model',
],
];

public $formConfig = [
'name' => 'lang:admin::lang.customer_groups.text_form_name',
'model' => 'Admin\Models\Customer_groups_model',
'create' => [
'title' => 'lang:admin::lang.form.create_title',
'redirect' => 'customer_groups/edit/{customer_group_id}',
'name' => 'lang:admin::lang.customer_groups.text_form_name',
'model' => 'Admin\Models\Customer_groups_model',
'create' => [
'title' => 'lang:admin::lang.form.create_title',
'redirect' => 'customer_groups/edit/{customer_group_id}',
'redirectClose' => 'customer_groups',
],
'edit' => [
'title' => 'lang:admin::lang.form.edit_title',
'redirect' => 'customer_groups/edit/{customer_group_id}',
'edit' => [
'title' => 'lang:admin::lang.form.edit_title',
'redirect' => 'customer_groups/edit/{customer_group_id}',
'redirectClose' => 'customer_groups',
],
'preview' => [
'title' => 'lang:admin::lang.form.preview_title',
'preview' => [
'title' => 'lang:admin::lang.form.preview_title',
'redirect' => 'customer_groups',
],
'delete' => [
'delete' => [
'redirect' => 'customer_groups',
],
'configFile' => 'customer_groups_model',
Expand All @@ -51,6 +52,32 @@ public function __construct()
AdminMenu::setContext('customer_groups', 'users');
}

public function index_onSetDefault()
{
if (Customer_groups_model::updateDefault(post('default'))) {
flash()->success(sprintf(lang('admin::lang.alert_success'), lang('admin::lang.customer_groups.alert_set_default')));
}

return $this->refreshList('list');
}

public function listOverrideColumnValue($record, $column, $alias = null)
{
if ($column->type != 'button')
return null;

if ($column->columnName != 'default')
return null;

$attributes = $column->attributes;
$column->iconCssClass = 'fa fa-star-o';
if ($record->getKey() == setting('customer_group_id')) {
$column->iconCssClass = 'fa fa-star';
}

return $attributes;
}

public function formValidate($model, $form)
{
$rules = [
Expand Down
1 change: 0 additions & 1 deletion app/admin/controllers/Locations.php
Expand Up @@ -103,7 +103,6 @@ public function listOverrideColumnValue($record, $column, $alias = null)
$column->iconCssClass = 'fa fa-star-o';
if ($record->getKey() == params('default_location_id')) {
$column->iconCssClass = 'fa fa-star';
$attributes['class'] .= ' active';
}

return $attributes;
Expand Down
30 changes: 15 additions & 15 deletions app/admin/controllers/Mealtimes.php
Expand Up @@ -11,32 +11,32 @@ class Mealtimes extends \Admin\Classes\AdminController

public $listConfig = [
'list' => [
'model' => 'Admin\Models\Mealtimes_model',
'title' => 'lang:admin::lang.mealtimes.text_title',
'model' => 'Admin\Models\Mealtimes_model',
'title' => 'lang:admin::lang.mealtimes.text_title',
'emptyMessage' => 'lang:admin::lang.mealtimes.text_empty',
'defaultSort' => ['order_id', 'DESC'],
'configFile' => 'mealtimes_model',
'defaultSort' => ['order_id', 'DESC'],
'configFile' => 'mealtimes_model',
],
];

public $formConfig = [
'name' => 'lang:admin::lang.mealtimes.text_form_name',
'model' => 'Admin\Models\Mealtimes_model',
'create' => [
'title' => 'lang:admin::lang.form.create_title',
'redirect' => 'mealtimes/edit/{mealtime_id}',
'name' => 'lang:admin::lang.mealtimes.text_form_name',
'model' => 'Admin\Models\Mealtimes_model',
'create' => [
'title' => 'lang:admin::lang.form.create_title',
'redirect' => 'mealtimes/edit/{mealtime_id}',
'redirectClose' => 'mealtimes',
],
'edit' => [
'title' => 'lang:admin::lang.form.edit_title',
'redirect' => 'mealtimes/edit/{mealtime_id}',
'edit' => [
'title' => 'lang:admin::lang.form.edit_title',
'redirect' => 'mealtimes/edit/{mealtime_id}',
'redirectClose' => 'mealtimes',
],
'preview' => [
'title' => 'lang:admin::lang.form.preview_title',
'preview' => [
'title' => 'lang:admin::lang.form.preview_title',
'redirect' => 'mealtimes',
],
'delete' => [
'delete' => [
'redirect' => 'mealtimes',
],
'configFile' => 'mealtimes_model',
Expand Down
6 changes: 3 additions & 3 deletions app/admin/controllers/Menus.php
Expand Up @@ -97,9 +97,9 @@ public function formValidate($model, $form)
['special.special_status', 'lang:admin::lang.menus.label_special_status', 'required|integer'],
];

$rules[] = ['special.start_date', 'lang:admin::lang.menus.label_start_date', 'valid_date'];
$rules[] = ['special.end_date', 'lang:admin::lang.menus.label_end_date', 'valid_date'];
$rules[] = ['special.special_price', 'lang:admin::lang.menus.label_special_price', 'numeric'];
$rules[] = ['special.start_date', 'lang:admin::lang.menus.label_start_date', 'required_if:special.special_status,1|valid_date'];
$rules[] = ['special.end_date', 'lang:admin::lang.menus.label_end_date', 'required_if:special.special_status,1|valid_date'];
$rules[] = ['special.special_price', 'lang:admin::lang.menus.label_special_price', 'required_if:special.special_status,1|numeric'];

return $this->validatePasses(post($form->arrayName), $rules);
}
Expand Down
45 changes: 29 additions & 16 deletions app/admin/controllers/Staffs.php
Expand Up @@ -12,32 +12,32 @@ class Staffs extends \Admin\Classes\AdminController

public $listConfig = [
'list' => [
'model' => 'Admin\Models\Staffs_model',
'title' => 'lang:admin::lang.staff.text_title',
'model' => 'Admin\Models\Staffs_model',
'title' => 'lang:admin::lang.staff.text_title',
'emptyMessage' => 'lang:admin::lang.staff.text_empty',
'defaultSort' => ['staff_id', 'DESC'],
'configFile' => 'staffs_model',
'defaultSort' => ['staff_id', 'DESC'],
'configFile' => 'staffs_model',
],
];

public $formConfig = [
'name' => 'lang:admin::lang.staff.text_form_name',
'model' => 'Admin\Models\Staffs_model',
'create' => [
'title' => 'lang:admin::lang.form.create_title',
'redirect' => 'staffs/edit/{staff_id}',
'name' => 'lang:admin::lang.staff.text_form_name',
'model' => 'Admin\Models\Staffs_model',
'create' => [
'title' => 'lang:admin::lang.form.create_title',
'redirect' => 'staffs/edit/{staff_id}',
'redirectClose' => 'staffs',
],
'edit' => [
'title' => 'lang:admin::lang.form.edit_title',
'redirect' => 'staffs/edit/{staff_id}',
'edit' => [
'title' => 'lang:admin::lang.form.edit_title',
'redirect' => 'staffs/edit/{staff_id}',
'redirectClose' => 'staffs',
],
'preview' => [
'title' => 'lang:admin::lang.form.preview_title',
'preview' => [
'title' => 'lang:admin::lang.form.preview_title',
'redirect' => 'staffs',
],
'delete' => [
'delete' => [
'redirect' => 'staffs',
],
'configFile' => 'staffs_model',
Expand All @@ -55,17 +55,30 @@ public function __construct()
AdminMenu::setContext('staffs', 'users');
}

public function listExtendQuery($query)
{
if (!AdminAuth::isSuperUser()) {
$query->whereNotSuperUser();
}
}

public function formExtendFields($form, $fields)
{
if (!AdminAuth::isSuperUser()) {
$form->removeField('staff_group_id');
$form->removeField('staff_location_id');
$form->removeField('user[username]');
$form->removeField('user[super_user]');
$form->removeField('staff_status');
}
}

public function formExtendQuery($query)
{
if (!AdminAuth::isSuperUser()) {
$query->whereNotSuperUser();
}
}

public function formValidate($model, $form)
{
$rules = [
Expand Down
38 changes: 30 additions & 8 deletions app/admin/dashboardwidgets/Charts.php
Expand Up @@ -6,6 +6,8 @@
use Admin\Models\Reservations_model;
use Admin\Models\Reviews_model;
use Carbon\Carbon;
use DateInterval;
use DatePeriod;
use DB;
use Illuminate\Support\Collection;

Expand Down Expand Up @@ -122,18 +124,38 @@ protected function makeDataset($config, $start, $end)
protected function queryDatasets($config, $start, $end)
{
$modelClass = $config['model'];
$dbColumn = $config['column'];
$dateColumnName = $config['column'];

$query = $modelClass::select(DB::raw($dbColumn.' as x'), DB::raw('count(*) as y'));
$query->whereBetween($dbColumn, [$start, $end])->groupBy('x');
$dateColumn = DB::raw('DATE_FORMAT('.$dateColumnName.', "%Y-%m-%d") as x');
$query = $modelClass::select($dateColumn, DB::raw('count(*) as y'));
$query->whereBetween($dateColumnName, [$start, $end])->groupBy('x');

return $this->getPointsArray($query->get());
$dateRanges = $this->getDatePeriod($start, $end);

return $this->getPointsArray($dateRanges, $query->get());
}

protected function getDatePeriod($start, $end)
{
return new DatePeriod(
Carbon::parse($start),
new DateInterval('P1D'),
Carbon::parse($end)
);
}

protected function getPointsArray(Collection $result)
protected function getPointsArray($dateRanges, Collection $result)
{
return $result->map(function ($model) {
return ['x' => $model->x, 'y' => $model->y];
})->toArray();
$points = [];
$keyedResult = $result->keyBy('x');
foreach ($dateRanges as $date) {
$x = $date->format('Y-m-d');
$points[] = [
'x' => $x,
'y' => $keyedResult->get($x) ?? 0,
];
}

return $points;
}
}
2 changes: 1 addition & 1 deletion app/admin/formwidgets/MapArea.php
Expand Up @@ -123,7 +123,7 @@ public function getSaveValue($value)
return FormField::NO_SAVE_DATA;
}

if (is_string($value) && !strlen($value)) {
if (!is_array($value) && !strlen($value)) {
return null;
}

Expand Down
5 changes: 3 additions & 2 deletions app/admin/formwidgets/components/assets/js/components.js
Expand Up @@ -25,11 +25,12 @@
$sortableContainer.sortable({
group: 'components',
containerSelector: this.options.sortableContainer,
containerPath: '> div',
itemPath: '> div',
itemSelector: '.components-item:not(:first-child)',
placeholder: '<div class="placeholder sortable-placeholder"></div>',
handle: '.handle',
nested: false,
vertical: false,
exclude: '.components-picker',
})
}

Expand Down
6 changes: 3 additions & 3 deletions app/admin/formwidgets/components/components.php
Expand Up @@ -2,11 +2,11 @@
data-control="components"
data-alias="<?= $this->alias ?>"
data-add-handler="<?= $onAddEventHandler ?>"
data-sortable-container=".components"
data-sortable-container=".components-container"
>

<div class="components">
<div class="d-flex align-content-stretch">
<div class="components-container d-flex align-content-stretch">
<div class="components-item mr-2 components-picker">
<div
class="component btn btn-light"
Expand All @@ -22,7 +22,7 @@ class="component btn btn-light"
<?php foreach ($components as $code => $component) { ?>
<?= $this->makePartial('component', [
'component' => $component,
'field' => $field,
'field' => $field,
]) ?>
<?php } ?>
<?php } ?>
Expand Down
1 change: 1 addition & 0 deletions app/admin/formwidgets/datepicker/assets/css/datepicker.css
@@ -1,5 +1,6 @@
.datepicker-dropdown {
background-color: var(--gray-200);
z-index: 9999 !important;
}
.datepicker-dropdown.datepicker-orient-bottom:before {
bottom: -7px;
Expand Down
7 changes: 3 additions & 4 deletions app/admin/formwidgets/maparea/area.php
Expand Up @@ -10,7 +10,7 @@ class="card map-area"
data-index-value="<?= $index ?>"
>
<div
class="map-area-header"
class="map-area-header p-3"
role="tab"
id="<?= $this->getId('area-header-'.$index) ?>"
>
Expand All @@ -20,8 +20,7 @@ class="map-area-header"
class="map-area-handle <?= $this->getId('area-handle-'.$index) ?>"
role="button">
<i class="fa fa-bars text-black-50"></i>
</a>
&nbsp;&nbsp;&nbsp;
</a>&nbsp;&nbsp;
<?php } ?>
<span
class="badge border-circle"
Expand All @@ -48,7 +47,7 @@ class="close text-danger"
</div>
<div
id="<?= $this->getId('area-body-'.$index) ?>"
class="map-area-body collapse<?= $index == 1 ? ' show' : '' ?>"
class="map-area-body p-3 collapse<?= $index == 1 ? ' show' : '' ?>"
role="tabpanel"
data-parent="#<?= $this->getId('areas') ?>"
aria-labelledby="<?= $this->getId('area-header-'.$index) ?>"
Expand Down

0 comments on commit 6394902

Please sign in to comment.