Skip to content

Commit

Permalink
Fixed #466
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Apr 18, 2017
1 parent 5ee15f0 commit 01fae59
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/app/core/services/graph.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {downgradeInjectable} from '@angular/upgrade/static';
*
* Holds the Graph Editor info in Memory (Query + Data)
*/
declare var angular : any;
declare var angular: any;
let GraphService = Class({
constructor: [function () {
this.databases = {}
Expand All @@ -32,6 +32,19 @@ let GraphService = Class({
this.databases[db][user].data.edges = this.databases[db][user].data.edges.concat(data.edges);
this.databases[db][user].data.vertices = this.databases[db][user].data.vertices.concat(data.vertices);
},

removeEdge(db, user, e){
this.init(db, user);
this.databases[db][user].data.edges = this.databases[db][user].data.edges.filter((edge) => {
return edge["@rid"] !== e.edge["@rid"];
})
},
removeVertex(db, user, v){
this.init(db, user);
this.databases[db][user].data.vertices = this.databases[db][user].data.vertices.filter((vertex) => {
return vertex["@rid"] !== v["@rid"];
})
},
data(db, user){
this.init(db, user);
return this.databases[db][user].data;
Expand Down
22 changes: 20 additions & 2 deletions src/controllers/graph-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,10 @@ GraphModule.controller("GraphController", ['$scope', '$routeParams', '$location'
verbose: false
}, function (data) {
$scope.graph.removeEdge(e);

$timeout(function () {
GraphService.removeEdge($scope.database, $scope.currentUser, e);
}, 100)
});
}
});
Expand Down Expand Up @@ -1053,6 +1057,9 @@ GraphModule.controller("GraphController", ['$scope', '$routeParams', '$location'
verbose: false
}, function (data) {
$scope.graph.removeVertex(v);
$timeout(function () {
GraphService.removeVertex($scope.database, $scope.currentUser, v);
}, 100);
});
}
});
Expand Down Expand Up @@ -1178,6 +1185,11 @@ GraphModule.controller("GraphController", ['$scope', '$routeParams', '$location'
modalScope.confirmSave = function (docs) {
$scope.graph.endEdgeCreation();
$scope.graph.data({edges: docs}).redraw();
$timeout(function () {
GraphService.add($scope.database, $scope.currentUser,
{vertices: [], edges: docs}
);
}, 100)
}
modalScope.cancelSave = function (error) {

Expand Down Expand Up @@ -1207,6 +1219,13 @@ GraphModule.controller("GraphController", ['$scope', '$routeParams', '$location'
modalScope.confirmSave = function (doc) {

$scope.graph.data({vertices: [doc]}).redraw();


$timeout(function () {
GraphService.add($scope.database, $scope.currentUser,
{vertices: [doc], edges: []}
);
}, 100)
}
$modal({
template: 'views/database/modalNew.html',
Expand Down Expand Up @@ -1308,8 +1327,7 @@ GraphModule.controller("GraphController", ['$scope', '$routeParams', '$location'
GraphService.query($scope.database, $scope.currentUser, $scope.queryText);
GraphService.add($scope.database, $scope.currentUser,
data.graph
)
;
);
}, 1000);
}).catch(function (err) {
Spinner.stopSpinner();
Expand Down

0 comments on commit 01fae59

Please sign in to comment.