Skip to content

Commit

Permalink
feat: add ability to re-order placeholders and redesign leaderboards …
Browse files Browse the repository at this point in the history
…page to match member list (#3559)
  • Loading branch information
samerton authored Dec 9, 2024
1 parent 1957877 commit 5b3498c
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 87 deletions.
10 changes: 8 additions & 2 deletions core/classes/Misc/Placeholders.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ public function __construct()
{
$this->_db = DB::getInstance();

$placeholders_query = $this->_db->get('placeholders_settings', ['name', '<>', ''])->results();
$placeholders_query = $this->_db->query(
<<<'SQL'
SELECT *
FROM nl2_placeholders_settings
ORDER BY `order`
SQL
)->results();
$placeholders = [];

foreach ($placeholders_query as $placeholder) {
Expand Down Expand Up @@ -78,7 +84,7 @@ public function loadUserPlaceholders(string $uuid): array
{
$binUuid = hex2bin(str_replace('-', '', $uuid));

$placeholder_query = $this->_db->query('SELECT * FROM nl2_users_placeholders up JOIN nl2_placeholders_settings ps ON up.name = ps.name AND up.server_id = ps.server_id WHERE up.uuid = ?', [$binUuid]);
$placeholder_query = $this->_db->query('SELECT * FROM nl2_users_placeholders up JOIN nl2_placeholders_settings ps ON up.name = ps.name AND up.server_id = ps.server_id WHERE up.uuid = ? ORDER BY ps.`order`', [$binUuid]);

if (!$placeholder_query->count()) {
return [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddPlaceholderOrderToPlaceholderSettingsTable extends AbstractMigration
{
public function change(): void
{
$this->table('nl2_placeholders_settings')
->addColumn('order', 'integer', ['length' => 11, 'null' => true, 'default' => null])
->update();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
<div class="card shadow border-left-primary">
<div class="card-body">
<h5><i class="icon fa fa-info-circle"></i> {$INFO}</h5>
{$PLACEHOLDERS_INFO}
<p>{$PLACEHOLDERS_INFO}</p>
<p style="margin-bottom: 0">{$DRAG_AND_DROP_INFO}</p>
</div>
</div>
<hr />
Expand Down Expand Up @@ -95,9 +96,9 @@
<th></th>
</tr>
</thead>
<tbody>
<tbody id="sortable">
{foreach from=$ALL_PLACEHOLDERS item=placeholder}
<tr>
<tr data-id="{$placeholder->server_id}-{$placeholder->name}" style="cursor: move">
<td>{$placeholder->server_id}</td>
<td><code>{$placeholder->name}</code></td>
<td>
Expand Down Expand Up @@ -216,8 +217,45 @@
});
}
</script>

{include file='scripts.tpl'}

<script type="text/javascript">
$(document).ready(function () {
$("#sortable").sortable({
start: function (event, ui) {
let start_pos = ui.item.index();
ui.item.data('startPos', start_pos);
},
update: function (event, ui) {
let placeholders = $("#sortable").children();
let toSubmit = [];
placeholders.each(function () {
toSubmit.push($(this).data().id);
});
$.ajax({
url: "{$REORDER_DRAG_URL}",
type: "POST",
data: {
action: "order",
dir: "drag",
{literal}placeholders: JSON.stringify({"placeholders": toSubmit}){/literal},
token: "{$TOKEN}"
},
success: function (response) {
// Success
},
error: function (xhr) {
// Error
console.log(xhr);
}
});
}
});
});
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions custom/panel_templates/Default/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ public function onPageLoad()

$this->addJSScript('$(".image-picker").imagepicker();');
}
} elseif (MINECRAFT_PAGE === 'placeholders') {
$this->assets()->include([
AssetTree::JQUERY_UI,
]);
}

break;
Expand Down
35 changes: 35 additions & 0 deletions custom/templates/DefaultRevamp/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,31 @@ body.pushable>.pusher {
max-width: none;
}

.ui.grid.segment.leaderboard_table {
margin-top: 0;
}

.leaderboard_table .ui.list {
margin-left: -10px;
}

.leaderboard_table .ui.list li a {
display: block;
height: 100%;
width: 100%;
}

.leaderboard_table .middle.aligned.content {
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;;
white-space: nowrap;
}

.leaderboard_table ol li:before {
display: none;
}

#reactions {
margin-top: 1rem;
padding: .7em 1.2em .7em 1.2em;
Expand Down Expand Up @@ -1211,6 +1236,16 @@ body.dark .ui.vertical.menu {
box-shadow: none;
}

body.dark .ui.vertical.menu .active.item {
background-color: #464646;
}

body.dark .ui.vertical.pointing.menu .active.item:after {
background-color: #464646;
border-top: 1px solid #464646;
border-right: 1px solid #464646;
}

body.dark .ui.segment#profile-header {
border: none;
}
Expand Down
90 changes: 50 additions & 40 deletions custom/templates/DefaultRevamp/leaderboards.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,62 @@

<br />

<div class="ui stackable grid">
<div class="ui stackable equal width grid">
<div class="ui centered row">
<div class="ui six wide tablet four wide computer column">
<div class="ui fluid vertical pointing menu">
<div class="ui four wide column">
<div class="ui fluid vertical menu pointing">
{foreach from=$LEADERBOARD_PLACEHOLDERS item=placeholder}
<a class="item leaderboard_tab" name="{$placeholder->safe_name}" server_id="{$placeholder->server_id}"
id="tab-{$placeholder->safe_name}-server-{$placeholder->server_id}"
onclick="showTable('{$placeholder->safe_name}', '{$placeholder->server_id}');">
{$placeholder->leaderboard_title}
</a>
<a
class="item leaderboard_tab"
name="{$placeholder->safe_name}"
server_id="{$placeholder->server_id}"
id="tab-{$placeholder->safe_name}-server-{$placeholder->server_id}"
onclick="showTable('{$placeholder->safe_name}', '{$placeholder->server_id}');"
>
{$placeholder->leaderboard_title}
</a>
{/foreach}
</div>
</div>
<div class="ui ten wide tablet twelve wide computer column">

<div class="ui column">
{foreach from=$LEADERBOARD_PLACEHOLDERS item=placeholder}
<div class="leaderboard_table" id="table-{$placeholder->safe_name}-server-{$placeholder->server_id}"
style="display: none;">
<h2>{$placeholder->leaderboard_title}</h2>
<table class="ui fixed single line selectable unstackable small padded res table">
<thead>
<tr>
<th>{$PLAYER}</th>
<th>{$SCORE}</th>
<th>{$LAST_UPDATED}</th>
</tr>
</thead>
<tbody>

{foreach from=$LEADERBOARD_PLACEHOLDERS_DATA item=data}
{if $data->name eq $placeholder->name and $data->server_id eq $placeholder->server_id}
<tr>
<td>
<img class="ui middle aligned" src="{$data->avatar}" alt="{$data->username}">
<span>{$data->username}</span>
</td>
<td>
{$data->value}
</td>
<td>
{$data->last_updated}
</td>
</tr>
{/if}
{/foreach}
</table>
</div>
<div class="ui stackable equal width left aligned three column grid segment leaderboard_table" style="display: none;" id="table-{$placeholder->safe_name}-server-{$placeholder->server_id}">
<div class="ui column">
<h3>{$placeholder->leaderboard_title}</h3>
<div>
<ol class="ui list large selection">
{foreach from=$LEADERBOARD_PLACEHOLDERS_DATA item=data}
{if $data->name eq $placeholder->name and $data->server_id eq $placeholder->server_id}
<li class="item">
<a href="{$data->profile}">
<div class="right floated content">
<div class="ui header">{$data->value}</div>
</div>

<img class="ui avatar image" src="{$data->avatar}" alt="{$data->username}" />

<div class="middle aligned content">
<span style="{$data->style}">
{$data->username}
</span>

{foreach from=$data->groups item=group}
{$group}
{/foreach}

<div class="description">
<span class="ui text small" data-toggle="tooltip" data-content="{$data->last_updated_full}">{$data->last_updated_string}</span>
</div>
</div>
</a>
</li>
{/if}
{/foreach}
</ol>
</div>
</div>
</div>
{/foreach}
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions modules/Core/language/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"admin/download": "Download",
"admin/download_sitemap": "Download Sitemap",
"admin/downloads_x": "Downloads: {{downloads}}",
"admin/drag_and_drop": "You can drag and drop the items in this list.",
"admin/drag_files_here": "Drag files here to upload.",
"admin/dropdown_items": "Dropdown Items",
"admin/dropdown_name": "Dropdown Name",
Expand Down Expand Up @@ -867,6 +868,7 @@
"general/invalid_token": "Invalid token, please try again.",
"general/ip": "IP",
"general/joined": "Joined",
"general/last_updated": "Last updated: {{lastUpdated}}",
"general/latest_member": "Latest Member",
"general/leaderboards": "Leaderboards",
"general/link": "Link",
Expand Down
10 changes: 9 additions & 1 deletion modules/Core/pages/leaderboards.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@
$leaderboard_users[$uuid] = $integration_user;
}

$last_updated = $timeago->inWords($row->last_updated, $language);

$row_data->server_id = $leaderboard_placeholder->server_id;
$row_data->name = $leaderboard_placeholder->name;
$row_data->username = Output::getClean($leaderboard_users[$uuid]->data()->username);
$row_data->avatar = AvatarSource::getAvatarFromUUID($uuid, 24);
$row_data->value = $row->value;
$row_data->last_updated = ucfirst($timeago->inWords($row->last_updated, $language));
$row_data->last_updated_string = $language->get('general', 'last_updated', ['lastUpdated' => $last_updated]);
$row_data->last_updated = $last_updated;
$row_data->last_updated_full = date(DATE_FORMAT, $row->last_updated);
$row_data->style = $leaderboard_users[$uuid]->getUser()->getGroupStyle();
$row_data->profile = $leaderboard_users[$uuid]->getUser()->getProfileURL();
$row_data->groups = $leaderboard_users[$uuid]->getUser()->getAllGroupHtml();
$row_data->groupIds = $leaderboard_users[$uuid]->getUser()->getAllGroupIds();

$leaderboard_placeholders_data[] = $row_data;
}
Expand Down
Loading

0 comments on commit 5b3498c

Please sign in to comment.