From d972748a9e938a81ac8e9ee5d71a00825193c480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 12 Dec 2020 14:59:58 +0300 Subject: [PATCH] Apps install page re-factoring.. --- app/Http/Controllers/Modules/Item.php | 69 ++++++++++++++++----- app/Traits/Modules.php | 27 +++++--- resources/assets/js/views/modules/item.js | 6 +- resources/views/modules/item/show.blade.php | 2 +- routes/admin.php | 1 + 5 files changed, 79 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/Modules/Item.php b/app/Http/Controllers/Modules/Item.php index 158b2b81d..c1e58412c 100644 --- a/app/Http/Controllers/Modules/Item.php +++ b/app/Http/Controllers/Modules/Item.php @@ -5,7 +5,9 @@ namespace App\Http\Controllers\Modules; use App\Abstracts\Http\Controller; use App\Models\Module\Module; use App\Traits\Modules; +use File; use Illuminate\Http\Request; +use Illuminate\Support\Str; class Item extends Controller { @@ -79,24 +81,41 @@ class Item extends Controller $steps = []; $name = $request['name']; + $alias = $request['alias']; - // Download - $steps[] = [ - 'text' => trans('modules.installation.download', ['module' => $name]), - 'url' => route('apps.download') - ]; + $module_path = config('module.paths.modules') . '/' . Str::studly($alias); - // Unzip - $steps[] = [ - 'text' => trans('modules.installation.unzip', ['module' => $name]), - 'url' => route('apps.unzip') - ]; + if (!File::isDirectory($module_path)) { + // Download + $steps[] = [ + 'text' => trans('modules.installation.download', ['module' => $name]), + 'url' => route('apps.download') + ]; - // Download - $steps[] = [ - 'text' => trans('modules.installation.install', ['module' => $name]), - 'url' => route('apps.install') - ]; + // Unzip + $steps[] = [ + 'text' => trans('modules.installation.unzip', ['module' => $name]), + 'url' => route('apps.unzip') + ]; + + // Copy + $steps[] = [ + 'text' => trans('modules.installation.file_copy', ['module' => $name]), + 'url' => route('apps.copy') + ]; + + // Install + $steps[] = [ + 'text' => trans('modules.installation.install', ['module' => $name]), + 'url' => route('apps.install') + ]; + } else { + // Install + $steps[] = [ + 'text' => trans('modules.installation.install', ['module' => $name]), + 'url' => route('apps.install') + ]; + } return response()->json([ 'success' => true, @@ -149,11 +168,27 @@ class Item extends Controller * * @return Response */ - public function install(Request $request) + public function copy(Request $request) { $path = $request['path']; - $json = $this->installModule($path); + $json = $this->copyModule($path); + + return response()->json($json); + } + + /** + * Show the form for viewing the specified resource. + * + * @param $request + * + * @return Response + */ + public function install(Request $request) + { + $alias = $request['alias']; + + $json = $this->installModule($alias); if ($json['success']) { $message = trans('modules.installed', ['module' => $json['data']['name']]); diff --git a/app/Traits/Modules.php b/app/Traits/Modules.php index 2bb37598f..2686e7c78 100644 --- a/app/Traits/Modules.php +++ b/app/Traits/Modules.php @@ -390,7 +390,7 @@ trait Modules ]; } - public function installModule($path) + public function copyModule($path) { $temp_path = storage_path('app/temp/' . $path); @@ -425,13 +425,26 @@ trait Modules event(new \App\Events\Module\Copied($module->alias, session('company_id'))); + return [ + 'success' => true, + 'error' => false, + 'message' => null, + 'data' => [ + 'path' => $path, + 'alias' => $module->alias, + ], + ]; + } + + public function installModule($alias) + { $company_id = session('company_id'); $locale = app()->getLocale(); - $command = "module:install {$module->alias} {$company_id} {$locale}"; + $command = "module:install {$alias} {$company_id} {$locale}"; if (true !== $result = Console::run($command)) { - $message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $module->alias]); + $message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $alias]); return [ 'success' => false, @@ -443,13 +456,13 @@ trait Modules return [ 'success' => true, - 'redirect' => route('apps.app.show', $module->alias), + 'redirect' => route('apps.app.show', $alias), 'error' => false, 'message' => null, 'data' => [ - 'path' => $path, - 'name' => module($module->alias)->getName(), - 'alias' => $module->alias, + 'path' => '', + 'name' => module($alias)->getName(), + 'alias' => $alias, ], ]; } diff --git a/resources/assets/js/views/modules/item.js b/resources/assets/js/views/modules/item.js index 6abd2c51b..b6d5163d0 100644 --- a/resources/assets/js/views/modules/item.js +++ b/resources/assets/js/views/modules/item.js @@ -52,6 +52,7 @@ const app = new Vue({ steps_total: 0, total: 0, path: '', + alias: '', version: '', status: 'success', html: '' @@ -98,7 +99,8 @@ const app = new Vue({ this.faq = true; }, - async onInstall(path, name, version) { + async onInstall(path, alias, name, version) { + this.installation.alias = alias; this.installation.show = true; this.installation.total = 0; this.installation.path = path; @@ -106,6 +108,7 @@ const app = new Vue({ let steps_promise = Promise.resolve(axios.post(url + '/apps/steps', { name: name, + alias: alias, version: version })); @@ -136,6 +139,7 @@ const app = new Vue({ this.installation.html = ' ' + data['text'] + '
'; let step_promise = Promise.resolve(axios.post(data.url, { + alias: this.installation.alias, version: this.installation.version, path: this.installation.path, })); diff --git a/resources/views/modules/item/show.blade.php b/resources/views/modules/item/show.blade.php index 8a8d2f8a1..686905e69 100644 --- a/resources/views/modules/item/show.blade.php +++ b/resources/views/modules/item/show.blade.php @@ -233,7 +233,7 @@ @else @can('create-modules-item') @if ($module->install) - @else diff --git a/routes/admin.php b/routes/admin.php index ee2ea519c..c7ebcd946 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -196,6 +196,7 @@ Route::group(['as' => 'apps.', 'prefix' => 'apps'], function () { Route::post('steps', 'Modules\Item@steps')->name('steps'); Route::post('download', 'Modules\Item@download')->name('download'); Route::post('unzip', 'Modules\Item@unzip')->name('unzip'); + Route::post('copy', 'Modules\Item@copy')->name('copy'); Route::post('install', 'Modules\Item@install')->name('install'); Route::post('{alias}/reviews', 'Modules\Item@reviews')->name('app.reviews');