Skip to content

Commit

Permalink
implemented #102
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Sep 1, 2014
1 parent 58aa92a commit 1c886cc
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 26 deletions.
58 changes: 43 additions & 15 deletions app/scripts/controllers/schema-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,25 @@ schemaModule.controller("SchemaController", ['$scope', '$routeParams', '$locatio
}
$scope.rename = function (cls, event) {

// TODO
// if (!$scope.popoverPromise) {
// var popScope = $scope.$new(true);
// popScope.rename = function (name) {
// ClassAlterApi.changeProperty($routeParams.database, { clazz: cls.name, name: "name", value: name}).then(function (data) {
// var noti = S("The class {{name}} has been renamed to {{newName}}").template({ name: cls.name, newName: name}).s;
// Notification.push({content: noti});
// cls.name = name;
// }, function err(data) {
// Notification.push({content: data, error: true});
// });
// }
// $scope.popoverPromise = $popover(angular.element(event.target), { scope: popScope, title: 'Rename Class', template: 'views/database/changeNamePopover.html', show: true});
// }

//modal
var modalScope = $scope.$new(true);
modalScope.what = 'class';
modalScope.tmpName = cls.name;
var modalPromise = $modal({template: 'views/database/changeNameModal.html', scope: modalScope, show: false});

modalScope.rename = function (name) {
if (name != cls.name) {
ClassAlterApi.changeProperty($routeParams.database, { clazz: cls.name, name: "name", value: name}).then(function (data) {
var noti = S("The class {{name}} has been renamed to {{newName}}").template({ name: cls.name, newName: name}).s;
Notification.push({content: noti});
cls.name = name;
}, function err(data) {
Notification.push({content: data, error: true});
});
}
}
modalPromise.$promise.then(modalPromise.show);

}
$scope.dropClass = function (nameClass) {
Expand Down Expand Up @@ -124,7 +129,7 @@ schemaModule.controller("SchemaController", ['$scope', '$routeParams', '$locatio
}
])
;
schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$modal', '$q', '$route', '$window', 'DatabaseApi', 'Spinner', function ($scope, $routeParams, $location, Database, CommandApi, $modal, $q, $route, $window, DatabaseApi, Spinner) {
schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$modal', '$q', '$route', '$window', 'DatabaseApi', 'Spinner', 'PropertyAlterApi', 'Notification', function ($scope, $routeParams, $location, Database, CommandApi, $modal, $q, $route, $window, DatabaseApi, Spinner, PropertyAlterApi, Notification) {
Database.setWiki("https://github.com/orientechnologies/orientdb-studio/wiki/Class");
var clazz = $routeParams.clazz;
$scope.class2show = clazz;
Expand Down Expand Up @@ -181,6 +186,29 @@ schemaModule.controller("ClassEditController", ['$scope', '$routeParams', '$loca
$scope.indexes = null;
$scope.indexes = Database.listIndexesForClass(clazz);

$scope.rename = function (props) {


//modal
var modalScope = $scope.$new(true);
modalScope.what = 'property';
modalScope.tmpName = props.name;
var modalPromise = $modal({template: 'views/database/changeNameModal.html', scope: modalScope, show: false});

modalScope.rename = function (name) {
if (name != props.name) {
PropertyAlterApi.changeProperty($routeParams.database, { clazz: $scope.class2show, property: props.name, name: "name", value: name}).then(function (data) {
var noti = S("The Property {{name}} has been renamed to {{newName}}").template({ name: props.name, newName: name}).s;
Notification.push({content: noti});
props.name = name;
}, function err(data) {
Notification.push({content: data, error: true});
});
}
}
modalPromise.$promise.then(modalPromise.show);

}

$scope.getEngine = function (index) {
var engine = '';
Expand Down
21 changes: 21 additions & 0 deletions app/scripts/services/database-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,24 @@ database.factory('ClassAlterApi', function ($http, $resource, $q) {
}
return resource
});
database.factory('PropertyAlterApi', function ($http, $resource, $q) {


var resource = $resource('function/:database');


resource.changeProperty = function (database, props) {

var deferred = $q.defer();
var text = API + 'command/' + database + '/sql/-/-1?format=rid,type,version,class,graph';
var query = "alter property {{clazz}}.{{property}} {{name}} {{value}}"
var queryText = S(query).template(props).s;
$http.post(text, queryText).success(function (data) {
deferred.resolve(data)
}).error(function (data) {
deferred.reject(data);
});
return deferred.promise;
}
return resource
});
11 changes: 11 additions & 0 deletions app/styles/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,14 @@ table.result-table > thead > tr > th {
width: 100%;
}

.cloud-db tr {
width: 100%;
display: inline-table;
}
.cloud-db tbody {
max-height: 200px;
width: 100%;
overflow: auto;
display:block;
}

40 changes: 40 additions & 0 deletions app/views/database/changeNameModal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" ng-click="$hide()" aria-hidden="true">×
</button>
<h4 class="modal-title">Change {{what}} name</h4>
</div>
<form class="form-horizontal" name="classForm" novalidate>
<div class="modal-body edge">
<div class="row-fluid">
<div class="span12">

<div class="form-group">
<label class="control-label col-md-3" for="inputName">New Name *</label>

<div class="col-md-9">
<input type="text" id="inputName" class="form-control" required
ng-model="tmpName"/>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-default" ng-click="$hide()">Close</button>
<button type="submit" class="btn btn-sm btn-primary"
ng-disabled="classForm.$invalid"
ng-click="rename(tmpName);$hide();">
Rename
</button>
</div>
</form>

</div>
</div>
</div>



2 changes: 1 addition & 1 deletion app/views/database/changeNamePopover.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h3 class="popover-title" ng-bind="title" ng-show="title"></h3>
</div>
<div class="form-actions">
<button class="btn btn-default btn-sm " ng-click="$hide()">Cancel</button>
<button class="btn btn-primary btn-sm" ng-disabled="!tmpName"
<button class="btn btn-primary btn-sm" type="submit" ng-disabled="!tmpName"
ng-click="rename(tmpName);$hide();tmpName = null;">
Rename
</button>
Expand Down
20 changes: 14 additions & 6 deletions app/views/database/editclass.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h4>Properties</h4>
<tbody>
<tr ng-repeat="result in property | orderBy:'name'">
<td>
{{result['name']}}
{{result['name']}}</a>
</td>
<td>
<select ng-model="result['type']" ng-options="p.toString() for p in listTypes"
Expand Down Expand Up @@ -132,11 +132,19 @@ <h4>Properties</h4>

</td>
<td>
<button href="javascript:void(0)" class="btn btn-danger btn-xs"
ng-click="dropProperty(result,result['name'])"><i
class="fa fa-trash-o"></i>
Drop
</button>
<div class="btn-group">
<button href="javascript:void(0)" class="btn btn-primary btn-xs"
ng-click="rename(result)">
Rename
</button>
</div>
<div class="btn-group">
<button href="javascript:void(0)" class="btn btn-danger btn-xs"
ng-click="dropProperty(result,result['name'])"><i
class="fa fa-trash-o"></i>
Drop
</button>
</div>
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion app/views/database/importCloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h3>Import Public Databases</h3>
</div>
</fieldset>
</form>
<table class="table">
<table class="table cloud-db">
<thead>
<th>Name</th>
<th>Description</th>
Expand Down
8 changes: 5 additions & 3 deletions app/views/database/schema.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@
</thead>
<tbody>
<tr ng-repeat="result in listClassesTotal | filter: queryy ">
<td>{{result['name']}} <a href="javascript:void(0)" ng-click="rename(result,$event)"
class="pull-right"><i
class="fa fa-edit"></i></a></td>
<td ng-click="openClass(result)">{{result['name']}}</td>
<td ng-click="openClass(result)">{{result['superClass']}}</td>
<td ng-click="openClass(result)">{{result['alias']}}</td>
<td ng-click="openClass(result)">
Expand All @@ -84,6 +82,10 @@
</td>
<td ng-click="openClass(result)">{{result['records']}}</td>
<td>
<button href="javascript:void(0)" class="btn btn-primary btn-xs"
ng-click="rename(result)">
Rename
</button>
<button href="javascript:void(0)" class="btn btn-default btn-xs"
ng-click="queryAll(result['name'])">
<i
Expand Down

0 comments on commit 1c886cc

Please sign in to comment.