From 9c303d32c718456d0555c75882ec13a1b7d6353c Mon Sep 17 00:00:00 2001 From: Joxit Date: Sun, 14 Mar 2021 10:06:51 +0100 Subject: [PATCH] feat(riot-v5): upgrade image content-digest, date, size and tag from tag-list --- .../tag-list/image-content-digest.riot | 50 +++++++++++++++++++ .../tag-list}/image-date.riot | 31 ++++++++---- .../tag-list}/image-size.riot | 24 ++++++--- .../tag-list}/image-tag.riot | 20 +++++--- src/components/tag-list/tag-list.riot | 9 +++- src/components/tag-list/tag-table.riot | 15 ++++-- src/scripts/docker-image.js | 9 ++-- src/tags/image-content-digest.riot | 48 ------------------ 8 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 src/components/tag-list/image-content-digest.riot rename src/{tags => components/tag-list}/image-date.riot (58%) rename src/{tags => components/tag-list}/image-size.riot (64%) rename src/{tags => components/tag-list}/image-tag.riot (69%) delete mode 100644 src/tags/image-content-digest.riot diff --git a/src/components/tag-list/image-content-digest.riot b/src/components/tag-list/image-content-digest.riot new file mode 100644 index 00000000..3cd1d2be --- /dev/null +++ b/src/components/tag-list/image-content-digest.riot @@ -0,0 +1,50 @@ + + +
{ state.displayId }
+ +
\ No newline at end of file diff --git a/src/tags/image-date.riot b/src/components/tag-list/image-date.riot similarity index 58% rename from src/tags/image-date.riot rename to src/components/tag-list/image-date.riot index 03b8bbd1..2e3894c0 100644 --- a/src/tags/image-date.riot +++ b/src/components/tag-list/image-date.riot @@ -15,16 +15,25 @@ along with this program. If not, see . --> -
{ registryUI.dateFormat(this.date) } ago
-
\ No newline at end of file diff --git a/src/tags/image-size.riot b/src/components/tag-list/image-size.riot similarity index 64% rename from src/tags/image-size.riot rename to src/components/tag-list/image-size.riot index c262fb58..17f3588a 100644 --- a/src/tags/image-size.riot +++ b/src/components/tag-list/image-size.riot @@ -15,13 +15,21 @@ along with this program. If not, see . --> -
{ registryUI.bytesToSize(this.size) }
-
\ No newline at end of file diff --git a/src/tags/image-tag.riot b/src/components/tag-list/image-tag.riot similarity index 69% rename from src/tags/image-tag.riot rename to src/components/tag-list/image-tag.riot index 484a569e..6b1a506c 100644 --- a/src/tags/image-tag.riot +++ b/src/components/tag-list/image-tag.riot @@ -15,13 +15,17 @@ along with this program. If not, see . --> -
{ opts.image.tag }
-
\ No newline at end of file diff --git a/src/components/tag-list/tag-list.riot b/src/components/tag-list/tag-list.riot index e14dc695..2985e181 100644 --- a/src/components/tag-list/tag-list.riot +++ b/src/components/tag-list/tag-list.riot @@ -36,7 +36,7 @@ along with this program. If not, see . - @@ -72,6 +72,10 @@ along with this program. If not, see . }, onMounted(props, state) { this.display(props, state) + window.addEventListener('resize', this.onResize); + // this may be run before the final document size is available, so schedule + // a correction once everything is set up. + window.requestAnimationFrame(this.onResize); }, display(props, state) { state.tags = []; @@ -82,7 +86,7 @@ along with this program. If not, see . if (this.status == 200) { const tags = JSON.parse(this.responseText).tags || []; state.tags = tags.map(function (tag) { - return new DockerImage(props.image, tag); + return new DockerImage(props.image, tag, null, props.registryUrl); }).sort(compare); window.requestAnimationFrame(self.onResize); self.update({ @@ -130,6 +134,7 @@ along with this program. If not, see . chars = 15 + 56 * ((innerWidth - 1024) / 416); } if (max > 20) chars -= (max - 20); + chars = Math.floor(chars) this.state.tags.map(function (image) { image.trigger('content-digest-chars', chars); }); diff --git a/src/components/tag-list/tag-table.riot b/src/components/tag-list/tag-table.riot index d498eebe..bc88984d 100644 --- a/src/components/tag-list/tag-table.riot +++ b/src/components/tag-list/tag-table.riot @@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . --> - + @@ -39,7 +39,7 @@ along with this program. If not, see . - + @@ -70,10 +70,17 @@ along with this program. If not, see . } from '../../scripts/http'; import { getPage, - } from '../../scripts/utils' + } from '../../scripts/utils'; + import ImageDate from './image-date.riot'; + import ImageSize from './image-size.riot'; + import ImageTag from './image-tag.riot'; + import ImageContentDigest from './image-content-digest.riot'; export default { components: { - + ImageDate, + ImageSize, + ImageTag, + ImageContentDigest, }, onBeforeMount(props) { this.state = { diff --git a/src/scripts/docker-image.js b/src/scripts/docker-image.js index 684d3546..bc75abc5 100644 --- a/src/scripts/docker-image.js +++ b/src/scripts/docker-image.js @@ -30,10 +30,11 @@ export function compare(e1, e2) { } export class DockerImage { - constructor(name, tag, list) { + constructor(name, tag, list, registryUrl) { this.name = name; this.tag = tag; this.list = list; + this.registryUrl = registryUrl; this.chars = 0; observable(this); this.on('get-size', function () { @@ -107,7 +108,7 @@ export class DockerImage { // registryUI.snackbar(this.responseText); } }); - oReq.open('GET', registryUI.url() + '/v2/' + self.name + '/manifests/' + self.tag); + oReq.open('GET', this.registryUrl + '/v2/' + self.name + '/manifests/' + self.tag); oReq.setRequestHeader( 'Accept', 'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json' + @@ -115,7 +116,7 @@ export class DockerImage { ); oReq.send(); } - getBlobs() { + getBlobs(blob) { const oReq = new Http(); const self = this; oReq.addEventListener('loadend', function () { @@ -140,7 +141,7 @@ export class DockerImage { registryUI.snackbar(this.responseText); } }); - oReq.open('GET', registryUI.url() + '/v2/' + self.name + '/blobs/' + blob); + oReq.open('GET', this.registryUrl + '/v2/' + self.name + '/blobs/' + blob); oReq.setRequestHeader( 'Accept', 'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json' diff --git a/src/tags/image-content-digest.riot b/src/tags/image-content-digest.riot deleted file mode 100644 index 5940aadd..00000000 --- a/src/tags/image-content-digest.riot +++ /dev/null @@ -1,48 +0,0 @@ - - -
{ this.display_id }
- -
\ No newline at end of file