Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make forum + category creation steps simpler in StaffCP #3314

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions custom/panel_templates/Default/assets/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,8 @@ footer.sticky-footer {
height: 16px;
width: 16px;
}

/* Make buttons dimmed when parent table row is not hovered */
.forumEditingRow:not(:hover) .btn {
opacity: 0.5;
}
211 changes: 139 additions & 72 deletions custom/panel_templates/Default/forum/forums.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,56 +36,123 @@
<div class="card shadow mb-4">
<div class="card-body">

<a href="{$NEW_FORUM_LINK}" class="btn btn-primary" {if count($FORUMS_ARRAY)}
style="margin-bottom: 15px;" {/if}>{$NEW_FORUM}</a>
{if !count($FORUMS_ARRAY)}
<hr />
<a href="{$NEW_CATEGORY_LINK}" class="btn btn-primary">
{$NEW_CATEGORY}
</a>
{if count($CATEGORIES_ARRAY)}
<hr>
{/if}

<!-- Success and Error Alerts -->
{include file='includes/alerts.tpl'}

{if count($FORUMS_ARRAY)}
<div class="table-responsive">
<table class="table">
<tbody id="sortable">
{foreach from=$FORUMS_ARRAY item=item name=forum_array}
<tr data-id="{$item.id}">
<td {if $item.parent_forum} style="padding-left:{math equation="x * y" x=25 y=$item.parent_forum_count}px" {/if}>
<a href="{$item.edit_link}">{$item.title}</a>{if $item.parent_forum}
<small>| {$item.parent_forum}</small>{/if}<br />{$item.description}
</td>
<td width="10%">
<div class="float-md-right">
{if $item.up_link}
<form action="{$item.up_link}" method="post"
style="display: inline">
<input type="hidden" name="token" value="{$TOKEN}" />
<button class="btn btn-success btn-sm"><i
class="fas fa-chevron-up"></i></button>
</form>
{if count($CATEGORIES_ARRAY)}
{foreach from=$CATEGORIES_ARRAY item=category}
<table class="table table-bordered table-sm">
<thead>
<tr style="background-color: #ededed;" class="forumEditingRow">
<th style="width: 70%">
{$category.title}
{if $category.description}
<br>
<small>
{$category.description}
</small>
{/if}
{if $item.down_link}
<form action="{$item.down_link}" method="post"
style="display: inline">
<input type="hidden" name="token" value="{$TOKEN}" />
<button class="btn btn-warning btn-sm"><i
class="fas fa-chevron-down"></i></button>
</form>
</th>
<th class="text-right align-middle">
<a class="btn btn-primary btn-sm" href="{$category.new_forum_link}">
{$NEW_FORUM}
</a>
<a class="btn btn-secondary btn-sm" href="{$category.edit_link}">
{$EDIT}
</a>
{if count($CATEGORIES_ARRAY) > 1}
<button class="btn btn-secondary btn-sm">
<i class="fas fa-up-down-left-right"></i>
</button>
{/if}
<a href="{$item.delete_link}" class="btn btn-danger btn-sm"><i
class="fas fa-trash"></i></a>
</div>
</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
<a class="btn btn-danger btn-sm" href="{$category.delete_link}">
<i class="fas fa-trash"></i>
</a>
</th>
</tr>
</thead>
<tbody>
{foreach from=$category.subforums item=subforum}
<tr class="forumEditingRow">
<td style="width: 70%">
{$subforum.title}
{if $subforum.description}
<br>
<small>
{$subforum.description}
</small>
{/if}
</td>
<td class="text-right align-middle">
<a class="btn btn-secondary btn-sm" href="{$subforum.edit_link}">
Edit
</a>
{if count($category.subforums) > 1}
<button class="btn btn-secondary btn-sm">
<i class="fas fa-up-down-left-right"></i>
</button>
{/if}
<a class="btn btn-danger btn-sm" href="{$subforum.delete_link}">
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
{/foreach}
</tbody>
</table>
{/foreach}
{else}
<p>{$NO_FORUMS}</p>
<p>{$NO_FORUMS}</p>
{/if}

