cli output save button

10.3.x-maintenance
Chris Charles 2017-05-16 08:11:32 +01:00
parent 6986d8b762
commit df556ad1bd
4 changed files with 51 additions and 2 deletions

View File

@ -1366,7 +1366,9 @@
"cliReboot": {
"message": "CLI reboot detected"
},
"cliSaveToFileBtn": {
"message": "Save"
},
"loggingNote": {
"message": "Data will be logged in this tab <span style=\"color: red\">only</span>, leaving the tab will <span style=\"color: red\">cancel</span> logging and application will return to its normal <strong>\"configurator\"</strong> state.<br /> You are free to select the global update period, data will be written into the log file every <strong>1</strong> second for performance reasons."
},

View File

@ -59,4 +59,8 @@
.tab-cli .window .wrapper {
white-space: pre-wrap;
}
.tab-cli .save {
color: white;
}

View File

@ -5,6 +5,9 @@
<p i18n="cliInfo"></p>
</div>
</div>
<div class="btn save_btn pull-right">
<a class="save" href="#" i18n="cliSaveToFileBtn"></a>
</div>
<div class="backdrop">
<div class="window">
<div class="wrapper"></div>

View File

@ -5,7 +5,8 @@ TABS.cli = {
'currentLine': "",
'sequenceElements': 0,
lineDelayMs: 15,
profileSwitchDelayMs: 100
profileSwitchDelayMs: 100,
outputHistory: ""
};
TABS.cli.initialize = function (callback) {
@ -15,6 +16,8 @@ TABS.cli.initialize = function (callback) {
GUI.active_tab = 'cli';
}
self.outputHistory = "";
$('#content').load("./tabs/cli.html", function () {
// translate to user-selected language
localize();
@ -23,6 +26,42 @@ TABS.cli.initialize = function (callback) {
var textarea = $('.tab-cli textarea');
$('.tab-cli .save').click(function() {
var prefix = 'cli';
var suffix = 'txt';
var filename = generateFilename(prefix, suffix);
var accepts = [{
extensions: [suffix],
}];
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, accepts: accepts}, function(entry) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return;
}
if (!entry) {
console.log('No file selected');
return;
}
entry.createWriter(function(writer) {
writer.onerror = function (){
console.error('Failed to write file');
};
writer.onwriteend = function(e) {
console.log('write complete');
};
writer.write(new Blob([self.outputHistory], {type: 'text/plain'}));
},function (){
console.error('Failed to get file writer');
});
});
});
textarea.keypress(function (event) {
if (event.which == 13) { // enter
event.preventDefault(); // prevent the adding of new line
@ -153,6 +192,7 @@ TABS.cli.read = function (readInfo) {
text += String.fromCharCode(data[i]);
this.currentLine += String.fromCharCode(data[i]);
}
this.outputHistory += String.fromCharCode(data[i])
}
if (this.currentLine == 'Rebooting') {
CONFIGURATOR.cliActive = false;