RandomSec/main/webapp/modules/core/scripts/project/edit-general-metadata-dialog.js

606 lines
32 KiB
JavaScript
Raw Normal View History

data package metadata (#1398) * 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
2018-02-02 14:24:19 +01:00
function EditGeneralMetadataDialog(projectId, callback) {
this._projectId = projectId;
this._callback = callback;
this._createDialog();
}
EditGeneralMetadataDialog.prototype._createDialog = function() {
var self = this;
var schema = {
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Data Package",
"description": "Data Package is a simple specification for data access and delivery.",
"type": "object",
"required": [
"resources"
],
"properties": {
"profile": {
"default": "data-package",
"propertyOrder": 10,
"title": "Profile",
"description": "The profile of this descriptor.",
"context": "Every Package and Resource descriptor has a profile. The default profile, if none is declared, is `data-package` for Package and `data-resource` for Resource.",
"type": "string",
"examples": [
"{\n \"profile\": \"tabular-data-package\"\n}\n",
"{\n \"profile\": \"http://example.com/my-profiles-json-schema.json\"\n}\n"
]
},
"name": {
"propertyOrder": 20,
"title": "Name",
"description": "An identifier string. Lower case characters with `.`, `_`, `-` and `/` are allowed.",
"type": "string",
"pattern": "^([-a-z0-9._/])+$",
"context": "This is ideally a url-usable and human-readable name. Name `SHOULD` be invariant, meaning it `SHOULD NOT` change when its parent descriptor is updated.",
"examples": [
"{\n \"name\": \"my-nice-name\"\n}\n"
]
},
"id": {
"propertyOrder": 30,
"title": "ID",
"description": "A property reserved for globally unique identifiers. Examples of identifiers that are unique include UUIDs and DOIs.",
"context": "A common usage pattern for Data Packages is as a packaging format within the bounds of a system or platform. In these cases, a unique identifier for a package is desired for common data handling workflows, such as updating an existing package. While at the level of the specification, global uniqueness cannot be validated, consumers using the `id` property `MUST` ensure identifiers are globally unique.",
"type": "string",
"examples": [
"{\n \"id\": \"b03ec84-77fd-4270-813b-0c698943f7ce\"\n}\n",
"{\n \"id\": \"http://dx.doi.org/10.1594/PANGAEA.726855\"\n}\n"
]
},
"title": {
"propertyOrder": 40,
"title": "Title",
"description": "A human-readable title.",
"type": "string",
"examples": [
"{\n \"title\": \"My Package Title\"\n}\n"
]
},
"description": {
"propertyOrder": 50,
"title": "Description",
"description": "A text description. Markdown is encouraged.",
"type": "string",
"examples": [
"{\n \"description\": \"# My Package description\\nAll about my package.\"\n}\n"
]
},
"homepage": {
"propertyOrder": 60,
"title": "Home Page",
"description": "The home on the web that is related to this data package.",
"type": "string",
"format": "uri",
"examples": [
"{\n \"homepage\": \"http://example.com/\"\n}\n"
]
},
"created": {
"propertyOrder": 70,
"title": "Created",
"description": "The datetime on which this descriptor was created.",
"context": "The datetime must conform to the string formats for datetime as described in [RFC3339](https://tools.ietf.org/html/rfc3339#section-5.6)",
"type": "string",
"format": "date-time",
"examples": [
"{\n \"created\": \"1985-04-12T23:20:50.52Z\"\n}\n"
]
},
"contributors": {
"propertyOrder": 80,
"title": "Contributors",
"description": "The contributors to this descriptor.",
"type": "array",
"minItems": 1,
"items": {
"title": "Contributor",
"description": "A contributor to this descriptor.",
"properties": {
"title": {
"title": "Title",
"description": "A human-readable title.",
"type": "string",
"examples": [
"{\n \"title\": \"My Package Title\"\n}\n"
]
},
"path": {
"title": "Path",
"description": "A fully qualified URL, or a POSIX file path..",
"type": "string",
"examples": [
"{\n \"path\": \"file.csv\"\n}\n",
"{\n \"path\": \"http://example.com/file.csv\"\n}\n"
],
"context": "Implementations need to negotiate the type of path provided, and dereference the data accordingly."
},
"email": {
"title": "Email",
"description": "An email address.",
"type": "string",
"format": "email",
"examples": [
"{\n \"email\": \"example@example.com\"\n}\n"
]
},
"organisation": {
"title": "Organization",
"description": "An organizational affiliation for this contributor.",
"type": "string"
},
"role": {
"type": "string",
"enum": [
"publisher",
"author",
"maintainer",
"wrangler",
"contributor"
],
"default": "contributor"
}
},
"required": [
"title"
],
"context": "Use of this property does not imply that the person was the original creator of, or a contributor to, the data in the descriptor, but refers to the composition of the descriptor itself."
},
"examples": [
"{\n \"contributors\": [\n {\n \"title\": \"Joe Bloggs\"\n }\n ]\n}\n",
"{\n \"contributors\": [\n {\n \"title\": \"Joe Bloggs\",\n \"email\": \"joe@example.com\",\n \"role\": \"author\"\n }\n ]\n}\n"
]
},
"keywords": {
"propertyOrder": 90,
"title": "Keywords",
"description": "A list of keywords that describe this package.",
"type": "array",
"minItems": 1,
"items": {
"type": "string"
},
"examples": [
"{\n \"keywords\": [\n \"data\",\n \"fiscal\",\n \"transparency\"\n ]\n}\n"
]
},
"image": {
"propertyOrder": 100,
"title": "Image",
"description": "A image to represent this package.",
"type": "string",
"examples": [
"{\n \"image\": \"http://example.com/image.jpg\"\n}\n",
"{\n \"image\": \"relative/to/image.jpg\"\n}\n"
]
},
"licenses": {
"propertyOrder": 110,
"title": "Licenses",
"description": "The license(s) under which this package is published.",
"type": "array",
"minItems": 1,
"items": {
"title": "License",
"description": "A license for this descriptor.",
"type": "object",
"properties": {
"name": {
"title": "Open Definition license identifier",
"description": "MUST be an Open Definition license identifier, see http://licenses.opendefinition.org/",
"type": "string",
"pattern": "^([-a-zA-Z0-9._])+$"
},
"path": {
"title": "Path",
"description": "A fully qualified URL, or a POSIX file path..",
"type": "string",
"examples": [
"{\n \"path\": \"file.csv\"\n}\n",
"{\n \"path\": \"http://example.com/file.csv\"\n}\n"
],
"context": "Implementations need to negotiate the type of path provided, and dereference the data accordingly."
},
"title": {
"title": "Title",
"description": "A human-readable title.",
"type": "string",
"examples": [
"{\n \"title\": \"My Package Title\"\n}\n"
]
}
},
"context": "Use of this property does not imply that the person was the original creator of, or a contributor to, the data in the descriptor, but refers to the composition of the descriptor itself."
},
"context": "This property is not legally binding and does not guarantee that the package is licensed under the terms defined herein.",
"examples": [
"{\n \"licenses\": [\n {\n \"name\": \"odc-pddl-1.0\",\n \"uri\": \"http://opendatacommons.org/licenses/pddl/\"\n }\n ]\n}\n"
]
},
"resources": {
"propertyOrder": 120,
"title": "Data Resources",
"description": "An `array` of Data Resource objects, each compliant with the [Data Resource](/data-resource/) specification.",
"type": "array",
"minItems": 1,
"items": {
"title": "Data Resource",
"description": "Data Resource.",
"type": "object",
"oneOf": [
{
"required": [
"name",
"data"
]
},
{
"required": [
"name",
"path"
]
}
],
"properties": {
"profile": {
"propertyOrder": 10,
"default": "data-resource",
"title": "Profile",
"description": "The profile of this descriptor.",
"context": "Every Package and Resource descriptor has a profile. The default profile, if none is declared, is `data-package` for Package and `data-resource` for Resource.",
"type": "string",
"examples": [
"{\n \"profile\": \"tabular-data-package\"\n}\n",
"{\n \"profile\": \"http://example.com/my-profiles-json-schema.json\"\n}\n"
]
},
"name": {
"propertyOrder": 20,
"title": "Name",
"description": "An identifier string. Lower case characters with `.`, `_`, `-` and `/` are allowed.",
"type": "string",
"pattern": "^([-a-z0-9._/])+$",
"context": "This is ideally a url-usable and human-readable name. Name `SHOULD` be invariant, meaning it `SHOULD NOT` change when its parent descriptor is updated.",
"examples": [
"{\n \"name\": \"my-nice-name\"\n}\n"
]
},
"path": {
"propertyOrder": 30,
"title": "Path",
"description": "A reference to the data for this resource, as either a path as a string, or an array of paths as strings. of valid URIs.",
"oneOf": [
{
"title": "Path",
"description": "A fully qualified URL, or a POSIX file path..",
"type": "string",
"examples": [
"{\n \"path\": \"file.csv\"\n}\n",
"{\n \"path\": \"http://example.com/file.csv\"\n}\n"
],
"context": "Implementations need to negotiate the type of path provided, and dereference the data accordingly."
},
{
"type": "array",
"minItems": 1,
"items": {
"title": "Path",
"description": "A fully qualified URL, or a POSIX file path..",
"type": "string",
"examples": [
"{\n \"path\": \"file.csv\"\n}\n",
"{\n \"path\": \"http://example.com/file.csv\"\n}\n"
],
"context": "Implementations need to negotiate the type of path provided, and dereference the data accordingly."
},
"examples": [
"[ \"file.csv\" ]\n",
"[ \"http://example.com/file.csv\" ]\n"
]
}
],
"context": "The dereferenced value of each referenced data source in `path` `MUST` be commensurate with a native, dereferenced representation of the data the resource describes. For example, in a *Tabular* Data Resource, this means that the dereferenced value of `path` `MUST` be an array.",
"examples": [
"{\n \"path\": [\n \"file.csv\",\n \"file2.csv\"\n ]\n}\n",
"{\n \"path\": [\n \"http://example.com/file.csv\",\n \"http://example.com/file2.csv\"\n ]\n}\n",
"{\n \"path\": \"http://example.com/file.csv\"\n}\n"
]
},
"data": {
"propertyOrder": 230,
"title": "Data",
"description": "Inline data for this resource."
},
"schema": {
"propertyOrder": 40,
"title": "Schema",
"description": "A schema for this resource.",
"type": "object"
},
"title": {
"propertyOrder": 50,
"title": "Title",
"description": "A human-readable title.",
"type": "string",
"examples": [
"{\n \"title\": \"My Package Title\"\n}\n"
]
},
"description": {
"propertyOrder": 60,
"title": "Description",
"description": "A text description. Markdown is encouraged.",
"type": "string",
"examples": [
"{\n \"description\": \"# My Package description\\nAll about my package.\"\n}\n"
]
},
"homepage": {
"propertyOrder": 70,
"title": "Home Page",
"description": "The home on the web that is related to this data package.",
"type": "string",
"format": "uri",
"examples": [
"{\n \"homepage\": \"http://example.com/\"\n}\n"
]
},
"sources": {
"propertyOrder": 140,
"options": {
"hidden": true
},
"title": "Sources",
"description": "The raw sources for this resource.",
"type": "array",
"minItems": 1,
"items": {
"title": "Source",
"description": "A source file.",
"type": "object",
"required": [
"title"
],
"properties": {
"title": {
"title": "Title",
"description": "A human-readable title.",
"type": "string",
"examples": [
"{\n \"title\": \"My Package Title\"\n}\n"
]
},
"path": {
"title": "Path",
"description": "A fully qualified URL, or a POSIX file path..",
"type": "string",
"examples": [
"{\n \"path\": \"file.csv\"\n}\n",
"{\n \"path\": \"http://example.com/file.csv\"\n}\n"
],
"context": "Implementations need to negotiate the type of path provided, and dereference the data accordingly."
},
"email": {
"title": "Email",
"description": "An email address.",
"type": "string",
"format": "email",
"examples": [
"{\n \"email\": \"example@example.com\"\n}\n"
]
}
}
},
"examples": [
"{\n \"sources\": [\n {\n \"name\": \"World Bank and OECD\",\n \"uri\": \"http://data.worldbank.org/indicator/NY.GDP.MKTP.CD\"\n }\n ]\n}\n"
]
},
"licenses": {
"description": "The license(s) under which the resource is published.",
"propertyOrder": 150,
"options": {
"hidden": true
},
"title": "Licenses",
"type": "array",
"minItems": 1,
"items": {
"title": "License",
"description": "A license for this descriptor.",
"type": "object",
"properties": {
"name": {
"title": "Open Definition license identifier",
"description": "MUST be an Open Definition license identifier, see http://licenses.opendefinition.org/",
"type": "string",
"pattern": "^([-a-zA-Z0-9._])+$"
},
"path": {
"title": "Path",
"description": "A fully qualified URL, or a POSIX file path..",
"type": "string",
"examples": [
"{\n \"path\": \"file.csv\"\n}\n",
"{\n \"path\": \"http://example.com/file.csv\"\n}\n"
],
"context": "Implementations need to negotiate the type of path provided, and dereference the data accordingly."
},
"title": {
"title": "Title",
"description": "A human-readable title.",
"type": "string",
"examples": [
"{\n \"title\": \"My Package Title\"\n}\n"
]
}
},
"context": "Use of this property does not imply that the person was the original creator of, or a contributor to, the data in the descriptor, but refers to the composition of the descriptor itself."
},
"context": "This property is not legally binding and does not guarantee that the package is licensed under the terms defined herein.",
"examples": [
"{\n \"licenses\": [\n {\n \"name\": \"odc-pddl-1.0\",\n \"uri\": \"http://opendatacommons.org/licenses/pddl/\"\n }\n ]\n}\n"
]
},
"format": {
"propertyOrder": 80,
"title": "Format",
"description": "The file format of this resource.",
"context": "`csv`, `xls`, `json` are examples of common formats.",
"type": "string",
"examples": [
"{\n \"format\": \"xls\"\n}\n"
]
},
"mediatype": {
"propertyOrder": 90,
"title": "Media Type",
"description": "The media type of this resource. Can be any valid media type listed with [IANA](https://www.iana.org/assignments/media-types/media-types.xhtml).",
"type": "string",
"pattern": "^(.+)/(.+)$",
"examples": [
"{\n \"mediatype\": \"text/csv\"\n}\n"
]
},
"encoding": {
"propertyOrder": 100,
"title": "Encoding",
"description": "The file encoding of this resource.",
"type": "string",
"default": "utf-8",
"examples": [
"{\n \"encoding\": \"utf-8\"\n}\n"
]
},
"bytes": {
"propertyOrder": 110,
"options": {
"hidden": true
},
"title": "Bytes",
"description": "The size of this resource in bytes.",
"type": "integer",
"examples": [
"{\n \"bytes\": 2082\n}\n"
]
},
"hash": {
"propertyOrder": 120,
"options": {
"hidden": true
},
"title": "Hash",
"type": "string",
"description": "The MD5 hash of this resource. Indicate other hashing algorithms with the {algorithm}:{hash} format.",
"pattern": "^([^:]+:[a-fA-F0-9]+|[a-fA-F0-9]{32}|)$",
"examples": [
"{\n \"hash\": \"d25c9c77f588f5dc32059d2da1136c02\"\n}\n",
"{\n \"hash\": \"SHA256:5262f12512590031bbcc9a430452bfd75c2791ad6771320bb4b5728bfb78c4d0\"\n}\n"
]
}
}
},
"examples": [
"{\n \"resources\": [\n {\n \"name\": \"my-data\",\n \"data\": [\n \"data.csv\"\n ],\n \"mediatype\": \"text/csv\"\n }\n ]\n}\n"
]
},
"sources": {
"propertyOrder": 200,
"options": {
"hidden": true
},
"title": "Sources",
"description": "The raw sources for this resource.",
"type": "array",
"minItems": 1,
"items": {
"title": "Source",
"description": "A source file.",
"type": "object",
"required": [
"title"
],
"properties": {
"title": {
"title": "Title",
"description": "A human-readable title.",
"type": "string",
"examples": [
"{\n \"title\": \"My Package Title\"\n}\n"
]
},
"path": {
"title": "Path",
"description": "A fully qualified URL, or a POSIX file path..",
"type": "string",
"examples": [
"{\n \"path\": \"file.csv\"\n}\n",
"{\n \"path\": \"http://example.com/file.csv\"\n}\n"
],
"context": "Implementations need to negotiate the type of path provided, and dereference the data accordingly."
},
"email": {
"title": "Email",
"description": "An email address.",
"type": "string",
"format": "email",
"examples": [
"{\n \"email\": \"example@example.com\"\n}\n"
]
}
}
},
"examples": [
"{\n \"sources\": [\n {\n \"name\": \"World Bank and OECD\",\n \"uri\": \"http://data.worldbank.org/indicator/NY.GDP.MKTP.CD\"\n }\n ]\n}\n"
]
}
}
};
var options = {
schema: schema
};
var frame = $(DOM.loadHTML("core", "scripts/project/edit-general-metadata-dialog.html"));
this._elmts = DOM.bind(frame);
this._level = DialogSystem.showDialog(frame);
var editor;
this._elmts.okButton.html($.i18n._('core-buttons')["ok"]);
this._elmts.okButton.click(function() { self._submit(editor); });
this._elmts.closeButton.html($.i18n._('core-buttons')["close"]);
this._elmts.closeButton.click(function() { self._dismiss(); });
$.get(
"command/core/get-imetaData",
{
project : this._projectId,
metadataFormat : "DATAPACKAGE_METADATA"
},
function(o) {
if (o.code === "error") {
alert(o.message);
}
editor = new JSONEditor(document.getElementById('jsoneditor'), options, o);
},
"json"
);
$(".dialog-container").css("top", Math.round(($(".dialog-overlay").height() - $(frame).height()) / 16) + "px");
};
EditGeneralMetadataDialog.prototype._dismiss = function() {
DialogSystem.dismissUntil(this._level - 1);
};
EditGeneralMetadataDialog.prototype._submit = function(editor) {
if (typeof this._callback === "function") {
this._callback(editor.getText());
}
this._dismiss();
};