From 4cb79a670f158c162ad6e8ebfe279a9ab5c05d26 Mon Sep 17 00:00:00 2001 From: Joxit Date: Fri, 16 Nov 2018 22:07:49 +0100 Subject: [PATCH] [feat #49] Add creation date to taglist --- gulpfile.js | 39 ++++++++++++++++--------------------- package.json | 14 +++++++------- src/index.html | 1 + src/tags/app.tag | 42 ++++++++++++++++++++++++++++++++-------- src/tags/image-date.tag | 43 +++++++++++++++++++++++++++++++++++++++++ src/tags/taglist.tag | 2 ++ 6 files changed, 104 insertions(+), 37 deletions(-) create mode 100644 src/tags/image-date.tag diff --git a/gulpfile.js b/gulpfile.js index 78046b21..84b1042d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -3,9 +3,10 @@ const cleanCSS = require('gulp-clean-css'); const concat = require('gulp-concat'); const del = require('del'); const filter = require('gulp-filter'); -const fs = require('fs'); const gIf = require('gulp-if'); const gulp = require('gulp'); +const parallel = gulp.parallel; +const series = gulp.series; const htmlmin = require('gulp-htmlmin'); const license = require('gulp-license'); const riot = require('gulp-riot'); @@ -37,7 +38,7 @@ const staticScripts = [ 'src/scripts/static.js' ]; -gulp.task('html', function() { +function html() { var htmlFilter = filter('**/*.html', {restore: true}); return gulp.src(['src/index.html']) .pipe(useref()) @@ -52,13 +53,13 @@ gulp.task('html', function() { })) .pipe(htmlFilter.restore) .pipe(gulp.dest('dist')); -}); +}; -gulp.task('clean', function(done) { +function clean() { return del(['dist']); -}); +}; -gulp.task('docker-registry-ui-static', ['html'], function() { +function appStatic() { return merge(gulp.src(staticScripts), gulp.src(staticTags).pipe(riot())) .pipe(concat('docker-registry-ui-static.js')) .pipe(minifier()) @@ -70,9 +71,9 @@ gulp.task('docker-registry-ui-static', ['html'], function() { })) .pipe(injectVersion()) .pipe(gulp.dest('dist/scripts')); -}); +}; -gulp.task('docker-registry-ui', ['html'], function() { +function app() { return merge(gulp.src(allScripts), gulp.src(allTags).pipe(riot())) .pipe(concat('docker-registry-ui.js')) .pipe(minifier()) @@ -84,15 +85,15 @@ gulp.task('docker-registry-ui', ['html'], function() { })) .pipe(injectVersion()) .pipe(gulp.dest('dist/scripts')); -}); +}; -gulp.task('vendor', ['html'], function() { +function vendor() { return gulp.src(['node_modules/riot/riot.min.js', 'node_modules/riot-route/dist/route.min.js', 'node_modules/riot-mui/build/js/riot-mui-min.js']) .pipe(concat('vendor.js')) .pipe(gulp.dest('dist/scripts')); -}); +}; -gulp.task('styles', ['html'], function() { +function styles() { return gulp.src(['src/*.css']) .pipe(concat('style.css')) .pipe(cleanCSS({ @@ -105,18 +106,12 @@ gulp.task('styles', ['html'], function() { organization: 'Jones Magloire @Joxit' })) .pipe(gulp.dest('dist/')); -}); +}; -gulp.task('fonts', function() { +function fonts() { return gulp.src('src/fonts/*') .pipe(filter('**/*.{otf,eot,svg,ttf,woff,woff2}')) .pipe(gulp.dest('dist/fonts')); -}); +}; -gulp.task('sources', ['docker-registry-ui', 'vendor', 'docker-registry-ui-static', 'styles'], function() { - gulp.start(); -}); - -gulp.task('build', ['clean'], function() { - gulp.start(['sources', 'fonts']); -}); \ No newline at end of file +exports.build = series(clean, html, parallel(fonts, styles, vendor, app, appStatic)); \ No newline at end of file diff --git a/package.json b/package.json index 782720d8..e4f9cae6 100644 --- a/package.json +++ b/package.json @@ -14,20 +14,20 @@ "dependencies": {}, "devDependencies": { "del": "^3.0.0", - "gulp": "^3.9", - "gulp-clean-css": "^3.9.4", + "gulp": "^4.0", + "gulp-clean-css": "^3.10.0", "gulp-concat": "^2.6.0", "gulp-filter": "^5.1.0", "gulp-htmlmin": "^3.0.0", "gulp-if": "^2.0.0", "gulp-inject-version": "^1.0.1", "gulp-license": "^1.1.0", - "gulp-riot": "^1.1.4", - "gulp-uglify": "^3.0.0", - "gulp-useref": "^3.1.5", - "riot": "^3.11.1", + "gulp-riot": "^1.1.5", + "gulp-uglify": "^3.0.1", + "gulp-useref": "^3.1.6", + "riot": "^3.13.1", "riot-mui": "^0.1.1", - "riot-route": "^3.1.3", + "riot-route": "^3.1.4", "stream-series": "^0.1.1", "uglify-es": "^3.3.10" } diff --git a/src/index.html b/src/index.html index edd98506..f002241b 100644 --- a/src/index.html +++ b/src/index.html @@ -48,6 +48,7 @@ + diff --git a/src/tags/app.tag b/src/tags/app.tag index 3dca3f25..4409b75f 100644 --- a/src/tags/app.tag +++ b/src/tags/app.tag @@ -78,7 +78,7 @@ return registryUI.snackbar(message, true); } registryUI.cleanName = function() { - var url = (registryUI.url() && registryUI.url().length > 0 && registryUI.url()) || window.location.host; + const url = (registryUI.url() && registryUI.url().length > 0 && registryUI.url()) || window.location.host; if (url) { return url.startsWith('http') ? url.replace(/https?:\/\//, '') : url; } @@ -114,6 +114,12 @@ } return this.fillInfo(); }); + this.on('get-date', function() { + if (this.date !== undefined) { + return this.trigger('date', this.date); + } + return this.fillInfo(); + }); }; registryUI.DockerImage._tagReduce = function (acc, e) { @@ -126,13 +132,13 @@ } registryUI.DockerImage.compare = function(e1, e2) { - var tag1 = e1.tag.match(/./g).reduce(registryUI.DockerImage._tagReduce, []); - var tag2 = e2.tag.match(/./g).reduce(registryUI.DockerImage._tagReduce, []); + const tag1 = e1.tag.match(/./g).reduce(registryUI.DockerImage._tagReduce, []); + const tag2 = e2.tag.match(/./g).reduce(registryUI.DockerImage._tagReduce, []); for (var i = 0; i < tag1.length && i < tag2.length; i++) { - var compare = tag1[i].localeCompare(tag2[i]); + const compare = tag1[i].localeCompare(tag2[i]); if (registryUI.isDigit(tag1[i].charAt(0)) && registryUI.isDigit(tag2[i].charAt(0))) { - var diff = tag1[i] - tag2[i]; + const diff = tag1[i] - tag2[i]; if (diff != 0) { return diff; } @@ -148,17 +154,18 @@ return; } this._fillInfoWaiting = true; - var oReq = new Http(); - var self = this; + const oReq = new Http(); + const self = this; oReq.addEventListener('loadend', function () { if (this.status == 200 || this.status == 202) { - var response = JSON.parse(this.responseText); + const response = JSON.parse(this.responseText); self.size = response.layers.reduce(function (acc, e) { return acc + e.size; }, 0); self.sha256 = response.config.digest; self.trigger('size', self.size); self.trigger('sha256', self.sha256); + self.getBlobs(response.config.digest) } else if (this.status == 404) { registryUI.errorSnackbar('Manifest for ' + self.name + ':' + self.tag + ' not found'); } else { @@ -169,6 +176,25 @@ oReq.setRequestHeader('Accept', 'application/vnd.docker.distribution.manifest.v2+json'); oReq.send(); } + + registryUI.DockerImage.prototype.getBlobs = function(blob) { + const oReq = new Http(); + const self = this; + oReq.addEventListener('loadend', function () { + if (this.status == 200 || this.status == 202) { + const response = JSON.parse(this.responseText); + self.creationDate = new Date(response.created); + self.trigger('creation-date', self.creationDate); + } else if (this.status == 404) { + registryUI.errorSnackbar('Blobs for ' + self.name + ':' + self.tag + ' not found'); + } else { + registryUI.snackbar(this.responseText); + } + }); + oReq.open('GET', registryUI.url() + '/v2/' + self.name + '/blobs/' + blob); + oReq.setRequestHeader('Accept', 'application/vnd.docker.distribution.manifest.v2+json'); + oReq.send(); + }; route.start(true); \ No newline at end of file diff --git a/src/tags/image-date.tag b/src/tags/image-date.tag new file mode 100644 index 00000000..4247f988 --- /dev/null +++ b/src/tags/image-date.tag @@ -0,0 +1,43 @@ + + +
{ this.dateFormat(this.date) } ago
+ +
\ No newline at end of file diff --git a/src/tags/taglist.tag b/src/tags/taglist.tag index 1871420c..3f68790f 100644 --- a/src/tags/taglist.tag +++ b/src/tags/taglist.tag @@ -31,6 +31,7 @@ Repository + Creation date Size Tag @@ -42,6 +43,7 @@ +