Skip to content

Commit 9b86c61

Browse files
Improve data export
1 parent dfee833 commit 9b86c61

2 files changed

Lines changed: 22 additions & 46 deletions

File tree

src/_shared/frametrail-core/storage/StorageAdapterDownload.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ class StorageAdapterDownload extends StorageAdapter {
146146
/**
147147
* Download current hypervideo as a flat hypervideo.json (matches on-disk server format).
148148
* @param {String} hypervideoID
149+
* @param {String} [dataPath] - Optional base URL for resources
149150
*/
150-
_performDownload(hypervideoID) {
151+
_performDownload(hypervideoID, dataPath) {
151152
var Database = this._frameTrailInstance.module('Database');
152153
var hvData = Database.convertToDatabaseFormat(hypervideoID);
154+
if (dataPath) {
155+
hvData.dataPath = dataPath;
156+
}
153157
var hvName = (Database.hypervideos[hypervideoID] && Database.hypervideos[hypervideoID].name) || 'hypervideo';
154158
var filename = hvName.replace(/[^a-z0-9]/gi, '_').substring(0, 50) + '.json';
155159
this._triggerDownload(JSON.stringify(hvData, null, 2), filename, 'application/json');

src/player/modules/HypervideoModel/module.js

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,27 +1075,15 @@
10751075
+ '</div>'
10761076
+ '</div>'
10771077

1078-
// Scope row — separate layoutRow so the grid equalizes heights across all three columns
1078+
// Download scope row — aligned to download column via empty placeholders
10791079
+ '<div class="layoutRow" style="margin-bottom: 4px;">'
1080-
+ '<div class="column-4" style="display: flex;">'
1081-
+ '<button class="' + (canSaveToServer ? 'pressed' : '') + '" style="flex: 1; padding: 8px; text-align: center; pointer-events: none;"'
1082-
+ (canSaveToServer ? '' : ' disabled') + '>'
1083-
+ labels['DownloadAllData']
1084-
+ '</button>'
1085-
+ '</div>'
1086-
+ '<div class="column-4" style="display: flex;">'
1087-
+ '<button class="' + (canSaveToLocal ? 'pressed' : '') + '" style="flex: 1; padding: 8px; text-align: center; pointer-events: none;"'
1088-
+ (canSaveToLocal ? '' : ' disabled') + '>'
1089-
+ labels['DownloadAllData']
1090-
+ '</button>'
1080+
+ '<div class="column-4"></div>'
1081+
+ '<div class="column-4"></div>'
1082+
+ '<div class="column-4">'
1083+
+ '<div style="display: flex; gap: 12px;">'
1084+
+ '<label><input type="radio" name="downloadScope" value="currentHv" checked> ' + labels['DownloadCurrentHypervideo'] + '</label>'
1085+
+ '<label><input type="radio" name="downloadScope" value="allData"> ' + labels['DownloadAllData'] + '</label>'
10911086
+ '</div>'
1092-
+ '<div class="column-4" style="display: flex;">'
1093-
+ '<button class="scopeCurrentHv pressed" style="flex: 1; padding: 8px; text-align: center;">'
1094-
+ labels['DownloadCurrentHypervideo']
1095-
+ '</button>'
1096-
+ '<button class="scopeAllData" style="flex: 1; padding: 8px; text-align: center; margin-left: -2px;">'
1097-
+ labels['DownloadAllData']
1098-
+ '</button>'
10991087
+ '</div>'
11001088
+ '</div>'
11011089

@@ -1107,10 +1095,10 @@
11071095
+ '<div class="downloadFormatSection">'
11081096
+ '<small>' + labels['DownloadFormat'] + '</small>'
11091097
+ '<div style="display: flex; gap: 12px; margin-top: 4px;">'
1110-
+ '<label><input type="radio" name="downloadFormat" value="json" checked> JSON</label>'
1111-
+ '<label><input type="radio" name="downloadFormat" value="html"> HTML</label>'
1098+
+ '<label><input type="radio" name="downloadFormat" value="html" checked> HTML</label>'
1099+
+ '<label><input type="radio" name="downloadFormat" value="json"> JSON</label>'
11121100
+ '</div>'
1113-
+ '<div class="downloadHtmlDataPath" style="display: none; margin-top: 6px;">'
1101+
+ '<div style="margin-top: 6px;">'
11141102
+ '<small>' + labels['DownloadResourceBaseUrl'] + '</small>'
11151103
+ '<input type="text" name="htmlDataPath" placeholder="https://example.com/_data/" style="margin-top: 2px;">'
11161104
+ '</div>'
@@ -1127,35 +1115,19 @@
11271115
+ '</div>';
11281116
var saveAsDialog = _saveAsWrapper.firstElementChild;
11291117

1130-
var scopeCurrentHvBtn = saveAsDialog.querySelector('.scopeCurrentHv');
1131-
var scopeAllDataBtn = saveAsDialog.querySelector('.scopeAllData');
11321118
var formatSection = saveAsDialog.querySelector('.downloadFormatSection');
1133-
var htmlDataPathDiv = saveAsDialog.querySelector('.downloadHtmlDataPath');
11341119
var optionsSection = saveAsDialog.querySelector('.downloadOptionsSection');
11351120

11361121
// Default htmlDataPath to the absolute URL of the current _data/ directory
11371122
var _dataPathInput = saveAsDialog.querySelector('[name="htmlDataPath"]');
11381123
var _resolvedDataURL = FrameTrail.module('RouteNavigation').resolveDataURL('');
11391124
_dataPathInput.value = new URL(_resolvedDataURL, window.location.href).href;
11401125

1141-
scopeCurrentHvBtn.addEventListener('click', function() {
1142-
scopeCurrentHvBtn.classList.add('pressed');
1143-
scopeAllDataBtn.classList.remove('pressed');
1144-
formatSection.style.display = '';
1145-
optionsSection.style.display = 'none';
1146-
});
1147-
1148-
scopeAllDataBtn.addEventListener('click', function() {
1149-
scopeAllDataBtn.classList.add('pressed');
1150-
scopeCurrentHvBtn.classList.remove('pressed');
1151-
formatSection.style.display = 'none';
1152-
optionsSection.style.display = '';
1153-
});
1154-
1155-
// Show/hide dataPath input when HTML format is selected
1156-
formatSection.querySelectorAll('[name="downloadFormat"]').forEach(function(radio) {
1126+
saveAsDialog.querySelectorAll('[name="downloadScope"]').forEach(function(radio) {
11571127
radio.addEventListener('change', function() {
1158-
htmlDataPathDiv.style.display = (radio.value === 'html' && radio.checked) ? '' : 'none';
1128+
var isAllData = radio.value === 'allData' && radio.checked;
1129+
formatSection.style.display = isAllData ? 'none' : '';
1130+
optionsSection.style.display = isAllData ? '' : 'none';
11591131
});
11601132
});
11611133

@@ -1182,7 +1154,7 @@
11821154
var hvID = FrameTrail.module('RouteNavigation').hypervideoID;
11831155
downloadAdapter._frameTrailInstance = FrameTrail;
11841156

1185-
var isAllData = scopeAllDataBtn.classList.contains('pressed');
1157+
var isAllData = saveAsDialog.querySelector('[name="downloadScope"][value="allData"]').checked;
11861158

11871159
if (isAllData) {
11881160
var includeMedia = saveAsDialog.querySelector('[name="includeMedia"]').checked;
@@ -1199,11 +1171,11 @@
11991171
}
12001172
} else {
12011173
var format = saveAsDialog.querySelector('[name="downloadFormat"]:checked').value;
1174+
var dataPath = saveAsDialog.querySelector('[name="htmlDataPath"]').value.trim();
12021175
if (format === 'html') {
1203-
var dataPath = saveAsDialog.querySelector('[name="htmlDataPath"]').value.trim();
12041176
downloadAdapter._generateStandaloneHTML(hvID, dataPath);
12051177
} else {
1206-
downloadAdapter._performDownload(hvID);
1178+
downloadAdapter._performDownload(hvID, dataPath);
12071179
}
12081180
}
12091181

0 commit comments

Comments
 (0)