Skip to content

Commit

Permalink
added tag 'release-beta-2024-05-17-12.08/+0200' for beta version in f…
Browse files Browse the repository at this point in the history
…older beta.
  • Loading branch information
klues committed May 17, 2024
1 parent 4e1416d commit 693aee7
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 53 deletions.
2 changes: 1 addition & 1 deletion latest/app/build/asterics-grid.bundle.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions latest/app/lang/i18n.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@
"deletingGrids": "Deleting grids",
"importingData": "Importing data",
"readingFile": "Reading file",
"retrievingGrids": "Retrieving grids",
"convertingToOBZ": "Converting to OBZ",
"extractingGridsFromFile": "Extracting grids from file",
"encryptingAndSavingGrids": "Encrypting and saving grids to database",
"creatingPageXOfY": "Creating page {0} of {1}",
Expand Down
32 changes: 20 additions & 12 deletions latest/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,35 @@ <h2 class="hide-mobile">{{ $t('users') }}</h2>
// polyfill for String.replaceAll, https://stackoverflow.com/questions/1144783/how-do-i-replace-all-occurrences-of-a-string-in-javascript
if(!String.prototype.replaceAll){Object.defineProperty(String.prototype,'replaceAll',{configurable:!0,writable:!0,enumerable:!1,value:function(search,replace){return this.replace(Object.prototype.toString.call(search)==='[object RegExp]'?search.global?search:RegExp(search.source,/\/([a-z]*)$/.exec(search.toString())[1]+'g'):RegExp(String(search).replace(/[.^$*+?()[{|\\]/g,"\\$&"),"g"),replace)}})}

testEval("function x(a = 1){}", "default parameters")
if(![].fill) {
logAndRedirect("Browser doesn't support Array.fill");
}

Modernizr.on('promises', function (result) {
checkResult(result, 'Promises');
});
Modernizr.on('indexeddb', function (result) {
checkResult(result, 'IndexedDB');
});
checkModernizr('promises');
checkModernizr('indexeddb');

function checkResult(result, feature) {
if (!result) {
logAndRedirect("Browser doesn't support " + feature + ".")
}
function checkModernizr(modernizrFeature) {
Modernizr.on(modernizrFeature, function (result) {
if (!result) {
logAndRedirect(modernizrFeature)
}
});
}

function logAndRedirect(msg) {
console.warn(msg);
function logAndRedirect(missingFeature) {
console.warn("Browser doesn't support " + missingFeature + ".");
window.location.replace("unsupported.html");
}

function testEval(evalString, msg) {
try {
eval(evalString);
} catch (e) {
console.log(e);
logAndRedirect(msg);
}
}
</script>

<!-- libraries, not provided by npm -->
Expand Down
2 changes: 1 addition & 1 deletion latest/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ self.addEventListener('install', (event) => {
self.addEventListener('activate', event => {
clients.claim();
sendToClients({type: constants.SW_EVENT_ACTIVATED, activated: true});
console.log('Service Worker active! Version: https://github.com/asterics/AsTeRICS-Grid/releases/tag/release-beta-2024-05-16-11.51/+0200');
console.log('Service Worker active! Version: https://github.com/asterics/AsTeRICS-Grid/releases/tag/release-beta-2024-05-17-12.08/+0200');
});

self.addEventListener('message', (event) => {
Expand Down
31 changes: 25 additions & 6 deletions latest/src/js/service/data/dataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,23 @@ dataService.downloadBackupToFile = async function () {
* @param options.exportUserSettings if true, all user settings are exported
* @param options.filename the filename to use for downloading
* @param options.obzFormat if true, data is returned in obz format (as blob)
* @param options.progressFn fn for reporting progress, called with params percentage and text
* @returns {Promise<{}|null>} promise resolving to a javascript object containing native AG backup data or to a blob
* containing the backup in .obz format if options.obzFormat is true.
*/
dataService.getBackupData = async function (gridIds, options) {
dataService.getBackupData = async function (gridIds, options = {}) {
if (!gridIds || gridIds.length === 0) {
return null;
}
options.progressFn = options.progressFn || (() => {});
let backupData = {};
options = options || {};
let globalGridId = null;
if (options.exportGlobalGrid) {
let globalGrid = await dataService.getGlobalGrid();
globalGridId = globalGrid ? globalGrid.id : null;
}
options.progressFn(10, i18nService.t('retrievingGrids'));
let allGrids = await dataService.getGrids(true, !options.exportGlobalGrid);
backupData.grids = allGrids.filter((grid) => gridIds.includes(grid.id) || globalGridId === grid.id);
if (options.exportOnlyCurrentLang) {
Expand Down Expand Up @@ -435,7 +438,12 @@ dataService.getBackupData = async function (gridIds, options) {
backupData.metadata.lastOpenedGridId = currentMetadata.lastOpenedGridId;
}
if (options.obzFormat) {
backupData = await obfConverter.backupDataToOBZ(backupData);
options.progressFn(10, i18nService.t('convertingToOBZ'));
backupData = await obfConverter.backupDataToOBZ(backupData, {
progressFn: (zipProgress => {
options.progressFn(10 + util.mapRange(zipProgress, 0, 100, 0, 90));
})
});
}
return backupData;
}
Expand All @@ -450,9 +458,10 @@ dataService.getBackupData = async function (gridIds, options) {
* @param options.exportUserSettings if true, all user settings are exported
* @param options.filename the base filename to use for downloading (without file extension)
* @param options.obzFormat if true, data is downloaded in obz format
* @param options.progressFn fn for reporting progress, called with params percentage and text
* @return {Promise<void>}
*/
dataService.downloadToFile = async function (gridIds, options) {
dataService.downloadToFile = async function (gridIds, options = {}) {
let backupData = await dataService.getBackupData(gridIds, options);
if (!backupData) {
return;
Expand All @@ -476,9 +485,11 @@ dataService.downloadToFile = async function (gridIds, options) {
/**
* converts a file (.grd, .obf, .obz) to standardized import data
* @param file
* @param options
* @return {Promise<null>}
*/
dataService.convertFileToImportData = async function (file) {
dataService.convertFileToImportData = async function (file, options = {}) {
options.progressFn = options.progressFn || (() => {});
let fileContent = await fileUtil.readFileContent(file);
let importData = null;
if (!fileContent) {
Expand All @@ -498,7 +509,11 @@ dataService.convertFileToImportData = async function (file) {
} else if (fileUtil.isObfFile(file)) {
importData = await obfConverter.OBFToGridData(JSON.parse(fileContent));
} else if (fileUtil.isObzFile(file)) {
let obzFileMap = await fileUtil.readZip(file, true);
let obzFileMap = await fileUtil.readZip(file, {
jsonFileExtensions: ["json", "obf"],
defaultEncoding: "base64",
progressFn: options.progressFn
});
importData = await obfConverter.OBZToImportData(obzFileMap);
}
return dataService.normalizeImportData(importData);
Expand Down Expand Up @@ -533,7 +548,11 @@ dataService.normalizeImportData = function (data) {
dataService.importBackupUploadedFile = async function (file, progressFn) {
progressFn = progressFn || (() => {});
progressFn(10, i18nService.t('extractingGridsFromFile'));
let importData = await dataService.convertFileToImportData(file);
let importData = await dataService.convertFileToImportData(file, {
progressFn: progress => {
progressFn(10 + util.mapRange(progress, 0, 100, 0, 10));
}
});
if (!importData) {
progressFn(100);
MainVue.setTooltip(i18nService.t('backupFileDoesntContainData'), { msgType: 'warn' });
Expand Down
69 changes: 42 additions & 27 deletions latest/src/js/util/fileUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,56 @@ let fileUtil = {};
/**
* reads the contents of a .zip file
* @param file the zip file to read
* @param parseJSON if true the file content is parsed as JSON
* @return a Promise resolving to a map {filename => String file content}
* @param options
* @param options.jsonFileExtensions array of file extensions that should be parsed as json (without dot, e.g. "json", "obf")
* @param options.defaultEncoding default file content encoding, see https://stuk.github.io/jszip/documentation/api_zipobject/async.html
* @param options.progressFn function that is called with current progress in percent
* @return a Promise resolving to a map {filename => file content}
*/
fileUtil.readZip = function (file, parseJSON) {
fileUtil.readZip = async function(file, options = {}) {
options.jsonFileExtensions = options.jsonFileExtensions || [];
options.progressFn = options.progressFn || (() => {});
let returnMap = {};
return new Promise((resolve) => {
import('jszip').then((JSZip) => {
JSZip.default.loadAsync(file).then((zip) => {
let promises = [];
Object.keys(zip.files).forEach((filename) => {
let file = zip.files[filename];
promises.push(
file.async('base64').then((content) => {
try {
returnMap[filename] = parseJSON ? JSON.parse(atob(content)) : content;
} catch (e) {
returnMap[filename] = content;
}
})
);
});
Promise.all(promises).then(() => {
resolve(returnMap);
});
});
});
});
const JSZipImport = await import('jszip');
const JSZip = JSZipImport.default;
let zip = await JSZip.loadAsync(file);
let promises = [];
let filenames = Object.keys(zip.files);
let readCount = 0;
for (let filename of filenames) {
let file = zip.files[filename];
let type = options.defaultEncoding || 'base64';
let parseJson = options.jsonFileExtensions.some(ext => filename.endsWith(`.${ext}`));
type = parseJson ? 'binarystring' : type;
promises.push(Promise.resolve().then(async () => {
let content = await file.async(type);
readCount++;
options.progressFn((readCount / filenames.length) * 100);
if (parseJson) {
try {
content = JSON.parse(content);
} catch (e) {
log.warn('couldn\'t parse json from zip!', filename);
}
}
returnMap[filename] = content;
}));
}
await Promise.all(promises);
return returnMap;
};

/**
* creates a .zip file based on a map of paths and file contents.
* @param fileMap map of elements "file path" -> "file content", which define which contents should be included at
* which paths in the .zip file. if "file content" is not a string, it is stringified before
* adding it to the .zip file.
* @param options
* @param options.progressFn function that is called with current progress in percent
* @return Promise which resolves to blob of created .zip file
*/
fileUtil.createZip = async function(fileMap = {}) {
fileUtil.createZip = async function(fileMap = {}, options = {}) {
options.progressFn = options.progressFn || (() => {});
const JSZipImport = await import('jszip');
const JSZip = JSZipImport.default;
let zip = new JSZip();
Expand All @@ -52,7 +65,9 @@ fileUtil.createZip = async function(fileMap = {}) {
}
zip.file(path, content, {binary: true}); //binary: true, in order to keep special chars correctly
}
return zip.generateAsync({ type: 'blob' });
return zip.generateAsync({ type: 'blob' }, (metadata) => {
options.progressFn(metadata.percent);
});
}

fileUtil.readFileContent = function (file) {
Expand Down
7 changes: 4 additions & 3 deletions latest/src/js/util/obfConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { modelUtil } from './modelUtil';
import { MetaData } from '../model/MetaData';
import { imageUtil } from './imageUtil';
import { util } from './util';
import { dataService } from '../service/data/dataService';

let obfConverter = {};
let OBF_FORMAT_VERSION = 'open-board-0.1';
Expand Down Expand Up @@ -43,11 +44,11 @@ obfConverter.gridDataToOBF = function(gridData, manifest) {
return obfGrid;
};

obfConverter.backupDataToOBZ = async function(backupData, options) {
obfConverter.backupDataToOBZ = async function(backupData, options = {}) {
if (!backupData || !backupData.grids) {
return null;
}
let metadata = backupData.metadata || {};
let metadata = backupData.metadata || (await dataService.getMetadata());
let manifest = {
format: OBF_FORMAT_VERSION,
root: metadata.homeGridId ? `${OBF_BOARDS_PATH_PREFIX}${metadata.homeGridId}${OBF_BOARD_POSTFIX}` : undefined,
Expand Down Expand Up @@ -85,7 +86,7 @@ obfConverter.backupDataToOBZ = async function(backupData, options) {
manifest.paths.boards[board.id] = path;
}
fileMap[OBF_MANIFEST_FILENAME] = manifest;
return fileUtil.createZip(fileMap);
return fileUtil.createZip(fileMap, options);
};

function gridElementToObfButton(gridElement, obfGrid) {
Expand Down
9 changes: 8 additions & 1 deletion latest/src/vue-components/modals/exportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import {i18nService} from "../../js/service/i18nService.js";
import {localStorageService} from "../../js/service/data/localStorageService.js";
import {util} from "../../js/util/util.js";
import { MainVue } from '../../js/vue/mainVue';
let constants = {
LANG_EXPORT_CURRENT: 'LANG_EXPORT_CURRENT',
Expand Down Expand Up @@ -166,7 +167,13 @@
exportDictionaries: this.options.exportDictionaries,
exportUserSettings: this.options.exportUserSettings,
filename: filename,
obzFormat: this.options.exportOBZ
obzFormat: this.options.exportOBZ,
progressFn: (percent, text) => {
MainVue.showProgressBar(percent, {
header: i18nService.t('exportToFile'),
text: text
});
}
});
this.$emit('close');
},
Expand Down
4 changes: 2 additions & 2 deletions latest/src/vue-components/modals/progressBarModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div id="progressWrapper" style="border: 1px solid; border-radius: 3px; width: 100%; height: 50px; margin: 0.5em 0">
<div id="progressBar" :style="`width: ${progressPercentage}%; height: 100%; background-color: green`"></div>
</div>
<div class="biggerFont" style="text-align: right; width: 100%">{{progressPercentage}}%</div>
<div class="biggerFont" style="text-align: right; width: 100%">{{Math.round(progressPercentage)}}%</div>
</div>

<div class="modal-footer">
Expand Down Expand Up @@ -56,7 +56,7 @@
this.options[key] = options[key];
}
});
if (this.progressPercentage === 100) {
if (Math.abs(this.progressPercentage - 100) < 0.001) {
setTimeout(() => {
this.options = JSON.parse(JSON.stringify(defaultOptions));
this.$emit('close');
Expand Down

0 comments on commit 693aee7

Please sign in to comment.