From fdd1011b3a228b5ae701bf870a36054dfcea1bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 1 Jun 2021 23:58:08 +0300 Subject: [PATCH] Wizard page re-factoring.. --- .../Data.php => ViewComposers/Wizard.php} | 101 ++++---- app/Providers/ViewComposer.php | 5 + resources/assets/js/Wizard.vue | 39 ++-- resources/assets/js/views/wizard/Company.vue | 220 +++++++++--------- .../views/partials/wizard/scripts.blade.php | 9 + routes/wizard.php | 2 - 6 files changed, 198 insertions(+), 178 deletions(-) rename app/Http/{Controllers/Wizard/Data.php => ViewComposers/Wizard.php} (73%) diff --git a/app/Http/Controllers/Wizard/Data.php b/app/Http/ViewComposers/Wizard.php similarity index 73% rename from app/Http/Controllers/Wizard/Data.php rename to app/Http/ViewComposers/Wizard.php index fa3a43b9f..6dd7594f7 100644 --- a/app/Http/Controllers/Wizard/Data.php +++ b/app/Http/ViewComposers/Wizard.php @@ -1,39 +1,58 @@ middleware('permission:create-common-companies')->only('create', 'store', 'duplicate', 'import'); - $this->middleware('permission:read-common-companies')->only('index', 'show', 'edit', 'export'); - $this->middleware('permission:update-common-companies')->only('update', 'enable', 'disable'); - $this->middleware('permission:delete-common-companies')->only('destroy'); + $translations = $this->getTransalations(); + + $currencies = $this->getCurrencies(); + + // Prepare codes + $codes = $this->getCurrencyCodes(); + + $taxes = $this->getTaxes(); + + $modules = $this->getFeaturedModules([ + 'query' => [ + 'limit' => 4 + ] + ]); + + $company = $this->getCompany(); + + $view->with([ + 'translations' => $translations, + 'company' => $company, + 'currencies' => $currencies, + 'currency_codes' => $codes, + 'taxes' => $taxes, + 'modules' => $modules, + ]); } - /** - * Show the form for creating a new resource. - * - * @return Response - */ - public function index() + /* Wizard page transactions */ + protected function getTransalations() { - $translations = [ + return [ 'company' => [ 'title' => trans_choice('general.companies', 1), 'api_key' => trans('modules.api_key'), @@ -101,10 +120,15 @@ class Data extends Controller 'error_message' => trans('errors.title.500'), ] ]; + } - $currencies = Currency::collect(); + protected function getCurrencies() + { + return Currency::all(); + } - // Prepare codes + protected function getCurrencyCodes() + { $codes = []; $money_currencies = MoneyCurrency::getCurrencies(); @@ -112,39 +136,28 @@ class Data extends Controller $codes[$key] = $key; } - $taxes = Tax::collect(); + return $codes; + } - $modules = $this->getFeaturedModules([ - 'query' => [ - 'limit' => 4 - ] - ]); + protected function getTaxes() + { + return Tax::all(); + } + protected function getCompany() + { $company = company(); $company->api_key = setting('apps.api_key'); $company->financial_start = setting('localisation.financial_start'); - if ($company->logo) { - $logo = \Plank\Mediable\Media::find($company->logo); + $logo_id = setting('company.logo'); - $logo->path = route('uploads.get', $logo->id); + $logo = Media::find($logo_id); + $logo->path = route('uploads.get', $logo->id); - $company->logo = $logo; - } + $company->logo = $logo; - return response()->json([ - 'success' => true, - 'errors' => false, - 'message' => 'Get all data...', - 'data' => [ - 'translations' => $translations, - 'company' => $company, - 'currencies' => $currencies, - 'currency_codes' => $codes, - 'taxes' => $taxes, - 'modules' => $modules, - ], - ]); + return $company; } } diff --git a/app/Providers/ViewComposer.php b/app/Providers/ViewComposer.php index db7bd740a..844a31dbf 100644 --- a/app/Providers/ViewComposer.php +++ b/app/Providers/ViewComposer.php @@ -73,6 +73,11 @@ class ViewComposer extends Provider ['documents.*', 'portal.documents.*'], 'App\Http\ViewComposers\DocumentType' ); + + // Wizard + View::composer( + 'layouts.wizard', 'App\Http\ViewComposers\Wizard' + ); } /** diff --git a/resources/assets/js/Wizard.vue b/resources/assets/js/Wizard.vue index 6131491eb..f5a8a293c 100644 --- a/resources/assets/js/Wizard.vue +++ b/resources/assets/js/Wizard.vue @@ -13,42 +13,35 @@ + + @stack('body_css') diff --git a/routes/wizard.php b/routes/wizard.php index 3f3f951ec..a746cfb07 100644 --- a/routes/wizard.php +++ b/routes/wizard.php @@ -9,8 +9,6 @@ use Illuminate\Support\Facades\Route; */ Route::group(['as' => 'wizard.'], function () { - Route::get('data', 'Wizard\Data@index')->name('data.index'); - Route::get('companies', 'Wizard\Companies@edit')->name('companies.edit'); Route::post('companies', 'Wizard\Companies@update')->middleware('dropzone')->name('companies.update');