Skip to content

Commit

Permalink
v0.1.0.2-alpha
Browse files Browse the repository at this point in the history
- Fixed module installation
- Fixed some translation issues
- Fixed empty table loading
  • Loading branch information
FlamesONE committed Mar 30, 2024
1 parent 101597f commit 04a2327
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 11 deletions.
40 changes: 33 additions & 7 deletions app/Core/Admin/Http/Controllers/Api/ModulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ModulesController extends AbstractController
public function __construct(ModuleManager $moduleManager, ModuleActions $moduleActions)
{
HasPermissionMiddleware::permission('admin.modules');

$this->moduleManager = $moduleManager;
$this->actions = $moduleActions;
}
Expand Down Expand Up @@ -139,20 +139,23 @@ protected function processZipFile(UploadedFile $file): Response
return $this->error(__('admin.modules_list.single_folder_expected'));
}

$folderName = str_replace('-main', '', reset($rootFolders));
// Remove '-main' suffix from the folder name
$originalFolderName = reset($rootFolders);
$folderName = preg_replace('/-main$/', '', $originalFolderName);
$extractPath = BASE_PATH . 'app/Modules/';

if( $this->moduleManager->issetModule($folderName) )
if ($this->moduleManager->issetModule($folderName))
return $this->error(__('admin.modules_list.module_already_exists'));

if (!fs()->exists($extractPath . $folderName)) {
fs()->mkdir($extractPath . $folderName, 0755);
}

if (!$zip->extractTo($extractPath)) {
$zip->close();
fs()->remove($extractPath . $folderName); // Clean up on failure
return $this->error(__('admin.modules_list.zip_extraction_failed'));
// Extract ZIP contents into the renamed folder
for ($i = 0; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
$newFilename = preg_replace('/^' . preg_quote($originalFolderName, '/') . '/', $folderName, $filename);
$this->extractFile($zip, $filename, $extractPath . $newFilename);
}

$zip->close();
Expand Down Expand Up @@ -196,6 +199,29 @@ protected function processZipFile(UploadedFile $file): Response
]);
}

/**
* Extracts a single file from a ZipArchive.
*
* @param ZipArchive $zip
* @param string $filename
* @param string $destination
*/
protected function extractFile($zip, $filename, $destination)
{
$fileStream = $zip->getStream($filename);
if (!$fileStream) {
throw new \Exception("Unable to retrieve stream for file $filename in ZIP archive.");
}

$dir = dirname($destination);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}

file_put_contents($destination, $fileStream);
fclose($fileStream);
}

/**
* Get the root folders in the ZIP archive.
*
Expand Down
7 changes: 7 additions & 0 deletions app/Core/Admin/Http/Views/assets/styles/base/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,11 @@ a {
&:hover {
color: darken($color-primary, 10);
}
}

.table_empty {
opacity: .5;
font-weight: 500;
text-align: center;
font-size: 20px;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@extends('Core.Admin.Http.Views.layout', [
'title' => __('admin.title', ['name' => __('admin.payments.payments')]),
'title' => __('admin.title', ['name' => __('admin.payments.payments_header')]),
])

@push('content')
Expand Down
2 changes: 1 addition & 1 deletion app/Core/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class App
*
* @var string
*/
public const VERSION = '0.1.0.1-alpha';
public const VERSION = '0.1.0.2-alpha';

/**
* Set the base path of the application
Expand Down
2 changes: 1 addition & 1 deletion app/Core/Http/Views/Installer/steps/1.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@endforeach
</div>

@btnInst(['text' => __('Продолжить'), 'disabled' => true])
@btnInst(['text' => __('def.continue'), 'disabled' => true])
</div>
@endpush

Expand Down
2 changes: 1 addition & 1 deletion app/Core/Http/Views/Installer/steps/7.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</form>
</div>
</div>
@btnInst(['text' => __('Завершить установку'), 'id' => 'continue'])
@btnInst(['text' => __('install.finish'), 'id' => 'continue'])
@endpush

@push('footer')
Expand Down
12 changes: 12 additions & 0 deletions app/Core/Table/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,25 @@ function(data, type, full, meta) {
return $this;
}

protected function generateEmpty() : string
{
$div = Html::el('div')->class('table_empty');
$div->addHtml(__('def.no_results_found'));

return $div->render();
}

/**
* Рендеринг HTML-таблицы.
*
* @return string HTML-код таблицы.
*/
public function render()
{
if( sizeof( $this->data ) === 0 && !$this->ajaxPath ) {
return $this->generateEmpty();
}

// Pretend multiload table styles on 1 page
if (!self::$initialised) {
template()->addStyle('tables_css');
Expand Down

0 comments on commit 04a2327

Please sign in to comment.