From a92ceb026124044dd87ccc59f409fd89035ff05e Mon Sep 17 00:00:00 2001 From: Hrishikesh S Date: Sun, 8 Jun 2014 17:06:42 +0530 Subject: [PATCH] Added highlighting of document contents. --- .../controllers/documents_controller.js | 2 +- .../javascripts/helpers/parse_json_helper.js | 17 +++++++++++++++-- .../javascripts/templates/document.handlebars | 2 +- .../assets/javascripts/views/document_view.js | 2 +- .../stylesheets/_pages/common_classes.scss | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Mongoman/app/assets/javascripts/controllers/documents_controller.js b/Mongoman/app/assets/javascripts/controllers/documents_controller.js index f3d4adf..3dbb532 100644 --- a/Mongoman/app/assets/javascripts/controllers/documents_controller.js +++ b/Mongoman/app/assets/javascripts/controllers/documents_controller.js @@ -17,7 +17,7 @@ Mongoman.DocumentsController = Ember.ArrayController.extend({ var keys = str.match(/[a-zA-Z0-9_\"\s\']+:\s+/g); if (keys) { for (var i = 0, j = keys.length; i < j; i++) { - str = str.replace(keys[i],'"' + keys[i].split(':')[0] + '":' ); + str = str.replace(keys[i],'"' + keys[i].split(':')[0].trim() + '":' ); } } else { diff --git a/Mongoman/app/assets/javascripts/helpers/parse_json_helper.js b/Mongoman/app/assets/javascripts/helpers/parse_json_helper.js index 7bbb10b..24eb6fb 100644 --- a/Mongoman/app/assets/javascripts/helpers/parse_json_helper.js +++ b/Mongoman/app/assets/javascripts/helpers/parse_json_helper.js @@ -6,7 +6,20 @@ Ember.Handlebars.registerBoundHelper('parseJSONString', function (json) { switch(type) { - case 'string' : return '"' + Handlebars.Utils.escapeExpression(json) + '"'; + case 'string' : + if(json.match(/^ObjectId*/)) { + return '' + ' ' + + Handlebars.Utils.escapeExpression(json) + '' + '' + } + else if(json.match(/^ISODate*/)) { + return '' + ' ' + + Handlebars.Utils.escapeExpression(json) + '' + '' + } + + return '"' + + Handlebars.Utils.escapeExpression(json) + '"'; + + case 'number' : case 'undefined' : case 'boolean' : @@ -25,7 +38,7 @@ Ember.Handlebars.registerBoundHelper('parseJSONString', function (json) { var htmlArray = []; for(var i = 0, len = keys.length; i < len; i++) { var k = keys[i]; - var html = "
" + k + '' + ': ' + "" + prettyPrint(json[k]) + "
"; + var html = "
" + k + '' + ': ' + "" + prettyPrint(json[k]) + "
"; htmlArray.push(html); } return '{' + "
" + htmlArray.join() + '
' + '
}'; diff --git a/Mongoman/app/assets/javascripts/templates/document.handlebars b/Mongoman/app/assets/javascripts/templates/document.handlebars index 65de94c..26a30ef 100644 --- a/Mongoman/app/assets/javascripts/templates/document.handlebars +++ b/Mongoman/app/assets/javascripts/templates/document.handlebars @@ -3,6 +3,6 @@ -
+
{{parseJSONString view.content}}
diff --git a/Mongoman/app/assets/javascripts/views/document_view.js b/Mongoman/app/assets/javascripts/views/document_view.js index 8c86241..2f0a493 100644 --- a/Mongoman/app/assets/javascripts/views/document_view.js +++ b/Mongoman/app/assets/javascripts/views/document_view.js @@ -15,7 +15,7 @@ Mongoman.DocumentView = Ember.View.extend({ } else { this.$('.document-content')[0].contentEditable = false - var updated_document = this.$('.document-content').text() + var updated_document = this.$('.document-content').text(); var jsonified = this.get('controller.jsonifyText')(updated_document.trim()) var url = '/documents/id?' Mongoman.PostRequest.post(url , {database_name : this.get('controller.database_name'), collection_name: this.get('controller.collection_name')}, 'PUT', jsonified) diff --git a/Mongoman/app/assets/stylesheets/_pages/common_classes.scss b/Mongoman/app/assets/stylesheets/_pages/common_classes.scss index 0dff436..c98666c 100644 --- a/Mongoman/app/assets/stylesheets/_pages/common_classes.scss +++ b/Mongoman/app/assets/stylesheets/_pages/common_classes.scss @@ -26,4 +26,4 @@ .flex { display: flex; align-items: center; -} \ No newline at end of file +}