From 1a5bfe9f711c19eb3f359f3f2ce59f2400d154f9 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Thu, 26 Nov 2020 16:18:02 +0300 Subject: [PATCH] partially refactoring the location module's admin side --- .../src/City/Form/CityFormBuilder.php | 75 +++------ .../src/District/Form/DistrictFormBuilder.php | 76 +++------ .../Controller/Admin/CitiesController.php | 32 +--- .../Controller/Admin/DistrictsController.php | 32 +--- .../Admin/NeighborhoodsController.php | 35 +--- .../Controller/Admin/VillageController.php | 33 +--- .../location-module/src/LocationModule.php | 27 +-- .../src/LocationModuleServiceProvider.php | 156 ------------------ .../Form/NeighborhoodFormBuilder.php | 76 +++------ .../src/Village/Form/VillageFormBuilder.php | 76 +++------ 10 files changed, 101 insertions(+), 517 deletions(-) diff --git a/addons/default/visiosoft/location-module/src/City/Form/CityFormBuilder.php b/addons/default/visiosoft/location-module/src/City/Form/CityFormBuilder.php index fee95979f..cb01a46ef 100644 --- a/addons/default/visiosoft/location-module/src/City/Form/CityFormBuilder.php +++ b/addons/default/visiosoft/location-module/src/City/Form/CityFormBuilder.php @@ -4,68 +4,35 @@ use Anomaly\Streams\Platform\Ui\Form\FormBuilder; class CityFormBuilder extends FormBuilder { + protected $country = null; - /** - * The form fields. - * - * @var array|string - */ - protected $fields = [ - 'name','slug','order','parent_country_id'=>[ - 'class' => 'hidden', - 'label' => '', - ], + protected $skips = [ + 'parent_country_id' ]; - /** - * Additional validation rules. - * - * @var array|string - */ - protected $rules = []; - - /** - * Fields to skip. - * - * @var array|string - */ - protected $skips = []; - - /** - * The form actions. - * - * @var array|string - */ - protected $actions = []; - - /** - * The form buttons. - * - * @var array|string - */ protected $buttons = [ 'cancel', ]; - /** - * The form options. - * - * @var array - */ - protected $options = []; + public function onSaving() + { + $country = $this->getCountry(); + $entry = $this->getFormEntry(); - /** - * The form sections. - * - * @var array - */ - protected $sections = []; + if ($country) { + $entry->parent_country_id = $country; + } + } - /** - * The form assets. - * - * @var array - */ - protected $assets = []; + public function getCountry() + { + return $this->country; + } + public function setCountry($country = null) + { + $this->country = $country; + + return $this; + } } diff --git a/addons/default/visiosoft/location-module/src/District/Form/DistrictFormBuilder.php b/addons/default/visiosoft/location-module/src/District/Form/DistrictFormBuilder.php index 66be690f6..86846d4d1 100644 --- a/addons/default/visiosoft/location-module/src/District/Form/DistrictFormBuilder.php +++ b/addons/default/visiosoft/location-module/src/District/Form/DistrictFormBuilder.php @@ -4,69 +4,35 @@ use Anomaly\Streams\Platform\Ui\Form\FormBuilder; class DistrictFormBuilder extends FormBuilder { + protected $city = null; - /** - * The form fields. - * - * @var array|string - */ - protected $fields = [ - 'name','slug','order','parent_city_id'=>[ - 'type' => 'anomaly.field_type.text', - 'class' => 'hidden', - 'label' => '', - ], + protected $skips = [ + 'parent_city_id' ]; - /** - * Additional validation rules. - * - * @var array|string - */ - protected $rules = []; - - /** - * Fields to skip. - * - * @var array|string - */ - protected $skips = []; - - /** - * The form actions. - * - * @var array|string - */ - protected $actions = []; - - /** - * The form buttons. - * - * @var array|string - */ protected $buttons = [ 'cancel', ]; - /** - * The form options. - * - * @var array - */ - protected $options = []; + public function onSaving() + { + $city = $this->getCity(); + $entry = $this->getFormEntry(); - /** - * The form sections. - * - * @var array - */ - protected $sections = []; + if ($city) { + $entry->parent_city_id = $city; + } + } - /** - * The form assets. - * - * @var array - */ - protected $assets = []; + public function getCity() + { + return $this->city; + } + public function setCity($city = null) + { + $this->city = $city; + + return $this; + } } diff --git a/addons/default/visiosoft/location-module/src/Http/Controller/Admin/CitiesController.php b/addons/default/visiosoft/location-module/src/Http/Controller/Admin/CitiesController.php index 035353c06..6ed43feb3 100644 --- a/addons/default/visiosoft/location-module/src/Http/Controller/Admin/CitiesController.php +++ b/addons/default/visiosoft/location-module/src/Http/Controller/Admin/CitiesController.php @@ -9,13 +9,6 @@ use Visiosoft\LocationModule\District\DistrictModel; class CitiesController extends AdminController { - - /** - * Display an index of existing entries. - * - * @param CityTableBuilder $table - * @return \Symfony\Component\HttpFoundation\Response - */ public function index(CityTableBuilder $table, Request $request) { if($this->request->action == "delete") { @@ -39,32 +32,13 @@ class CitiesController extends AdminController return $table->render(); } - /** - * Create a new entry. - * - * @param CityFormBuilder $form - * @return \Symfony\Component\HttpFoundation\Response - */ - public function create(CityFormBuilder $form,Request $request) + public function create(CityFormBuilder $form) { - if($this->request->action == "save") { - if ($form->hasFormErrors()) { - return back(); - } - $form->make(); - return $this->redirect->to('/admin/location/cities?country='.$request->parent_country_id); - } + $form->setCountry($this->request->get('cities')); - return $this->view->make('visiosoft.module.location::location/admin-sub-location'); + return $form->render(); } - /** - * Edit an existing entry. - * - * @param CityFormBuilder $form - * @param $id - * @return \Symfony\Component\HttpFoundation\Response - */ public function edit(CityFormBuilder $form, $id) { return $form->render($id); diff --git a/addons/default/visiosoft/location-module/src/Http/Controller/Admin/DistrictsController.php b/addons/default/visiosoft/location-module/src/Http/Controller/Admin/DistrictsController.php index 0381eea2f..dc391e261 100644 --- a/addons/default/visiosoft/location-module/src/Http/Controller/Admin/DistrictsController.php +++ b/addons/default/visiosoft/location-module/src/Http/Controller/Admin/DistrictsController.php @@ -9,13 +9,6 @@ use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel; class DistrictsController extends AdminController { - - /** - * Display an index of existing entries. - * - * @param DistrictTableBuilder $table - * @return \Symfony\Component\HttpFoundation\Response - */ public function index(DistrictTableBuilder $table, Request $request) { if($this->request->action == "delete") { @@ -39,32 +32,13 @@ class DistrictsController extends AdminController return $table->render(); } - /** - * Create a new entry. - * - * @param DistrictFormBuilder $form - * @return \Symfony\Component\HttpFoundation\Response - */ - public function create(DistrictFormBuilder $form,Request $request) + public function create(DistrictFormBuilder $form) { - if($this->request->action == "save") { - if ($form->hasFormErrors()) { - return back(); - } - $form->make(); - return $this->redirect->to('/admin/location/districts?city='.$request->parent_city_id); - } + $form->setCity($this->request->get('districts')); - return $this->view->make('visiosoft.module.location::location/admin-sub-location'); + return $form->render(); } - /** - * Edit an existing entry. - * - * @param DistrictFormBuilder $form - * @param $id - * @return \Symfony\Component\HttpFoundation\Response - */ public function edit(DistrictFormBuilder $form, $id) { return $form->render($id); diff --git a/addons/default/visiosoft/location-module/src/Http/Controller/Admin/NeighborhoodsController.php b/addons/default/visiosoft/location-module/src/Http/Controller/Admin/NeighborhoodsController.php index 453d38b02..6fea82c3c 100644 --- a/addons/default/visiosoft/location-module/src/Http/Controller/Admin/NeighborhoodsController.php +++ b/addons/default/visiosoft/location-module/src/Http/Controller/Admin/NeighborhoodsController.php @@ -9,13 +9,6 @@ use Visiosoft\LocationModule\Village\VillageModel; class NeighborhoodsController extends AdminController { - - /** - * Display an index of existing entries. - * - * @param NeighborhoodTableBuilder $table - * @return \Symfony\Component\HttpFoundation\Response - */ public function index(NeighborhoodTableBuilder $table, Request $request) { if($this->request->action == "delete") { @@ -39,35 +32,13 @@ class NeighborhoodsController extends AdminController return $table->render(); } - /** - * Create a new entry. - * - * @param NeighborhoodFormBuilder $form - * @return \Symfony\Component\HttpFoundation\Response - */ - public function create(NeighborhoodFormBuilder $form,Request $request) + public function create(NeighborhoodFormBuilder $form) { -// dd($request); - // return $form->render(); - if($this->request->action == "save") { - if ($form->hasFormErrors()) { - return back(); - } - $form->make(); + $form->setDistrict($this->request->get('neighborhoods')); - return $this->redirect->to('/admin/location/neighborhoods?district='.$request->parent_district_id); - } - - return $this->view->make('visiosoft.module.location::location/admin-sub-location'); + return $form->render(); } - /** - * Edit an existing entry. - * - * @param NeighborhoodFormBuilder $form - * @param $id - * @return \Symfony\Component\HttpFoundation\Response - */ public function edit(NeighborhoodFormBuilder $form, $id) { return $form->render($id); diff --git a/addons/default/visiosoft/location-module/src/Http/Controller/Admin/VillageController.php b/addons/default/visiosoft/location-module/src/Http/Controller/Admin/VillageController.php index 8aa9aadc9..a09533472 100644 --- a/addons/default/visiosoft/location-module/src/Http/Controller/Admin/VillageController.php +++ b/addons/default/visiosoft/location-module/src/Http/Controller/Admin/VillageController.php @@ -8,13 +8,6 @@ use Visiosoft\LocationModule\Village\VillageModel; class VillageController extends AdminController { - - /** - * Display an index of existing entries. - * - * @param VillageTableBuilder $table - * @return \Symfony\Component\HttpFoundation\Response - */ public function index(VillageTableBuilder $table, Request $request) { $villages = new VillageModel(); @@ -31,33 +24,13 @@ class VillageController extends AdminController return $table->render(); } - /** - * Create a new entry. - * - * @param VillageFormBuilder $form - * @return \Symfony\Component\HttpFoundation\Response - */ - public function create(VillageFormBuilder $form,Request $request) + public function create(VillageFormBuilder $form) { - // return $form->render(); - if($this->request->action == "save") { - if ($form->hasFormErrors()) { - return back(); - } - $form->make(); - return $this->redirect->to('/admin/location/village?neighborhood='.$request->parent_neighborhood_id); - } + $form->setNeighborhood($this->request->get('village')); - return $this->view->make('visiosoft.module.location::location/admin-sub-location'); + return $form->render(); } - /** - * Edit an existing entry. - * - * @param VillageFormBuilder $form - * @param $id - * @return \Symfony\Component\HttpFoundation\Response - */ public function edit(VillageFormBuilder $form, $id) { return $form->render($id); diff --git a/addons/default/visiosoft/location-module/src/LocationModule.php b/addons/default/visiosoft/location-module/src/LocationModule.php index 6b85568a5..1aa429a9a 100644 --- a/addons/default/visiosoft/location-module/src/LocationModule.php +++ b/addons/default/visiosoft/location-module/src/LocationModule.php @@ -4,36 +4,19 @@ use Anomaly\Streams\Platform\Addon\Module\Module; class LocationModule extends Module { - - /** - * The navigation display flag. - * - * @var bool - */ protected $navigation = true; - /** - * The addon icon. - * - * @var string - */ protected $icon = 'fa fa-location-arrow'; - /** - * The module sections. - * - * @var array - */ protected $sections = [ 'countries' => [ 'buttons' => [ - 'new_country'=> [], + 'new_country', ], ], - 'cities' => [], - 'districts' => [], - 'neighborhoods' => [], - 'village' => [], + 'cities', + 'districts', + 'neighborhoods', + 'village', ]; - } diff --git a/addons/default/visiosoft/location-module/src/LocationModuleServiceProvider.php b/addons/default/visiosoft/location-module/src/LocationModuleServiceProvider.php index d26365f34..18343e219 100644 --- a/addons/default/visiosoft/location-module/src/LocationModuleServiceProvider.php +++ b/addons/default/visiosoft/location-module/src/LocationModuleServiceProvider.php @@ -17,48 +17,15 @@ use Visiosoft\LocationModule\Neighborhood\NeighborhoodRepository; use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface; use Visiosoft\LocationModule\Village\VillageRepository; use Visiosoft\LocationModule\Village\VillageModel; -use Illuminate\Routing\Router; use Visiosoft\LocationModule\Country\Contract\CountryRepositoryInterface; use Visiosoft\LocationModule\Country\CountryRepository; class LocationModuleServiceProvider extends AddonServiceProvider { - - /** - * Additional addon plugins. - * - * @type array|null - */ protected $plugins = [ LocationModulePlugin::class ]; - /** - * The addon Artisan commands. - * - * @type array|null - */ - protected $commands = []; - - /** - * The addon's scheduled commands. - * - * @type array|null - */ - protected $schedules = []; - - /** - * The addon API routes. - * - * @type array|null - */ - protected $api = []; - - /** - * The addon routes. - * - * @type array|null - */ protected $routes = [ 'admin/location/village' => 'Visiosoft\LocationModule\Http\Controller\Admin\VillageController@index', 'admin/location/village/create' => 'Visiosoft\LocationModule\Http\Controller\Admin\VillageController@create', @@ -104,141 +71,18 @@ class LocationModuleServiceProvider extends AddonServiceProvider ], ]; - /** - * The addon middleware. - * - * @type array|null - */ - protected $middleware = [ - //Visiosoft\AdvsModule\Http\Middleware\ExampleMiddleware::class - ]; - - /** - * Addon group middleware. - * - * @var array - */ - protected $groupMiddleware = [ - //'web' => [ - // Visiosoft\AdvsModule\Http\Middleware\ExampleMiddleware::class, - //], - ]; - - /** - * Addon route middleware. - * - * @type array|null - */ - protected $routeMiddleware = []; - - /** - * The addon event listeners. - * - * @type array|null - */ - protected $listeners = [ - //Visiosoft\AdvsModule\Event\ExampleEvent::class => [ - // Visiosoft\AdvsModule\Listener\ExampleListener::class, - //], - ]; - - /** - * The addon alias bindings. - * - * @type array|null - */ - protected $aliases = [ - //'Example' => Visiosoft\AdvsModule\Example::class - ]; - - /** - * The addon class bindings. - * - * @type array|null - */ protected $bindings = [ LocationCitiesEntryModel::class => CityModel::class, LocationDistrictsEntryModel::class => DistrictModel::class, LocationNeighborhoodsEntryModel::class => NeighborhoodModel::class, - // AdvsCfValuesEntryModel::class => CfValueModel::class, - // AdvsCustomFieldAdvsEntryModel::class => CustomFieldAdvModel::class, - // AdvsCustomFieldsEntryModel::class => CustomFieldModel::class, LocationVillageEntryModel::class => VillageModel::class, ]; - /** - * The addon singleton bindings. - * - * @type array|null - */ protected $singletons = [ CityRepositoryInterface::class => CityRepository::class, DistrictRepositoryInterface::class => DistrictRepository::class, NeighborhoodRepositoryInterface::class => NeighborhoodRepository::class, - // CfValueRepositoryInterface::class => CfValueRepository::class, - // CustomFieldAdvRepositoryInterface::class => CustomFieldAdvRepository::class, - // CustomFieldRepositoryInterface::class => CustomFieldRepository::class, VillageRepositoryInterface::class => VillageRepository::class, CountryRepositoryInterface::class => CountryRepository::class, ]; - - /** - * Additional service providers. - * - * @type array|null - */ - protected $providers = [ - //\ExamplePackage\Provider\ExampleProvider::class - ]; - - /** - * The addon view overrides. - * - * @type array|null - */ - protected $overrides = [ - 'streams::form/form' => 'visiosoft.module.advs::form/form', - //'streams::errors/404' => 'module::errors/404', - //'streams::errors/500' => 'module::errors/500', - ]; - - /** - * The addon mobile-only view overrides. - * - * @type array|null - */ - protected $mobile = [ - //'streams::errors/404' => 'module::mobile/errors/404', - //'streams::errors/500' => 'module::mobile/errors/500', - ]; - - /** - * Register the addon. - */ - public function register() - { - // Run extra pre-boot registration logic here. - // Use method injection or commands to bring in services. - } - - /** - * Boot the addon. - */ - public function boot() - { - } - - /** - * Map additional addon routes. - * - * @param Router $router - */ - // public function map(Router $router) - // { - // // Register dynamic routes here for example. - // // Use method injection or commands to bring in services. - // } - public function map(Router $router) - { - } } diff --git a/addons/default/visiosoft/location-module/src/Neighborhood/Form/NeighborhoodFormBuilder.php b/addons/default/visiosoft/location-module/src/Neighborhood/Form/NeighborhoodFormBuilder.php index 063931bda..713012ac6 100644 --- a/addons/default/visiosoft/location-module/src/Neighborhood/Form/NeighborhoodFormBuilder.php +++ b/addons/default/visiosoft/location-module/src/Neighborhood/Form/NeighborhoodFormBuilder.php @@ -4,69 +4,35 @@ use Anomaly\Streams\Platform\Ui\Form\FormBuilder; class NeighborhoodFormBuilder extends FormBuilder { + protected $district = null; - /** - * The form fields. - * - * @var array|string - */ - protected $fields = [ - 'name','slug','order','parent_district_id'=>[ - 'type' => 'anomaly.field_type.text', - 'class' => 'hidden', - 'label' => '', - ], + protected $skips = [ + 'parent_district_id' ]; - /** - * Additional validation rules. - * - * @var array|string - */ - protected $rules = []; - - /** - * Fields to skip. - * - * @var array|string - */ - protected $skips = []; - - /** - * The form actions. - * - * @var array|string - */ - protected $actions = []; - - /** - * The form buttons. - * - * @var array|string - */ protected $buttons = [ 'cancel', ]; - /** - * The form options. - * - * @var array - */ - protected $options = []; + public function onSaving() + { + $district = $this->getDistrict(); + $entry = $this->getFormEntry(); - /** - * The form sections. - * - * @var array - */ - protected $sections = []; + if ($district) { + $entry->parent_district_id = $district; + } + } - /** - * The form assets. - * - * @var array - */ - protected $assets = []; + public function getDistrict() + { + return $this->district; + } + public function setDistrict($district = null) + { + $this->district = $district; + + return $this; + } } diff --git a/addons/default/visiosoft/location-module/src/Village/Form/VillageFormBuilder.php b/addons/default/visiosoft/location-module/src/Village/Form/VillageFormBuilder.php index 08b85c6fd..8fc900693 100644 --- a/addons/default/visiosoft/location-module/src/Village/Form/VillageFormBuilder.php +++ b/addons/default/visiosoft/location-module/src/Village/Form/VillageFormBuilder.php @@ -4,69 +4,35 @@ use Anomaly\Streams\Platform\Ui\Form\FormBuilder; class VillageFormBuilder extends FormBuilder { + protected $neighborhood = null; - /** - * The form fields. - * - * @var array|string - */ - protected $fields = [ - 'name','slug','order','parent_neighborhood_id'=>[ - 'type' => 'anomaly.field_type.text', - 'class' => 'hidden', - 'label' => '', - ], + protected $skips = [ + 'parent_neighborhood_id' ]; - /** - * Additional validation rules. - * - * @var array|string - */ - protected $rules = []; - - /** - * Fields to skip. - * - * @var array|string - */ - protected $skips = []; - - /** - * The form actions. - * - * @var array|string - */ - protected $actions = []; - - /** - * The form buttons. - * - * @var array|string - */ protected $buttons = [ 'cancel', ]; - /** - * The form options. - * - * @var array - */ - protected $options = []; + public function onSaving() + { + $neighborhood = $this->getNeighborhood(); + $entry = $this->getFormEntry(); - /** - * The form sections. - * - * @var array - */ - protected $sections = []; + if ($neighborhood) { + $entry->parent_neighborhood_id = $neighborhood; + } + } - /** - * The form assets. - * - * @var array - */ - protected $assets = []; + public function getNeighborhood() + { + return $this->neighborhood; + } + public function setNeighborhood($neighborhood = null) + { + $this->neighborhood = $neighborhood; + + return $this; + } }