Commit 3f299d06 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

frontend send properly parsed data for zip file

parent 051815d4
......@@ -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();
......
"use strict";
var types = ["IMAGE", "OVERLAY", "MAP"];
var types = ["IMAGE", "OVERLAY", "MAP", "GLYPH"];
/**
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment