c4b0ff6bea
* fix the appbundle issue #1209 * fix #1162 allow the JRE 9 * fix the package declarations * remove the _ from the method name * use the explicit scoping * remote extra ; * fix issued from codacy * fix issued from codacy * add preferences link to the index page * handle the empty user metadata * fix 'last modified' sorting issue #1307 * prevent overflow of the table. issue #1306 * add isoDateParser to sort the date * prevent overflow of the project index * remove sorter arrow for action columns * disable editing the internal metadata * adjust the width of the table * change MetaData to Metadata * change the filed name from rowNumber to rowCount * put back the incidently deleted gitignore * add double quote to prevent word splitting * UI improvement on metadata view and project list view * remove the date field in metadata * message notification of the free RAM. Issue #1295 * UI tuning for metadata view * shorten the ISO date to locale date format * Added translation using Weblate (Portuguese (Brazil)) * remove the rename link * Ignore empty language files introduced by Weblate * Add UI for Invert text filter * Backend support for Inverting Text search facets * Fix reset on text search facet * More succinct return statements * add tests for SetProjectMetadataCommand * Tidying up for Codacy * Added Tests for TextSearchFilter * Corrections for Codacy * More code tidy up * let the browser auto fit the table cell when resizing/zooming * fix import multiple excel with mulitple sheets issue #1328 * check if the project has the userMetadata * fix the unit test support multi files with multi tables for open office * prevent the same key for user metadata * replace _ with variable for exception * fix the no-undef issue * to adjust the width of transform dialog. issue #1332 * fix the row count refresh issue * extract method * move the log message * cosmatic changes for codacy * fix typo * bump to version 2.8 * .gitignore is now working * preview stage won't have the metadata populated, so protect NPE * Update README.md No more direct link to the last version tag, which will avoid having to think of updating the readme * refacotring the ProjectMetadata class * introduce the IMetadata interface * create submodule of dataschema * add back * setup lib for dataschema; upgrade the apache lang to lang3 * replace escape* functions from apache lang3 * replace the ProjectMetadata with IMetadata interface * add missing jars * set the IMetadata a field of Project * remove PreferenceStore out of Project model * fix test SetProjectMetadataCommandTests by casting * introdcue the AbstractMetadata * introdcue the AbstractMetadata * reorganize the metadata package * allow have mulitiple metadata for a project * support for mulitple metadata format * remove jdk7 since 'table schema' java implmentation only support jdk8+ * set execute permission for script * fix the Unit Test after Metadata refactoring * restore the apache lang2.5 since jetty 6.1.22 depend on it * add commons lang 2.5 jar * git submodule add https://github.com/frictionlessdata/datapackage-java * remove the metadata parameter from the ProjectManager.registerProject method * remove hashmap _projectsMetadata field from the ProjectManager and FileProjectManager * init the Project.metadataMap * fix Unit Test * restore the ProjectMetaData map to ProjectManager * put the ProjectMetaDta in place for ProjectManager and Project object * check null of singleton instead of create a constructor just for test * load the data package metadata * importing data package * importing data package * encapsulate the Package class into DataPackageMetadata * user _ to indicate the class fields * introduce base URL in order to download the data files * import data package UI and draft backend * import data package UI * fix typo * download the data set pointed from metadata resource * save and load the data package metadata * avoid magic string * package cleanup * set the java_version to 1.8 * set the min jdk to 1.8 * add the 3rd party src in the build.xml * skip the file selection page if only 1 DATA file * add files structure for json editor * seperate out the metadata file from the retrival file list * rename the OKF_METADATA to DATAPACKAGE_METADATA * clean up * implement GetMetadateCommand class * display the metadata in json format * git submodule update --remote --merge * adjust the setting after pulling from datapackage origin * fix the failed UT DateExtensionTests.testFetchCounts due to new json jar json-20160810.jar will complain: JSONObject["float"] not a string. * clean up the weird loop array syntax get complained * remove the unused constant * export in data package format * interface cleanup * fix UT * edit the metadata * add UT for SetMetadataCommand * fix UT for SetMetadataCommand * display the data package metadata link on the project index page * update submodule * log the exceptions * Ajv does not work properly, use the back end validation instead * enable the validation for jsoneditor * first draft of the data validation * create a map to hold the constraint and its handler * rename * support for minLength and maxLength from spec * add validate command * test the opeation instead of validate command * rename the UT * format the error message and push to the report * fix row number * add resource bundle for validator * inject the code of the constrains * make the StrSubstitutor works * extract the type and format information * add the customizedFormat to interface to allow format properly * get rid of magic string * take care of missing parts of the data package * implement RequiredConstraint * patch for number type * add max/min constraints * get the constrains directly from field * implement the PatternConstraint * suppress warning * fix the broken UT when expecting 2 digits fraction * handle the cast and type properly * fix the missing resource files for data package when run from command line * use the copy instead of copydir * add script for appveyor * update script for appveyor * do recursive clone * correct the git url * fix clone path * clone folder option does not work * will put another PR for this. delete for now * revert the interface method name * lazy loading the project data * disable the validate menu for now * add UT * assert UTs * add UT * fix #1386 * remove import * test the thread * Revert "test the thread" This reverts commit 779214160055afe3ccdcc18c57b0c7c72e87c824. * fix the URLCachingTest UT * define the template data package * tidy up the metadata interface * check the http response code * fix the package * display user friendly message when URL path is not reachable * populate the data package schema * Delete hs_err_pid15194.log * populate data package info * add username preference and it will be pulled as the creator of the metadata * undo the project.updateColumnChange() and start to introduce the fields into the existing core model * tightly integrate the data package metadata * tightly integrate the data package metadata for project level * remove the submodule * move the edit botton * clean up build * load the new property * load the project metadata * fix issues from codacy * remove unused fields and annotation * check the http response code firstly * import zipped data package * allow without keywords * process the zip data package from url * merge the tags * check store firstly * remove the table schema src * move the json schema files to schema dir * add comment * add comment * remove git moduels * add incidently deleted file * fix typo * remove SetMetadataCommand * revert change * merge from master
360 lines
13 KiB
JavaScript
360 lines
13 KiB
JavaScript
/*
|
|
|
|
Copyright 2011, Google Inc.
|
|
All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions are
|
|
met:
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
* Redistributions in binary form must reproduce the above
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
in the documentation and/or other materials provided with the
|
|
distribution.
|
|
* Neither the name of Google Inc. nor the names of its
|
|
contributors may be used to endorse or promote products derived from
|
|
this software without specific prior written permission.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
Refine.DefaultImportingController.prototype._showFileSelectionPanel = function() {
|
|
var self = this;
|
|
|
|
this._selectedMap = {};
|
|
this._prepareFileSelectionPanel();
|
|
|
|
this._fileSelectionPanelElmts.nextButton.click(function() {
|
|
self._commitFileSelection();
|
|
});
|
|
this._renderFileSelectionPanel();
|
|
this._createProjectUI.showCustomPanel(this._fileSelectionPanel);
|
|
};
|
|
|
|
Refine.DefaultImportingController.prototype._disposeFileSelectionPanel = function() {
|
|
if (this._fileSelectionPanelResizer) {
|
|
$(window).unbind("resize", this._fileSelectionPanelResizer);
|
|
}
|
|
this._fileSelectionPanel.unbind().empty();
|
|
};
|
|
|
|
Refine.DefaultImportingController.prototype._prepareFileSelectionPanel = function() {
|
|
var self = this;
|
|
|
|
this._fileSelectionPanel.unbind().empty().html(
|
|
DOM.loadHTML("core", "scripts/index/default-importing-controller/file-selection-panel.html"));
|
|
|
|
this._fileSelectionPanelElmts = DOM.bind(this._fileSelectionPanel);
|
|
|
|
$('#or-import-select').text($.i18n._('core-index-import')["select-file"]);
|
|
$('#or-import-severalFile').text($.i18n._('core-index-import')["several-file"]);
|
|
$('#or-import-selExt').text($.i18n._('core-index-import')["sel-by-extension"]);
|
|
$('#or-import-regex').text($.i18n._('core-index-import')["sel-by-regex"]);
|
|
|
|
this._fileSelectionPanelElmts.startOverButton.html($.i18n._('core-buttons')["startover"]);
|
|
this._fileSelectionPanelElmts.nextButton.html($.i18n._('core-buttons')["conf-pars-opt"]);
|
|
this._fileSelectionPanelElmts.selectAllButton.text($.i18n._('core-buttons')["select-all"]);
|
|
this._fileSelectionPanelElmts.unselectAllButton.text($.i18n._('core-buttons')["unselect-all"]);
|
|
this._fileSelectionPanelElmts.selectRegexButton.text($.i18n._('core-buttons')["select"]);
|
|
this._fileSelectionPanelElmts.unselectRegexButton.text($.i18n._('core-buttons')["unselect"]);
|
|
|
|
this._fileSelectionPanelElmts.startOverButton.click(function() {
|
|
self._startOver();
|
|
});
|
|
|
|
this._fileSelectionPanelResizer = function() {
|
|
var elmts = self._fileSelectionPanelElmts;
|
|
var width = self._fileSelectionPanel.width();
|
|
var height = self._fileSelectionPanel.height();
|
|
var headerHeight = elmts.wizardHeader.outerHeight(true);
|
|
var controlPanelWidth = 350;
|
|
|
|
elmts.controlPanel
|
|
.css("left", "0px")
|
|
.css("top", headerHeight + "px")
|
|
.css("width", (controlPanelWidth - DOM.getHPaddings(elmts.controlPanel)) + "px")
|
|
.css("height", (height - headerHeight - DOM.getVPaddings(elmts.controlPanel)) + "px");
|
|
|
|
elmts.filePanel
|
|
.css("left", controlPanelWidth + "px")
|
|
.css("top", headerHeight + "px")
|
|
.css("width", (width - controlPanelWidth - DOM.getHPaddings(elmts.filePanel)) + "px")
|
|
.css("height", (height - headerHeight - DOM.getVPaddings(elmts.filePanel)) + "px");
|
|
};
|
|
|
|
$(window).resize(this._fileSelectionPanelResizer);
|
|
this._fileSelectionPanelResizer();
|
|
};
|
|
|
|
Refine.DefaultImportingController.prototype._renderFileSelectionPanel = function() {
|
|
this._renderFileSelectionPanelFileTable();
|
|
this._renderFileSelectionPanelControlPanel();
|
|
};
|
|
|
|
Refine.DefaultImportingController.prototype._renderFileSelectionPanelFileTable = function() {
|
|
var self = this;
|
|
var files = this._job.config.retrievalRecord.files;
|
|
|
|
this._fileSelectionPanelElmts.filePanel.empty();
|
|
|
|
var fileTable = $('<table><tr><th>'+$.i18n._('core-index-import')["import"]+'</th><th>'+$.i18n._('core-index-import')["name"]+'</th><th>'+$.i18n._('core-index-import')["mime-type"]+'</th><th>'+$.i18n._('core-index-import')["format"]+'</th><th>'+$.i18n._('core-index-import')["size"]+'</th></tr></table>')
|
|
.appendTo(this._fileSelectionPanelElmts.filePanel)[0];
|
|
|
|
var round = function(n) {
|
|
return Math.round(n * 10) / 10;
|
|
};
|
|
var renderSize = function(fileRecord) {
|
|
var bytes = fileRecord.size;
|
|
var gigabytes = bytes / 1073741824;
|
|
var megabytes = bytes / 1048576;
|
|
var kilobytes = bytes / 1024;
|
|
if (gigabytes > 1) {
|
|
return round(gigabytes) + " GB";
|
|
} else if (megabytes > 1) {
|
|
return round(megabytes) + " MB";
|
|
} else if (kilobytes > 1) {
|
|
return round(kilobytes) + " KB";
|
|
} else {
|
|
return fileRecord.size + " bytes";
|
|
}
|
|
};
|
|
var renderFile = function(fileRecord, index) {
|
|
var id = "import-file-selection-" + Math.round(Math.random() * 1000000);
|
|
var tr = fileTable.insertRow(fileTable.rows.length);
|
|
$(tr).addClass((index % 2 === 0) ? 'even' : 'odd');
|
|
|
|
var createLabeledCell = function(className) {
|
|
var td = $('<td>').appendTo(tr);
|
|
if (className) {
|
|
td.addClass(className);
|
|
}
|
|
return $('<label>').attr('for', id).appendTo(td);
|
|
};
|
|
|
|
var checkbox = $('<input>')
|
|
.attr("id", id)
|
|
.attr("type", "checkbox")
|
|
.attr("index", index)
|
|
.appendTo(createLabeledCell())
|
|
.click(function() {
|
|
var fileRecord = files[index];
|
|
if (this.checked) {
|
|
self._selectedMap[fileRecord.location] = fileRecord;
|
|
} else {
|
|
delete self._selectedMap[fileRecord.location];
|
|
}
|
|
self._updateFileSelectionSummary();
|
|
});
|
|
if (fileRecord.metaDataFormat) {
|
|
checkbox.removeAttr("checked").attr("disabled", "disabled");
|
|
} else if (fileRecord.selected) {
|
|
// Initial selection determined on server side.
|
|
checkbox.attr("checked", "checked");
|
|
self._selectedMap[fileRecord.location] = fileRecord;
|
|
}
|
|
|
|
createLabeledCell("default-importing-file-selection-filename").text(fileRecord.fileName);
|
|
createLabeledCell().text(fileRecord.declaredMimeType || fileRecord.mimeType || "unknown");
|
|
createLabeledCell().text(fileRecord.format || "unknown");
|
|
createLabeledCell().text(renderSize(fileRecord));
|
|
};
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
renderFile(files[i], i);
|
|
}
|
|
};
|
|
|
|
Refine.DefaultImportingController.prototype._renderFileSelectionPanelControlPanel = function() {
|
|
var self = this;
|
|
var files = this._job.config.retrievalRecord.files;
|
|
|
|
this._fileSelectionPanelElmts.extensionContainer.empty();
|
|
this._fileSelectionPanelElmts.selectAllButton.unbind().click(function(evt) {
|
|
for (var i = 0; i < files.length; i++) {
|
|
var fileRecord = files[i];
|
|
self._selectedMap[fileRecord.location] = fileRecord;
|
|
}
|
|
self._fileSelectionPanelElmts.filePanel.find("input").attr("checked", "checked");
|
|
self._updateFileSelectionSummary();
|
|
});
|
|
this._fileSelectionPanelElmts.unselectAllButton.unbind().click(function(evt) {
|
|
self._selectedMap = {};
|
|
self._fileSelectionPanelElmts.filePanel.find("input").removeAttr("checked");
|
|
self._updateFileSelectionSummary();
|
|
});
|
|
|
|
var table = $('<table></table>')
|
|
.appendTo(this._fileSelectionPanelElmts.extensionContainer)[0];
|
|
|
|
var renderExtension = function(extension) {
|
|
var tr = table.insertRow(table.rows.length);
|
|
$('<td>').text(extension.extension).appendTo(tr);
|
|
$('<td>').text(extension.count + (extension.count > 1 ? " files" : " file")).appendTo(tr);
|
|
$('<button>')
|
|
.text($.i18n._('core-buttons')["select"])
|
|
.addClass("button")
|
|
.appendTo($('<td>').appendTo(tr))
|
|
.click(function() {
|
|
for (var i = 0; i < files.length; i++) {
|
|
var file = files[i];
|
|
if (!(file.location in self._selectedMap)) {
|
|
if (file.fileName.endsWith(extension.extension)) {
|
|
self._selectedMap[file.location] = file;
|
|
self._fileSelectionPanelElmts.filePanel
|
|
.find("input[index='" + i + "']")
|
|
.attr("checked", "checked");
|
|
}
|
|
}
|
|
}
|
|
self._updateFileSelectionSummary();
|
|
});
|
|
$('<button>')
|
|
.text($.i18n._('core-buttons')["unselect"])
|
|
.addClass("button")
|
|
.appendTo($('<td>').appendTo(tr))
|
|
.click(function() {
|
|
for (var i = 0; i < files.length; i++) {
|
|
var file = files[i];
|
|
if (file.location in self._selectedMap) {
|
|
if (file.fileName.endsWith(extension.extension)) {
|
|
delete self._selectedMap[file.location];
|
|
self._fileSelectionPanelElmts.filePanel
|
|
.find("input[index='" + i + "']")
|
|
.removeAttr("checked");
|
|
}
|
|
}
|
|
}
|
|
self._updateFileSelectionSummary();
|
|
});
|
|
};
|
|
for (var i = 0; i < this._extensions.length; i++) {
|
|
renderExtension(this._extensions[i]);
|
|
}
|
|
|
|
this._updateFileSelectionSummary();
|
|
|
|
this._fileSelectionPanelElmts.regexInput.unbind().bind("keyup change input",function() {
|
|
var count = 0;
|
|
var elmts = self._fileSelectionPanelElmts.filePanel
|
|
.find(".default-importing-file-selection-filename")
|
|
.removeClass("highlighted");
|
|
try {
|
|
var regex = new RegExp(this.value);
|
|
elmts.each(function() {
|
|
if (regex.test($(this).text())) {
|
|
$(this).addClass("highlighted");
|
|
count++;
|
|
}
|
|
});
|
|
} catch (e) {
|
|
// Ignore
|
|
}
|
|
self._fileSelectionPanelElmts.regexSummary.text(count + (count == 1 ? " match" : " matches"));
|
|
});
|
|
this._fileSelectionPanelElmts.selectRegexButton.unbind().click(function() {
|
|
self._fileSelectionPanelElmts.filePanel
|
|
.find(".default-importing-file-selection-filename")
|
|
.removeClass("highlighted");
|
|
try {
|
|
var regex = new RegExp(self._fileSelectionPanelElmts.regexInput[0].value);
|
|
for (var i = 0; i < files.length; i++) {
|
|
var file = files[i];
|
|
if (!(file.location in self._selectedMap)) {
|
|
if (regex.test(file.fileName)) {
|
|
self._selectedMap[file.location] = file;
|
|
self._fileSelectionPanelElmts.filePanel
|
|
.find("input[index='" + i + "']")
|
|
.attr("checked", "checked");
|
|
}
|
|
}
|
|
}
|
|
self._updateFileSelectionSummary();
|
|
} catch (e) {
|
|
// Ignore
|
|
}
|
|
});
|
|
this._fileSelectionPanelElmts.unselectRegexButton.unbind().click(function() {
|
|
self._fileSelectionPanelElmts.filePanel
|
|
.find(".default-importing-file-selection-filename")
|
|
.removeClass("highlighted");
|
|
try {
|
|
var regex = new RegExp(self._fileSelectionPanelElmts.regexInput[0].value);
|
|
for (var i = 0; i < files.length; i++) {
|
|
var file = files[i];
|
|
if (file.location in self._selectedMap) {
|
|
if (regex.test(file.fileName)) {
|
|
delete self._selectedMap[file.location];
|
|
self._fileSelectionPanelElmts.filePanel
|
|
.find("input[index='" + i + "']")
|
|
.removeAttr("checked");
|
|
}
|
|
}
|
|
}
|
|
self._updateFileSelectionSummary();
|
|
} catch (e) {
|
|
// Ignore
|
|
}
|
|
});
|
|
};
|
|
|
|
Refine.DefaultImportingController.prototype._updateFileSelectionSummary = function() {
|
|
var fileSelection = [];
|
|
var files = this._job.config.retrievalRecord.files;
|
|
for (var i = 0; i < files.length; i++) {
|
|
if (files[i].location in this._selectedMap) {
|
|
fileSelection.push(i);
|
|
}
|
|
}
|
|
this._job.config.fileSelection = fileSelection;
|
|
this._fileSelectionPanelElmts.summary.text(fileSelection.length + " of " + files.length + " files selected");
|
|
};
|
|
|
|
Refine.DefaultImportingController.prototype._commitFileSelection = function() {
|
|
if (this._job.config.fileSelection.length === 0) {
|
|
alert();
|
|
return;
|
|
}
|
|
|
|
var self = this;
|
|
var dismissBusy = DialogSystem.showBusy($.i18n._('core-index-import')["inspecting-files"]);
|
|
$.post(
|
|
"command/core/importing-controller?" + $.param({
|
|
"controller": "core/default-importing-controller",
|
|
"jobID": this._jobID,
|
|
"subCommand": "update-file-selection"
|
|
}),
|
|
{
|
|
"fileSelection" : JSON.stringify(this._job.config.fileSelection)
|
|
},
|
|
function(data) {
|
|
dismissBusy();
|
|
|
|
if (!(data)) {
|
|
self._createProjectUI.showImportJobError($.i18n._('core-index-import')["unknown-err"]);
|
|
} else if (data.code == "error" || !("job" in data)) {
|
|
self._createProjectUI.showImportJobError((data.message) ? ($.i18n._('core-index-import')["error"]+ ' ' + data.message) : $.i18n._('core-index-import')["unknown-err"]);
|
|
} else {
|
|
// Different files might be selected. We start over again.
|
|
delete this._parserOptions;
|
|
|
|
self._job = data.job;
|
|
self._showParsingPanel(true);
|
|
}
|
|
},
|
|
"json"
|
|
);
|
|
};
|