From 73565912926776a48663442f06fabc1a5187c7e6 Mon Sep 17 00:00:00 2001 From: Joxit Date: Sun, 26 May 2019 01:20:02 +0200 Subject: [PATCH 01/11] feat(pagination): Show only 100 first elements --- src/scripts/utils.js | 6 ++++++ src/tags/app.tag | 4 ++-- src/tags/image-date.tag | 2 ++ src/tags/taglist.tag | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/scripts/utils.js b/src/scripts/utils.js index 96067a6..79056bb 100644 --- a/src/scripts/utils.js +++ b/src/scripts/utils.js @@ -65,4 +65,10 @@ registryUI.getHistoryIcon = function(attribute) { default: '' } +} + +registryUI.getPage = function(elts, page, limit) { + if (!limit) { limit = 100; } + if (!elts) { return []; } + return elts.slice(page * limit, limit); } \ No newline at end of file diff --git a/src/tags/app.tag b/src/tags/app.tag index 190a784..6fcf3c3 100644 --- a/src/tags/app.tag +++ b/src/tags/app.tag @@ -130,8 +130,8 @@ along with this program. If not, see . return this.fillInfo(); }); this.on('get-date', function() { - if (this.date !== undefined) { - return this.trigger('date', this.date); + if (this.creationDate !== undefined) { + return this.trigger('creation-date', this.creationDate); } return this.fillInfo(); }); diff --git a/src/tags/image-date.tag b/src/tags/image-date.tag index 1064d70..03b8bbd 100644 --- a/src/tags/image-date.tag +++ b/src/tags/image-date.tag @@ -24,5 +24,7 @@ self.localDate = date.toLocaleString() self.update(); }); + + opts.image.trigger('get-date'); \ No newline at end of file diff --git a/src/tags/taglist.tag b/src/tags/taglist.tag index 9b31ccc..06a46f7 100644 --- a/src/tags/taglist.tag +++ b/src/tags/taglist.tag @@ -16,7 +16,7 @@ along with this program. If not, see . --> - +
arrow_back @@ -50,7 +50,7 @@ along with this program. If not, see . - + { image.name } @@ -76,6 +76,7 @@ along with this program. If not, see . + diff --git a/src/scripts/utils.js b/src/scripts/utils.js index 79056bb..2fcca52 100644 --- a/src/scripts/utils.js +++ b/src/scripts/utils.js @@ -71,4 +71,28 @@ registryUI.getPage = function(elts, page, limit) { if (!limit) { limit = 100; } if (!elts) { return []; } return elts.slice(page * limit, limit); +} + +registryUI.getNumPages = function(elts, limit) { + if (!limit) { limit = 100; } + if (!elts) { return 0; } + return Math.trunc((elts.length / limit) % 10); +} + +registryUI.getPageLabels = function(page, nPages) { + var pageLabels = []; + var maxItems = 10; + if (nPages === 0) { return pageLabels; } + if (page !== 0 && nPages >= maxItems) { + pageLabels.push({'icon': 'first_page', page: 0}); + pageLabels.push({'icon': 'chevron_left', page: page - 1}); + } + for (var i = Math.max(1, page - maxItems); i <= Math.min(nPages, page + maxItems); i++) { + pageLabels.push({page: i}); + } + if (page !== nPages && nPages >= maxItems) { + pageLabels.push({'icon': 'chevron_right', page: nPages}); + pageLabels.push({'icon': 'last_page', page: 0}); + } + return pageLabels; } \ No newline at end of file diff --git a/src/style.css b/src/style.css index 145b89c..3abe299 100644 --- a/src/style.css +++ b/src/style.css @@ -48,16 +48,22 @@ main { font-weight: inherit; } -material-card { - min-height: 200px; +material-card, pagination .conatianer { max-width: 75%; margin: auto; margin-top: 20px; margin-bottom: 20px; } -material-card.header { - min-height: auto; +pagination .conatianer { + display: flex; + display: -moz-flex; + display: -webkit-flex; + display: -ms-flexbox; +} + +pagination .conatianer .pagination-centered { + margin: auto; } @media screen and (max-width: 950px){ @@ -216,12 +222,14 @@ material-card table th { } material-card material-button:hover, -material-card table tbody tr:hover { +material-card table tbody tr:hover, +pagination material-button:hover { background-color: #eee; } material-card material-button, -material-card table tbody tr { +material-card table tbody tr, +pagination material-button { transition-duration: .28s; transition-timing-function: cubic-bezier(.4, 0, .2, 1); transition-property: background-color; @@ -330,7 +338,8 @@ dropdown-item, #menu-control-dropdown p { background-color: #e0e0e0; } -material-popup material-button { +material-popup material-button, +pagination material-button { background-color: #fff; color: #000; } @@ -449,7 +458,8 @@ tag-history-button button { border: none; } -material-card material-button { +material-card material-button, +pagination material-button { max-height: 30px; max-width: 30px; } @@ -458,7 +468,8 @@ material-button:hover material-waves { background: none; } -material-card material-button { +material-card material-button, +pagination material-button { background-color: inherit; } @@ -510,4 +521,8 @@ material-checkbox .checkbox { material-checkbox .checkbox.checked { background-color: #777; +} + +pagination material-button { + padding: 0.2em 0.75em; } \ No newline at end of file diff --git a/src/tags/pagination.tag b/src/tags/pagination.tag new file mode 100644 index 0000000..97c0a6d --- /dev/null +++ b/src/tags/pagination.tag @@ -0,0 +1,31 @@ + + + +
+
+ + { p.icon } +
{ p.page }
+
+
+
+ + + \ No newline at end of file diff --git a/src/tags/taglist.tag b/src/tags/taglist.tag index 90248c1..4208cc9 100644 --- a/src/tags/taglist.tag +++ b/src/tags/taglist.tag @@ -30,6 +30,7 @@ along with this program. If not, see .
+ @@ -76,6 +77,7 @@ along with this program. If not, see .
+ \ No newline at end of file diff --git a/src/tags/taglist.tag b/src/tags/taglist.tag index 81d683d..2514a2d 100644 --- a/src/tags/taglist.tag +++ b/src/tags/taglist.tag @@ -83,7 +83,7 @@ along with this program. If not, see . \ No newline at end of file diff --git a/src/tags/pagination.tag b/src/tags/pagination.tag index 7ac292d..ee9df82 100644 --- a/src/tags/pagination.tag +++ b/src/tags/pagination.tag @@ -25,7 +25,16 @@ along with this program. If not, see .
\ No newline at end of file diff --git a/src/tags/taglist.tag b/src/tags/taglist.tag index 2514a2d..a2008dd 100644 --- a/src/tags/taglist.tag +++ b/src/tags/taglist.tag @@ -113,6 +113,11 @@ along with this program. If not, see . } }); + this.on('page-update', function(page) { + self.page = page; + this.update(); + }); + this._getRemoveImageTags = function() { var images = self.refs['taglist-tag'].tags['remove-image']; if (!(images instanceof Array)) { From dbb746981ab0a0d6ffec03e63ed51e05cc0fb1f5 Mon Sep 17 00:00:00 2001 From: Joxit Date: Sat, 15 Jun 2019 22:37:24 +0200 Subject: [PATCH 07/11] fix(pagination): Improve spacing for page next and first page buttons --- src/scripts/utils.js | 12 +++++++++--- src/style.css | 18 ++++++++++++++++++ src/tags/pagination.tag | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/scripts/utils.js b/src/scripts/utils.js index 878685e..4aece62 100644 --- a/src/scripts/utils.js +++ b/src/scripts/utils.js @@ -84,11 +84,17 @@ registryUI.getPageLabels = function(page, nPages) { var maxItems = 10; if (nPages === 1) { return pageLabels; } if (page !== 1 && nPages >= maxItems) { - pageLabels.push({'icon': 'first_page', page: 0}); + pageLabels.push({'icon': 'first_page', page: 1}); pageLabels.push({'icon': 'chevron_left', page: page - 1}); } - for (var i = Math.max(1, page - maxItems); i <= Math.min(nPages, page + maxItems); i++) { - pageLabels.push({page: i, current: i === page}); + var start = Math.round(Math.max(1, Math.min(page - maxItems / 2, nPages - maxItems + 1))); + for (var i = start; i < Math.min(nPages + 1, start + maxItems); i++) { + pageLabels.push({ + page: i, + current: i === page, + 'space-left': page === 1 && nPages > maxItems, + 'space-right': page === nPages && nPages > maxItems + }); } if (page !== nPages && nPages >= maxItems) { pageLabels.push({'icon': 'chevron_right', page: page + 1}); diff --git a/src/style.css b/src/style.css index 3630f98..ca3b8ac 100644 --- a/src/style.css +++ b/src/style.css @@ -527,6 +527,24 @@ pagination material-button { padding: 0.2em 0.75em; } +pagination material-button .content { + display: flex; + align-content: center; + line-height: 1.9em; +} + pagination material-button.current { border: 1px solid rgba(0, 0, 0, .12); +} + +pagination material-button.current.space-left { + margin-left: 85px; +} + +pagination material-button.current.space-right { + margin-right: 85px; +} + +pagination material-button .content i.material-icons { + color: #000; } \ No newline at end of file diff --git a/src/tags/pagination.tag b/src/tags/pagination.tag index ee9df82..1263a9e 100644 --- a/src/tags/pagination.tag +++ b/src/tags/pagination.tag @@ -18,7 +18,7 @@ along with this program. If not, see .
- + { p.icon }
{ p.page }
From e5a406a6bae30f7f640ee7918f05a6512ef844a0 Mon Sep 17 00:00:00 2001 From: Joxit Date: Sun, 16 Jun 2019 23:07:54 +0200 Subject: [PATCH 08/11] fix(pagination): Reset the number of selected tags to delete when the page is updated --- src/tags/taglist.tag | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tags/taglist.tag b/src/tags/taglist.tag index a2008dd..0370e24 100644 --- a/src/tags/taglist.tag +++ b/src/tags/taglist.tag @@ -115,6 +115,7 @@ along with this program. If not, see . this.on('page-update', function(page) { self.page = page; + this.toDelete = 0; this.update(); }); From ef149bf1cc0c9471f4e11100bb95355c82a7ae1a Mon Sep 17 00:00:00 2001 From: Joxit Date: Mon, 17 Jun 2019 00:46:46 +0200 Subject: [PATCH 09/11] chore: Memory optimization when delete is not activated --- src/tags/remove-image.tag | 17 +++++++++-------- src/tags/taglist.tag | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/tags/remove-image.tag b/src/tags/remove-image.tag index 15f4a9f..d3ed8c5 100644 --- a/src/tags/remove-image.tag +++ b/src/tags/remove-image.tag @@ -15,16 +15,21 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . --> - + delete - + diff --git a/src/tags/taglist.tag b/src/tags/taglist.tag index 0370e24..c207d11 100644 --- a/src/tags/taglist.tag +++ b/src/tags/taglist.tag @@ -48,7 +48,7 @@ along with this program. If not, see . onclick="registryUI.taglist.reverse();">Tag History - 0 } show="{ registryUI.isImageRemoveActivated }"> + 0 } if="{ registryUI.isImageRemoveActivated }"> 0 }> delete @@ -73,7 +73,7 @@ along with this program. If not, see . - + From 0ac7a151d9a044e7a5f35332174bb428718f7300 Mon Sep 17 00:00:00 2001 From: Joxit Date: Sun, 23 Jun 2019 22:55:32 +0200 Subject: [PATCH 10/11] fix(pagination): Wrong calcul for num pages --- src/scripts/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/utils.js b/src/scripts/utils.js index 4aece62..877f4f5 100644 --- a/src/scripts/utils.js +++ b/src/scripts/utils.js @@ -76,7 +76,7 @@ registryUI.getPage = function(elts, page, limit) { registryUI.getNumPages = function(elts, limit) { if (!limit) { limit = 100; } if (!elts) { return 0; } - return Math.trunc((elts.length / limit) % 10) + 1; + return Math.trunc(elts.length / limit) + 1; } registryUI.getPageLabels = function(page, nPages) { From 79960ea52df8ffb5193a04bd3a5e4f34410e4f25 Mon Sep 17 00:00:00 2001 From: Joxit Date: Thu, 27 Jun 2019 23:54:20 +0200 Subject: [PATCH 11/11] fix(pagination): page switch and regression on multi delete --- src/tags/pagination.tag | 1 - src/tags/remove-image.tag | 93 +++++++++++++++++++++------------------ src/tags/taglist.tag | 4 +- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/src/tags/pagination.tag b/src/tags/pagination.tag index 1263a9e..0607d1a 100644 --- a/src/tags/pagination.tag +++ b/src/tags/pagination.tag @@ -30,7 +30,6 @@ along with this program. If not, see . 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) } }); diff --git a/src/tags/remove-image.tag b/src/tags/remove-image.tag index d3ed8c5..5e0212a 100644 --- a/src/tags/remove-image.tag +++ b/src/tags/remove-image.tag @@ -22,7 +22,55 @@ along with this program. If not, see . diff --git a/src/tags/taglist.tag b/src/tags/taglist.tag index c207d11..f06bedf 100644 --- a/src/tags/taglist.tag +++ b/src/tags/taglist.tag @@ -114,7 +114,8 @@ along with this program. If not, see . }); this.on('page-update', function(page) { - self.page = page; + self.page = page < 1 ? 1 : page; + registryUI.updateQueryString(registryUI.getQueryParams({ page: self.page }) ); this.toDelete = 0; this.update(); }); @@ -167,6 +168,7 @@ along with this program. If not, see . registryUI.taglist.tags = registryUI.taglist.tags.map(function(tag) { return new registryUI.DockerImage(registryUI.taglist.name, tag); }).sort(registryUI.DockerImage.compare); + self.trigger('page-update', Math.min(self.page, registryUI.getNumPages(registryUI.taglist.tags))) } else if (this.status == 404) { registryUI.snackbar('Server not found', true); } else {