From de374a614a348c7adf8bcb881db54e325dc4f883 Mon Sep 17 00:00:00 2001 From: Marco Lazzara Date: Sat, 28 Sep 2013 12:18:57 +0200 Subject: [PATCH 1/7] minor fixes --- app/scripts/api.js | 4 +- .../controllers/function-controller.js | 2 +- app/scripts/controllers/schema-controller.js | 106 +++++++++++------- app/scripts/services/database-services.js | 15 ++- app/views/database/browse.html | 9 +- app/views/database/editclass.html | 2 +- 6 files changed, 84 insertions(+), 54 deletions(-) diff --git a/app/scripts/api.js b/app/scripts/api.js index 1c3542f8..1e4c0b53 100644 --- a/app/scripts/api.js +++ b/app/scripts/api.js @@ -1,4 +1,4 @@ -//var API = '/api/'; -var API = '/'; +var API = '/api/'; +//var API = '/'; \ No newline at end of file diff --git a/app/scripts/controllers/function-controller.js b/app/scripts/controllers/function-controller.js index d7c71e85..93f549de 100644 --- a/app/scripts/controllers/function-controller.js +++ b/app/scripts/controllers/function-controller.js @@ -154,7 +154,7 @@ schemaModule.controller("FunctionController", ['$scope', '$routeParams', '$locat } $scope.saveFunction = function () { console.log($scope.functionToExecute) - if ($scope.functionToExecute['language'] != undefined && $scope.functionToExecute['name']!= undefined && $scope.functionToExecute['name']!= '') { + if ($scope.functionToExecute['language'] != undefined && $scope.functionToExecute['name'] != undefined && $scope.functionToExecute['name'] != '') { if ($scope.isNewFunction == true) { DocumentApi.createDocument($scope.database.getName(), $scope.functionToExecute['@rid'], $scope.functionToExecute, function (data) { diff --git a/app/scripts/controllers/schema-controller.js b/app/scripts/controllers/schema-controller.js index c9a50b35..56169e34 100644 --- a/app/scripts/controllers/schema-controller.js +++ b/app/scripts/controllers/schema-controller.js @@ -86,60 +86,52 @@ schemaModule.controller("SchemaController", ['$scope', '$routeParams', '$locatio }]); -schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$modal', '$q', '$route', function ($scope, $routeParams, $location, Database, CommandApi, $modal, $q, $route) { - +schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$modal', '$q', '$route', '$window', 'DatabaseApi', function ($scope, $routeParams, $location, Database, CommandApi, $modal, $q, $route, $window, DatabaseApi) { var clazz = $routeParams.clazz; $scope.class2show = clazz; $scope.database = Database; - - - $scope.listClasses = $scope.database.listNameOfClasses(); + $scope.database.refreshMetadata($routeParams.database); + $scope.modificati = undefined; $scope.limit = 20; $scope.queries = new Array; $scope.classClickedHeaders = ['name', 'type', 'linkedType', 'linkedClass', 'mandatory', 'readonly', 'notNull', 'min', 'max', 'Actions']; - + $scope.property = null; $scope.property = Database.listPropertiesForClass(clazz); - $scope.propertyNames = new Array; + for (inn in $scope.property) { $scope.propertyNames.push($scope.property[inn]['name']) } - // console.log($scope.propertyNames) + $scope.listClasses = $scope.database.listNameOfClasses(); + + $scope.indexes = null; $scope.indexes = Database.listIndexesForClass(clazz); - // for(zz in $scope.indexes) - // console.log(zz) $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.modificato = function (result, prop) { var key = result['name']; - // console.log(result[prop]) if ($scope.modificati[result['name']] == undefined) { $scope.modificati[result['name']] = new Array(prop); } - else { - var elem = $scope.modificati[result['name']] var already = false; for (i in elem) { if (prop == elem[i]) { already = true - } } if (already == false) { - elem.push(prop); } @@ -152,7 +144,6 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca modalScope.classInject = clazz; modalScope.parentScope = $scope; modalScope.propertiesName = $scope.propertyNames; - // modalScope.rid = rid; var modalPromise = $modal({template: 'views/database/newIndex.html', scope: modalScope}); $q.when(modalPromise).then(function (modalEl) { modalEl.modal('show'); @@ -164,7 +155,6 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca modalScope.classInject = clazz; modalScope.parentScope = $scope; modalScope.propertiesName = $scope.propertyNames; - // modalScope.rid = rid; var modalPromise = $modal({template: 'views/database/newProperty.html', scope: modalScope}); $q.when(modalPromise).then(function (modalEl) { modalEl.modal('show'); @@ -179,42 +169,65 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca //il nome da andare a cercare nella lista dei modificati var keyName = properties[result]['name']; + //l'array da modificare var arrayToUpdate = $scope.modificati[keyName]; - if (arrayToUpdate != undefined) { + if (!$scope.recursiveSaveProperty(arrayToUpdate, clazz, properties, result, keyName)) { - for (i in arrayToUpdate) { + return; + } - var prop = arrayToUpdate[i]; - var newValue = properties[result][prop] != '' ? properties[result][prop] : null; - var sql = 'ALTER PROPERTY ' + clazz + '.' + keyName + ' ' + prop + ' ' + newValue; - // console.log(sql); - CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { - }); - } - } +// } } //clear - $scope.modificati = new Array; + $scope.modificati = undefined; + $scope.database.refreshMetadata($routeParams.database); } + $scope.recursiveSaveProperty = function (arrayToUpdate, clazz, properties, result, keyName) { + + if (arrayToUpdate != undefined && arrayToUpdate.length > 0) { + + var prop = arrayToUpdate[0]; + var newValue = properties[result][prop] != '' ? properties[result][prop] : null; + var sql = 'ALTER PROPERTY ' + clazz + '.' + keyName + ' ' + prop + ' ' + newValue; + + + CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { + if (data) { + var index = arrayToUpdate.indexOf(prop); + arrayToUpdate.splice(index, 1); + $scope.recursiveSaveProperty(arrayToUpdate, clazz); + } + }, function (error) { + if (error) { + console.log('error') + return false; + + } + }); + + } + return true; + } + $scope.dropIndex = function (nameIndex) { Utilities.confirm($scope, $modal, $q, { title: 'Warning!', - body: 'You are dropping index ' + nameIndex + '. Are you sure?', + body: 'You are dropping index ' + nameIndex.name + '. Are you sure?', success: function () { - var sql = 'DROP INDEX ' + nameIndex; + var sql = 'DROP INDEX ' + nameIndex.name; CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { - + var index = $scope.indexes.indexOf(nameIndex) + $scope.indexes.splice(index, 1); + $scope.indexes.splice(); }); - var index = $scope.indexes.indexOf($scope.indexes[nameIndex]) - $scope.indexes.splice(index, 1) - $scope.indexes.splice() + } @@ -223,7 +236,7 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca } $scope.dropProperty = function (result, elementName) { - console.log(result); +// console.log(result); Utilities.confirm($scope, $modal, $q, { title: 'Warning!', @@ -286,7 +299,12 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca } $scope.refreshPage = function () { - + $scope.database.refreshMetadata($routeParams.database); +// Database.refreshMetadata($scope.database,function(data){ +// console.log('aaa'); +// }); +// console.log('refresh'); +// $window.location.reload() $route.reload(); } @@ -299,7 +317,9 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca } -}]); +} +]) +; schemaModule.controller("IndexController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$modal', '$q', function ($scope, $routeParams, $location, Database, CommandApi, $modal, $q) { @@ -368,10 +388,13 @@ schemaModule.controller("IndexController", ['$scope', '$routeParams', '$location CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { - $scope.hide(); - $scope.parentScope.refreshPage(); + if (data) { + console.log(data); + $scope.hide(); +// $scope.parentScope.database.refreshMetadata($routeParams.database); + $scope.parentScope.refreshPage(); + } }); - console.log(sql); } @@ -403,7 +426,6 @@ schemaModule.controller("PropertyController", ['$scope', '$routeParams', '$locat if (propName == undefined || propType == undefined) return; - var linkedType = prop['linkedType'] != null ? prop['linkedType'] : ''; var linkedClass = prop['linkedClass'] != null ? prop['linkedClass'] : ''; var sql = 'CREATE PROPERTY ' + $scope.classInject + '.' + propName + ' ' + propType + ' ' + linkedType + ' ' + linkedClass; diff --git a/app/scripts/services/database-services.js b/app/scripts/services/database-services.js index 246c3937..cc51ed89 100644 --- a/app/scripts/services/database-services.js +++ b/app/scripts/services/database-services.js @@ -36,9 +36,9 @@ database.factory('Database', function (DatabaseApi, localStorageService) { mapping: { 'BINARY': 'b', 'BYTE': 'b', 'DATE': 'a', 'DATETIME': 't', 'FLOAT': 'f', 'DECIMAL': 'c', 'LONG': 'l', 'DOUBLE': 'd', 'SHORT': 's', 'LINKSET': 'e'}, getMetadata: function () { /*if (current.metadata == null) { - var tmp = localStorageService.get("CurrentDB"); - if (tmp != null) current = tmp; - } */ + var tmp = localStorageService.get("CurrentDB"); + if (tmp != null) current = tmp; + } */ return current.metadata; }, setMetadata: function (metadata) { @@ -291,7 +291,7 @@ database.factory('Database', function (DatabaseApi, localStorageService) { var iterator = clazz; while ((iterator = this.getSuperClazz(iterator)) != "") { sup = iterator; - if(sup == 'V' || sup == 'E'){ + if (sup == 'V' || sup == 'E') { return true; } } @@ -484,13 +484,17 @@ database.factory('CommandApi', function ($http, $resource, Notification) { var noti = "Query executed in " + time + " sec. Returned " + records + " record(s)"; Notification.push({content: noti}); } - callback(data); + if (data!=undefined) + callback(data); + else + callback('ok'); }).error(function (data) { Notification.push({content: data}); if (error) error(data); }); } } + resource.getAll = function (database, clazz, callback) { var text = API + 'command/' + database + '/sql/-/-1?format=rid,type,version,class,shallow,graph'; var query = "select * from " + clazz; @@ -594,6 +598,5 @@ database.factory('FunctionApi', function ($http, $resource, Notification) { if (error) error(data); }); } - return resource; }); diff --git a/app/views/database/browse.html b/app/views/database/browse.html index a03bc8d0..66f4aedc 100644 --- a/app/views/database/browse.html +++ b/app/views/database/browse.html @@ -92,9 +92,14 @@ + + + + +
-
- +
+
\ No newline at end of file diff --git a/app/views/database/editclass.html b/app/views/database/editclass.html index 765e8894..3550c3e6 100644 --- a/app/views/database/editclass.html +++ b/app/views/database/editclass.html @@ -112,7 +112,7 @@

