mirror of
https://github.com/Joxit/docker-registry-ui.git
synced 2025-04-29 00:19:54 +03:00
feat(pagination): Add handler to pagination buttons
This commit is contained in:
parent
02210e0943
commit
92fc37adb4
5 changed files with 47 additions and 3 deletions
|
@ -85,7 +85,7 @@ registryUI.removeServer = function(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
registryUI.updateHistory = function(url) {
|
registryUI.updateHistory = function(url) {
|
||||||
history.pushState(null, '', (url ? '?url=' + registryUI.encodeURI(url) : '?') + window.location.hash);
|
registryUI.updateQueryString({ url: registryUI.encodeURI(url) })
|
||||||
registryUI._url = url;
|
registryUI._url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,10 +100,12 @@ registryUI.getUrlQueryParam = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
registryUI.encodeURI = function(url) {
|
registryUI.encodeURI = function(url) {
|
||||||
|
if (!url) { return; }
|
||||||
return url.indexOf('&') < 0 ? window.encodeURIComponent(url) : btoa(url);
|
return url.indexOf('&') < 0 ? window.encodeURIComponent(url) : btoa(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
registryUI.decodeURI = function(url) {
|
registryUI.decodeURI = function(url) {
|
||||||
|
if (!url) { return; }
|
||||||
return url.startsWith('http') ? window.decodeURIComponent(url) : atob(url);
|
return url.startsWith('http') ? window.decodeURIComponent(url) : atob(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ registryUI.getPage = function(elts, page, limit) {
|
||||||
registryUI.getNumPages = function(elts, limit) {
|
registryUI.getNumPages = function(elts, limit) {
|
||||||
if (!limit) { limit = 100; }
|
if (!limit) { limit = 100; }
|
||||||
if (!elts) { return 0; }
|
if (!elts) { return 0; }
|
||||||
return Math.trunc((elts.length / limit) % 10);
|
return Math.trunc((elts.length / limit) % 10) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
registryUI.getPageLabels = function(page, nPages) {
|
registryUI.getPageLabels = function(page, nPages) {
|
||||||
|
@ -96,3 +96,13 @@ registryUI.getPageLabels = function(page, nPages) {
|
||||||
}
|
}
|
||||||
return pageLabels;
|
return pageLabels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registryUI.updateQueryString = function(qs) {
|
||||||
|
var search = '';
|
||||||
|
for (var key in qs) {
|
||||||
|
if (qs[key] !== undefined) {
|
||||||
|
search += (search.length > 0 ? '&' : '?') +key + '=' + qs[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
history.pushState(null, '', search + window.location.hash);
|
||||||
|
}
|
|
@ -231,6 +231,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
return qs.page !== undefined ? parseInt(qs.page.replace(/#.*/, '')) : 1;
|
return qs.page !== undefined ? parseInt(qs.page.replace(/#.*/, '')) : 1;
|
||||||
} catch(e) { return 1; }
|
} catch(e) { return 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registryUI.getQueryParams = function(update) {
|
||||||
|
var qs = route.query();
|
||||||
|
update = update || {};
|
||||||
|
for (var key in qs) {
|
||||||
|
if (qs[key] !== undefined) {
|
||||||
|
qs[key] = qs[key].replace(/#!.*/, '');
|
||||||
|
} else {
|
||||||
|
delete qs[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var key in update) {
|
||||||
|
if (update[key] !== undefined) {
|
||||||
|
qs[key] = update[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return qs;
|
||||||
|
}
|
||||||
route.start(true);
|
route.start(true);
|
||||||
</script>
|
</script>
|
||||||
</app>
|
</app>
|
|
@ -25,7 +25,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<script>
|
<script>
|
||||||
|
this.on('updated', function() {
|
||||||
|
if (!this.tags['material-button']) { return; }
|
||||||
|
var buttons = Array.isArray(this.tags['material-button']) ? this.tags['material-button'] : [this.tags['material-button']];
|
||||||
|
buttons.forEach(function(button) {
|
||||||
|
button.root.onclick = function() {
|
||||||
|
registryUI.updateQueryString(registryUI.getQueryParams({ page: button.p.page }) );
|
||||||
|
registryUI.taglist.instance.trigger('page-update', button.p.page)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<!-- End of tag -->
|
<!-- End of tag -->
|
||||||
</pagination>
|
</pagination>
|
|
@ -113,6 +113,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.on('page-update', function(page) {
|
||||||
|
self.page = page;
|
||||||
|
this.update();
|
||||||
|
});
|
||||||
|
|
||||||
this._getRemoveImageTags = function() {
|
this._getRemoveImageTags = function() {
|
||||||
var images = self.refs['taglist-tag'].tags['remove-image'];
|
var images = self.refs['taglist-tag'].tags['remove-image'];
|
||||||
if (!(images instanceof Array)) {
|
if (!(images instanceof Array)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue