partially refactoring the location module's admin side

This commit is contained in:
Diatrex 2020-11-26 16:18:02 +03:00
parent 971e7cdd5e
commit 1a5bfe9f71
10 changed files with 101 additions and 517 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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',
];
}

View File

@ -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)
{
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}