Skip to content

Commit

Permalink
v0.2.2-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
FlamesONE committed Jun 24, 2024
1 parent 5acaa8c commit 7002df8
Show file tree
Hide file tree
Showing 50 changed files with 2,230 additions and 470 deletions.
6 changes: 3 additions & 3 deletions app/Core/Admin/Http/Controllers/Api/DatabasesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(DatabasesService $databasesService)
public function store(FluteRequest $request): Response
{
try {
$this->validate($request);
$this->validation($request);

$this->databasesService->store(
$request->mod,
Expand Down Expand Up @@ -50,7 +50,7 @@ public function delete(FluteRequest $request, $id): Response
public function update(FluteRequest $request, $id): Response
{
try {
$this->validate($request);
$this->validation($request);

$this->databasesService->update(
(int) $id,
Expand All @@ -66,7 +66,7 @@ public function update(FluteRequest $request, $id): Response
}
}

protected function validate( FluteRequest $request )
protected function validation( FluteRequest $request )
{
if( empty( $request->input('mod') ) || empty( $request->input('dbname') ) )
throw new \Exception(__('admin.databases.params_empty'));
Expand Down
17 changes: 17 additions & 0 deletions app/Core/Admin/Http/Controllers/Api/IconsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Flute\Core\Admin\Http\Controllers\Api;

use Flute\Core\PhosphorIcons\PhosphorIconsParser;
use Flute\Core\Support\AbstractController;
use Flute\Core\Support\FluteRequest;

class IconsController extends AbstractController
{
public function getAll(FluteRequest $request)
{
return $this->json([
'icons' => app(PhosphorIconsParser::class)->getAll()
]);
}
}
6 changes: 3 additions & 3 deletions app/Core/Admin/Http/Controllers/Api/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public function saveOrder(FluteRequest $request)
foreach ($order as $value) {
$item = rep(NavbarItem::class)->select()->load('roles')->where(['id' => (int) $value['id']])->fetchOne();

if ($item && navbar()->hasAccess($item)) {
if ($item && navbar()->hasAccess($item, true)) {
$item->position = $value['position'];

if ($value['parent_id'] == null) {
$item->parent = null;
} else {
$parent = rep(NavbarItem::class)->select()->load('roles')->where(['id' => (int) $value['parent_id']])->fetchOne();

if ($parent && navbar()->hasAccess($parent))
if ($parent && navbar()->hasAccess($parent, true))
$item->parent = $parent;
}

Expand Down Expand Up @@ -151,7 +151,7 @@ protected function getItem(string $id)
if (!$navigation)
return $this->error(__('admin.navigation.not_found'), 404);

if (!navbar()->hasAccess($navigation))
if (!navbar()->hasAccess($navigation, true))
return $this->error(__('def.no_access'));

return $navigation;
Expand Down
6 changes: 4 additions & 2 deletions app/Core/Admin/Http/Controllers/Api/ServersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ public function checkRcon(FluteRequest $request)

try {
$query = new SourceQuery();
$query->Connect($ip, $port, 5, ((int) $game === 10) ? SourceQuery::GOLDSOURCE : SourceQuery::SOURCE);

$query->Connect($ip, $port, 3, ((int) $game === 10) ? SourceQuery::GOLDSOURCE : SourceQuery::SOURCE);
$query->SetRconPassword($rcon);

$rcon = $query->Rcon($command);

return $this->success($rcon);
return $this->json([
'result' => $rcon
]);
} catch (\Exception $e) {
return $this->error($e->getMessage());
} finally {
Expand Down
2 changes: 1 addition & 1 deletion app/Core/Admin/Http/Controllers/Views/NavbarView.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function edit(FluteRequest $request, string $id)
{
$navigation = rep(NavbarItem::class)->select()->load('roles')->where('id', (int) $id)->fetchOne();

if (!navbar()->hasAccess($navigation))
if (!navbar()->hasAccess($navigation, true))
return $this->error(__('def.no_access'));

if (!$navigation)
Expand Down
13 changes: 11 additions & 2 deletions app/Core/Admin/Http/Controllers/Views/Payments/PaymentsView.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public function edit(FluteRequest $request, string $id): Response
return view("Core/Admin/Http/Views/pages/payments/edit", [
'gateway' => $payment,
'additional' => \Nette\Utils\Json::decode($payment->additional),
'drivers' => $this->getAllDrivers()
'drivers' => $this->getAllDrivers($payment->adapter)
]);
}

protected function getAllDrivers()
protected function getAllDrivers(?string $currentGateway = null)
{
$namespaceMap = app()->getLoader()->getPrefixesPsr4();
$result = [];
Expand Down Expand Up @@ -215,6 +215,15 @@ protected function getAllDrivers()
}
}

foreach ($result as $key => $val) {
$find = rep(PaymentGateway::class)->findOne([
"adapter" => $val['name']
]);

if ($find && $currentGateway !== $val['name'])
unset($result[$key]);
}

return $result;
}

Expand Down
15 changes: 11 additions & 4 deletions app/Core/Admin/Http/Controllers/Views/SocialsView.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function edit(FluteRequest $request, string $id): Response

return view("Core/Admin/Http/Views/pages/socials/edit", [
'social' => $social,
'drivers' => $this->getAllDrivers()
'drivers' => $this->getAllDrivers($social->key)
]);
}

Expand All @@ -147,7 +147,7 @@ protected function getSocialNetwork(int $id): ?SocialNetwork
return rep(SocialNetwork::class)->findByPK($id);
}

protected function getAllDrivers()
protected function getAllDrivers(?string $currentDriver = null)
{
$namespaceMap = app()->getLoader()->getPrefixesPsr4();
$result = [];
Expand Down Expand Up @@ -175,9 +175,16 @@ protected function getAllDrivers()
return Strings::startsWith($item, "Hybridauth\\Provider");
}), $result);

foreach( $result as $key => $item ) {
foreach ($result as $key => $item) {
$ex = explode('\\', $item);
$result[$key] = $ex[array_key_last($ex)];
$driver = $ex[array_key_last($ex)];

$find = rep(SocialNetwork::class)->findOne([
"key" => $driver
]);

if (!$find || ($driver === $currentDriver))
$result[$key] = $driver;
}

return $result;
Expand Down
30 changes: 23 additions & 7 deletions app/Core/Admin/Http/Views/assets/js/components/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const contentCache = {};
constructor() {
this.draggabillies = [];
this.contentContainers = {};
this.abortControllers = {};
}

init(el) {
Expand Down Expand Up @@ -425,6 +426,12 @@ const contentCache = {};
// Получаем ID вкладки
const tabId = tabEl.getAttribute('data-tab-id');

// Отмена загрузки контента при закрытии вкладки
if (this.abortControllers[tabId]) {
this.abortControllers[tabId].abort();
delete this.abortControllers[tabId];
}

// Удаляем контейнер контента, связанный с этой вкладкой
const contentContainer = document.getElementById(
`content-${tabId}`,
Expand Down Expand Up @@ -758,27 +765,34 @@ function refreshCurrentPage() {
}

function fetchContent(url, container, tabEl, reload = false, title = null) {
fetch(appendGet(url, 'loadByTab', '1'))
const tabId = tabEl.getAttribute('data-tab-id');
const abortController = new AbortController();
chromeTabs.abortControllers[tabId] = abortController;

fetch(appendGet(url, 'loadByTab', '1'), { signal: abortController.signal })
.then((response) => {
if (!response.ok) {
throw new Error('Not 2xx response', { cause: response });
}

return response.text();
})
.then((html) => {
const containerId = container.getAttribute('id');
if (!container) return; // Check if container is still in DOM

const containerId = container.getAttribute('id');
container.classList.remove('loading');
container.innerHTML = html;

loadScriptsFromContainer(containerId);

recoverContainerIDS(containerId);
})
.catch((error) => {
console.error('Error loading the page: ', error);
showErrorPage(true);
if (error.name === 'AbortError') {
console.log('Content load aborted:', url);
} else {
console.error('Error loading the page: ', error);
showErrorPage(true);
}
})
.finally(() => {
setTimeout(() => {
Expand All @@ -793,6 +807,7 @@ function fetchContent(url, container, tabEl, reload = false, title = null) {
}, 700);
});
}

function displayLoading(show) {
const loadingElement = document.getElementById('loading');
loadingElement.style.setProperty('--animate-duration', '.3s');
Expand Down Expand Up @@ -1048,14 +1063,15 @@ function removeScriptsByContainerId(containerId) {
function initEditor(container) {
container.find('.editor-ace').each(function () {
let editor = ace.edit(this);
let mode = $(this).data('editor-lang') || 'json';
let unformattedContent = editor.getSession().getValue();
let formattedContent = js_beautify(unformattedContent, {
indent_size: 4,
space_in_empty_paren: true,
});
editor.getSession().setValue(formattedContent);
editor.setTheme('ace/theme/solarized_dark');
editor.session.setMode('ace/mode/json');
editor.session.setMode(`ace/mode/${mode}`);
});
}

Expand Down
116 changes: 98 additions & 18 deletions app/Core/Admin/Http/Views/assets/js/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ function transformUrl(url) {
}
}

function sendRequest(data, path = null, method = 'POST', callback) {
function sendRequest(
data,
path = null,
method = 'POST',
callback = null,
needToRefresh = true,
) {
toast({
type: 'async',
message: translate('admin.is_loading'),
Expand All @@ -93,27 +99,31 @@ function sendRequest(data, path = null, method = 'POST', callback) {
data: data,
success: function (response) {
callback && callback(response);
Modals.clear();

if (method === 'DELETE') {
tryAndDeleteTab(transformUrl(path));
refreshCurrentPage();
} else {
refreshCurrentPage();
if (!path.includes('admin/api/settings')) {
if (
path.includes('edit') ||
path.includes('add') ||
path.includes('delete')
)
fetchContentAndAddTab(
replaceURLForTab(
window.location.pathname,
),
);
if (needToRefresh) {
Modals.clear();

if (method === 'DELETE') {
tryAndDeleteTab(transformUrl(path));
refreshCurrentPage();
} else {
refreshCurrentPage();
if (!path.includes('admin/api/settings')) {
if (
path.includes('edit') ||
path.includes('add') ||
path.includes('delete')
)
fetchContentAndAddTab(
replaceURLForTab(
window.location.pathname,
),
);
refreshCurrentPage();
}
}
}

resolve(response?.success || translate('def.success'));
},
error: function (jqXHR, textStatus, errorThrown) {
Expand Down Expand Up @@ -398,6 +408,76 @@ $(function () {
container.addEventListener('mouseleave', function () {
container.style.width = '35px';
});

let icons = [];

const $iconMenu = $(
'<div id="icon-menu" class="icon-menu"></div>',
).appendTo('body');
const $iconMenuHeader = $(`
<div class="icon-menu-header">
<input type="text" id="icon-search" placeholder="" data-translate="def.search" data-translate-attribute="placeholder">
<div class="form-group">
<select id="icon-style">
<option value="ph-thin">Thin</option>
<option value="ph-light">Light</option>
<option value="ph" selected>Regular</option>
<option value="ph-bold">Bold</option>
<option value="ph-duotone">Duotone</option>
</select>
</div>
</div>
`).appendTo($iconMenu);
const $iconList = $(
'<div id="icon-list" class="icon-list"></div>',
).appendTo($iconMenu);

function fetchIcons() {
$.getJSON(u('admin/api/get-icons'), function (data) {
icons = data.icons;
updateIconList();
});
}

function updateIconList() {
const searchValue = $('#icon-search').val().toLowerCase();
const style = $('#icon-style').val();
$iconList.empty();
icons
.filter((icon) => icon.includes(searchValue))
.forEach((icon) => {
const iconElement = `<i class="${style} ph-${icon}"></i>`;
$iconList.append(iconElement);
});
}

$(document).on('focus', '#icon', function () {
const inputOffset = $(this).offset();
const inputHeight = $(this).outerHeight() + 10;
$iconMenu
.css({
top: inputOffset.top + inputHeight,
left: inputOffset.left,
})
.slideDown(300);
});

$(document).on('click', function (event) {
if (!$(event.target).closest('#icon-menu, #icon').length) {
$iconMenu.slideUp(300);
}
});

$iconMenuHeader.on('input', '#icon-search', updateIconList);
$iconMenuHeader.on('change', '#icon-style', updateIconList);

$iconList.on('click', 'i', function () {
const iconClass = $(this).attr('class');
$('#icon').val(`<i class="${iconClass}"></i>`).trigger('input');
$iconMenu.slideUp();
});

fetchIcons();
});

window.defaultEditorData = {};
Loading

0 comments on commit 7002df8

Please sign in to comment.