Skip to content

Commit

Permalink
Fix update one operation
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelTallet committed Jul 16, 2020
1 parent 310568d commit 2dc0ad4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @var string
*/
define('MPG_APP_VERSION', '0.9.6');
define('MPG_APP_VERSION', '0.9.7');

/**
* Development mode?
Expand Down
12 changes: 10 additions & 2 deletions static/js/jsonview.bundle.mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,26 @@ var JsonView = (function (exports) {
} else {

// XXX Modification made for MongoDB PHP GUI.
if ( node.key === '_id' ) {
MPG.documentId = node.value;
MPG.documentIdType = 'int';
}
if ( node.key === '$oid' ) {
MPG.documentId = node.value;
MPG.documentIdType = 'string';
}
if ( node.depth >= 2 && node.depth <= 5 && node.key !== '$oid' ) {
if ( node.depth >= 2 && node.depth <= 5 && !(/(_id|\$oid)/).test(node.key) ) {
var documentFieldIsUpdatable = true;
} else {
var documentFieldIsUpdatable = false;
}

el.innerHTML = notExpandedTemplate({
key: node.key,
value: node.value,

// XXX Modification made for MongoDB PHP GUI.
value: ( node.value === '' ) ? '<i>empty</i>' : node.value,

type: _typeof(node.value),

// XXX Modification made for MongoDB PHP GUI.
Expand Down
28 changes: 25 additions & 3 deletions static/js/mpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ MPG.collectionFields = [];
*/
MPG.documentId = '';

/**
* Type of document ID.
* XXX Used by JsonView parser.
*
* @type {string}
*/
MPG.documentIdType = '';

/**
* Initializes CodeMirror instance.
*
Expand Down Expand Up @@ -412,7 +420,15 @@ MPG.eventListeners.addDeleteOne = function() {
if ( filterOrDocTextAreaValue === '' ) {
return window.alert('Please fill the filter text area.');
}


var deleteConfirmation = window.confirm(
'Do you really want to delete document matching this criteria:\n' + filterOrDocTextAreaValue
)

if ( deleteConfirmation === false ) {
return;
}

requestBody.filter = JSON.parse(filterOrDocTextAreaValue);

MPG.helpers.doAjaxRequest(
Expand Down Expand Up @@ -459,9 +475,15 @@ MPG.eventListeners.addUpdate = function() {
documentFieldNewValue, documentField.dataset.documentFieldType
);

if ( MPG.documentIdType === 'int' ) {
var documentId = parseInt(documentField.dataset.documentId);
} else {
var documentId = documentField.dataset.documentId;
}

var requestBody = {
"filter": {
"_id": documentField.dataset.documentId
"_id": documentId
},
"update": {
"$set": {}
Expand All @@ -481,7 +503,7 @@ MPG.eventListeners.addUpdate = function() {
documentFieldNewValue
);
}

},
JSON.stringify(requestBody)
);
Expand Down

0 comments on commit 2dc0ad4

Please sign in to comment.