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