{* {if count($FORUMS_ARRAY)}*}
{* <div class="table-responsive">*}
{* <table class="table">*}
{* <tbody id="sortable">*}
{* {foreach from=$FORUMS_ARRAY item=item name=forum_array}*}
{* <tr data-id="{$item.id}">*}
{* <td {if $item.parent_forum} style="padding-left:{math equation="x * y" x=25 y=$item.parent_forum_count}px" {/if}>*}
{* <a href="{$item.edit_link}">{$item.title}</a>{if $item.parent_forum}*}
{* <small>| {$item.parent_forum}</small>{/if}<br />{$item.description}*}
{* </td>*}
{* <td width="10%">*}
{* <div class="float-md-right">*}
{* {if $item.up_link}*}
{* <form action="{$item.up_link}" method="post"*}
{* style="display: inline">*}
{* <input type="hidden" name="token" value="{$TOKEN}" />*}
{* <button class="btn btn-success btn-sm"><i*}
{* class="fas fa-chevron-up"></i></button>*}
{* </form>*}
{* {/if}*}
{* {if $item.down_link}*}
{* <form action="{$item.down_link}" method="post"*}
{* style="display: inline">*}
{* <input type="hidden" name="token" value="{$TOKEN}" />*}
{* <button class="btn btn-warning btn-sm"><i*}
{* class="fas fa-chevron-down"></i></button>*}
{* </form>*}
{* {/if}*}
{* <a href="{$item.delete_link}" class="btn btn-danger btn-sm"><i*}
{* class="fas fa-trash"></i></a>*}
{* </div>*}
{* </td>*}
{* </tr>*}
{* {/foreach}*}
{* </tbody>*}
{* </table>*}
{* </div>*}
{* {else}*}
{* <p>{$NO_FORUMS}</p>*}
{* {/if}*}

</div>
</div>

Expand All @@ -109,38 +176,38 @@
{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 forums = $("#sortable").children();
let toSubmit = [];
forums.each(function () {
toSubmit.push($(this).data().id);
});
$.ajax({
url: "{$REORDER_DRAG_URL}",
type: "GET",
data: {
action: "order",
dir: "drag",
{literal}forums: JSON.stringify({"forums": toSubmit}){/literal}
},
success: function (response) {
// Success
},
error: function (xhr) {
// Error
console.log(xhr);
}
});
}
});
});
{*$(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 forums = $("#sortable").children();*}
{* let toSubmit = [];*}
{* forums.each(function () {*}
{* toSubmit.push($(this).data().id);*}
{* });*}
{* $.ajax({*}
{* url: "{$REORDER_DRAG_URL}",*}
{* type: "GET",*}
{* data: {*}
{* action: "order",*}
{* dir: "drag",*}
{* {literal}forums: JSON.stringify({"forums": toSubmit}){/literal}*}
{* },*}
{* success: function (response) {*}
{* // Success*}
{* },*}
{* error: function (xhr) {*}
{* // Error*}
{* console.log(xhr);*}
{* }*}
{* });*}
{* }*}
{* });*}
{*});*}
</script>
</body>
Expand Down
5 changes: 4 additions & 1 deletion custom/panel_templates/Default/forum/forums_new_step_1.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
</div>
<div class="form-group">
<input type="hidden" name="token" value="{$TOKEN}">
{if $PRESELECTED_CATEGORY}
<input type="hidden" name="pre_selected_category" value="{$PRESELECTED_CATEGORY}">
{/if}
<input type="submit" class="btn btn-primary" value="{$SUBMIT}">
</div>
</form>
Expand Down Expand Up @@ -132,4 +135,4 @@

</body>

</html>
</html>
4 changes: 2 additions & 2 deletions custom/panel_templates/Default/forum/forums_new_step_2.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<label for="InputParent">{$SELECT_PARENT_FORUM}</label>
<select class="form-control" id="InputParent" name="parent">
{foreach from=$PARENT_FORUMS item=item}
<option value="{$item.id}">{$item.name}</option>
<option value="{$item.id}" {if isset($PRESELECTED_CATEGORY) && $PRESELECTED_CATEGORY == $item.id}selected{/if}>{$item.name}</option>
{/foreach}
</select>
</div>
Expand Down Expand Up @@ -152,4 +152,4 @@

</body>

</html>
</html>
18 changes: 16 additions & 2 deletions modules/Forum/classes/Forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,16 +796,30 @@ public function getAnySubforums(
* @return array An array of the ids of the labels the user has access to
*/
public static function getAccessibleLabels(array $labels, array $user_groups): array {
return array_reduce($labels, function(&$prev, $topic_label) use ($user_groups) {
return array_reduce($labels, static function (&$prev, $topic_label) use ($user_groups) {
$label = DB::getInstance()->get('forums_topic_labels', ['id', $topic_label])->first();
if ($label) {
$label_group_ids = explode(',', $label->gids);
$hasPerm = array_reduce($user_groups, fn($prev, $group_id) => $prev || in_array($group_id, $label_group_ids));
$hasPerm = array_reduce($user_groups, static fn ($prev, $group_id) => $prev || in_array($group_id, $label_group_ids));
if ($hasPerm) {
$prev[] = $label->id;
}
}
return $prev;
}, []);
}

public function recursiveGetSubForums(int $parent_id, array $current = []): array {
$forums = $this->_db->query(
'SELECT * FROM nl2_forums WHERE parent = ? ORDER BY forum_order',
[$parent_id]
);
if ($forums->count()) {
foreach ($forums->results() as $forum) {
$current[$parent_id][] = $forum;
$current = $this->recursiveGetSubForums($forum->id, $current);
}
}
return $current;
}
}
Loading