Skip to content

Commit

Permalink
Showing contents of object #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Westergaard Lassen committed Feb 3, 2014
1 parent c81c8d0 commit 644a8af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/key.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<h1>{{bucketName}}/{{keyName}}</h1>
<form role="form" class="form-horizontal">
<form role="form" class="form-horizontal" ng-submit="save()">
<div class="form-group">
<labal for="data" class="col-lg-2 control-label">Data</labal>
<label for="contentType" class="col-lg-2 control-label">Content type</label>
<div class="col-lg-10">
<textarea id="data" class="col-lg-12" rows="10" ng-model="data"></textarea>
<input id="contentType" type="text" ng-model="object.contentType"/>
</div>
</div>
<div class="form-group">
<label for="data" class="col-lg-2 control-label">Data</label>
<div class="col-lg-10">
<textarea id="data" class="col-lg-12" rows="10" ng-model="object.data"></textarea>
</div>
</div>
<button class="btn btn-default" type="submit">save</button>
</form>
27 changes: 23 additions & 4 deletions src/ngriakadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ module.config(function ($routeProvider) {
when('/buckets/:bucket/keys/:key', {controller: KeyCtrl, templateUrl: 'key.html'}).
otherwise({redirectTo: '/'});
});

module.config(function (RestangularProvider) {
RestangularProvider.setFullResponse(true)
});

module.directive('quorum', function () {
return {
restrict: 'A',
Expand Down Expand Up @@ -126,14 +131,28 @@ function BucketCtrl($scope, $routeParams, $http, $location, production, $log) {
};
}

function KeyCtrl($scope, $routeParams, $http, Restangular) {
function KeyCtrl($scope, $routeParams, Restangular) {
$scope.bucketName = decodeURIComponent($routeParams.bucket);
$scope.keyName = decodeURIComponent($routeParams.key)
var Key = Restangular.one('buckets', encodeURIComponent($scope.bucketName)).one('keys', encodeURIComponent($scope.keyName));

Key.get().then(
function(data, status, headers, config) {
$scope.data = data;
$scope.object = {}

Key.head().then(
function(response) {
var contentType = response.headers()['content-type'];
$scope.object.contentType = contentType
if (_.contains(['application/x-www-form-urlencoded', 'application/json', 'text/html', 'text/javascript'], contentType)) {
Key.get().then(function(response) {
$scope.object.data = response.data;
});
}
}
)

$scope.save = function() {
//$scope.key.put({}, {'content-type': $scope.contentType});
alert(angular.toJson($scope.key))
$scope.key.data.put();
}
}

0 comments on commit 644a8af

Please sign in to comment.