Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ecf0515

Browse files
committedDec 14, 2016
Let users save logs
Adds a "Save" link to the log viewer that saves the log contents as a file.
1 parent 8e40552 commit ecf0515

File tree

8 files changed

+104
-10
lines changed

8 files changed

+104
-10
lines changed
 

‎.jshintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"Clipboard": false,
3737
"$": false,
3838
"_" : false,
39-
"URITemplate": false
39+
"URITemplate": false,
40+
"saveAs": false
4041
}
4142
}

‎app/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ <h1>JavaScript Required</h1>
153153
<script src="bower_components/js-yaml/dist/js-yaml.js"></script>
154154
<script src="bower_components/angular-moment/angular-moment.js"></script>
155155
<script src="bower_components/angular-utf8-base64/angular-utf8-base64.js"></script>
156+
<script src="bower_components/file-saver/FileSaver.js"></script>
156157
<!-- endbower -->
157158
<!-- endbuild -->
158159

‎app/scripts/directives/logViewer.js

+9
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ angular.module('openshiftConsole')
385385
streamer.start();
386386
};
387387

388+
// Detect if we can save files.
389+
// https://github.com/eligrey/FileSaver.js#supported-browsers
390+
$scope.canSave = !!new Blob();
391+
$scope.saveLog = function() {
392+
var text = $('.log-line-text').text();
393+
var filename = _.get($scope, 'object.metadata.name', 'openshift') + '.log';
394+
var blob = new Blob([text], { type: "text/plain;charset=utf-8" });
395+
saveAs(blob, filename);
396+
};
388397

389398
// Kibana archives -------------------------------------------------
390399

‎app/views/directives/logs/_log-viewer.html

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@
1616
</form>
1717
<span ng-if="state && state !== 'empty'" class="action-divider">|</span>
1818
</span>
19+
<span ng-if="canSave && state && state !== 'empty'">
20+
<a href=""
21+
ng-click="saveLog()"
22+
role="button">
23+
Save
24+
<i class="fa fa-download"></i></a>
25+
<span ng-if="state && state !== 'empty'" class="action-divider">|</span>
26+
</span>
1927
<a ng-if="state && state !== 'empty'"
2028
href=""
2129
ng-click="goChromeless(options, fullLogUrl)"
2230
role="button">
23-
Expand Log
24-
<i class="fa fa-external-link"></i>
25-
</a>
31+
Expand
32+
<i class="fa fa-external-link"></i></a>
2633
</div>
2734
</div>
2835

