Apps install page re-factoring..

This commit is contained in:
Cüneyt Şentürk 2020-12-12 14:59:58 +03:00
parent d15677c2ac
commit d972748a9e
5 changed files with 79 additions and 26 deletions

View File

@ -5,7 +5,9 @@ namespace App\Http\Controllers\Modules;
use App\Abstracts\Http\Controller; use App\Abstracts\Http\Controller;
use App\Models\Module\Module; use App\Models\Module\Module;
use App\Traits\Modules; use App\Traits\Modules;
use File;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Str;
class Item extends Controller class Item extends Controller
{ {
@ -79,7 +81,11 @@ class Item extends Controller
$steps = []; $steps = [];
$name = $request['name']; $name = $request['name'];
$alias = $request['alias'];
$module_path = config('module.paths.modules') . '/' . Str::studly($alias);
if (!File::isDirectory($module_path)) {
// Download // Download
$steps[] = [ $steps[] = [
'text' => trans('modules.installation.download', ['module' => $name]), 'text' => trans('modules.installation.download', ['module' => $name]),
@ -92,11 +98,24 @@ class Item extends Controller
'url' => route('apps.unzip') 'url' => route('apps.unzip')
]; ];
// Download // Copy
$steps[] = [
'text' => trans('modules.installation.file_copy', ['module' => $name]),
'url' => route('apps.copy')
];
// Install
$steps[] = [ $steps[] = [
'text' => trans('modules.installation.install', ['module' => $name]), 'text' => trans('modules.installation.install', ['module' => $name]),
'url' => route('apps.install') 'url' => route('apps.install')
]; ];
} else {
// Install
$steps[] = [
'text' => trans('modules.installation.install', ['module' => $name]),
'url' => route('apps.install')
];
}
return response()->json([ return response()->json([
'success' => true, 'success' => true,
@ -149,11 +168,27 @@ class Item extends Controller
* *
* @return Response * @return Response
*/ */
public function install(Request $request) public function copy(Request $request)
{ {
$path = $request['path']; $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']) { if ($json['success']) {
$message = trans('modules.installed', ['module' => $json['data']['name']]); $message = trans('modules.installed', ['module' => $json['data']['name']]);

View File

@ -390,7 +390,7 @@ trait Modules
]; ];
} }
public function installModule($path) public function copyModule($path)
{ {
$temp_path = storage_path('app/temp/' . $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'))); 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'); $company_id = session('company_id');
$locale = app()->getLocale(); $locale = app()->getLocale();
$command = "module:install {$module->alias} {$company_id} {$locale}"; $command = "module:install {$alias} {$company_id} {$locale}";
if (true !== $result = Console::run($command)) { 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 [ return [
'success' => false, 'success' => false,
@ -443,13 +456,13 @@ trait Modules
return [ return [
'success' => true, 'success' => true,
'redirect' => route('apps.app.show', $module->alias), 'redirect' => route('apps.app.show', $alias),
'error' => false, 'error' => false,
'message' => null, 'message' => null,
'data' => [ 'data' => [
'path' => $path, 'path' => '',
'name' => module($module->alias)->getName(), 'name' => module($alias)->getName(),
'alias' => $module->alias, 'alias' => $alias,
], ],
]; ];
} }

View File

@ -52,6 +52,7 @@ const app = new Vue({
steps_total: 0, steps_total: 0,
total: 0, total: 0,
path: '', path: '',
alias: '',
version: '', version: '',
status: 'success', status: 'success',
html: '' html: ''
@ -98,7 +99,8 @@ const app = new Vue({
this.faq = true; this.faq = true;
}, },
async onInstall(path, name, version) { async onInstall(path, alias, name, version) {
this.installation.alias = alias;
this.installation.show = true; this.installation.show = true;
this.installation.total = 0; this.installation.total = 0;
this.installation.path = path; this.installation.path = path;
@ -106,6 +108,7 @@ const app = new Vue({
let steps_promise = Promise.resolve(axios.post(url + '/apps/steps', { let steps_promise = Promise.resolve(axios.post(url + '/apps/steps', {
name: name, name: name,
alias: alias,
version: version version: version
})); }));
@ -136,6 +139,7 @@ const app = new Vue({
this.installation.html = '<span class="text-default"><i class="fa fa-spinner fa-spin update-spin"></i> ' + data['text'] + '</span> </br>'; this.installation.html = '<span class="text-default"><i class="fa fa-spinner fa-spin update-spin"></i> ' + data['text'] + '</span> </br>';
let step_promise = Promise.resolve(axios.post(data.url, { let step_promise = Promise.resolve(axios.post(data.url, {
alias: this.installation.alias,
version: this.installation.version, version: this.installation.version,
path: this.installation.path, path: this.installation.path,
})); }));

View File

@ -233,7 +233,7 @@
@else @else
@can('create-modules-item') @can('create-modules-item')
@if ($module->install) @if ($module->install)
<button type="button" @click="onInstall('{{ $module->action_url }}', '{{ $module->name }}', '{{ $module->version }}')" class="btn btn-success btn-block" id="install-module"> <button type="button" @click="onInstall('{{ $module->action_url }}', '{{ $module->slug }}', '{{ $module->name }}', '{{ $module->version }}')" class="btn btn-success btn-block" id="install-module">
{{ trans('modules.install') }} {{ trans('modules.install') }}
</button> </button>
@else @else

View File

@ -196,6 +196,7 @@ Route::group(['as' => 'apps.', 'prefix' => 'apps'], function () {
Route::post('steps', 'Modules\Item@steps')->name('steps'); Route::post('steps', 'Modules\Item@steps')->name('steps');
Route::post('download', 'Modules\Item@download')->name('download'); Route::post('download', 'Modules\Item@download')->name('download');
Route::post('unzip', 'Modules\Item@unzip')->name('unzip'); 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('install', 'Modules\Item@install')->name('install');
Route::post('{alias}/reviews', 'Modules\Item@reviews')->name('app.reviews'); Route::post('{alias}/reviews', 'Modules\Item@reviews')->name('app.reviews');