From 3f299d067372d2cdea7654c4d76b0422c47b7e7c Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 10 May 2019 17:55:52 +0200 Subject: [PATCH] frontend send properly parsed data for zip file --- .../src/main/js/gui/admin/AddProjectDialog.js | 79 ++++++++++++++++++- frontend-js/src/main/js/gui/admin/ZipEntry.js | 2 +- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/frontend-js/src/main/js/gui/admin/AddProjectDialog.js b/frontend-js/src/main/js/gui/admin/AddProjectDialog.js index d01c5e8536..685eaf7d78 100644 --- a/frontend-js/src/main/js/gui/admin/AddProjectDialog.js +++ b/frontend-js/src/main/js/gui/admin/AddProjectDialog.js @@ -64,6 +64,11 @@ AddProjectDialog.prototype.createGui = function () { content: self.createOverlaysTabContent(), disabled: true }); + guiUtils.addTab(self, { + name: "GLYPHS", + content: self.createGlyphsTabContent(), + disabled: true + }); guiUtils.addTab(self, { name: "SUBMAPS", content: self.createSubmapsTabContent(), @@ -526,6 +531,64 @@ AddProjectDialog.prototype._createOverlayTable = function () { return result; }; +/** + * + * @returns {HTMLElement} + */ +AddProjectDialog.prototype.createGlyphsTabContent = function () { + var self = this; + var result = Functions.createElement({ + type: "div", + className: "minerva-project-glyphs-tab" + }); + result.appendChild(self._createGlyphsTable()); + return result; +}; + +/** + * + * @returns {HTMLElement} + * @private + */ +AddProjectDialog.prototype._createGlyphsTable = function () { + var self = this; + var result = Functions.createElement({ + type: "div", + style: "margin-top:10px;" + }); + + var glyphsTable = Functions.createElement({ + type: "table", + name: "glyphsTable", + className: "display", + style: "width:100%" + }); + result.appendChild(glyphsTable); + + $(glyphsTable).DataTable({ + columns: [{ + title: 'File name' + }] + }); + + self.addListener("onZipFileUpload", function () { + var entries = self.getZipEntries(); + var dataTable = $($("[name='glyphsTable']", self.getElement())[0]).DataTable(); + var data = []; + for (var i = 0; i < entries.length; i++) { + var entry = entries[i]; + if (entry.getType() === "GLYPHS") { + var row = []; + row[0] = entry.getFilename(); + data.push(row); + } + } + dataTable.clear().rows.add(data).draw(); + }); + + return result; +}; + /** * * @returns {HTMLElement} @@ -813,6 +876,10 @@ AddProjectDialog.prototype.destroy = function () { if ($.fn.DataTable.isDataTable(overlaysTable)) { $(overlaysTable).DataTable().destroy(); } + var glyphsTable = $("[name=glyphsTable]", self.getElement())[0]; + if ($.fn.DataTable.isDataTable(glyphsTable)) { + $(glyphsTable).DataTable().destroy(); + } var submapsTable = $("[name=submapsTable]", self.getElement())[0]; if ($.fn.DataTable.isDataTable(submapsTable)) { $(submapsTable).DataTable().destroy(); @@ -1284,6 +1351,7 @@ AddProjectDialog.prototype.setZipFileContent = function (file) { }).then(function (result) { var entries = []; var overlays = 0; + var glyphs = 0; var maps = 0; var images = 0; @@ -1297,6 +1365,8 @@ AddProjectDialog.prototype.setZipFileContent = function (file) { images++; } else if (entry.getType() === 'OVERLAY') { overlays++; + } else if (entry.getType() === 'GLYPHS') { + glyphs++; } } } @@ -1305,6 +1375,11 @@ AddProjectDialog.prototype.setZipFileContent = function (file) { } else { guiUtils.hideTab(self, $(".minerva-project-overlays-tab", self.getElement())[0]); } + if (glyphs > 0) { + guiUtils.showTab(self, $(".minerva-project-glyphs-tab", self.getElement())[0]); + } else { + guiUtils.hideTab(self, $(".minerva-project-glyphs-tab", self.getElement())[0]); + } if (maps > 1) { guiUtils.showTab(self, $(".minerva-project-submaps-tab", self.getElement())[0]); } else { @@ -1352,6 +1427,8 @@ AddProjectDialog.prototype.createZipEntry = function (jsZipEntry, zipObject) { } } else if (filename.indexOf("images") === 0) { type = "IMAGE"; + } else if (filename.indexOf("glyphs") === 0) { + type = "GLYPH"; } else if (filename.indexOf("layouts") === 0 || filename.indexOf("overlays") === 0) { type = "OVERLAY"; processingPromise = zipObject.file(jsZipEntry.name).async("string").then(function (content) { @@ -1372,7 +1449,7 @@ AddProjectDialog.prototype.createZipEntry = function (jsZipEntry, zipObject) { type = "MAP"; data.root = true; } else { - throw new Error("Unrecognized file: " + filename); + throw new ValidationError("Unrecognized file: " + filename); } if (type === "MAP") { var name = jsZipEntry.name.toLowerCase(); diff --git a/frontend-js/src/main/js/gui/admin/ZipEntry.js b/frontend-js/src/main/js/gui/admin/ZipEntry.js index 92546fd6c9..ad70fbb141 100644 --- a/frontend-js/src/main/js/gui/admin/ZipEntry.js +++ b/frontend-js/src/main/js/gui/admin/ZipEntry.js @@ -1,6 +1,6 @@ "use strict"; -var types = ["IMAGE", "OVERLAY", "MAP"]; +var types = ["IMAGE", "OVERLAY", "MAP", "GLYPH"]; /** * -- GitLab