diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dc7ee0dc3072adb358a97b791b70cf67b0c0604..b48f78dfa34c31328062cd7343d175ba6276f879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 information (like plots, video players, thumbnails...) can be shown. * Enable with build property `BUILD_MODULE_EXT_BOTTOM_LINE=ENABLED`. * More documentation in `src/core/js/ext_bottom_line.js`. +* ext_revisions (v0.1 - EXPERIMENTAL) + * Creates a backup copy of each entity which is updated via the edit_mode. + * Enable via the build property `BUILD_MODULE_EXT_REVISIONS=ENABLED`. + * Needs two special entities. A RecordType "Obsolete" and a reference + property "revisionOf" with data type "Obsolete". * Map (v0.3) * Adds a button to the navbar which toggles a map in the top of the main panel. The map currently shows all known entities which have geolocation diff --git a/src/core/js/ext_revisions.js b/src/core/js/ext_revisions.js index cf0da0c78a83b87c38ecfdce9e3d576328e2b04c..3ee086e60ed34ac659c5bb92de71d78b38f30e2b 100644 --- a/src/core/js/ext_revisions.js +++ b/src/core/js/ext_revisions.js @@ -2,8 +2,8 @@ * ** header v3.0 * This file is a part of the CaosDB Project. * - * Copyright (C) 2019 IndiScale GmbH (info@indiscale.com) - * Copyright (C) 2019 Timm Fitschen (t.fitschen@indiscale.com) + * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -31,7 +31,7 @@ * proxy (or wrapper) function adds further functionality. * * The extended update function creates a back-up version of the updated entity - * and and adds a revisionOf property to the updated entity which references + * and adds a revisionOf property to the updated entity which references * the back-up. The back-up entity loses all of its original parents and gets * an "Obsolete" as only parent instead. * @@ -55,8 +55,6 @@ var ext_revisions = function ($, logger, edit_mode, getEntityID, transaction, _c /** * Default names for the two entities which are required by this module. - * - * TODO: rename */ var _datamodel = { obsolete: "Obsolete", revisionOf: "revisionOf" }; @@ -75,16 +73,18 @@ var ext_revisions = function ($, logger, edit_mode, getEntityID, transaction, _c logger.debug("insert obsolete", id); // create new obsolete entity from the original - var obsolete = await transaction.retrieveEntityById(id); + const obsolete = await transaction.retrieveEntityById(id); $(obsolete).attr("id", "-1"); $(obsolete).find("Permissions").remove(); $(obsolete).find("Parent").remove(); $(obsolete).append(`<Parent name="${_datamodel.obsolete}"/>`); - var doc = _createDocument("Request"); + const doc = _createDocument("Request"); doc.firstElementChild.appendChild(obsolete); - var result = await transaction.insertEntitiesXml(doc); - return $(result.firstElementChild).find("[id]").first().attr("id"); + const result = await transaction.insertEntitiesXml(doc); + const obsolete_id = $(result.firstElementChild).find("[id]").first().attr("id"); + logger.trace("leave _insert_obsolete", obsolete_id); + return obsolete_id; }; /** @@ -98,11 +98,12 @@ var ext_revisions = function ($, logger, edit_mode, getEntityID, transaction, _c * @returns {string} A HTML represesentation of an entity property. */ var _make_revision_of_property = async function (obsolete_id) { - logger.debug("_make_revision_of_property", obsolete_id); - var ret = (await transformation.transformProperty(str2xml(`<Response><Property id="${_datamodel._revisionOfId}" name="${_datamodel.revisionOf}" datatype="${_datamodel.obsolete}"></Property></Response>`))).firstElementChild; + logger.trace("enter _make_revision_of_property", obsolete_id); + const ret = (await transformation.transformProperty(str2xml(`<Response><Property id="${_datamodel._revisionOfId}" name="${_datamodel.revisionOf}" datatype="${_datamodel.obsolete}"></Property></Response>`))).firstElementChild; - $(ret).append(`<div class="caosdb-property-edit-value"><select><option value="${obsolete_id}" selected="selected"></option></select></div>`); + $(ret).find(".caosdb-f-property-value").append(`<div class="caosdb-property-edit-value"><select><option value="${obsolete_id}" selected="selected"></option></select></div>`); + logger.trace("leave _make_revision_of_property", ret); return ret; } @@ -215,6 +216,7 @@ var ext_revisions = function ($, logger, edit_mode, getEntityID, transaction, _c // private members, exposed for testing _make_revision_of_property: _make_revision_of_property, _datamodel: _datamodel, + _logger: logger, } }($, log.getLogger("ext_revisions"), edit_mode, getEntityID, transaction, _createDocument); diff --git a/test/core/js/modules/ext_revisions.js.js b/test/core/js/modules/ext_revisions.js.js index bd9787afec3039984e3b067638c9ae6a9a3fd422..e90fd7c97851e5f054690cb0d376be5e14d826e4 100644 --- a/test/core/js/modules/ext_revisions.js.js +++ b/test/core/js/modules/ext_revisions.js.js @@ -2,7 +2,8 @@ * ** header v3.0 * This file is a part of the CaosDB Project. * - * Copyright (C) 2019 IndiScale GmbH + * Copyright (C) 2020 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as @@ -33,6 +34,7 @@ var ext_revisions_test_suite = function ($, ext_revisions, QUnit, edit_mode) { this.original_insert = transaction.insertEntitiesXml; this.original_retrieve = transaction.retrieveEntityById; this.original_query = query; + ext_revisions._logger.setLevel("trace"); }, beforeEach: function (assert) { // setup before each test @@ -80,6 +82,7 @@ var ext_revisions_test_suite = function ($, ext_revisions, QUnit, edit_mode) { assert.equal(rec.id, "-1", "insert with tmp id"); assert.equal($(rec).find("Parent").attr("name"), datamodel.obsolete, "Obsolete Parent"); xml.firstElementChild.firstElementChild.id = "2345"; + console.log(xml2str(xml)); done(); return xml; };