[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX][ENH] Tiki structures: Fix structure management issues (pagination, ...
"Baraka Kinywa \(@bkinywa24\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <69396b866abfc_2a17dc2084058@gitlab-sidekiq-low-urgency-cpu-bound-v2-7766bb4d68-ncwdr.mail> |
Baraka Kinywa pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki
Commits:
d254d13e by Espoir Baraka at 2025-12-10T14:38:13+02:00
[FIX][ENH] Tiki structures: Fix structure management issues (pagination,...
---
* [FIX][ENH] Tiki structures: Fix structure management issues (pagination,...
---
* [FIX][ENH] Tiki structures: Fix structure management issues (pagination, sublevel state persistence)
See merge request tikiwiki/tiki!9157
(cherry picked from commit 3b3e129b3eb035dbec23427b35c5538242206868)
See merge request tikiwiki/tiki!9214
- - - - -
7 changed files:
- + auto-imports.d.ts
- src/js/jquery-tiki/tiki-edit_structure.js
- templates/structures_toc-leaf.tpl
- templates/tiki-admin_structures.tpl
- templates/tiki-edit_structure.tpl
- tiki-admin_structures.php
- tiki-edit_structure.php
Changes:
=====================================
auto-imports.d.ts
=====================================
@@ -0,0 +1,10 @@
+/* eslint-disable */
+/* prettier-ignore */
+// @ts-nocheck
+// noinspection JSUnusedGlobalSymbols
+// Generated by unplugin-auto-import
+// biome-ignore lint: disable
+export {}
+declare global {
+
+}
=====================================
src/js/jquery-tiki/tiki-edit_structure.js
=====================================
@@ -8,6 +8,80 @@ import Sortable from "sortablejs";
$(function () {
let tocDirty = false;
+ // Get page_ref_id from URL parameters
+ const getPageRefId = function () {
+ const params = new URLSearchParams(window.location.search);
+ return params.get("page_ref_id");
+ };
+
+ // Restore collapsed/expanded state from localStorage
+ const restoreStructureState = function () {
+ const pageRefId = getPageRefId();
+ if (pageRefId) {
+ const storageKey = "tiki_structure_state_" + pageRefId;
+ const savedState = localStorage.getItem(storageKey);
+ // First, hide all sub-levels by default (except root level)
+ $(".admintoclevel").each(function () {
+ const $node = $(this);
+ const $children = $node.find("ol.admintoc").first().parent();
+ // Only hide if it's not the root level (check if it has a parent admintoclevel)
+ if ($node.parents(".admintoclevel").length > 0 && $children.length > 0) {
+ $children.hide();
+ $node.find(".flip-children .icon").setIcon("caret-right");
+ }
+ });
+
+ // Then restore saved expanded states
+ if (savedState) {
+ try {
+ const state = JSON.parse(savedState);
+ Object.keys(state).forEach(function (nodeId) {
+ const $node = $("#" + nodeId);
+ if ($node.length && state[nodeId] === "expanded") {
+ const $children = $node.find("ol.admintoc").first().parent();
+ $children.show();
+ $node.find(".flip-children .icon").setIcon("caret-down");
+ }
+ });
+ } catch (e) {
+ console.error("Error restoring structure state:", e);
+ }
+ }
+ } else {
+ // If no storage key, hide all sub-levels by default
+ $(".admintoclevel").each(function () {
+ const $node = $(this);
+ const $children = $node.find("ol.admintoc").first().parent();
+ if ($node.parents(".admintoclevel").length > 0 && $children.length > 0) {
+ $children.hide();
+ $node.find(".flip-children .icon").setIcon("caret-right");
+ }
+ });
+ }
+ };
+
+ // Save collapsed/expanded state to localStorage
+ const saveStructureState = function () {
+ const pageRefId = getPageRefId();
+ if (pageRefId) {
+ const storageKey = "tiki_structure_state_" + pageRefId;
+ const state = {};
+ $(".admintoclevel").each(function () {
+ const $node = $(this);
+ const nodeId = $node.attr("id");
+ if (nodeId) {
+ const $children = $node.find("ol.admintoc").first().parent();
+ state[nodeId] = $children.is(":visible") ? "expanded" : "collapsed";
+ }
+ });
+ try {
+ localStorage.setItem(storageKey, JSON.stringify(state));
+ } catch (e) {
+ console.error("Error saving structure state:", e);
+ }
+ }
+ };
+
const setupStructure = function () {
const sortableOptions = {
group: {
@@ -58,12 +132,14 @@ $(function () {
$children.find(".icon-caret-down").setIcon("caret-right");
}
$children.hide("fast");
+ saveStructureState();
} else {
$this.find(".icon").setIcon("caret-down");
if (event.altKey) {
$children.find(".icon-caret-right").setIcon("caret-down");
}
$children.show("fast");
+ saveStructureState();
}
});
@@ -116,6 +192,7 @@ $(function () {
});
setupStructure();
+ restoreStructureState();
$(".save_structure").on("click", function () {
const $sortable = $(this).parent().find(".admintoc").first();
@@ -175,6 +252,7 @@ $(function () {
if (data) {
$sortable.replaceWith(data.html);
setupStructure();
+ restoreStructureState();
$(".save_structure").hide();
tocDirty = false;
}
=====================================
templates/structures_toc-leaf.tpl
=====================================
@@ -35,7 +35,7 @@
{if $toc_type eq 'admin'}
<div class="actions input-group input-group-sm mb-2">
{if ! empty($structure_tree.sub) && count($structure_tree.sub)}
- <span class="input-group-text flip-children">{icon name='caret-down'}</span>
+ <span class="input-group-text flip-children">{icon name='caret-right'}</span>
{/if}
<span class="input-group-text">{icon name='sort'}</span>
<input type="text" class="page-alias-input form-control" value="{$structure_tree.page_alias|escape}" placeholder="{tr}Page alias...{/tr}">
@@ -68,9 +68,7 @@
{icon name='lock' alt="{tr}Locked{/tr}" title=$title}
</div>
{else}
- {self_link _script='tiki-editpage.php' page=$structure_tree.pageName _class='tips input-group-text' _title=':{tr}Edit page{/tr}'}
- {icon name="edit"}
- {/self_link}
+ {button _keepall='y' href='tiki-editpage.php' page=$structure_tree.pageName _class='tips input-group-text' _title=':{tr}Edit page{/tr}' _icon_name='edit'}
{/if}
{if empty($page)}
{self_link _class="tips input-group-text add_new_child_page" _title=":{tr}Add new child page{/tr}"}
=====================================
templates/tiki-admin_structures.tpl
=====================================
@@ -198,7 +198,9 @@
</form>
{/if}
- {pagination_links count=$count step=$maxRecords offset=$offset}{/pagination_links}
+ {if !empty($count) && $count > 0 && !empty($maxRecords) && $maxRecords > 0 && $count > $maxRecords}
+ {pagination_links count=$count step=$maxRecords offset=$offset}{/pagination_links}
+ {/if}
{/tab}
{if $tiki_p_edit_structures == 'y'}
=====================================
templates/tiki-edit_structure.tpl
=====================================
@@ -128,9 +128,11 @@
{capture assign=title}{tr _0=$page_info.user}locked by %0{/tr}{/capture}
{icon name='lock' alt="{tr}Locked{/tr}" title=$title}
{else}
- {self_link _script='tiki-editpage.php' page=$structure_name _class='tips btn btn-link btn-sm' _title=':{tr}Edit page{/tr}'}
- {icon name="edit"}
- {/self_link}
+ {if !empty($structure_name)}
+ {button _keepall='y' href='tiki-editpage.php' page=$structure_name _class='tips btn btn-link btn-sm' _title=':{tr}Edit page{/tr}' _icon_name='edit'}
+ {elseif !empty($pageName)}
+ {button _keepall='y' href='tiki-editpage.php' page=$pageName _class='tips btn btn-link btn-sm' _title=':{tr}Edit page{/tr}' _icon_name='edit'}
+ {/if}
{/if}
{if empty($page)}
{self_link _class="tips btn btn-link btn-sm add_new_child_page" _title=":{tr}Add new child page{/tr}"}
@@ -184,13 +186,19 @@
{/if}
</div>
<ul id="page_list_container" class="list-group">
- {foreach $listpages.data as $aPage}
- <li class="list-group-item" data-page-name="{$aPage.pageName|escape}">
- {$aPage.pageName|escape}
- </li>
- {/foreach}
+ {if !empty($listpages.data)}
+ {foreach $listpages.data as $aPage}
+ <li class="list-group-item" data-page-name="{$aPage.pageName|escape}">
+ {$aPage.pageName|escape}
+ </li>
+ {/foreach}
+ {else}
+ <li class="list-group-item">{tr}No pages found{/tr}</li>
+ {/if}
</ul>
- {pagination_links count=$listpages.count step=$maxRecords offset=$offset}{/pagination_links}
+ {if !empty($listpages.count) && $listpages.count > 0 && !empty($maxRecords) && $maxRecords > 0 && $listpages.count > $maxRecords}
+ {pagination_links count=$listpages.count step=$maxRecords offset=$offset}{/pagination_links}
+ {/if}
</div>
</div>
</form>
=====================================
tiki-admin_structures.php
=====================================
@@ -243,7 +243,10 @@ $smarty->assign_by_ref('sort_mode', $sort_mode);
// default $maxRecords defined in tiki-setup.php
if (isset($_REQUEST['maxRecords'])) {
$maxRecords = $_REQUEST['maxRecords'];
+} else {
+ $maxRecords = $prefs['maxRecords'];
}
+$smarty->assign('maxRecords', $maxRecords);
$filter = '';
if (! empty($_REQUEST['lang'])) {
$filter['lang'] = $_REQUEST['lang'];
=====================================
tiki-edit_structure.php
=====================================
@@ -220,10 +220,13 @@ if ($editable === 'y') {
}
$smarty->assign_by_ref('offset', $offset);
+ $maxRecords = $prefs['maxRecords'];
+ $smarty->assign('maxRecords', $maxRecords);
+
// Get all wiki pages for the dropdown menu
$listpages = $tikilib->list_pages(
$offset,
- $prefs['maxRecords'],
+ $maxRecords,
'pageName_asc',
$find_objects,
'',
@@ -234,19 +237,25 @@ if ($editable === 'y') {
$filter
);
- if ($prefs['page_n_times_in_a_structure'] === 'n') {
- // pages can appear only once in a structure so filter them out
- $listpages['data'] = array_filter($listpages['data'], function ($item) use ($subtree) {
- foreach ($subtree as $sub) {
- if ($item['pageName'] === $sub['pageName']) {
- return false;
- }
- }
- return true;
- });
+ // Filter out pages already in the structure
+ $structure_page_names = [];
+ foreach ($subtree as $sub) {
+ if (isset($sub['pageName']) && ! empty($sub['pageName']) && ! ($sub['last'] == true && $sub['first'] == false)) {
+ $structure_page_names[$sub['pageName']] = true;
+ }
}
+ $filtered_data = array_filter($listpages['data'], function ($item) use ($structure_page_names) {
+ return ! isset($structure_page_names[$item['pageName']]);
+ });
+ $listpages['data'] = array_values($filtered_data);
$smarty->assign_by_ref('listpages', $listpages);
+} else {
+ $offset = $_REQUEST["offset"] ?? 0;
+ $smarty->assign_by_ref('offset', $offset);
+ $maxRecords = $prefs['maxRecords'];
+ $smarty->assign('maxRecords', $maxRecords);
+ $smarty->assign('listpages', ['data' => [], 'count' => 0]);
} // end of security hardening
$page_info = $structlib->s_get_page_info($_REQUEST["page_ref_id"]);
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/d254d13e141ba02a50ebd2127cb98af44f84e321
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/d254d13e141ba02a50ebd2127cb98af44f84e321
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs