Skip to content

Commit 32e5366

Browse files
maggiolo00maggiolo00
authored andcommitted
fixed some issues #56, #55, #46, #39, #12
1 parent 6514e9e commit 32e5366

16 files changed

Lines changed: 224 additions & 47 deletions

app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<script type="text/javascript" src="components/codemirror/mode/sql/sql.js"></script>
9595
<script type="text/javascript" src="components/codemirror/addon/hint/show-hint.js"></script>
9696
<script src="scripts/util/orientdb-hint.js"></script>
97-
<script type="text/javascript" src="components/angular-ui-codemirror/ui-codemirror.js"></script>
97+
<script type="text/javascript" src="scripts/widgets/patch/ui-codemirror.js"></script>
9898
<script src="components/angular-ui-bootstrap-bower/ui-bootstrap.js"></script>
9999
<script src="components/angular-ui-bootstrap-bower/ui-bootstrap-tpls.js"></script>
100100
<script src="components/angular-scroll/angular-scroll.min.js"></script>

app/scripts/app.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ App.config(function ($routeProvider) {
8181
controller: 'ClassEditController',
8282
resolve: DatabaseResolve
8383
})
84+
.when('/database/:database/schema/create/:clazz', {
85+
templateUrl: 'views/database/createRecord.html',
86+
controller: 'CreateController',
87+
resolve: DatabaseResolve
88+
}).
89+
when('/database/:database/schema/editclass/:clazz', {
90+
templateUrl: 'views/database/editclass.html',
91+
controller: 'ClassEditController',
92+
resolve: DatabaseResolve
93+
})
8494
.when('/database/:database/db', {
8595
templateUrl: 'views/database/configuration.html',
8696
controller: 'ConfigurationController',

app/scripts/controllers/document-controller.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ function BaseEditController($scope, $routeParams, $route, $location, $modal, $q,
288288
if (type == 'INTEGER') {
289289
$scope.doc[name] = 0;
290290
}
291+
console.log(type);
291292
if (Database.getMappingFor(type)) {
292293
if (types) {
293294
types = types + ',' + name + '=' + Database.getMappingFor(type);
@@ -319,4 +320,19 @@ function BaseEditController($scope, $routeParams, $route, $location, $modal, $q,
319320
$scope.create = function () {
320321
$location.path('database/' + $scope.database + '/browse/create/' + $scope.doc['@class']);
321322
}
322-
}
323+
}
324+
DocController.controller("EmbeddedController", ['$scope', '$ojson', function ($scope, $ojson) {
325+
326+
327+
$scope.viewerOptions = {
328+
lineWrapping: true,
329+
lineNumbers: true,
330+
mode: 'javascript',
331+
onLoad: function (_cm) {
332+
$scope.vcm = _cm;
333+
$scope.vcm.setValue(JSON.stringify($scope.doc[$scope.header]));
334+
}
335+
336+
};
337+
338+
}]);

app/scripts/controllers/function-controller.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ schemaModule.controller("FunctionController", ['$scope', '$routeParams', '$locat
1313
$scope.executeFunction();
1414

1515
}
16+
},
17+
onLoad: function (_cm) {
18+
$scope.vcm = _cm;
19+
$scope.createNewFunction();
1620
}
1721
};
1822
Database.setWiki("https://github.com/orientechnologies/orientdb-studio/wiki/Functions");
@@ -159,6 +163,8 @@ schemaModule.controller("FunctionController", ['$scope', '$routeParams', '$locat
159163
$scope.selectedLanguage = selectedFunction['language'];
160164
$scope.functionToExecute = selectedFunction;
161165
$scope.inParams = $scope.functionToExecute['parameters'];
166+
$scope.vcm.setValue($scope.consoleValue != null ? $scope.consoleValue : "");
167+
162168
}
163169

164170
$scope.showInConsole = function (selectedFunction) {
@@ -195,6 +201,7 @@ schemaModule.controller("FunctionController", ['$scope', '$routeParams', '$locat
195201
if ($scope.isNewFunction == true) {
196202
DocumentApi.createDocument($scope.database.getName(), $scope.functionToExecute['@rid'], $scope.functionToExecute, function (data) {
197203
$scope.getListFunction();
204+
$scope.isNewFunction = false;
198205
var message = 'Function saved successfully. Server returns ' + JSON.stringify(data);
199206
Notification.push({content: message });
200207
}
@@ -240,7 +247,6 @@ schemaModule.controller("FunctionController", ['$scope', '$routeParams', '$locat
240247
});
241248

242249
}
243-
$scope.createNewFunction();
244250
}])
245251
;
246252

app/scripts/controllers/header-controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ angular.module('header.controller', ['database.services']).controller("HeaderCon
3131
var find = $location.path().indexOf("/" + element.name.toLowerCase());
3232
if (find != -1) {
3333
$scope.selectedMenu = element;
34-
34+
if (!$scope.$$phase && !$scope.$root.$$phase) {
35+
$scope.$apply();
36+
}
37+
return;
3538
}
3639

3740
});

app/scripts/controllers/schema-controller.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ schemaModule.controller("SchemaController", ['$scope', '$routeParams', '$locatio
2323
$scope.classClicked = clazz;
2424
}
2525
$scope.openClass = function (clazz) {
26-
$location.path("/database/" + $scope.database.getName() + "/browse/editclass/" + clazz.name);
26+
$location.path("/database/" + $scope.database.getName() + "/schema/editclass/" + clazz.name);
2727
}
2828
$scope.refreshWindow = function () {
2929
$window.location.reload();
@@ -343,7 +343,7 @@ schemaModule.controller("IndexController", ['$scope', '$routeParams', '$location
343343
$scope.prop2add.splice(index, 1)
344344
}
345345
var first = true;
346-
$scope.nameIndexToShow = $scope.classInject + '_';
346+
$scope.nameIndexToShow = $scope.classInject + '.';
347347

348348
for (entry in $scope.prop2add) {
349349
if (first) {
@@ -526,7 +526,6 @@ schemaModule.controller("NewClassController", ['$scope', '$routeParams', '$locat
526526
schemaModule.controller("IndexesController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$modal', '$q', '$route', function ($scope, $routeParams, $location, Database, CommandApi, $modal, $q, $route) {
527527

528528
$scope.indexes = Database.getMetadata()["indexes"];
529-
console.log($scope.indexes);
530529

531530
$scope.rebuildIndex = function (indexName) {
532531
var sql = 'REBUILD INDEX ' + indexName;
@@ -551,4 +550,20 @@ schemaModule.controller("IndexesController", ['$scope', '$routeParams', '$locati
551550
}
552551
});
553552
}
553+
$scope.getFields = function (definition) {
554+
var fields = "";
555+
if (definition) {
556+
if (definition.indexDefinitions) {
557+
fields += " [";
558+
definition.indexDefinitions.forEach(function (elem, idx, array) {
559+
if (idx > 0)fields += ","
560+
fields += elem.field;
561+
});
562+
fields += "]";
563+
} else {
564+
fields += "[" + definition.field + "]";
565+
}
566+
}
567+
return fields;
568+
}
554569
}]);

app/scripts/services/database-services.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ database.factory('Database', function (DatabaseApi, localStorageService) {
3434

3535
listTypes: ['BINARY', 'BYTE', 'BOOLEAN', 'EMBEDDED', 'EMBEDDEDLIST', 'EMBEDDEDMAP', 'EMBEDDEDSET', 'DECIMAL', 'FLOAT', 'DATE', 'DATETIME', 'DOUBLE', 'INTEGER', 'LINK', 'LINKLIST', 'LINKMAP', 'LINKSET', 'LONG', 'SHORT', 'STRING'],
3636

37-
mapping: { 'BINARY': 'b', 'BYTE': 'b', 'DATE': 'a', 'DATETIME': 't', 'FLOAT': 'f', 'DECIMAL': 'c', 'LONG': 'l', 'DOUBLE': 'd', 'SHORT': 's', 'LINKSET': 'e'},
37+
mapping: { 'BINARY': 'b', 'BYTE': 'b', 'DATE': 'a', 'DATETIME': 't', 'FLOAT': 'f', 'DECIMAL': 'c', 'LONG': 'l', 'DOUBLE': 'd', 'SHORT': 's', 'LINKSET': 'e', 'EMBEDDEDLIST': 'e', 'EMBEDDEDMAP': 'e', 'EMBEDDEDSET': 'e', 'EMBEDDED': 'e'},
3838
getMetadata: function () {
3939
/*if (current.metadata == null) {
4040
var tmp = localStorageService.get("CurrentDB");
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use strict';
2+
angular.module('ui.codemirror', []).constant('uiCodemirrorConfig', {}).directive('uiCodemirror', [
3+
'uiCodemirrorConfig',
4+
function (uiCodemirrorConfig) {
5+
return {
6+
restrict: 'EA',
7+
require: '?ngModel',
8+
priority: 1,
9+
compile: function compile(tElement) {
10+
if (angular.isUndefined(window.CodeMirror)) {
11+
throw new Error('ui-codemirror need CodeMirror to work... (o rly?)');
12+
}
13+
var value = tElement.text();
14+
var codeMirror = new window.CodeMirror(function (cm_el) {
15+
angular.forEach(tElement.prop('attributes'), function (a) {
16+
if (a.name === 'ui-codemirror') {
17+
cm_el.setAttribute('ui-codemirror-opts', a.textContent);
18+
} else {
19+
cm_el.setAttribute(a.name, a.textContent);
20+
}
21+
});
22+
if (tElement.parent().length <= 0) {
23+
tElement.wrap('<div>');
24+
}
25+
tElement.replaceWith(cm_el);
26+
}, { value: value });
27+
return function postLink(scope, iElement, iAttrs, ngModel) {
28+
var options, opts;
29+
options = uiCodemirrorConfig.codemirror || {};
30+
opts = angular.extend({}, options, scope.$eval(iAttrs.uiCodemirror), scope.$eval(iAttrs.uiCodemirrorOpts));
31+
function updateOptions(newValues) {
32+
for (var key in newValues) {
33+
if (newValues.hasOwnProperty(key)) {
34+
codeMirror.setOption(key, newValues[key]);
35+
}
36+
}
37+
}
38+
updateOptions(opts);
39+
if (angular.isDefined(scope.$eval(iAttrs.uiCodemirror))) {
40+
scope.$watch(iAttrs.uiCodemirror, updateOptions, true);
41+
}
42+
codeMirror.on('change', function (instance) {
43+
var newValue = instance.getValue();
44+
if (ngModel && newValue !== ngModel.$viewValue) {
45+
ngModel.$setViewValue(newValue);
46+
}
47+
if (!scope.$$phase && !scope.$root.$$phase) {
48+
scope.$apply();
49+
}
50+
});
51+
if (ngModel) {
52+
ngModel.$formatters.push(function (value) {
53+
if (angular.isUndefined(value) || value === null) {
54+
return '';
55+
} else if (angular.isObject(value) || angular.isArray(value)) {
56+
throw new Error('ui-codemirror cannot use an object or an array as a model');
57+
}
58+
return value;
59+
});
60+
ngModel.$render = function () {
61+
var safeViewValue = ngModel.$viewValue || '';
62+
codeMirror.setValue(safeViewValue);
63+
};
64+
}
65+
if (iAttrs.uiRefresh) {
66+
scope.$watch(iAttrs.uiRefresh, function (newVal, oldVal) {
67+
if (newVal !== oldVal) {
68+
codeMirror.refresh();
69+
}
70+
});
71+
}
72+
if (angular.isFunction(opts.onLoad)) {
73+
opts.onLoad(codeMirror);
74+
}
75+
};
76+
}
77+
};
78+
}
79+
]);

app/scripts/widgets/widget.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ Widget.directive('ridrender', function (Database) {
380380
i++;
381381
}
382382
});
383-
html = html.replace(/,([^,]*)$/,'$1');
383+
html = html.replace(/,([^,]*)$/, '$1');
384384
html += "</ul>";
385385
if (html != "" && i == value.length) {
386386
element.html(html);
@@ -390,16 +390,6 @@ Widget.directive('ridrender', function (Database) {
390390
}
391391
};
392392
});
393-
Widget.directive("autofill", function () {
394-
return {
395-
require: "ngModel",
396-
link: function (scope, element, attrs, ngModel) {
397-
scope.$on("autofill:update", function() {
398-
ngModel.$setViewValue(element.val());
399-
});
400-
}
401-
}
402-
});
403393
Widget.directive('dtpicker', function () {
404394

405395

0 commit comments

Comments
 (0)