From e990c39a1873f66e501faef97da8dc8d0531ed9e Mon Sep 17 00:00:00 2001 From: Joxit Date: Tue, 13 Apr 2021 05:34:28 +0200 Subject: [PATCH] feat: allow sorting of tags by creation date and size (#125) closes #125 --- .../tag-list/copy-to-clipboard.riot | 29 ++++++----- .../tag-list/image-content-digest.riot | 48 +++++++++++-------- src/components/tag-list/image-date.riot | 14 +++--- src/components/tag-list/image-size.riot | 18 +++++-- src/components/tag-list/tag-table.riot | 41 ++++++++++++++-- 5 files changed, 107 insertions(+), 43 deletions(-) diff --git a/src/components/tag-list/copy-to-clipboard.riot b/src/components/tag-list/copy-to-clipboard.riot index b10a48d..8858897 100644 --- a/src/components/tag-list/copy-to-clipboard.riot +++ b/src/components/tag-list/copy-to-clipboard.riot @@ -16,7 +16,7 @@ -->
- + content_copy @@ -27,33 +27,40 @@ ERROR_CAN_NOT_READ_CONTENT_DIGEST } from '../../scripts/utils'; export default { - onBeforeMount(props, state) { + onMounted(props, state) { + this.load(props, state); + }, + onUpdated(props, state) { + this.load(props, state); + }, + getDockerCmd(props) { if (props.target === 'tag') { - state.dockerCmd = `docker pull ${props.pullUrl}/${props.image.name}:${props.image.tag}`; + return `docker pull ${props.pullUrl}/${props.image.name}:${props.image.tag}`; + } else { + return `docker pull ${props.pullUrl}/${props.image.name}@${props.image.digest}` } }, - onMounted(props, state) { - if (props.target !== 'tag') { + load(props, state) { + if (props.target !== 'tag' && !props.image.digest) { props.image.one('content-digest', (digest) => { - this.update({ - dockerCmd: `docker pull ${props.pullUrl}/${props.image.name}@${digest}` - }) + this.update() }); props.image.trigger('get-content-digest'); } }, copy() { - if (!this.state.dockerCmd) { + const copyText = this.$('input'); + if (!copyText.value) { this.props.onNotify(ERROR_CAN_NOT_READ_CONTENT_DIGEST); return; } - const copyText = this.$('input'); + copyText.style.display = 'block'; copyText.select(); document.execCommand('copy'); copyText.style.display = 'none'; - this.props.onNotify('`' + this.state.dockerCmd + '` has been copied to clipboard.') + this.props.onNotify('`' + copyText.value + '` has been copied to clipboard.') } } diff --git a/src/components/tag-list/image-content-digest.riot b/src/components/tag-list/image-content-digest.riot index 3cd1d2b..9fef135 100644 --- a/src/components/tag-list/image-content-digest.riot +++ b/src/components/tag-list/image-content-digest.riot @@ -15,11 +15,20 @@ Copyright (C) 2016-2021 Jones Magloire @Joxit along with this program. If not, see . --> -
{ state.displayId }
+
{ getDigest(props.image, state.chars) }
diff --git a/src/components/tag-list/image-date.riot b/src/components/tag-list/image-date.riot index 9827ecd..33d69b9 100644 --- a/src/components/tag-list/image-date.riot +++ b/src/components/tag-list/image-date.riot @@ -15,17 +15,14 @@ along with this program. If not, see . --> -
{ dateFormat(state.date) } ago
+
{ getDate(props.image) } ago
\ No newline at end of file diff --git a/src/components/tag-list/image-size.riot b/src/components/tag-list/image-size.riot index 619af6e..ed8fe2f 100644 --- a/src/components/tag-list/image-size.riot +++ b/src/components/tag-list/image-size.riot @@ -15,21 +15,33 @@ along with this program. If not, see . --> -
{ bytesToSize(state.size) }
+
{ getImageSize(props.image) }
\ No newline at end of file diff --git a/src/components/tag-list/tag-table.riot b/src/components/tag-list/tag-table.riot index 43d8e99..d69fc8d 100644 --- a/src/components/tag-list/tag-table.riot +++ b/src/components/tag-list/tag-table.riot @@ -19,13 +19,21 @@ along with this program. If not, see . - - + +
Creation dateSize + Creation date + + Size + Content Digest Tag + onclick="{ onReverseOrder }">Tag History @@ -138,7 +146,32 @@ along with this program. If not, see . toDelete: this.state.toDelete }) }, - getPage, + onReverseOrder() { + this.state.orderType = null; + this.state.desc = false; + this.props.onReverseOrder(); + }, + onPageReorder(type) { + this.update({ + orderType: type, + desc: (this.state.orderType && this.state.orderType !== type) || !this.state.desc + }) + }, + getPage(tags, page) { + const sortedTags = getPage(tags, page); + if (this.state.orderType === 'date') { + sortedTags.sort((e1, e2) => + !this.state.desc ? + e2.creationDate.getTime() - e1.creationDate.getTime() : + e1.creationDate.getTime() - e2.creationDate.getTime()); + } else if (this.state.orderType === 'size') { + sortedTags.sort((e1, e2) => + !this.state.desc ? + e2.size - e1.size : + e1.size - e2.size); + } + return sortedTags; + }, matchSearch }