Skip to content

Commit

Permalink
Remove load-more functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 2, 2024
1 parent 3f4983e commit 6ca4e54
Showing 1 changed file with 2 additions and 125 deletions.
127 changes: 2 additions & 125 deletions asset/js/widget/ActionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ define(["../notjQuery"], function (notjQuery) {

this.lastActivatedItemUrl = null;
this.lastTimeoutId = null;
this.isProcessingLoadMore = false;
this.activeRequests = {};

this.listIdentifier = '[data-interactable-action-list]';
Expand All @@ -20,11 +19,7 @@ define(["../notjQuery"], function (notjQuery) {
this.on('column-moved', this.onColumnMoved, this);*/

notjQuery(document).on('keydown','body', this.onKeyDown, this);
/*notjQuery(this.list).on('rendered', this.onRendered, this);
this.on('click', '.load-more[data-no-icinga-ajax] a', this.onLoadMoreClick, this);
this.on('keypress', '.load-more[data-no-icinga-ajax] a', this.onKeyPress, this);*/
//notjQuery(this.list).on('rendered', this.onRendered, this);

// this.onRendered(this.list);

Expand Down Expand Up @@ -243,8 +238,7 @@ define(["../notjQuery"], function (notjQuery) {
let focusedElement = document.activeElement;

if (
_this.isProcessingLoadMore
|| ! event.key // input auto-completion is triggered
! event.key // input auto-completion is triggered
|| (event.key.toLowerCase() !== 'a' && ! pressedArrowDownKey && ! pressedArrowUpKey)
) {
return;
Expand Down Expand Up @@ -305,9 +299,6 @@ define(["../notjQuery"], function (notjQuery) {
toActiveItem = pressedArrowDownKey ? firstListItem : lastListItem;
// reset all on manual page refresh
_this.clearSelection(activeItems);
if (toActiveItem.classList.contains('load-more')) {
toActiveItem = toActiveItem.previousElementSibling;
}
} else if (isMultiSelectableList && event.shiftKey) {
if (activeItems.length === 1) {
toActiveItem = directionalNextItem;
Expand All @@ -334,15 +325,6 @@ define(["../notjQuery"], function (notjQuery) {
}
} else {
toActiveItem = directionalNextItem;

if (toActiveItem) {
if (toActiveItem.classList.contains('load-more')) {
clearTimeout(_this.lastTimeoutId);
_this.handleLoadMoreNavigate(toActiveItem, lastActivatedItem, event.key);
return;
}
}

while (toActiveItem) {
if (toActiveItem.hasAttribute(this.removeBrackets(this.listItemIdentifier))) {
_this.clearSelection(activeItems);
Expand Down Expand Up @@ -564,111 +546,6 @@ define(["../notjQuery"], function (notjQuery) {
return Array.from(items);
}

/**
* Handle the navigation on load-more button
*
* @param loadMoreElement
* @param lastActivatedItem
* @param pressedKey Pressed key (`ArrowUp` or `ArrowDown`)
*/
handleLoadMoreNavigate(loadMoreElement, lastActivatedItem, pressedKey) {
let req = this.loadMore(loadMoreElement.firstChild);
this.isProcessingLoadMore = true;
req.done(() => {
this.isProcessingLoadMore = false;
// list has now new items, so select the lastActivatedItem and then move forward
let toActiveItem = lastActivatedItem.nextElementSibling;
while (toActiveItem) {
if (toActiveItem.hasAttribute(this.removeBrackets(this.listItemIdentifier))) {
this.clearSelection([lastActivatedItem]);
this.setActive(toActiveItem);
this.setLastActivatedItemUrl(toActiveItem.dataset.icingaDetailFilter);
this.scrollItemIntoView(toActiveItem, pressedKey);
this.addSelectionCountToFooter(toActiveItem.parentElement);
this.loadDetailUrl(toActiveItem.parentElement);
return;
}

toActiveItem = toActiveItem.nextElementSibling;
}
});
}

/**
* Click on load-more button
*
* @param event
*
* @returns {boolean}
*/
onLoadMoreClick(event) {
event.stopPropagation();
event.preventDefault();

event.data.self.loadMore(event.target);

return false;
}

onKeyPress(event) {
if (event.key === ' ') { // space
event.data.self.onLoadMoreClick(event);
}
}

/**
* Load more list items based on the given anchor
*
* @param anchor
*
* @returns {*|{getAllResponseHeaders: function(): *|null, abort: function(*): this, setRequestHeader: function(*, *): this, readyState: number, getResponseHeader: function(*): null|*, overrideMimeType: function(*): this, statusCode: function(*): this}|jQuery|boolean}
*/
loadMore(anchor) {
let showMore = anchor.parentElement;
var progressTimer = this.icinga.timer.register(function () {
var label = anchor.innerText;

var dots = label.substr(-3);
if (dots.slice(0, 1) !== '.') {
dots = '. ';
} else {
label = label.slice(0, -3);
if (dots === '...') {
dots = '. ';
} else if (dots === '.. ') {
dots = '...';
} else if (dots === '. ') {
dots = '.. ';
}
}

anchor.innerText = label + dots;
}, null, 250);

let url = anchor.getAttribute('href');
let req = this.icinga.loader.loadUrl(
// Add showCompact, we don't want controls in paged results
this.icinga.utils.addUrlFlag(url, 'showCompact'),
$(showMore.parentElement),
undefined,
undefined,
'append',
false,
progressTimer
);
req.addToHistory = false;
req.done(function () {
showMore.remove();

// Set data-icinga-url to make it available for Icinga.History.getCurrentState()
req.$target.closest('.container').data('icingaUrl', url);

this.icinga.history.replaceCurrentState();
});

return req;
}

/**
* Create the detail url for multi selectable list
*
Expand Down

0 comments on commit 6ca4e54

Please sign in to comment.