Class: {{class2show}}

Rebuild - Drop + Drop From 42195802b452e263196a899177b34a33c95ce805 Mon Sep 17 00:00:00 2001 From: Marco Lazzara Date: Sat, 28 Sep 2013 15:11:18 +0200 Subject: [PATCH 2/7] bug fixed on add newClass, removed pagination on class panel --- app/scripts/controllers/schema-controller.js | 38 ++++++++++---------- app/views/database/schema.html | 35 +++++++++--------- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/app/scripts/controllers/schema-controller.js b/app/scripts/controllers/schema-controller.js index 56169e34..628b213b 100644 --- a/app/scripts/controllers/schema-controller.js +++ b/app/scripts/controllers/schema-controller.js @@ -1,11 +1,13 @@ var schemaModule = angular.module('schema.controller', ['database.services']); -schemaModule.controller("SchemaController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$modal', '$q', function ($scope, $routeParams, $location, Database, CommandApi, $modal, $q) { +schemaModule.controller("SchemaController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$modal', '$q', '$route', '$window', function ($scope, $routeParams, $location, Database, CommandApi, $modal, $q, $route, $window) { //for pagination $scope.countPage = 10; $scope.countPageOptions = [10, 20, 50, 100]; $scope.currentPage = 1; + $scope.database = Database; + $scope.database.refreshMetadata($routeParams.database); $scope.database = Database; $scope.listClassesTotal = $scope.database.listClasses(); @@ -21,6 +23,11 @@ schemaModule.controller("SchemaController", ['$scope', '$routeParams', '$locatio $scope.openClass = function (clazz) { $location.path("/database/" + $scope.database.getName() + "/browse/editclass/" + clazz.name); } + $scope.refreshWindow = function () { +// $scope.database.refreshMetadata($routeParams.database); + $window.location.reload(); +// $route.reload(); + } $scope.$watch("countPage", function (data) { if ($scope.listClassesTotal) { $scope.listClasses = $scope.listClassesTotal.slice(0, $scope.countPage); @@ -39,10 +46,10 @@ schemaModule.controller("SchemaController", ['$scope', '$routeParams', '$locatio CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { - var elem = $scope.listClasses.indexOf(nameClass); + var elem = $scope.listClassesTotal.indexOf(nameClass); console.log(elem); - $scope.listClasses.splice(elem, 1) - $scope.listClasses.splice(); + $scope.listClassesTotal.splice(elem, 1) + $scope.listClassesTotal.splice(); }); } @@ -300,10 +307,6 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca } $scope.refreshPage = function () { $scope.database.refreshMetadata($routeParams.database); -// Database.refreshMetadata($scope.database,function(data){ -// console.log('aaa'); -// }); -// console.log('refresh'); // $window.location.reload() $route.reload(); } @@ -502,33 +505,28 @@ schemaModule.controller("NewClassController", ['$scope', '$routeParams', '$locat $scope.saveNewClass = function () { var sql = 'CREATE CLASS ' + $scope.property['name']; - var abstract = $scope.property['abstract'] ? ' ABSTRACT ' : ''; - var alias = $scope.property['alias'] == null || $scope.property['alias'] == '' ? null : $scope.property['alias']; - - sql = sql + abstract; - var supercl = $scope.property['superclass'] != null ? ' extends ' + $scope.property['superclass'] : ''; - sql = sql + supercl; + CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { if (alias != null) { sql = 'ALTER CLASS ' + $scope.property['name'] + ' SHORTNAME ' + alias; CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { - $route.reload(); $scope.hide(); + $scope.parentScope.refreshPage(); + }, function (error) { + $scope.hide(); + $scope.parentScope.refreshPage(); }); } else { - $route.reload(); + console.log('reload'); + $scope.parentScope.refreshWindow(); $scope.hide(); } - }); - - } - }]); diff --git a/app/views/database/schema.html b/app/views/database/schema.html index 21864d66..03ddc760 100644 --- a/app/views/database/schema.html +++ b/app/views/database/schema.html @@ -10,23 +10,22 @@
-
- -
- -
-
+ + + + + + + + + + + + + + + + @@ -43,7 +42,7 @@ - + From 538c76ae2c7e70f411b99456a8e7dc4f9e1ee94a Mon Sep 17 00:00:00 2001 From: Marco Lazzara Date: Sat, 28 Sep 2013 15:11:58 +0200 Subject: [PATCH 3/7] api.js modified --- app/scripts/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/api.js b/app/scripts/api.js index 1e4c0b53..2e3034a2 100644 --- a/app/scripts/api.js +++ b/app/scripts/api.js @@ -1,4 +1,4 @@ -var API = '/api/'; -//var API = '/'; \ No newline at end of file +//var API = '/api/'; +var API = '/'; \ No newline at end of file From 1b5f87ac565c3a2d4b29ea407be924550490b5db Mon Sep 17 00:00:00 2001 From: Marco Lazzara Date: Sun, 29 Sep 2013 11:56:33 +0200 Subject: [PATCH 4/7] added error notifications on creating new class and new index --- app/scripts/api.js | 4 +- app/scripts/controllers/schema-controller.js | 14 +-- app/views/database/newClass.html | 104 ++++++++++--------- app/views/database/newIndex.html | 4 + 4 files changed, 71 insertions(+), 55 deletions(-) diff --git a/app/scripts/api.js b/app/scripts/api.js index 2e3034a2..1e4c0b53 100644 --- a/app/scripts/api.js +++ b/app/scripts/api.js @@ -1,4 +1,4 @@ -//var API = '/api/'; -var API = '/'; \ No newline at end of file +var API = '/api/'; +//var API = '/'; \ No newline at end of file diff --git a/app/scripts/controllers/schema-controller.js b/app/scripts/controllers/schema-controller.js index 628b213b..f521e34b 100644 --- a/app/scripts/controllers/schema-controller.js +++ b/app/scripts/controllers/schema-controller.js @@ -391,12 +391,11 @@ schemaModule.controller("IndexController", ['$scope', '$routeParams', '$location CommandApi.queryText({database: $routeParams.database, language: 'sql', text: sql, limit: $scope.limit}, function (data) { - if (data) { - console.log(data); $scope.hide(); -// $scope.parentScope.database.refreshMetadata($routeParams.database); $scope.parentScope.refreshPage(); - } + },function(error){ + $scope.testMsgClass = 'alert alert-error' + $scope.testMsg = error; }); @@ -518,8 +517,8 @@ schemaModule.controller("NewClassController", ['$scope', '$routeParams', '$locat $scope.hide(); $scope.parentScope.refreshPage(); }, function (error) { - $scope.hide(); - $scope.parentScope.refreshPage(); + $scope.testMsg = error; + $scope.testMsgClass = 'alert alert-error' }); } else { @@ -527,6 +526,9 @@ schemaModule.controller("NewClassController", ['$scope', '$routeParams', '$locat $scope.parentScope.refreshWindow(); $scope.hide(); } + }, function (error) { + $scope.testMsgClass = 'alert alert-error' + $scope.testMsg = error; }); } }]); diff --git a/app/views/database/newClass.html b/app/views/database/newClass.html index 185099c8..0074e79a 100644 --- a/app/views/database/newClass.html +++ b/app/views/database/newClass.html @@ -1,53 +1,63 @@
- - -
diff --git a/app/views/database/newIndex.html b/app/views/database/newIndex.html index ea908251..ef8515f7 100644 --- a/app/views/database/newIndex.html +++ b/app/views/database/newIndex.html @@ -37,6 +37,10 @@

Index:{{newIndex['name']}}

+
+ + {{ testMsg }} +
- + From 80fd96aa0f664ba593e0a1f611a42fa879966afa Mon Sep 17 00:00:00 2001 From: Marco Lazzara Date: Sun, 29 Sep 2013 18:01:01 +0200 Subject: [PATCH 7/7] modified api.js --- app/scripts/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/api.js b/app/scripts/api.js index 1e4c0b53..2e3034a2 100644 --- a/app/scripts/api.js +++ b/app/scripts/api.js @@ -1,4 +1,4 @@ -var API = '/api/'; -//var API = '/'; \ No newline at end of file +//var API = '/api/'; +var API = '/'; \ No newline at end of file
{{result['name']}} {{result['superClass']}} {{result['alias']}}
{{index.name}}