Permalink
Browse files

editing relations

  • Loading branch information...
1 parent 5c12060 commit ac0358711b6b5548ff25331cb665ecefcf5d4e25 Studener, Max committed Feb 26, 2014
@@ -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,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 />
@@ -1,7 +1,7 @@
function EditConnectionCtrl($scope, $filter, $http,$location,$log) {
$scope.initLoad = function(){
- $scope.url = $location.absUrl().replace('/edit', '')
+ $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
Oops, something went wrong.

0 comments on commit ac03587

Please sign in to comment.