Include markdown sample

Fix UI refresh problem
Enable invocation from portal
This commit is contained in:
Alex Ellis
2017-01-31 09:08:58 +00:00
parent c211ba0d07
commit 4e73f787da
11 changed files with 152 additions and 7 deletions

View File

@ -50,11 +50,11 @@
</div>
<div flex></div>
</md-content>
<md-content flex layout="column" ng-repeat="function in functions" ng-show="function.name == selectedFunction.name">
<md-card md-theme="default" md-theme-watch>
<md-card-title>
<md-card-title-text>
<span class="md-headline">
@ -77,12 +77,44 @@
<input ng-model="function.image" type="text" readonly="readonly">
</md-input-container>
</div>
<md-card-title-text>
</md-card-title>
</md-card>
<md-card>
<md-card-title>
<md-card-title-text>
<span class="md-headline">
Invoke function
</span>
<div layout-gt-sm="row">
<md-input-container class="md-block" flex-gt-sm>
<button ng-click="fireRequest()" class="md-raised md-button md-ink-ripple" type="button">
<span class="ng-scope">Invoke</span><div class="md-ripple-container"></div>
</button>
</md-input-container>
</div>
<div layout-gt-sm="row">
<md-input-container class="md-block" flex-gt-sm>
<label>Request body</label>
<textarea ng-model="invocation.request" cols="80" rows="4"></textarea>
</md-input-container>
</div>
<div layout-gt-sm="row">
<md-input-container class="md-block" flex-gt-sm>
<label>Response status</label>
<input ng-model="invocationStatus" type="text" readonly="readonly">
</md-input-container>
</div>
<div layout-gt-sm="row">
<md-input-container class="md-block" flex-gt-sm>
<label>Response body</label>
<textarea ng-model="invocationResponse" cols="80" rows=10></textarea>
</md-input-container>
</div>
<md-card-title-text>
</md-card-title>
</md-card>
</md-content>
</section>
</div>

View File

@ -3,11 +3,55 @@ var app = angular.module('faasGateway', ['ngMaterial']);
app.controller("home", ['$scope', '$log', '$http', '$location', '$timeout', function($scope, $log, $http, $location, $timeout) {
$scope.functions = [];
$scope.invocationRequest = "";
$scope.invocationResponse = "";
$scope.invocationStatus = "";
$scope.invocation = {
};
$scope.invocation.request = ""
setInterval(function() {
fetch();
refreshData();
}, 1000);
$scope.fireRequest = function() {
$http({url:"/function/"+$scope.selectedFunction.name, data: $scope.invocation.request, method: "POST", headers: {"Content-Type": "text/plain"}, responseType: "text"}).
then(function(response) {
$scope.invocationResponse = response.data;
$scope.invocationStatus = response.status;
}).catch(function(error1) {
$scope.invocationResponse = error1;
$scope.invocationStatus = null;
});
console.log("POST /function/"+ $scope.selectedFunction.name);
console.log("Body: " + $scope.invocation.request);
};
var refreshData = function () {
var previous = $scope.functions;
var cl = function(previousItems) {
$http.get("/system/functions").then(function(response) {
if(response && response.data) {
if(previousItems.length !=response.data.length) {
$scope.functions = response.data;
} else {
for(var i =0;i<$scope.functions.length;i++) {
for(var j =0;j<response.data.length;j++) {
if($scope.functions[i].name == response.data[j].name) {
$scope.functions[i].replicas=response.data[j].replicas;
$scope.functions[i].invocationCount=response.data[j].invocationCount;
}
}
}
}
}
});
};
cl(previous);
}
var fetch = function() {
$http.get("/system/functions").then(function(response) {
$scope.functions = response.data;
@ -15,7 +59,12 @@ app.controller("home", ['$scope', '$log', '$http', '$location', '$timeout', func
};
$scope.showFunction = function(fn) {
$scope.selectedFunction = fn;
if($scope.selectedFunction!=fn) {
$scope.selectedFunction = fn;
$scope.invocation.request = "";
$scope.invocationResponse = "";
$scope.invocationStatus = "";
}
};
// TODO: popup + form to create new Docker service.

View File

@ -10,4 +10,4 @@ docker rm -f gateway_extract
echo Building alexellis2/faas-gateway:latest
docker build -t alexellis2/faas-gateway:latest-dev4 .
docker build --no-cache -t alexellis2/faas-gateway:latest-dev4 .