Skip to content

Commit

Permalink
Fixed #435
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Jan 16, 2017
1 parent 122d17b commit 1b6d76b
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 8 deletions.
17 changes: 15 additions & 2 deletions src/controllers/document-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,13 @@ DocController.controller("EditController", ['$scope', '$routeParams', '$location
var rid = $routeParams.rid;
$scope.doc = DocumentApi.get({database: database, document: rid}, function () {

$scope.template = Database.isGraph($scope.doc['@class']) ? 'views/database/editVertex.html' : 'views/database/editDocument.html'
if (Database.isVertex($scope.doc['@class'])) {
$scope.template = 'views/database/editVertex.html';
} else if (Database.isEdge($scope.doc['@class'])) {
$scope.template = 'views/database/editEdge.html';
} else {
$scope.template = 'views/database/editDocument.html';
}
}, function (error) {
Notification.push({content: JSON.stringify(error)});
$location.path('404');
Expand All @@ -259,7 +265,14 @@ DocController.controller("CreateController", ['$scope', '$routeParams', '$locati
$scope.doc = DocumentApi.createNewDoc(clazz);
$scope.headers = Database.getPropertyFromDoc($scope.doc);
$scope.isNew = true;
$scope.template = Database.isGraph(clazz) ? 'views/database/editVertex.html' : 'views/database/editDocument.html'

if (Database.isVertex(clazz)) {
$scope.template = 'views/database/editVertex.html';
} else if (Database.isEdge(clazz)) {
$scope.template = 'views/database/editEdge.html';
} else {
$scope.template = 'views/database/editDocument.html';
}

}]);
DocController.controller("DocumentModalBrowseController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', '$timeout', function ($scope, $routeParams, $location, Database, CommandApi, $timeout) {
Expand Down
145 changes: 139 additions & 6 deletions src/controllers/graph-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {BaseEditController} from './document-controller';

import '../views/vertex/addLabel.html';
import '../views/database/editVertex.html';
import '../views/database/editEdge.html';
import '../views/database/modalNew.html';
import '../views/database/modalEdit.html';
import '../views/database/modalNewEdge.html';
Expand All @@ -16,6 +17,7 @@ import '../views/database/graph/asideEdge.html';
import '../views/database/graph/asideVertex.html';
import '../views/database/graphConfig.html';
import '../views/vertex/modalConnection.html';
import '../views/vertex/modalVertexSelect.html';

import angular from 'angular';

Expand Down Expand Up @@ -177,12 +179,7 @@ GraphModule.controller("VertexEditController", ['$scope', '$injector', '$routePa
}
$scope.follow = function (rid) {
var edgeDoc = DocumentApi.get({database: $scope.database, document: rid}, function () {
if (Database.isEdge(edgeDoc['@class'])) {
$scope.showModal(rid);
}
else {
$scope.navigate(rid);
}
$scope.navigate(rid);

}, function (error) {
Notification.push({content: JSON.stringify(error)});
Expand Down Expand Up @@ -234,6 +231,63 @@ GraphModule.controller("VertexEditController", ['$scope', '$injector', '$routePa
});
}
}]);

GraphModule.controller("EdgeEditController", ['$scope', '$injector', '$routeParams', '$location', '$modal', '$q', 'DocumentApi', 'Database', 'CommandApi', 'Notification', function ($scope, $injector, $routeParams, $location, $modal, $q, DocumentApi, Database, CommandApi, Notification) {


$injector.invoke(BaseEditController, this, {$scope: $scope});
Database.setWiki("Edit-edge.html");
$scope.label = 'Edge';
$scope.fixed = Database.header;
$scope.canSave = true;
$scope.canDelete = true;
$scope.canCreate = true;
$scope.canAdd = true;
$scope.pageLimit = 10;
$scope.limitProof = 10;
$scope.limits = [];
$scope.popover = {
title: 'Add edge'
}


$scope.showVertexModal = function (direction) {
var modalScope = $scope.$new(true);
modalScope.db = $scope.database;

modalScope.onSubmit = (rid) => {
if (rid && rid.length > 0) {
$scope.doc[direction] = rid[0];
}
}
var modalPromise = $modal({
template: 'views/vertex/modalVertexSelect.html',
persist: false,
show: false,
scope: modalScope,
modalClass: 'createEdge'
});
modalPromise.$promise.then(modalPromise.show);

}

$scope.editUrl = (rid) => {
if (rid) {
return `#/database/${$routeParams.database}/browse/edit/${rid.replace('#', '')}`;
}
return "";
}
if (!$scope.doc) {
$scope.reload();
} else {
$scope.headers = Database.getPropertyFromDoc($scope.doc).filter((c) => {
return c != "in" && c != "out";
});
$scope.isGraph = Database.isGraph($scope.doc['@class']);
}


}]);
GraphModule.controller("VertexPopoverLabelController", ['$scope', '$routeParams', '$location', 'DocumentApi', 'Database', 'Notification', function ($scope, $routeParams, $location, DocumentApi, Database, Notification) {

$scope.init = function (where) {
Expand Down Expand Up @@ -346,6 +400,85 @@ GraphModule.controller("VertexModalBrowseController", ['$scope', '$routeParams',

}]);

GraphModule.controller("VertexModalSelectController", ['$scope', '$routeParams', '$location', 'Database', 'CommandApi', 'Icon', '$timeout', '$route', function ($scope, $routeParams, $location, Database, CommandApi, Icon, $timeout, $route) {

$scope.database = Database;
$scope.limit = 20;
$scope.queries = new Array;
$scope.added = new Array;
$scope.loaded = true;


$scope.editorOptions = {
lineWrapping: true,
lineNumbers: true,
readOnly: false,
mode: 'text/x-sql',
metadata: Database,
extraKeys: {
"Ctrl-Enter": function (instance) {
$scope.$apply(function () {
$scope.query();
});
},
"Ctrl-Space": "autocomplete"
},
onLoad: function (_cm) {
$scope.cm = _cm;

$scope.cm.on("change", function () { /* script */
var wrap = $scope.cm.getWrapperElement();
var approp = $scope.cm.getScrollInfo().height > 300 ? "300px" : "auto";
if (wrap.style.height != approp) {
wrap.style.height = approp;
$scope.cm.refresh();
}
});
$scope.cm.refresh();

}
};
$scope.query = function () {

CommandApi.queryText({
database: $routeParams.database,
language: 'sql',
text: $scope.queryText,
limit: $scope.limit,
verbose: false
}, function (data) {
if (data.result) {
$scope.headers = Database.getPropertyTableFromResults(data.result);
$scope.results = data.result;
}
if ($scope.queries.indexOf($scope.queryText) == -1)
$scope.queries.push($scope.queryText);
}, function err(data) {
$scope.error = data;
$timeout(function () {
$scope.error = null;
}, 2000);
});
}


$scope.select = function (result) {
var index = $scope.added.indexOf(result['@rid']);
if (!$scope.multiple) {
$scope.added.splice(0, $scope.added.length);
}
if (index == -1) {
$scope.added.push(result['@rid']);
} else {
$scope.added.splice(index, 1);
}
}
$scope.okSelect = function () {
$scope.onSubmit($scope.added);
}

}]);

GraphModule.controller("GraphController", ['$scope', '$routeParams', '$location', '$modal', '$q', 'Database', 'CommandApi', 'Spinner', 'Aside', 'DocumentApi', 'localStorageService', 'Icon', 'GraphConfig', 'Notification', '$rootScope', 'History', '$timeout', '$document', 'BrowseConfig', 'GraphService', function ($scope, $routeParams, $location, $modal, $q, Database, CommandApi, Spinner, Aside, DocumentApi, localStorageService, Icon, GraphConfig, Notification, $rootScope, History, $timeout, $document, BrowseConfig, GraphService) {


Expand Down
29 changes: 29 additions & 0 deletions src/views/database/editEdge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="row opanel" ng-controller="EdgeEditController">
<div class="col-md-2">
<div class="panel panel-default panel-orient">
<div class="panel-heading">
From Vertex
<!--<a ng-show="isNew" href="javascript:void(0)" ng-click="showVertexModal('out')"><i-->
<!--class="fa fa-plus-circle"></i></a>-->
</div>
<div class="panel-body">
<h4 ng-show="doc['out']"><a href="{{editUrl(doc['out'])}}">{{doc['out']}}</a></h4>
</div>
</div>
</div>
<div class="col-md-8">
<ng-include src="'views/database/record.html'" onload=""></ng-include>
</div>
<div class="col-md-2">
<div class="panel panel-default panel-orient">
<div class="panel-heading">
To Vertex
<!--<a ng-show="isNew" href="javascript:void(0)" ng-click="showVertexModal('in')"><i-->
<!--class="fa fa-plus-circle"></i></a>-->
</div>
<div class="panel-body">
<h4 ng-show="doc['in']"><a href="{{editUrl(doc['in'])}}">{{doc['in']}}</a></h4>
</div>
</div>
</div>
</div>
75 changes: 75 additions & 0 deletions src/views/vertex/modalVertexSelect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<div class="modal" ng-controller="VertexModalSelectController">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" ng-click="$hide()" aria-hidden="true">×
</button>
<h3>Select Vertex </h3>
</div>


<div class="modal-body modal-query">

<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<p><strong>Ctrl + Enter</strong> to execute the query</p>
</div>
<div class="col-md-6">
<form class="form-inline nomargin">
<button ng-click="query()" class="btn btn-xs pull-right">
<i class="fa fa-cog"></i> Run
</button>
</form>
</div>
</div>
<div class="row ">
<form ng:submit="query()" class="form-inline">
<div ui-codemirror="editorOptions" ng-model="queryText"></div>
</form>
</div>

<div class="row query-result">
<div class="table-responsive">

<table st-table="displayedRecords" st-safe-src="results"
class="table table-striped table-bordered table-hover table-condensed pointer"
ng-show="headers">
<thead>
<tr>
<th>#</th>
<th ng-repeat="header in headers">{{header}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="result in displayedRecords">
<td><input type="checkbox" ng-checked="added.indexOf(result['@rid'])!=-1" ng-click="select(result)"/>
</td>
<td ng-repeat="header in headers">{{result[header]}}</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="{{headers.length}}" class="text-center">
<div st-pagination="" st-items-by-page="5" st-displayed-pages="7"></div>
</td>
</tr>
</table>
</div>
<div class="row">
<div class="alert alert-danger" ng-show="error">
{{error}}
</div>
</div>
</div>
</div>

<div class="modal-footer">
<button type="button" class="btn" ng-click="$hide()">Close</button>
<button class="btn btn-primary" ng-disabled="added.length==0"
ng-click="modal.saved=true;$hide();okSelect()">Ok
</button>
</div>
</div>
</div>
</div>

0 comments on commit 1b6d76b

Please sign in to comment.