Skip to content

Commit a8c043f

Browse files
author
Gary Keeble
committed
Enable Log Header "Save" Feature
Enable changes on log header dialog box. Missing values from the log header can be entered on the dialog box and saved. The original log file remains unaltered and any existing values in the header will overwrite the dialog box entries.
1 parent d6c4172 commit a8c043f

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

js/flightlog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function FlightLog(logData) {
117117
};
118118

119119
this.setSysConfig = function(newSysConfig) {
120-
parser.sysConfig = newSysConfig;
120+
$.extend(true, parser.sysConfig, newSysConfig);
121121
};
122122

123123

js/main.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ function BlackboxLogViewer() {
3939
// JSON graph configuration:
4040
graphConfig = {},
4141

42+
offsetCache = [], // Storage for the offset cache (last 20 files)
43+
currentOffsetCache = {log:null, index:null, video:null, offset:null},
44+
4245
// JSON array of graph configurations for New Workspaces feature
4346
lastGraphConfig = null, // Undo feature - go back to last configuration.
4447
workspaceGraphConfigs = {}, // Workspaces
@@ -100,7 +103,7 @@ function BlackboxLogViewer() {
100103
*/
101104
$(".video-offset").val((videoOffset >= 0 ? "+" : "") + (videoOffset.toFixed(3) != videoOffset ? videoOffset.toFixed(3) : videoOffset));
102105

103-
if (wihtoutRefresh) invalidateGraph();
106+
if (withoutRefresh) invalidateGraph();
104107
}
105108

106109
function isInteger(value) {
@@ -434,6 +437,7 @@ function BlackboxLogViewer() {
434437
for (var i = 0; i < flightLog.getLogCount(); i++) {
435438
if (flightLog.openLog(i)) {
436439
success = true;
440+
currentOffsetCache.index = i;
437441
break;
438442
}
439443
}
@@ -443,9 +447,11 @@ function BlackboxLogViewer() {
443447
}
444448
} else {
445449
flightLog.openLog(logIndex);
450+
currentOffsetCache.index = logIndex;
446451
}
447452
} catch (e) {
448453
alert("Error opening log: " + e);
454+
currentOffsetCache.index = null;
449455
return;
450456
}
451457

@@ -510,6 +516,8 @@ function BlackboxLogViewer() {
510516
}
511517

512518
renderLogFileInfo(file);
519+
currentOffsetCache.log = file.name; // store the name of the loaded log file
520+
currentOffsetCache.index = null; // and clear the index
513521

514522
hasLog = true;
515523
$("html").addClass("has-log");
@@ -524,13 +532,15 @@ function BlackboxLogViewer() {
524532
}
525533

526534
function loadVideo(file) {
535+
currentOffsetCache.video = file.name; // store the name of the loaded video
527536
if (videoURL) {
528537
URL.revokeObjectURL(videoURL);
529538
videoURL = false;
530539
}
531540

532541
if (!URL.createObjectURL) {
533542
alert("Sorry, your web browser doesn't support showing videos from your local computer. Try Google Chrome instead.");
543+
currentOffsetCache.video = null; // clear the associated video name
534544
return;
535545
}
536546

@@ -634,6 +644,13 @@ function BlackboxLogViewer() {
634644
]};
635645
}
636646
});
647+
648+
// Get the offsetCache buffer
649+
prefs.get('offsetCache', function(item) {
650+
if(item) {
651+
offsetCache = item;
652+
}
653+
})
637654

638655
activeGraphConfig.addListener(function() {
639656
invalidateGraph();
@@ -677,12 +694,11 @@ function BlackboxLogViewer() {
677694
}
678695
});
679696

680-
681697
$(".file-open").change(function(e) {
682698
var
683699
files = e.target.files,
684700
i;
685-
701+
686702
for (i = 0; i < files.length; i++) {
687703
var
688704
isLog = files[i].name.match(/\.(TXT|CFL|LOG)$/i),
@@ -701,8 +717,19 @@ function BlackboxLogViewer() {
701717
loadVideo(files[i]);
702718
}
703719
}
704-
});
705720

721+
// finally, see if there is an offsetCache value already, and auto set the offset
722+
for(i=0; i<offsetCache.length; i++) {
723+
if(
724+
(currentOffsetCache.log == offsetCache[i].log) &&
725+
(currentOffsetCache.index == offsetCache[i].index) &&
726+
(currentOffsetCache.video == offsetCache[i].video) ) {
727+
setVideoOffset(offsetCache[i].offset, true);
728+
}
729+
730+
}
731+
});
732+
706733
// New View Controls
707734
$(".view-craft").click(function() {
708735
hasCraft = !hasCraft;
@@ -814,7 +841,14 @@ function BlackboxLogViewer() {
814841
var offset = parseFloat($(".video-offset").val());
815842

816843
if (!isNaN(offset)) {
817-
videoOffset = offset;
844+
videoOffset = offset;
845+
// Store the video offset to the local cache
846+
currentOffsetCache.offset = offset;
847+
if(hasLog && hasVideo) {
848+
if(offsetCache.length > 20) offsetCache.shift();
849+
offsetCache.push(currentOffsetCache);
850+
prefs.set('offsetCache', offsetCache);
851+
}
818852
invalidateGraph();
819853
}
820854
});
@@ -853,10 +887,11 @@ function BlackboxLogViewer() {
853887
headerDialog = new HeaderDialog($("#dlgHeaderDialog"), function(newSysConfig) {
854888
if(newSysConfig!=null) {
855889
prefs.set('lastHeaderData', newSysConfig);
856-
//flightLog.setSysConfig(newSysConfig);
890+
flightLog.setSysConfig(newSysConfig);
857891

858892
// Save Current Position then re-calculate all the log information
859893
var activePosition = (hasVideo)?video.currentTime:currentBlackboxTime;
894+
860895
selectLog(null);
861896
if (hasVideo) {
862897
setVideoTime(activePosition);

0 commit comments

Comments
 (0)