Skip to content

Commit

Permalink
PlayerJS: Fix pin slot for remaining data slots (xibosignage#2377)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenberttpingol authored Feb 21, 2024
1 parent a8c7071 commit 0891a46
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/src/xibo-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ const XiboPlayer = function() {
Object.keys(dataSlots[currentSlot].items).filter(function(k) {
return dataSlots[currentSlot].items[k].pinSlot === true;
}).length > 0;
dataSlots[currentSlot].pinnedItems =
PlayerHelper.getPinnedItems(dataSlots[currentSlot].items);
}
});
}
Expand Down Expand Up @@ -346,9 +348,11 @@ const XiboPlayer = function() {
break;
}

// Slots loop
for (const [, itemValue] of Object.entries(currCollection)) {
const itemObj = dataElements[itemValue];
const slotItems = itemObj.items;
const pinnedItems = itemObj.pinnedItems;
const currentSlot = itemObj.slot;

// Skip if currentKey is less than the currentSlot
Expand All @@ -366,6 +370,16 @@ const XiboPlayer = function() {
continue;
}

// Skip slot if all slot items are pinned and
// currentKey is more than the maxSlot and
// currentSlot is a pinned slot
if (lastSlotFilled === null &&
currentKey > maxSlot && itemObj.hasPinnedSlot &&
Object.keys(pinnedItems).length === Object.keys(slotItems).length
) {
continue;
}

// Loop through data slot items (elements or groups)
for (const [dataSlotItemKey] of Object.entries(slotItems)) {
const dataSlotItem = itemObj.items[dataSlotItemKey];
Expand Down
16 changes: 16 additions & 0 deletions ui/src/helpers/player-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ const PlayerHelper = function() {
}, []);
};

this.getPinnedItems = function(dataSlotItems) {
if (Object.values(dataSlotItems).length === 0) {
return dataSlotItems;
}

return Object.keys(dataSlotItems).reduce(function(items, itemKey) {
const item = dataSlotItems[itemKey];

if (item.pinSlot) {
items[itemKey] = item;
}

return items;
}, {});
};

/**
* Get items by Key
* @param {Object} items
Expand Down

0 comments on commit 0891a46

Please sign in to comment.