From e74a1ea5b6810dcc8cd9947191548e1c8db77042 Mon Sep 17 00:00:00 2001 From: maggiolo00 Date: Sat, 15 Mar 2014 18:09:56 +0100 Subject: [PATCH] fixed bugs, #48 #46 #47 #49 #50 --- .../controllers/database-controller.js | 29 +++--- .../controllers/function-controller.js | 4 +- app/scripts/controllers/schema-controller.js | 9 +- app/scripts/widgets/widget.js | 89 +++++++++++++++++++ app/styles/main.css | 4 +- app/views/database/browseConfig.html | 9 +- app/views/database/functions.html | 2 +- app/views/database/query.html | 12 +-- 8 files changed, 131 insertions(+), 27 deletions(-) diff --git a/app/scripts/controllers/database-controller.js b/app/scripts/controllers/database-controller.js index 4f096f99c3f..949f5972d98 100644 --- a/app/scripts/controllers/database-controller.js +++ b/app/scripts/controllers/database-controller.js @@ -16,6 +16,7 @@ dbModule.controller("BrowseController", ['$scope', '$routeParams', '$location', dbTime = new Object; localStorageService.add("Timeline", dbTime); } + $scope.timeline = dbTime[Database.getName()]; if (!$scope.timeline) { $scope.timeline = new Array; @@ -60,14 +61,6 @@ dbModule.controller("BrowseController", ['$scope', '$routeParams', '$location', } }; - $scope.viewerOptions = { - lineWrapping: true, - lineNumbers: true, - readOnly: true, - mode: 'javascript' - - }; - $scope.query = function () { Spinner.start(); @@ -153,10 +146,22 @@ dbModule.controller("BrowseController", ['$scope', '$routeParams', '$location', } }]); -dbModule.controller("QueryController", ['$scope', '$routeParams', '$filter', '$location', 'Database', 'CommandApi', 'localStorageService', 'Spinner', 'ngTableParams', 'scroller', function ($scope, $routeParams, $filter, $location, Database, CommandApi, localStorageService, Spinner, ngTableParams, scroller) { +dbModule.controller("QueryController", ['$scope', '$routeParams', '$filter', '$location', 'Database', 'CommandApi', 'localStorageService', 'Spinner', 'ngTableParams', 'scroller','$ojson', function ($scope, $routeParams, $filter, $location, Database, CommandApi, localStorageService, Spinner, ngTableParams, scroller,$ojson) { var data = $scope.item.resultTotal; + + $scope.viewerOptions = { + lineWrapping: true, + lineNumbers: true, + readOnly: true, + mode: 'javascript', + onLoad : function(_cm){ + $scope.item.cm = _cm; + $scope.item.cm.setValue($ojson.format($scope.item.rawData)); + } + + }; $scope.tableParams = new ngTableParams({ page: 1, // show first page count: 10 // count per page @@ -205,8 +210,12 @@ dbModule.controller("QueryController", ['$scope', '$routeParams', '$filter', '$l } $scope.changeQuery = function () { $scope.queryText = $scope.item.query; - $scope.cm.setValue($scope.queryText); scroller.scrollTo(0, 0, 2000); + $scope.cm.focus(); + + $scope.cm.setValue($scope.queryText); + $scope.cm.setCursor($scope.cm.lineCount()); + } }]); diff --git a/app/scripts/controllers/function-controller.js b/app/scripts/controllers/function-controller.js index 723ed58c245..758ba1a9499 100644 --- a/app/scripts/controllers/function-controller.js +++ b/app/scripts/controllers/function-controller.js @@ -45,7 +45,8 @@ schemaModule.controller("FunctionController", ['$scope', '$routeParams', '$locat if ($scope.functions.length > 0 && $scope.functionToExecute != undefined) { var index = $scope.functionsrid.indexOf($scope.functionToExecute['name']); - $scope.showInConsoleAfterSave($scope.functions[index]); + if (index != -1) + $scope.showInConsoleAfterSave($scope.functions[index]); } } }); @@ -239,6 +240,7 @@ schemaModule.controller("FunctionController", ['$scope', '$routeParams', '$locat }); } + $scope.createNewFunction(); }]) ; diff --git a/app/scripts/controllers/schema-controller.js b/app/scripts/controllers/schema-controller.js index 0f30fda13b9..a43ceb841e6 100644 --- a/app/scripts/controllers/schema-controller.js +++ b/app/scripts/controllers/schema-controller.js @@ -98,7 +98,7 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca $scope.modificati = undefined; $scope.limit = 20; $scope.queries = new Array; - $scope.classClickedHeaders = ['Name', 'Type', 'Linked_Type', 'Linked_Class', 'Mandatory', 'Read_Only', 'Not_Null', 'Min', 'Max','Collate', 'Actions']; + $scope.classClickedHeaders = ['Name', 'Type', 'Linked_Type', 'Linked_Class', 'Mandatory', 'Read_Only', 'Not_Null', 'Min', 'Max', 'Collate', 'Actions']; $scope.property = null; $scope.property = Database.listPropertiesForClass(clazz); $scope.propertyNames = new Array; @@ -123,6 +123,7 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca var sql = 'DROP CLASS ' + nameClass; CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { + Database.setMetadata(null); $location.path("/database/" + $scope.database.getName() + "/schema"); }); @@ -145,7 +146,7 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca $scope.queryText = "" $scope.modificati = new Array; $scope.listTypes = ['BINARY', 'BOOLEAN', 'EMBEDDED', 'EMBEDDEDLIST', 'EMBEDDEDMAP', 'EMBEDDEDSET', 'DECIMAL', 'FLOAT', 'DATE', 'DATETIME', 'DOUBLE', 'INTEGER', 'LINK', 'LINKLIST', 'LINKMAP', 'LINKSET', 'LONG', 'SHORT', 'STRING']; - $scope.collateTypes = ['Case Insensitive', 'default']; + $scope.collateTypes = ['Case Insensitive', 'default']; $scope.modificato = function (result, prop) { var key = result['name']; if ($scope.modificati[result['name']] == undefined) { @@ -215,8 +216,8 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca var prop = arrayToUpdate[0]; var newValue = properties[result][prop] != '' ? properties[result][prop] : null; - if(newValue == 'Case Insensitive') - newValue = 'ci'; + if (newValue == 'Case Insensitive') + newValue = 'ci'; var sql = 'ALTER PROPERTY ' + clazz + '.' + keyName + ' ' + prop + ' ' + newValue; CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { if (data) { diff --git a/app/scripts/widgets/widget.js b/app/scripts/widgets/widget.js index 6d4f91a0a8f..72564e701ab 100644 --- a/app/scripts/widgets/widget.js +++ b/app/scripts/widgets/widget.js @@ -421,3 +421,92 @@ Widget.directive('collaterender', function () { } }; }); +Widget.provider("$ojson", function () { + + var $jsonProvider = { + + $get: function ($q, $modal, $rootScope) { + + var $ojson = {}; + + $ojson.repeat = function (s, count) { + return new Array(count + 1).join(s); + } + + $ojson.formatJson = function (json, indentChars) { + var i = 0, + il = 0, + tab = (typeof indentChars !== "undefined") ? indentChars : " ", + newJson = "", + indentLevel = 0, + inString = false, + currentChar = null; + + for (i = 0, il = json.length; i < il; i += 1) { + currentChar = json.charAt(i); + + switch (currentChar) { + case '{': + case '[': + if (!inString) { + newJson += currentChar + "\r\n" + this.repeat(tab, indentLevel + 1); + indentLevel += 1; + } else { + newJson += currentChar; + } + break; + case '}': + case ']': + if (!inString) { + indentLevel -= 1; + newJson += "\r\n" + this.repeat(tab, indentLevel) + currentChar; + } else { + newJson += currentChar; + } + break; + case ',': + if (!inString) { + newJson += ",\r\n" + this.repeat(tab, indentLevel); + } else { + newJson += currentChar; + } + break; + case ':': + if (!inString) { + newJson += ": "; + } else { + newJson += currentChar; + } + break; + case ' ': + case "\n": + case "\t": + if (inString) { + newJson += currentChar; + } + break; + case '"': + if (i > 0 && json.charAt(i - 1) !== '\\') { + inString = !inString; + } + newJson += currentChar; + break; + default: + newJson += currentChar; + break; + } + } + return newJson; + } + $ojson.format = function (text) { + return this.formatJson(text); + } + + + return $ojson; + } + } + + + return $jsonProvider; +}); diff --git a/app/styles/main.css b/app/styles/main.css index 82be2705e57..8725f34afcd 100644 --- a/app/styles/main.css +++ b/app/styles/main.css @@ -23,7 +23,9 @@ body div.container-studio { min-height: 50px; max-height: 300px; } - +.jsonView .CodeMirror { + height: 200px !important; +} .CodeMirror-scroll { /*overflow-y: hidden;*/ /*overflow-x: auto;*/ diff --git a/app/views/database/browseConfig.html b/app/views/database/browseConfig.html index 1775c8604e5..551024a8c66 100644 --- a/app/views/database/browseConfig.html +++ b/app/views/database/browseConfig.html @@ -9,11 +9,12 @@ ng-options="q for q in contentType"> - + + + - - -
diff --git a/app/views/database/functions.html b/app/views/database/functions.html index 05da8396184..3068e13bd58 100644 --- a/app/views/database/functions.html +++ b/app/views/database/functions.html @@ -90,7 +90,7 @@ - diff --git a/app/views/database/query.html b/app/views/database/query.html index d889268a0dd..d63e96be171 100644 --- a/app/views/database/query.html +++ b/app/views/database/query.html @@ -30,9 +30,9 @@
--> -
+
- +
@@ -43,13 +43,13 @@
-