Changeset 32838


Ignore:
Timestamp:
2019-03-02T19:41:08+13:00 (5 years ago)
Author:
ak19
Message:

Save and rebuild works with map, but as with save shortcut key on map editor, the metamode ends up as accumulate still in doc.xml. Some other issues (not related to saveandrebuild) need fixing up like a popup about unsaved changes appearing even after save and rebuild has finished and possibly more things).

Location:
main/trunk/greenstone3/web/interfaces/default/js
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts.js

    r32837 r32838  
    117117
    118118var gsmap_store = {};
     119var gps_metadata_name = "GPS.mapOverlay";
    119120
    120121// Called by documentedit_scripts_util.js when saving and rebuilding.
    121122// This function should return all the doc sections' map overlay data so that
    122123// setArchivesMetadata can be called for each and the entire collection rebuilt with the changes
    123 function getDocMapsEditDataForSaving() {
     124function getDocMapsEditDataForSaving(collName) {
    124125    var map_editors_array = Object.values(gsmap_store);
    125126    var modifiedMaps = []; // the array that is the return value: an array of only all the modified maps
    126127   
    127     // get collection name
    128     var coll = gs.cgiParams.c;
    129 
    130128   
    131129    for(var i = 0; i < map_editors_array.length; i++) {
    132130        var map_editor = map_editors_array[i];
    133         var oldMapData = map_editor.savedOverlays;
    134         var newMapData = JSON.stringify(ShapesUtil.overlayToJSON(map_editor.overlays));
     131        var oldMapData = map_editor.savedOverlays; // stringified JSON shape
     132        var newMapData = JSON.stringify(ShapesUtil.overlayToJSON(map_editor.overlays)); // stringified JSON shape too
    135133       
    136         if(oldMapData !== newMapData) {
     134        // We only consider a map editor's map data to have been modified in the following cases:
     135        // - if oldMapData is null, new mapData should not be empty array
     136        // - OR oldMapData had some value and it's not the same as newMapData
     137        if(!oldMapData && newMapData !== "[]" /*|| oldMapData && oldMapData !== newMapData*/) {
     138            var nodeID = map_editors_array[i].id;
     139            console.log("old vs new mapdata for nodeID " + nodeID);
     140            console.log(oldMapData);
     141            console.log(newMapData);
    137142           
    138             var nodeID = map_editors_array[i].id;
    139             var val = map_editors_array[i].overlays;
    140143            modifiedMaps.push({
    141                 collection: coll,
     144                collection: collName,
    142145                docID: nodeID,
    143                 name:"GSP.mapOverlay",
    144                 pos: 0,
     146                name:gps_metadata_name,
     147                metapos: 0,
    145148                value:newMapData               
    146149            });
  • main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_util.js

    r32770 r32838  
    447447
    448448  var changes = changesToUpdate();
     449 
    449450  //Clean changes
    450451  editableInitStates = editableLastStates;
     452 
    451453    for(var i = 0; i < changes.length; i++)
    452454    {
    453455        var changedElem = changes[i];
    454         //Save metadata     
     456        //Save metadata
     457       
    455458        if(gs.functions.hasClass(changedElem, "metaTableCellArea"))
    456459        {
     
    514517    }
    515518
     519    // Check for changes to any map editors in the document
     520    var modified_map_editors_data = getDocMapsEditDataForSaving(gs.cgiParams.c); // collection 
     521    for(var i = 0; i < modified_map_editors_data.length; i++) {     
     522        metadataChanges.push(modified_map_editors_data[i]); // of the form { collection: gs.cgiParams.c, docID: nodeID, name:"GSP.mapOverlay", metapos: 0, value: <stringifiedJSON> }
     523        addCollectionToBuild(gs.cgiParams.c); // collection
     524    }
     525
     526   
    516527   
    517528    var processChangesLoop = function(index)
    518529    {
    519      
    520530        var change = metadataChanges[index];
    521        
     531               
    522532        var callbackFunction;
    523533        if(index + 1 == metadataChanges.length)
     
    532542            gs.functions.removeArchivesMetadata(collection, gs.xsltParams.site_name, change.docID, change.name, null, encodeDelimiters(change.value), function(){callbackFunction();});
    533543        } else {
    534           if(change.orig)
     544          // Checking "if(change.metapos)" doesn't work for us as it becomes false when the property doesn't exist AND when the property is 0. But metapos IS 0 for us.
     545          // https://ultimatecourses.com/blog/methods-to-determine-if-an-object-has-a-given-property
     546          if('metapos' in change && change.metapos === 0) {// && change.metapos === 0) { // for maps
     547               
     548                // collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction               
     549                //console.log("@@@ metapos! change: ", change);
     550                gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, change.metapos, change.value /*TODO: encodeDelimiters(change.value)*/, null, "override", function(){callbackFunction();});
     551            }
     552          else if(change.orig)
    535553            {
    536554            gs.functions.setArchivesMetadata(change.collection, gs.xsltParams.site_name, change.docID, change.name, null, encodeDelimiters(change.value), encodeDelimiters(change.orig), "override", function(){callbackFunction();});
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js

    r32837 r32838  
    111111        console.log(enableMessage);
    112112       
    113        
     113        // Comment out following section in entirety -- from "e=e" to end of "if(e)" -- if
     114        // you don't want to see the popup about changes that haven't been saved yet
    114115        e = e || window.event;
    115116        // For IE and Firefox
     
    126127            }               
    127128        }
     129       
    128130    }
    129131}
     
    332334    //Keyboard shortcuts           
    333335    var mapAndControls = document.getElementById("map-and-controls-" + this.id);
    334     console.log("@@@@ initMapEditor. mapAndControls: " + mapAndControls);
     336    console.log("@@@@ initMapEditor. mapAndControls: ", mapAndControls);
    335337   
    336338    //Sets shift as unpressed
     
    399401    var site_name = gs.xsltParams.site_name;
    400402    var nodeID = this.id; // documentID, hopefully contains section ID too
    401     var metaname = "GPS.mapOverlay";
    402    
     403    var metaname = gps_metadata_name;
     404       
    403405    // collection, site, documentID, metadataName, metadataPosition, responseFunction
    404406    gs.functions.getArchivesMetadata(collection, site_name, nodeID, metaname, 0, function(responseText){
     
    660662    console.log("Save pressed");
    661663   
    662     var json_overlays = ShapesUtil.overlayToJSON(this.overlays);
     664    var json_overlays = JSON.stringify(ShapesUtil.overlayToJSON(this.overlays));   
     665    that.savedOverlays = json_overlays; // save the old version to compare with future changes
    663666    var collection = gs.cgiParams.c;
    664667    var site_name = gs.xsltParams.site_name;
     
    667670   
    668671    // collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction   
    669     gs.functions.setArchivesMetadata(collection, site_name, nodeID, metaname, 0, JSON.stringify(json_overlays), null, "override", function(){
     672    gs.functions.setArchivesMetadata(collection, site_name, nodeID, metaname, 0, json_overlays, null, "override", function(){
    670673            console.log("SAVED");
    671674        }
    672675    );
    673676   
    674     gs.functions.getArchivesMetadata(collection, site_name, nodeID, metaname, 0, function(responseText){
     677    /*gs.functions.getArchivesMetadata(collection, site_name, nodeID, metaname, 0, function(responseText){
    675678            var JSONString = responseText.getValue();
    676679            that.savedOverlays = JSONString;
    677680        }
    678     ); 
     681    );*/
     682   
    679683   
    680684}
Note: See TracChangeset for help on using the changeset viewer.