|
@@ -0,0 +1,145 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Http\Admin;
|
|
|
|
+
|
|
|
|
+use AdminColumn;
|
|
|
|
+use AdminColumnEditable;
|
|
|
|
+use AdminDisplay;
|
|
|
|
+use AdminForm;
|
|
|
|
+use AdminFormElement;
|
|
|
|
+use AdminSection;
|
|
|
|
+use App\User;
|
|
|
|
+use App\Watcher;
|
|
|
|
+use Illuminate\Database\Eloquent\Model;
|
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
+use SleepingOwl\Admin\Contracts\Display\DisplayInterface;
|
|
|
|
+use SleepingOwl\Admin\Contracts\Form\FormInterface;
|
|
|
|
+use SleepingOwl\Admin\Contracts\Initializable;
|
|
|
|
+use SleepingOwl\Admin\Form\Buttons\Cancel;
|
|
|
|
+use SleepingOwl\Admin\Form\Buttons\Save;
|
|
|
|
+use SleepingOwl\Admin\Section;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Class Users
|
|
|
|
+ *
|
|
|
|
+ * @property \App\User $model
|
|
|
|
+ *
|
|
|
|
+ * @see http://sleepingowladmin.ru/docs/model_configuration_section
|
|
|
|
+ */
|
|
|
|
+class Locations extends Section implements Initializable
|
|
|
|
+{
|
|
|
|
+ /**
|
|
|
|
+ * @see http://sleepingowladmin.ru/docs/model_configuration#ограничение-прав-доступа
|
|
|
|
+ *
|
|
|
|
+ * @var bool
|
|
|
|
+ */
|
|
|
|
+ protected $checkAccess = false;
|
|
|
|
+ protected $redirect = ['edit' => 'display', 'create' => 'display'];
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $title;
|
|
|
|
+
|
|
|
|
+ public function initialize()
|
|
|
|
+ {
|
|
|
|
+ $this->creating(function ($config, Model $model) {
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $alias;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return DisplayInterface
|
|
|
|
+ */
|
|
|
|
+ public function onDisplay()
|
|
|
|
+ {
|
|
|
|
+ $form = AdminDisplay::datatablesAsync()->setDisplaySearch(true)
|
|
|
|
+ ->setOrder([[0, 'desc']])
|
|
|
|
+ ->setHtmlAttribute('class', 'table-primary')
|
|
|
|
+ ->setColumns(
|
|
|
|
+ AdminColumn::link('id', '#')->setWidth('30px'),
|
|
|
|
+ AdminColumnEditable::text('lat', 'lat')->setWidth('100px'),
|
|
|
|
+ AdminColumnEditable::text('lng', 'lng')->setWidth('100px'),
|
|
|
|
+ AdminColumnEditable::text('created_at', 'Date')->setWidth('100px')
|
|
|
|
+ )->paginate(20);
|
|
|
|
+
|
|
|
|
+ $filters = request()->get('payload', []);
|
|
|
|
+ Log::info($filters);
|
|
|
|
+ if (! empty($filters['user_id'])) {
|
|
|
|
+ $userId = $filters['user_id'];
|
|
|
|
+ $form->setApply(function ($query) use ($userId) {
|
|
|
|
+ $query->where('user_id', $userId);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $form;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param int $id
|
|
|
|
+ *
|
|
|
|
+ * @return FormInterface
|
|
|
|
+ */
|
|
|
|
+ public function onEdit($id)
|
|
|
|
+ {
|
|
|
|
+ $users = [];
|
|
|
|
+ foreach (User::all() as $user) {
|
|
|
|
+ $users[$user->id] = $user['name'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $formElements = [
|
|
|
|
+ AdminFormElement::select('user_id', 'User', $users),
|
|
|
|
+ AdminFormElement::columns()
|
|
|
|
+ ->addColumn(function () {
|
|
|
|
+ return [
|
|
|
|
+ AdminFormElement::text('lat', 'lat')
|
|
|
|
+ ];
|
|
|
|
+ })
|
|
|
|
+ ->addColumn(function () {
|
|
|
|
+ return [
|
|
|
|
+ AdminFormElement::text('lng', 'lng')
|
|
|
|
+ ];
|
|
|
|
+ })
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $form = AdminForm::panel();
|
|
|
|
+
|
|
|
|
+ $form->addBody($formElements);
|
|
|
|
+
|
|
|
|
+ $form->getButtons()->setButtons([
|
|
|
|
+ 'save' => new Save(),
|
|
|
|
+ 'cancel' => new Cancel(),
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ return $form;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return FormInterface
|
|
|
|
+ */
|
|
|
|
+ public function onCreate()
|
|
|
|
+ {
|
|
|
|
+ return $this->onEdit(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+ public function onDelete($id)
|
|
|
|
+ {
|
|
|
|
+ // remove if unused
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
|
|
+ public function onRestore($id)
|
|
|
|
+ {
|
|
|
|
+ // remove if unused
|
|
|
|
+ }
|
|
|
|
+}
|