‎bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"angular-inview": "1.5.7",
4545
"js-yaml": "3.6.1",
4646
"angular-moment": "1.0.0",
47-
"angular-utf8-base64": "0.0.5"
47+
"angular-utf8-base64": "0.0.5",
48+
"file-saver": "1.3.3"
4849
},
4950
"devDependencies": {
5051
"angular-mocks": "1.3.20",

‎dist/scripts/scripts.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -11676,7 +11676,12 @@ autoScroll:!1
1167611676
}), D.start();
1167711677
}
1167811678
};
11679-
return g.getLoggingURL().then(function(b) {
11679+
return l.canSave = !!new Blob(), l.saveLog = function() {
11680+
var a = $(".log-line-text").text(), b = _.get(l, "object.metadata.name", "openshift") + ".log", c = new Blob([ a ], {
11681+
type:"text/plain;charset=utf-8"
11682+
});
11683+
saveAs(c, b);
11684+
}, g.getLoggingURL().then(function(b) {
1168011685
var d = _.get(l.context, "project.metadata.name"), f = _.get(l.options, "container");
1168111686
d && f && u && b && (angular.extend(l, {
1168211687
kibanaAuthUrl:a.trustAsResourceUrl(URI(b).segment("auth").segment("token").normalizePathname().toString()),

‎dist/scripts/templates.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -7080,10 +7080,15 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
70807080
"</form>\n" +
70817081
"<span ng-if=\"state && state !== 'empty'\" class=\"action-divider\">|</span>\n" +
70827082
"</span>\n" +
7083+
"<span ng-if=\"canSave && state && state !== 'empty'\">\n" +
7084+
"<a href=\"\" ng-click=\"saveLog()\" role=\"button\">\n" +
7085+
"Save\n" +
7086+
"<i class=\"fa fa-download\"></i></a>\n" +
7087+
"<span ng-if=\"state && state !== 'empty'\" class=\"action-divider\">|</span>\n" +
7088+
"</span>\n" +
70837089
"<a ng-if=\"state && state !== 'empty'\" href=\"\" ng-click=\"goChromeless(options, fullLogUrl)\" role=\"button\">\n" +
7084-
"Expand Log\n" +
7085-
"<i class=\"fa fa-external-link\"></i>\n" +
7086-
"</a>\n" +
7090+
"Expand\n" +
7091+
"<i class=\"fa fa-external-link\"></i></a>\n" +
70877092
"</div>\n" +
70887093
"</div>\n" +
70897094
"<div ng-if=\"largeLog\" class=\"alert alert-info log-size-warning\">\n" +

‎dist/scripts/vendor.js

+66-1
Original file line numberDiff line numberDiff line change
@@ -56108,4 +56108,69 @@ encode:a.encode,
5610856108
urldecode:b.decode,
5610956109
urlencode:b.encode
5611056110
};
56111-
}());
56111+
}());
56112+
56113+
var saveAs = saveAs || function(a) {
56114+
"use strict";
56115+
if (!("undefined" == typeof a || "undefined" != typeof navigator && /MSIE [1-9]\./.test(navigator.userAgent))) {
56116+
var b = a.document, c = function() {
56117+
return a.URL || a.webkitURL || a;
56118+
}, d = b.createElementNS("http://www.w3.org/1999/xhtml", "a"), e = "download" in d, f = function(a) {
56119+
var b = new MouseEvent("click");
56120+
a.dispatchEvent(b);
56121+
}, g = /constructor/i.test(a.HTMLElement) || a.safari, h = /CriOS\/[\d]+/.test(navigator.userAgent), i = function(b) {
56122+
(a.setImmediate || a.setTimeout)(function() {
56123+
throw b;
56124+
}, 0);
56125+
}, j = "application/octet-stream", k = 4e4, l = function(a) {
56126+
var b = function() {
56127+
"string" == typeof a ? c().revokeObjectURL(a) :a.remove();
56128+
};
56129+
setTimeout(b, k);
56130+
}, m = function(a, b, c) {
56131+
b = [].concat(b);
56132+
for (var d = b.length; d--; ) {
56133+
var e = a["on" + b[d]];
56134+
if ("function" == typeof e) try {
56135+
e.call(a, c || a);
56136+
} catch (f) {
56137+
i(f);
56138+
}
56139+
}
56140+
}, n = function(a) {
56141+
return /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type) ? new Blob([ String.fromCharCode(65279), a ], {
56142+
type:a.type
56143+
}) :a;
56144+
}, o = function(b, i, k) {
56145+
k || (b = n(b));
56146+
var o, p = this, q = b.type, r = q === j, s = function() {
56147+
m(p, "writestart progress write writeend".split(" "));
56148+
}, t = function() {
56149+
if ((h || r && g) && a.FileReader) {
56150+
var d = new FileReader();
56151+
return d.onloadend = function() {
56152+
var b = h ? d.result :d.result.replace(/^data:[^;]*;/, "data:attachment/file;"), c = a.open(b, "_blank");
56153+
c || (a.location.href = b), b = void 0, p.readyState = p.DONE, s();
56154+
}, d.readAsDataURL(b), void (p.readyState = p.INIT);
56155+
}
56156+
if (o || (o = c().createObjectURL(b)), r) a.location.href = o; else {
56157+
var e = a.open(o, "_blank");
56158+
e || (a.location.href = o);
56159+
}
56160+
p.readyState = p.DONE, s(), l(o);
56161+
};
56162+
return p.readyState = p.INIT, e ? (o = c().createObjectURL(b), void setTimeout(function() {
56163+
d.href = o, d.download = i, f(d), s(), l(o), p.readyState = p.DONE;
56164+
})) :void t();
56165+
}, p = o.prototype, q = function(a, b, c) {
56166+
return new o(a, b || a.name || "download", c);
56167+
};
56168+
return "undefined" != typeof navigator && navigator.msSaveOrOpenBlob ? function(a, b, c) {
56169+
return b = b || a.name || "download", c || (a = n(a)), navigator.msSaveOrOpenBlob(a, b);
56170+
} :(p.abort = function() {}, p.readyState = p.INIT = 0, p.WRITING = 1, p.DONE = 2, p.error = p.onwritestart = p.onprogress = p.onwrite = p.onabort = p.onerror = p.onwriteend = null, q);
56171+
}
56172+
}("undefined" != typeof self && self || "undefined" != typeof window && window || this.content);
56173+
56174+
"undefined" != typeof module && module.exports ? module.exports.saveAs = saveAs :"undefined" != typeof define && null !== define && null !== define.amd && define("FileSaver.js", function() {
56175+
return saveAs;
56176+
});

0 commit comments

Comments
 (0)
Please sign in to comment.