forked from dcflachs/compose_plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Sortable stacks with lock functionality #87
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
af28854
fix(compose): add checks for existing containers and networks before …
mstrhakr 5f6964d
feat(sortable): implement sortable stacks with lock functionality and…
mstrhakr b567e84
fix(sortable): extract js to own file
mstrhakr 50e52ae
feat(sortable): load sortable functions from external composeSortable.js
mstrhakr 792e023
fix(sortable): update LockButton assignment to prevent hoisting issues
mstrhakr 78387ad
feat(sortable): update mover icon style to enhance visibility in stac…
mstrhakr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /** | ||
| * Compose Manager – Stack sortable (drag-and-drop reordering) | ||
| * | ||
| * Depends on globals provided by the page: | ||
| * caURL – AJAX endpoint for exec.php | ||
| * composeClientDebug – debug/logging helper (common.js) | ||
| * $.cookie / $.removeCookie – jquery.cookie plugin | ||
| * $.fn.sortable – jQuery UI Sortable | ||
| */ | ||
|
|
||
| // ── Sort-mode state ──────────────────────────────────────────────── | ||
|
|
||
| function isComposeSortModeEnabled() { | ||
| return $.cookie('lockbutton') != null; | ||
| } | ||
|
|
||
| // ── Lock / Unlock button UI ──────────────────────────────────────── | ||
|
|
||
| function updateComposeLockButtonUI() { | ||
| var unlocked = isComposeSortModeEnabled(); | ||
| var $button = $('div.nav-item.LockButton'); | ||
| if (!$button.length) { | ||
| return; | ||
| } | ||
|
|
||
| if (unlocked) { | ||
| $button.find('a').prop('title', 'Lock sortable items'); | ||
| $button.find('b').removeClass('icon-u-lock green-text').addClass('icon-u-lock-open red-text'); | ||
| $button.find('span').text('Lock sortable items'); | ||
| } else { | ||
| $button.find('a').prop('title', 'Unlock sortable items'); | ||
| $button.find('b').removeClass('icon-u-lock-open red-text').addClass('icon-u-lock green-text'); | ||
| $button.find('span').text('Unlock sortable items'); | ||
| } | ||
| } | ||
|
|
||
| // ── Persist sort order ───────────────────────────────────────────── | ||
|
|
||
| function saveComposeSortOrder() { | ||
| var projects = $('#compose_list > tr.compose-sortable').map(function() { | ||
| return $(this).data('project'); | ||
| }).get(); | ||
|
|
||
| return $.post(caURL, { | ||
| action: 'saveStackOrder', | ||
| projects: projects | ||
| }).fail(function(xhr) { | ||
| composeClientDebug('[saveComposeSortOrder] failed', { | ||
| status: xhr.status, | ||
| response: xhr.responseText | ||
| }, 'daemon', 'error'); | ||
| }); | ||
| } | ||
|
|
||
| // ── Details-row helpers (detach during drag, reattach on drop) ───── | ||
|
|
||
| function getComposeDetailsRowForItem($item) { | ||
| if (!$item || !$item.length) { | ||
| return $(); | ||
| } | ||
|
|
||
| var rowId = $item.attr('id') || ''; | ||
| if (rowId.indexOf('stack-row-') !== 0) { | ||
| return $(); | ||
| } | ||
|
|
||
| return $('#details-row-' + rowId.replace('stack-row-', '')); | ||
| } | ||
|
|
||
| function reattachComposeDetailsRow($item) { | ||
| var $detailsRow = $item.data('compose-details-row'); | ||
| if ($detailsRow && $detailsRow.length) { | ||
| $detailsRow.insertAfter($item); | ||
| $item.removeData('compose-details-row'); | ||
| } | ||
| } | ||
|
|
||
| // ── jQuery UI Sortable initialisation ────────────────────────────── | ||
|
|
||
| function initComposeSortable() { | ||
| var $tbody = $('#compose_list'); | ||
| if (!$tbody.length) { | ||
| return; | ||
| } | ||
|
|
||
| if ($tbody.hasClass('ui-sortable')) { | ||
| $tbody.sortable('destroy'); | ||
| } | ||
|
|
||
| if (!isComposeSortModeEnabled()) { | ||
| $tbody.removeClass('compose-sort-enabled'); | ||
| return; | ||
| } | ||
|
|
||
| $tbody.addClass('compose-sort-enabled'); | ||
| $tbody.sortable({ | ||
| helper: 'clone', | ||
| items: '> tr.compose-sortable', | ||
| cursor: 'grab', | ||
| axis: 'y', | ||
| containment: 'parent', | ||
| cancel: '[data-stackid], .compose-updatecolumn a, .compose-updatecolumn .exec, .auto_start, .switchButton, a, button, input', | ||
| delay: 100, | ||
| opacity: 0.5, | ||
| zIndex: 9999, | ||
| forcePlaceholderSize: true, | ||
| start: function(event, ui) { | ||
| var $detailsRow = getComposeDetailsRowForItem(ui.item); | ||
| if ($detailsRow.length) { | ||
| ui.item.data('compose-details-row', $detailsRow.detach()); | ||
| } | ||
| }, | ||
| update: function() { | ||
| saveComposeSortOrder(); | ||
| }, | ||
| stop: function(event, ui) { | ||
| reattachComposeDetailsRow(ui.item); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // ── Sync all sort-mode UI (icons, class, sortable instance) ──────── | ||
|
|
||
| function syncComposeSortModeUI() { | ||
| var unlocked = isComposeSortModeEnabled(); | ||
| $('#compose_stacks tr.compose-sortable').each(function() { | ||
| var $row = $(this); | ||
| $row.find('.expand-icon').toggle(!unlocked); | ||
| $row.find('.mover').toggle(unlocked); | ||
| }); | ||
|
|
||
| $('#compose_list').toggleClass('compose-sort-enabled', unlocked); | ||
| updateComposeLockButtonUI(); | ||
| initComposeSortable(); | ||
| } | ||
|
|
||
| // ── Global entry-point called by Unraid navigation lock button ───── | ||
| // When embedded in the Docker tab, DockerContainers.page defines its own | ||
| // LockButton(). We save the previous implementation (if any) and chain | ||
| // to it so both Docker containers AND Compose stacks react to the button. | ||
| // IMPORTANT: We use window.LockButton assignment (not a function declaration) | ||
| // to avoid hoisting — a hoisted function declaration would overwrite the | ||
| // global LockButton before we can capture it. | ||
|
|
||
| var _composePrevLockButton = window.LockButton || null; | ||
|
|
||
| window.LockButton = function LockButton() { | ||
| if (_composePrevLockButton) { | ||
| // Let the Docker (or other) handler run first — it toggles the | ||
| // cookie and manages its own sortable / UI state. | ||
| _composePrevLockButton(); | ||
| } else { | ||
| // Standalone page (header-menu mode) — we own the cookie. | ||
| if (isComposeSortModeEnabled()) { | ||
| $.removeCookie('lockbutton'); | ||
| } else { | ||
| $.cookie('lockbutton', 'lockbutton'); | ||
| } | ||
| } | ||
|
|
||
| syncComposeSortModeUI(); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initComposeSortable()callssortable()unconditionally. In other plugin code (e.g. settings page) there’s an explicit guard fortypeof $.fn.sortable === 'function', implying jQuery UI Sortable may not always be available. Add the same guard here to prevent runtime JS errors on pages where the sortable plugin isn’t loaded.