Permalink
Browse files

Merge pull request #3 from maxstudener/master

Editing connections and relations
  • Loading branch information...
2 parents 0a01491 + ac03587 commit 3e897bfc43f5b01ac1561a5b1db623aa38c19f08 Kyle Smith committed Feb 26, 2014
@@ -23,6 +23,16 @@ def create
render json: con
end
+ def edit
+ end
+
+ def update
+ connection = ConnectionAttributes.where(id: params[:id]).first
+ connection.update_attributes!(params["connection"])
+
+ render json: connection
+ end
+
def tables
set_connection
connection_name = params[:connection_name]
@@ -24,6 +24,16 @@ def create
render json: relation
end
+ def edit
+ end
+
+ def update
+ relation = Relation.where(id: params[:id]).first
+ relation.update_attributes!(params["relation"])
+
+ render json: relation
+ end
+
def destroy
relation = Relation.find(params[:id])
if relation.destroy
@@ -0,0 +1,12 @@
+<script src="/javascripts/controllers/connection-edit.js"></script>
+
+<div class="container">
+
+ <div class="row" ng-controller="EditConnectionCtrl" ng-init="initLoad()">
+ <br />
+ <ui-codemirror ui-codemirror-opts="editorOptions" ng-model="jsonDataString"></ui-codemirror>
+
+ <button class="btn btn-default btn-primary" ng-click="sendData()">Update</button>
+
+ </div>
+</div>
@@ -4,11 +4,8 @@
<div class="row" ng-repeat="connection in connections">
<h3>{{connection.name}}</h3>
<ui-codemirror ui-codemirror-opts="editorOptions" ng-model="connection.jsonString"></ui-codemirror>
- <form ng-action="/relations/{{connection._id}}" class="button_to" method="post">
- <div>
- <input class="btn btn-sm btn-danger" type="submit" value="Delete" ng-click='destroyConnection(connection._id)'>
- <input name="authenticity_token" type="hidden" value="<%= form_authenticity_token %>">
- </div>
- </form>
+
+ <a class="btn btn-sm btn-primary" ng-href="/connections/{{connection._id}}/edit">Edit</a>
+ <button class="btn btn-sm btn-danger" ng-click='destroyConnection(connection._id)'>Delete</button>
</div>
</div>
@@ -6,7 +6,6 @@
<link rel='stylesheet' type='text/css' href='/stylesheets/base.css'/>
<script src='/javascripts/jquery/jquery-2.0.3.min.js'></script>
<script src='/javascripts/angular/angular.min.js'></script>
- <script src='/javascripts/underscore/underscore.min.js'></script>
<script src='/javascripts/bootstrap/ui-bootstrap.min.js'></script>
<script src='/javascripts/bootstrap/ui-bootstrap-tpls.min.js'></script>
@@ -16,7 +15,6 @@
<script type="text/javascript" src="/bower_components/codemirror/mode/javascript/javascript.js"></script>
<script type="text/javascript" src="/bower_components/angular-ui-codemirror/ui-codemirror.js"></script>
- <script src='/javascripts/fixedHeaders.js'></script>
<script>var app = angular.module('data-pet', ['ui.bootstrap', 'ui.codemirror']);</script>
<%= csrf_meta_tags %>
@@ -0,0 +1,245 @@
+<script src='/javascripts/controllers/relations-edit.js'></script>
+
+<div class='container' ng-controller='relationsController' ng-init='initialize()'>
+<br />
+<div ng-show='message !== null' class='alert alert-{{messageClass}}' >
+ {{message}}
+</div>
+<h3>Edit Relation</h3>
+
+<!-- GENERAL INFORMATION -->
+<div class='container'>
+
+ <!-- Relation Name -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>Relation Name</label>
+ </div>
+ <div class='col-xs-9'>
+ <input type='text' class='form-control' ng-model='relation.relation_name'/>
+ </div>
+ </div>
+ <br/>
+
+ <!-- Relation Type -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>Relation Type</label>
+ </div>
+ <div class='col-xs-9'>
+ <select class='form-control'
+ ng-model='relation.relation_type'
+ ng-change="changedType()"
+ >
+ <option ng-repeat='type in types' value='{{type.value}}'>{{type.name}}</option>
+ </select>
+ </div>
+ </div>
+ <br/>
+
+ <!-- Connection Name -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>From Connection Name</label>
+ </div>
+ <div class='col-xs-9'>
+ <select class='form-control'
+ ng-model='relation.from_connection_id'
+ ng-change='updateFromConnection()'
+ >
+ <option ng-repeat='connection in connections' value='{{connection._id}}'>{{connection.name}}</option>
+ </select>
+ </div>
+ </div>
+ <br/>
+
+ <!-- Table Name -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>From Table Name</label>
+ </div>
+ <div class='col-xs-9'>
+ <input class='form-control'
+ autocomplete="off"
+ ng-model='relation.from_table_name'
+ typeahead='table.fullTableName for table in fromConnection.tables | filter:$viewValue | limitTo:8'
+ typeahead-on-select='loadColumns(relation.from_connection_id, relation.from_table_name); loadRelations(relation.from_connection_id, relation.from_table_name)'
+ typeahead-editable=false
+ />
+ </div>
+ </div>
+
+ <br/>
+
+ <!-- Relation Connection Name -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>To Connection Name</label>
+ </div>
+ <div class='col-xs-9'>
+ <select class='form-control'
+ ng-model='relation.to_connection_id'
+ ng-change='updateToConnection()'
+ >
+ <option ng-repeat='connection in connections' value='{{connection._id}}'>{{connection.name}}</option>
+ </select>
+ </div>
+ </div>
+ <br/>
+
+ <!-- Relation Table Name -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>To Table Name</label>
+ </div>
+ <div class='col-xs-9'>
+ <input class='form-control'
+ autocomplete="off"
+ ng-model='relation.to_table_name'
+ typeahead='table.fullTableName for table in toConnection.tables | filter:$viewValue | limitTo:8'
+ typeahead-on-select='loadColumns(relation.to_connection_id, relation.to_table_name)'
+ typeahead-editable=false
+ />
+ </div>
+ </div>
+</div>
+<br/>
+
+<!-- WHERE CLAUSES -->
+<div class='container'>
+ <h3>Where&nbsp&nbsp<span class='glyphicon glyphicon-plus' ng-click='addWhereClause()'></span></h3>
+ <h6 ng-show='type=="has_many_through"' style='color:red;'>* Optional for 'has_many_through' relation type.</h6>
+
+ <div ng-repeat='whereClause in relation.where_clauses'>
+ <div class='row'>
+ <span style='float:right;' class='glyphicon glyphicon-remove' ng-click='removeWhereClause(whereClause.id)'></span>
+ </div>
+
+ <!-- Where Clause / Relation Table Column -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label ng-show='relation.to_connection_id !== null'>Column to {{relation.to_table_name}}</label>
+ </div>
+ <div class='col-xs-9'>
+ <input class='form-control'
+ autocomplete="off"
+ ng-model='whereClause.to_table_column'
+ typeahead='column for column in columnData[relation.to_connection_id][relation.to_table_name] | filter:$viewValue | limitTo:8'
+ typeahead-editable=false
+ >
+ </div>
+ </div>
+ <br/>
+
+ <!-- Where Clause / Comparison Operator -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>Is</label>
+ </div>
+ <div class='col-xs-9'>
+ <select class='form-control'
+ ng-model='whereClause.comparison_operator'
+ >
+ <option ng-repeat='operator in comparisonOperators' value='{{operator.name}}'>{{operator.name}}</option>
+ </select>
+ </div>
+ </div>
+ <br/>
+
+ <!-- Where Clause / Comparison Type -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>Comparison Type</label>
+ </div>
+ <div class='col-xs-9'>
+ <select class='form-control'
+ ng-model='whereClause.comparison_type'
+ >
+ <option ng-repeat='type in comparisonTypes' value='{{type.name}}'>{{type.name}}</option>
+ </select>
+ </div>
+ </div>
+ <br/>
+
+ <!-- Where Clause / Comparison Value -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label ng-show='whereClause.comparison_type=="Value"'>Comparison Value</label>
+ <label ng-show='whereClause.comparison_type=="Column"'>Column from {{relation.from_table_name}}</label>
+ </div>
+ <div class='col-xs-9'>
+ <input class='form-control'
+ autocomplete="off"
+ ng-model='whereClause.comparison_value'
+ typeahead='column for column in columnData[relation.from_connection_id][relation.from_table_name] | filter:$viewValue | limitTo:8'
+ >
+ </div>
+ </div>
+ <hr/>
+ </div>
+</div>
+
+
+<!-- THROUGH RELATION -->
+<div class='container' ng-show='relation.relation_type=="has_many_through"'>
+ <h3>Through</h3>
+
+ <!-- Through Relation Name -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ <label>Through Relation Name</label>
+ </div>
+ <div class='col-xs-9'>
+ <select class='form-control'
+ ng-model='relation.through_relation_id'
+ ng-change='loadRelationColumns(relation.through_relation_id)'
+ >
+ <option ng-repeat='throughRelation in relationData[relation.from_connection_id][relation.from_table_name]' value='{{throughRelation._id}}'>{{throughRelation.relation_name}}</option>
+ </select>
+ </div>
+ </div>
+
+ <!-- JOIN CLAUSES -->
+ <h3>Joining&nbsp&nbsp<span class='glyphicon glyphicon-plus' ng-click='addJoinClause()'></span></h3>
+
+ <div ng-repeat='joinClause in relation.join_clauses'>
+ <div class='row'>
+ <span style='float:right;' class='glyphicon glyphicon-remove' ng-click='removeJoinClause(joinClause.id)'></span>
+ </div>
+
+ <!-- From Column -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ Column from {{throughRelation.to_table_name}}
+ </div>
+ <div class='col-xs-9'>
+ <input class='form-control'
+ autocomplete="off"
+ ng-model='joinClause.from_column'
+ typeahead='column for column in columnData[throughRelation.to_connection_id][throughRelation.to_table_name] | filter:$viewValue | limitTo:8'
+ typeahead-editable=false
+ >
+ </div>
+ </div>
+ <br/>
+
+ <!-- Join Column -->
+ <div class='row'>
+ <div class='col-xs-3 right'>
+ Column from {{relation.to_table_name}}
+ </div>
+ <div class='col-xs-9'>
+ <input class='form-control'
+ autocomplete="off"
+ ng-model='joinClause.join_column'
+ typeahead='column for column in columnData[relation.to_connection_id][relation.to_table_name] | filter:$viewValue | limitTo:8'
+ typeahead-editable=false
+ >
+ </div>
+ </div>
+ <hr/>
+ </div>
+</div>
+<input type='button' value='Create Relation' class='btn btn-primary' ng-click='createRelation()'/>
+</div>
+<br /><br />
@@ -0,0 +1,26 @@
+function EditConnectionCtrl($scope, $filter, $http,$location,$log) {
+
+ $scope.initLoad = function(){
+ $scope.url = $location.absUrl().replace('/edit', '');
+ $http.get($scope.url + '.json').success(function(data){
+ $scope.jsonData = data;
+ delete $scope.jsonData['_id']; //no reason to edit id
+ $scope.jsonDataString = JSON.stringify($scope.jsonData, null, '\t');
+ })
+ }
+
+ $scope.editorOptions = {
+ lineWrapping : true,
+ lineNumbers: true,
+ mode: {name: "javascript", json: true},
+ smartIndent: true,
+ tabSize: 2
+ };
+
+ $scope.sendData = function(){
+ $scope.jsonData = JSON.parse($scope.jsonDataString);
+ $http.put($scope.url, {'connection': $scope.jsonData}).success(function(){
+ alert('success');
+ });
+ }
+}
Oops, something went wrong.

0 comments on commit 3e897bf

Please sign in to comment.