Integrated new_ui 'Add Cluster' functionality with back-end

Notes:
* Mongo's Object('sdfsdf') is not JSON serializable, made str(doc['_id'])) to fix
* In my version there is no method .asdict on recordtype, only _asdict
This commit is contained in:
Kirill Ishanov
2013-10-20 04:32:23 -07:00
parent a4eb7b8428
commit c2133435df
3 changed files with 20 additions and 7 deletions

View File

@@ -30,9 +30,10 @@ angular.module('rubick.controllers', []).
});
$scope.addCluster = function() {
$scope.newCluster.nodesCount = 20;
$scope.newCluster.status = "Available";
$scope.clusters.push($scope.newCluster);
console.log($scope.newCluster);
$http.post('/clusters', $scope.newCluster).success(function() {
$scope.clusters.push($scope.newCluster);
});
$scope.newCluster = undefined;
$('#add-cluster-modal').modal('hide');
}

View File

@@ -47,10 +47,21 @@
</div>
</div>
</div>
<div class="field">
<label>SSH Key (for root user)</label>
<div class="ui left labeled icon input">
<textarea ng-model="newCluster.description"></textarea>
<!--<i class="file icon"></i>-->
<!--<div class="ui corner label">-->
<!--<i class="icon asterisk"></i>-->
<!--</div>-->
</div>
</div>
<div class="field">
<label>IP Address (of any node in management network)</label>
<div class="ui left labeled icon input">
<input type="text" placeholder="172.168.10.5" ng-model="newCluster.ip">
<input type="text" placeholder="172.168.10.5"
ng-model="newCluster.nodes">
<i class="terminal icon"></i>
<div class="ui corner label">
<i class="icon asterisk"></i>
@@ -60,7 +71,7 @@
<div class="field">
<label>SSH Key (for root user)</label>
<div class="ui left labeled icon input">
<textarea ng-model="newCluster.sshKey"></textarea>
<textarea ng-model="newCluster.private_key"></textarea>
<i class="file icon"></i>
<div class="ui corner label">
<i class="icon asterisk"></i>

View File

@@ -37,7 +37,7 @@ class Cluster(recordtype('Cluster',
default=None)):
@classmethod
def from_doc(klass, doc):
doc['id'] = doc['_id']
doc['id'] = str(doc['_id'])
del doc['_id']
return Cluster(**doc)
@@ -90,11 +90,12 @@ def get_clusters():
@app.route('/clusters', methods=['POST'])
def add_cluster():
print request.data
form = ClusterForm.from_json(json.loads(request.data))
if form.validate():
cluster = Cluster()
form.populate_obj(cluster)
get_db()['clusters'].save(cluster.asdict())
get_db()['clusters'].save(cluster._asdict())
return '', 201
else:
return json.dumps(dict(errors=form.errors)), 422