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\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']]);

View File

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

View File

@ -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 = '<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, {
alias: this.installation.alias,
version: this.installation.version,
path: this.installation.path,
}));

View File

@ -233,7 +233,7 @@
@else
@can('create-modules-item')
@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') }}
</button>
@else

View File

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