Skip to content

Commit

Permalink
0.2.1.5-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
FlamesONE committed Jun 22, 2024
1 parent 39009c5 commit b3f719c
Show file tree
Hide file tree
Showing 43 changed files with 2,145 additions and 1,273 deletions.
45 changes: 45 additions & 0 deletions app/Core/Admin/Http/Controllers/Api/HelperAdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

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

use Flute\Core\Admin\Http\Middlewares\HasPermissionMiddleware;
use Flute\Core\Support\AbstractController;
use Flute\Core\Support\FluteRequest;

class HelperAdminController extends AbstractController
{
public function __construct()
{
HasPermissionMiddleware::permission('admin.system');
}

public function getIP(FluteRequest $fluteRequest)
{
return json([
'ip' => $fluteRequest->getClientIp(),
]);
}

public function checkSteam(FluteRequest $fluteRequest)
{
$token = $fluteRequest->input('apiKey');

if (!$token)
return $this->error(__("admin.app.token_incorrect"));

config()->set('app.steam_api', $token);

try {

$player = steam()->getUser(76561198295345385, true);

if (empty($player)) {
return $this->error(__("admin.app.token_incorrect"));
}
} catch (\Exception $e) {
return $this->error(__("admin.app.token_incorrect"));
}

return $this->success();
}
}
22 changes: 0 additions & 22 deletions app/Core/Admin/Http/Controllers/Api/IPController.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected function initConfigServices(): void
{
$this->configServices = [
'app' => app(AppConfigService::class),
'additional' => app(AppConfigService::class),
'auth' => app(AuthConfigService::class),
'database' => app(DatabaseConfigService::class),
'lang' => app(LangConfigService::class),
Expand Down
5 changes: 2 additions & 3 deletions app/Core/Admin/Http/Controllers/Views/DatabasesView.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ public function list(): Response
{
$table = table();

$result = rep(DatabaseConnection::class)->select();
$result = rep(DatabaseConnection::class)->select()->load('server');

$result = $result->fetchAll();

foreach ($result as $key => $row) {
// $result[$key]->mod = basename($row->mod);
$result[$key]->server = ($result[$key]->server->id . ' - ' . $result[$key]->server->name);
$result[$key]->server = $result[$key]->server ? ($result[$key]->server->id . ' - ' . $result[$key]->server->name) : '-';
}

$table->addColumns([
Expand Down
25 changes: 17 additions & 8 deletions app/Core/Admin/Http/Views/assets/js/components/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,13 +1068,13 @@ function changeTabIcon(tabEl, container, isLoading) {
} else {
let originalIcon = tabEl.getAttribute('data-original-icon');
// if (!originalIcon) {
const tabUrl = tabEl.getAttribute('data-tab-url');
const matchingLinkIcon = document.querySelector(
`.sidebar-menu a[href="${tabUrl}"] i`,
);
if (matchingLinkIcon) {
originalIcon = matchingLinkIcon.outerHTML;
}
const tabUrl = tabEl.getAttribute('data-tab-url');
const matchingLinkIcon = document.querySelector(
`.sidebar-menu a[href="${tabUrl}"] i`,
);
if (matchingLinkIcon) {
originalIcon = matchingLinkIcon.outerHTML;
}
// }

if (originalIcon) {
Expand Down Expand Up @@ -1130,7 +1130,16 @@ $(function () {

$(document).on(
'click',
'.admin-header a.btn[href], .table-action-buttons a[href], .social-action-buttons a[href], .payment-action-buttons a[href], .payment-promo-action-buttons a[href], .servers-action-buttons a[href], .user-action-buttons a[href], .sortable-buttons a[href], .back-btn[href], [data-tab]',
`.admin-header a.btn[href],
.table-action-buttons a[href],
.social-action-buttons a[href],
.payment-action-buttons a[href],
.payment-promo-action-buttons a[href],
.servers-action-buttons a[href],
.user-action-buttons a[href],
.sortable-buttons a[href],
.back-btn[href],
[data-tab]`,
(event) => {
let link = event.currentTarget;

Expand Down
48 changes: 47 additions & 1 deletion app/Core/Admin/Http/Views/assets/js/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ function serializeFormData($form) {
return formData;
}

function sendRequestFormData(data, path = null, method = 'POST') {
function sendRequestFormData(
data,
path = null,
method = 'POST',
callback = null,
) {
let result = null;

$.ajax({
Expand Down Expand Up @@ -245,13 +250,54 @@ function sendRequestFormData(data, path = null, method = 'POST') {
return result;
}

function addToggleButton($input) {
if ($input.next('.toggle-visibility').length === 0) {
const $container = $('<div class="password-input-container"></div>');
const $toggleButton = $(
'<button type="button" class="toggle-visibility"><i class="ph ph-eye"></i></button>',
);

$toggleButton.on('click', function () {
if ($input.attr('type') === 'password') {
$input.attr('type', 'text');
$toggleButton.html('<i class="ph ph-eye-closed"></i>');
} else {
$input.attr('type', 'password');
$toggleButton.html('<i class="ph ph-eye"></i>');
}
});

$input.wrap($container);
$input.after($toggleButton);
}
}

$(function () {
$('.editor-ace').each(function () {
let editor = ace.edit(this);
editor.setTheme('ace/theme/solarized_dark');
editor.session.setMode('ace/mode/json');
});

$('input[type="password"]').each(function () {
addToggleButton($(this));
});

// Alternative setup using MutationObserver
const inputPasswordObserver = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length) {
$(mutation.addedNodes)
.find('input[type="password"]')
.each(function () {
addToggleButton($(this));
});
}
});
});

inputPasswordObserver.observe(document.body, { childList: true, subtree: true });

$(document).on('submit', '[data-form]', async (ev) => {
let $form = $(ev.currentTarget);

Expand Down
76 changes: 68 additions & 8 deletions app/Core/Admin/Http/Views/assets/js/pages/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
const $steamApiInput = $('#steam_api');
const $checkButton = $('#check_steam_api');

function checkSteamApiKey() {
const apiKey = $steamApiInput.val();
if (apiKey) {
$checkButton.attr('aria-busy', true);
fetch(u('admin/api/check-steam'), {
headers: {
'x-csrf-token': csrfToken,
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({ apiKey }),
method: 'POST',
})
.then((response) => response.json())
.then((res) => {
$checkButton.attr('aria-busy', false);
$checkButton.addClass('d-none');

if (res.error) {
toast({
type: 'error',
message: res.error,
});
} else {
toast({
type: 'success',
message: translate('def.success'),
});
}
})
.catch((error) => {
$checkButton.attr('aria-busy', false);

toast({
type: 'error',
message: translate('def.unknown_error'),
});
});
}
}

function toggleCheckButton() {
if ($steamApiInput.val()) {
$checkButton.removeClass('d-none');
} else {
$checkButton.addClass('d-none');
}
}

$steamApiInput.on('change', toggleCheckButton);
$checkButton.on('click', checkSteamApiKey);

toggleCheckButton();

$(document).on('change', 'input[type="file"]', function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
Expand Down Expand Up @@ -41,13 +98,15 @@ $(document).on('click', '[data-id]', function (e) {
let el = $(this);
let tabId = el.data('id');

$('.main_settings').attr('aria-busy', 'false');

if (el.hasClass('active')) return;

// Обновляем классы для вкладок и контента
$('[data-id]').not(el).removeClass('active');
el.addClass('active');
$('.settings-container > div').removeClass('active');
$(`.settings-container > #${tabId}`).addClass('active');
$('.main_settings > div').removeClass('active');
$(`.main_settings > #${tabId}`).addClass('active');

// Обновляем URL без перезагрузки страницы
if (history.pushState) {
Expand All @@ -70,7 +129,7 @@ function handleTabParameter() {
if (tab) {
let el = $(`[data-id=${tab}]`);
if (el.length) {
el.click(); // Активируем вкладку если она существует
el.click();
}
}
}
Expand All @@ -88,6 +147,7 @@ document
.querySelector('.chrome-tabs')
.addEventListener('contentRender', ({ detail }) => {
handleTabParameter();
toggleCheckButton();

db_connections = $('[data-database]')
.map(function () {
Expand Down Expand Up @@ -159,7 +219,7 @@ $(document).on('click', '[data-deleteconnection]', async function () {
}
});

$(document).on('submit', '.settings-container > div.active > form', (ev) => {
$(document).on('submit', '.main_settings > div.active > form', (ev) => {
let $form = $(ev.currentTarget);
let id = $('[data-id].active').data('id');
let rand = Math.random();
Expand Down Expand Up @@ -258,7 +318,7 @@ $(document).on('submit', '#dbEditConnectionForm', (ev) => {
$(document).on('click', '[data-addb]', async () => {
let modalId = await Modals.open({
title: translate('admin.add_db_title'),
closeOnBackground: false,

content: {
form: await createDb(),
},
Expand Down Expand Up @@ -289,7 +349,7 @@ $(document).on('click', '[data-changedb]', async function (e) {

let modalId = await Modals.open({
title: translate('admin.edit_db_title', { name: dbName }),
closeOnBackground: false,

content: {
form: await createDb(connectionData, dbName),
},
Expand Down Expand Up @@ -317,7 +377,7 @@ $(document).on('click', '[data-changedb]', async function (e) {
$(document).on('click', '[data-addconnection]', async () => {
let modalId = await Modals.open({
title: translate('admin.add_connection_title'),
closeOnBackground: false,

content: {
form: await createDbConnectionFormConfig(),
},
Expand Down Expand Up @@ -348,7 +408,7 @@ $(document).on('click', '[data-changeconnection]', async function (e) {

let modalId = await Modals.open({
title: translate(`admin.edit_connection_title`, { name: connName }),
closeOnBackground: false,

content: {
form: await createDbConnectionFormConfig(connectionData, connName),
},
Expand Down
4 changes: 2 additions & 2 deletions app/Core/Admin/Http/Views/assets/js/pages/users/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ $(function () {
selectedRoles[userId].forEach(function (role) {
let backgroundColor = role.color || '';
$('#user_chils').append(
`<div class="chip" data-id="${role.id}" style="background-color: ${backgroundColor}">${role.name}<span class="remove-role">&times;</span></div>`,
`<div class="chip" data-id="${role.id}" style="background-color: ${backgroundColor}">${role.name}<span class="remove-role"><i class="ph ph-x"></i></span></div>`,
);
});
}

function renderSuggestions() {
var userId = $('#edit').data('userid');

if (typeof selectedRoles[userId] === undefined) return;
if (!userId || typeof selectedRoles[userId] === undefined || roles === undefined) return;

$('#user_dialog').find('.suggestions').remove();
let availableRoles = roles.filter(
Expand Down
Loading

0 comments on commit b3f719c

Please sign in to comment.