From 0a1c83d0dd39f876e979609e397c33a1d0c32fb7 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Wed, 24 Feb 2021 12:17:46 +0300 Subject: [PATCH] #3025 Making the announcement status flexible. --- .../advs-module/resources/lang/en/field.php | 11 ++ .../advs-module/resources/lang/en/message.php | 1 + .../advs-module/src/Adv/AdvModel.php | 5 + .../src/Adv/Contract/AdvInterface.php | 2 + .../src/Adv/Form/SimpleAdvFormFields.php | 12 +- .../src/Adv/Form/SimpleAdvFormHandler.php | 2 +- .../src/AdvsModuleServiceProvider.php | 12 ++ .../Controller/Admin/StatusController.php | 32 ++--- .../src/Http/Controller/StatusController.php | 37 +++++ .../Contract/StatusRepositoryInterface.php | 2 +- .../src/Status/Form/StatusFormBuilder.php | 56 -------- .../src/Status/StatusRepository.php | 16 +-- .../src/Status/Table/StatusTableBuilder.php | 49 ------- .../src/Status/Table/StatusTableColumns.php | 28 ++++ .../profile-module/resources/assets/js/ads.js | 40 +++++- .../resources/views/profile/ads.twig | 2 + .../Http/Controller/MyProfileController.php | 10 +- .../src/ProfileModuleServiceProvider.php | 134 ------------------ 18 files changed, 174 insertions(+), 277 deletions(-) create mode 100644 addons/default/visiosoft/advs-module/src/Http/Controller/StatusController.php create mode 100644 addons/default/visiosoft/advs-module/src/Status/Table/StatusTableColumns.php diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/field.php b/addons/default/visiosoft/advs-module/resources/lang/en/field.php index ee3c61e7f..c7bf94723 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/field.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/field.php @@ -279,6 +279,17 @@ return [ 'yes' => [ 'name' => 'Yes' ], + 'no' => [ + 'name' => 'No' + ], + 'is_system' => [ + 'name' => 'Is System', + 'instructions' => 'System status are required and should not be changed', + ], + 'user_access' => [ + 'name' => 'User Access', + 'instructions' => 'Can a user use this status on his ads?', + ], "no_location" => "No location is selected.", "continue" => 'Continue', "gallery" => 'Gallery', diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/message.php b/addons/default/visiosoft/advs-module/resources/lang/en/message.php index 60f9ffec9..64e9a67a5 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/message.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/message.php @@ -30,4 +30,5 @@ return [ 'approve_status_change' => "Your Ad's Status Has Been Set to Active!", 'passive_status_change' => "Your Ad's Status Has Been Set to Passive!", 'sold_status_change' => "Your Ad's Status Has Been Set to Sold!", + 'status_change' => "Your Ad's Status Has Been Set to :status!", ]; diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index 5416c4d80..4d94070cd 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -411,4 +411,9 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface 'publish_at' => date('Y-m-d H:i:s') ]); } + + public function changeStatus($status) + { + $this->update(['status' => $status]); + } } diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php index 3c6374283..06f037a75 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php @@ -87,4 +87,6 @@ interface AdvInterface extends EntryInterface public function getStatus(); public function approve(); + + public function changeStatus($status); } diff --git a/addons/default/visiosoft/advs-module/src/Adv/Form/SimpleAdvFormFields.php b/addons/default/visiosoft/advs-module/src/Adv/Form/SimpleAdvFormFields.php index 2b519de33..d6f737e10 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Form/SimpleAdvFormFields.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Form/SimpleAdvFormFields.php @@ -1,11 +1,14 @@ all()->pluck('name', 'slug')->all(); + $form_fields = [ 'name', 'price', @@ -23,6 +26,13 @@ class SimpleAdvFormFields 'cat10', 'is_get_adv', 'stock', + 'status' => [ + 'type' => 'anomaly.field_type.select', + "config" => [ + "options" => $statuses, + "mode" => "search", + ] + ], 'files', ]; diff --git a/addons/default/visiosoft/advs-module/src/Adv/Form/SimpleAdvFormHandler.php b/addons/default/visiosoft/advs-module/src/Adv/Form/SimpleAdvFormHandler.php index c78c58c3f..176bc5632 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Form/SimpleAdvFormHandler.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Form/SimpleAdvFormHandler.php @@ -18,7 +18,7 @@ class SimpleAdvFormHandler $builder->saveForm(); $ad = $advRepository->find($builder->getFormEntryId()); - if ($ad->status !== 'approved') { + if (!$builder->getFormValue('status') && $ad->status !== 'approved') { $ad->approve(); } diff --git a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php index 538657d81..ccfcbb300 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php @@ -3,6 +3,7 @@ use Anomaly\FilesModule\File\FileModel; use Anomaly\Streams\Platform\Addon\AddonCollection; use Anomaly\Streams\Platform\Addon\AddonServiceProvider; +use Anomaly\Streams\Platform\Model\Advs\AdvsStatusEntryModel; use Anomaly\Streams\Platform\Model\Location\LocationVillageEntryModel; use Anomaly\Streams\Platform\Ui\Table\Event\TableIsQuerying; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; @@ -21,6 +22,9 @@ use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface use Visiosoft\AdvsModule\Productoption\ProductoptionRepository; use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueRepositoryInterface; use Visiosoft\AdvsModule\ProductoptionsValue\ProductoptionsValueRepository; +use Visiosoft\AdvsModule\Status\Contract\StatusRepositoryInterface; +use Visiosoft\AdvsModule\Status\StatusModel; +use Visiosoft\AdvsModule\Status\StatusRepository; use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface; use Visiosoft\LocationModule\Village\VillageRepository; use Visiosoft\LocationModule\Village\VillageModel; @@ -229,6 +233,12 @@ class AdvsModuleServiceProvider extends AddonServiceProvider 'admin/advs/product_options' => 'Visiosoft\AdvsModule\Http\Controller\Admin\ProductoptionsController@index', 'admin/advs/product_options/create' => 'Visiosoft\AdvsModule\Http\Controller\Admin\ProductoptionsController@create', 'admin/advs/product_options/edit/{id}' => 'Visiosoft\AdvsModule\Http\Controller\Admin\ProductoptionsController@edit', + + // StatusController + 'ad/{ad_id}/change-status/{status_id}' => [ + 'as' => 'visiosoft.module.advs::ad.change.status', + 'uses' => 'Visiosoft\AdvsModule\Http\Controller\StatusController@change' + ], ]; protected $middleware = [ @@ -245,6 +255,7 @@ class AdvsModuleServiceProvider extends AddonServiceProvider protected $bindings = [ LocationVillageEntryModel::class => VillageModel::class, AdvsAdvsEntryModel::class => AdvModel::class, + AdvsStatusEntryModel::class => StatusModel::class, 'my_form' => AdvFormBuilder::class, ]; @@ -257,6 +268,7 @@ class AdvsModuleServiceProvider extends AddonServiceProvider ProductoptionRepositoryInterface::class => ProductoptionRepository::class, OptionConfigurationRepositoryInterface::class => OptionConfigurationRepository::class, ProductoptionsValueRepositoryInterface::class => ProductoptionsValueRepository::class, + StatusRepositoryInterface::class => StatusRepository::class, ]; public function boot(AddonCollection $addonCollection, FileModel $fileModel) diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/StatusController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/StatusController.php index e61072dd4..a6be53102 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/StatusController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/Admin/StatusController.php @@ -1,43 +1,33 @@ render(); } - /** - * Create a new entry. - * - * @param StatusFormBuilder $form - * @return \Symfony\Component\HttpFoundation\Response - */ public function create(StatusFormBuilder $form) { return $form->render(); } - /** - * Edit an existing entry. - * - * @param StatusFormBuilder $form - * @param $id - * @return \Symfony\Component\HttpFoundation\Response - */ - public function edit(StatusFormBuilder $form, $id) + public function edit(StatusFormBuilder $form, StatusRepositoryInterface $statusRepository, $id) { + $status = $statusRepository->find($id); + + if ($status->is_system) { + $form->skipField('user_access'); + } + + $form->skipField('is_system'); + $form->skipField('slug'); + return $form->render($id); } } diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/StatusController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/StatusController.php new file mode 100644 index 000000000..2ba44ab41 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/StatusController.php @@ -0,0 +1,37 @@ +advRepository = $advRepository; + $this->statusRepository = $statusRepository; + } + + public function change($adID, $statusID) + { + $ad = $this->advRepository->find($adID); + $status = $this->statusRepository->find($statusID); + + if (!$ad || !$status) { + abort(404); + } + + $ad->changeStatus($status->slug); + + $this->messages->success(trans( + 'visiosoft.module.advs::message.status_change', + ['status' => $status->name] + )); + + return redirect()->back(); + } +} diff --git a/addons/default/visiosoft/advs-module/src/Status/Contract/StatusRepositoryInterface.php b/addons/default/visiosoft/advs-module/src/Status/Contract/StatusRepositoryInterface.php index fe7c6a517..6d6833b4a 100644 --- a/addons/default/visiosoft/advs-module/src/Status/Contract/StatusRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Status/Contract/StatusRepositoryInterface.php @@ -4,5 +4,5 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface; interface StatusRepositoryInterface extends EntryRepositoryInterface { - + public function getUserAccessibleStatuses(); } diff --git a/addons/default/visiosoft/advs-module/src/Status/Form/StatusFormBuilder.php b/addons/default/visiosoft/advs-module/src/Status/Form/StatusFormBuilder.php index 426d3110d..3d61a7f2f 100644 --- a/addons/default/visiosoft/advs-module/src/Status/Form/StatusFormBuilder.php +++ b/addons/default/visiosoft/advs-module/src/Status/Form/StatusFormBuilder.php @@ -4,63 +4,7 @@ use Anomaly\Streams\Platform\Ui\Form\FormBuilder; class StatusFormBuilder extends FormBuilder { - - /** - * The form fields. - * - * @var array|string - */ - protected $fields = []; - - /** - * 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 = []; - - /** - * The form sections. - * - * @var array - */ - protected $sections = []; - - /** - * The form assets. - * - * @var array - */ - protected $assets = []; - } diff --git a/addons/default/visiosoft/advs-module/src/Status/StatusRepository.php b/addons/default/visiosoft/advs-module/src/Status/StatusRepository.php index fab83372a..7d54161c0 100644 --- a/addons/default/visiosoft/advs-module/src/Status/StatusRepository.php +++ b/addons/default/visiosoft/advs-module/src/Status/StatusRepository.php @@ -5,21 +5,15 @@ use Anomaly\Streams\Platform\Entry\EntryRepository; class StatusRepository extends EntryRepository implements StatusRepositoryInterface { - - /** - * The entry model. - * - * @var StatusModel - */ protected $model; - /** - * Create a new StatusRepository instance. - * - * @param StatusModel $model - */ public function __construct(StatusModel $model) { $this->model = $model; } + + public function getUserAccessibleStatuses() + { + return $this->newQuery()->where(['is_system' => 0, 'user_access' => 1])->get(); + } } diff --git a/addons/default/visiosoft/advs-module/src/Status/Table/StatusTableBuilder.php b/addons/default/visiosoft/advs-module/src/Status/Table/StatusTableBuilder.php index 950e729f0..a9f061c9a 100644 --- a/addons/default/visiosoft/advs-module/src/Status/Table/StatusTableBuilder.php +++ b/addons/default/visiosoft/advs-module/src/Status/Table/StatusTableBuilder.php @@ -4,60 +4,11 @@ use Anomaly\Streams\Platform\Ui\Table\TableBuilder; class StatusTableBuilder extends TableBuilder { - - /** - * The table views. - * - * @var array|string - */ - protected $views = []; - - /** - * The table filters. - * - * @var array|string - */ - protected $filters = []; - - /** - * The table columns. - * - * @var array|string - */ - protected $columns = [ - 'name', - ]; - - /** - * The table buttons. - * - * @var array|string - */ protected $buttons = [ 'edit' ]; - /** - * The table actions. - * - * @var array|string - */ protected $actions = [ 'delete' ]; - - /** - * The table options. - * - * @var array - */ - protected $options = []; - - /** - * The table assets. - * - * @var array - */ - protected $assets = []; - } diff --git a/addons/default/visiosoft/advs-module/src/Status/Table/StatusTableColumns.php b/addons/default/visiosoft/advs-module/src/Status/Table/StatusTableColumns.php new file mode 100644 index 000000000..9184d4381 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Status/Table/StatusTableColumns.php @@ -0,0 +1,28 @@ + [ + 'value' => function (EntryInterface $entry) use ($yes, $no) { + return $entry->is_system ? $yes : $no; + } + ], + 'user_access' => [ + 'value' => function (EntryInterface $entry) use ($yes, $no) { + return $entry->user_access ? $yes : $no; + } + ], + ]; + + $builder->setColumns($columns); + } +} diff --git a/addons/default/visiosoft/profile-module/resources/assets/js/ads.js b/addons/default/visiosoft/profile-module/resources/assets/js/ads.js index 67a85f9d0..5ecf7295e 100644 --- a/addons/default/visiosoft/profile-module/resources/assets/js/ads.js +++ b/addons/default/visiosoft/profile-module/resources/assets/js/ads.js @@ -164,6 +164,29 @@ function dropdownRow(id, type) { extend_ad + "\n"; + if (Object.keys(userStatus).length) { + let statusItems = '' + for (const status in userStatus) { + statusItems += ` +
  • + + ${userStatus[status]} + +
  • + ` + } + + dropdown += ` + + `; + } + dropdown += ""; return dropdown; @@ -173,6 +196,21 @@ function addDropdownBlock() { const dropdowns = $('.my-ads-dropdown') for (let i = 0; i < dropdowns.length; i++) { const currentDropdown = $(dropdowns[i]) - $('.dropdown-menu', currentDropdown).append(dropdownBlock.replace(':id', currentDropdown.data('id'))) + $('> .dropdown-menu', currentDropdown).append(dropdownBlock.replace(':id', currentDropdown.data('id'))) } } + +// Nested dropdown +$('.tab-pane').on('click', '.dropdown-menu button.dropdown-toggle', function(e) { + if (!$(this).next().hasClass('show')) { + $(this).parents('.dropdown-menu').first().find('.show').removeClass('show'); + } + var $subMenu = $(this).next('.dropdown-menu'); + $subMenu.toggleClass('show'); + + $(this).parents('.my-ads-dropdown.show').on('hidden.bs.dropdown', function(e) { + $('.dropdown-submenu .show').removeClass('show'); + }); + + return false; +}); diff --git a/addons/default/visiosoft/profile-module/resources/views/profile/ads.twig b/addons/default/visiosoft/profile-module/resources/views/profile/ads.twig index 225679fb3..8a1062eda 100644 --- a/addons/default/visiosoft/profile-module/resources/views/profile/ads.twig +++ b/addons/default/visiosoft/profile-module/resources/views/profile/ads.twig @@ -74,6 +74,8 @@ var edit_ad = "{{ trans('visiosoft.module.profile::button.edit') }}"; var ads_per_page = "{{ setting_value('streams::per_page') }}"; var no_ads_message = "{{ trans('visiosoft.module.advs::field.no_ads') }}"; + let userStatus = JSON.parse(`{{ userStatus|raw }}`) + let statusChangeLink = `{{ changeStatusUrl }}` let dropdownBlock = `{{ addBlock('profile/dropdown-ad', {'id': ':id'})|raw }}` {{ asset_add('scripts.js','visiosoft.module.profile::assets/js/ads.js') }} diff --git a/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php b/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php index c4f169965..3bc410054 100644 --- a/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php +++ b/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Auth; use Rinvex\Subscriptions\Models\Plan; use Visiosoft\AdvsModule\Adv\AdvModel; use Visiosoft\AdvsModule\Adv\Event\ChangeStatusAd; +use Visiosoft\AdvsModule\Status\Contract\StatusRepositoryInterface; use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\AlgoliaModule\Search\SearchModel; use Visiosoft\CloudsiteModule\CloudsiteModule; @@ -222,9 +223,14 @@ class MyProfileController extends PublicController } - public function myAds() + public function myAds(StatusRepositoryInterface $statusRepository) { - return $this->view->make('visiosoft.module.profile::profile/ads'); + $userStatus = $statusRepository->getUserAccessibleStatuses()->pluck('name', 'id')->toJson(); + $changeStatusUrl = route('visiosoft.module.advs::ad.change.status', [':adID', ':statusID']); + return $this->view->make( + 'visiosoft.module.profile::profile/ads', + compact('userStatus', 'changeStatusUrl') + ); } public function updateAjaxProfile(UserRepositoryInterface $user) diff --git a/addons/default/visiosoft/profile-module/src/ProfileModuleServiceProvider.php b/addons/default/visiosoft/profile-module/src/ProfileModuleServiceProvider.php index 15d9efa83..2d8df1b3e 100644 --- a/addons/default/visiosoft/profile-module/src/ProfileModuleServiceProvider.php +++ b/addons/default/visiosoft/profile-module/src/ProfileModuleServiceProvider.php @@ -26,42 +26,10 @@ use Visiosoft\ProfileModule\Profile\User\UserFormBuilder; class ProfileModuleServiceProvider extends AddonServiceProvider { - - /** - * Additional addon plugins. - * - * @type array|null - */ protected $plugins = [ ProfileModulePlugin::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 AdressController 'admin/profile' => 'Visiosoft\ProfileModule\Http\Controller\Admin\AdressController@index', @@ -147,58 +115,10 @@ class ProfileModuleServiceProvider extends AddonServiceProvider 'ajax/get-user-info' => 'Visiosoft\ProfileModule\Http\Controller\CacheController@getUserInfo', ]; - /** - * The addon middleware. - * - * @type array|null - */ - protected $middleware = [ - //Visiosoft\ProfileModule\Http\Middleware\ExampleMiddleware::class - ]; - - /** - * Addon group middleware. - * - * @var array - */ - protected $groupMiddleware = [ - //'web' => [ - // Visiosoft\ProfileModule\Http\Middleware\ExampleMiddleware::class, - //], - ]; - - /** - * Addon route middleware. - * - * @type array|null - */ - protected $routeMiddleware = []; - - /** - * The addon event listeners. - * - * @type array|null - */ - protected $listeners = [ - //Visiosoft\ProfileModule\Event\ExampleEvent::class => [ - // Visiosoft\ProfileModule\Listener\ExampleListener::class, - //], - ]; - - /** - * The addon alias bindings. - * - * @type array|null - */ protected $aliases = [ 'Excel' => Excel::class, ]; - /** - * The addon class bindings. - * - * @type array|null - */ protected $bindings = [ 'updatePassword' => PasswordFormBuilder::class, 'userProfile' => UserFormBuilder::class, @@ -210,11 +130,6 @@ class ProfileModuleServiceProvider extends AddonServiceProvider ProfileEducationEntryModel::class => EducationModel::class, ]; - /** - * The addon singleton bindings. - * - * @type array|null - */ protected $singletons = [ AdressRepositoryInterface::class => AdressRepository::class, EducationRepositoryInterface::class => EducationRepository::class, @@ -223,47 +138,10 @@ class ProfileModuleServiceProvider extends AddonServiceProvider 'forgot_pass' => ForgotPassFormBuilder::class, ]; - /** - * Additional service providers. - * - * @type array|null - */ protected $providers = [ ExcelServiceProvider::class, ]; - /** - * The addon view overrides. - * - * @type array|null - */ - protected $overrides = [ - //'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(AddonCollection $addonCollection) { $slug = 'export'; @@ -273,16 +151,4 @@ class ProfileModuleServiceProvider extends AddonServiceProvider ]; $addonCollection->get('anomaly.module.users')->addSection($slug, $section); } - - /** - * 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. - } - }