From 2dc0ad45d7661e3d08b6e023b81c3bcf3bdc348b Mon Sep 17 00:00:00 2001 From: Samuel Tallet Date: Thu, 16 Jul 2020 20:37:42 +0200 Subject: [PATCH] Fix update one operation --- index.php | 2 +- static/js/jsonview.bundle.mod.js | 12 ++++++++++-- static/js/mpg.js | 28 +++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 73334a3..d9aa03f 100644 --- a/index.php +++ b/index.php @@ -20,7 +20,7 @@ * * @var string */ -define('MPG_APP_VERSION', '0.9.6'); +define('MPG_APP_VERSION', '0.9.7'); /** * Development mode? diff --git a/static/js/jsonview.bundle.mod.js b/static/js/jsonview.bundle.mod.js index ba4e73a..ba0b922 100644 --- a/static/js/jsonview.bundle.mod.js +++ b/static/js/jsonview.bundle.mod.js @@ -190,10 +190,15 @@ 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; @@ -201,7 +206,10 @@ var JsonView = (function (exports) { el.innerHTML = notExpandedTemplate({ key: node.key, - value: node.value, + + // XXX Modification made for MongoDB PHP GUI. + value: ( node.value === '' ) ? 'empty' : node.value, + type: _typeof(node.value), // XXX Modification made for MongoDB PHP GUI. diff --git a/static/js/mpg.js b/static/js/mpg.js index b6b830d..d8a9e67 100644 --- a/static/js/mpg.js +++ b/static/js/mpg.js @@ -56,6 +56,14 @@ MPG.collectionFields = []; */ MPG.documentId = ''; +/** + * Type of document ID. + * XXX Used by JsonView parser. + * + * @type {string} + */ +MPG.documentIdType = ''; + /** * Initializes CodeMirror instance. * @@ -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( @@ -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": {} @@ -481,7 +503,7 @@ MPG.eventListeners.addUpdate = function() { documentFieldNewValue ); } - + }, JSON.stringify(requestBody) );