summaryrefslogtreecommitdiffstats
path: root/testapi/3rd_party
diff options
context:
space:
mode:
authorgrakiss <grakiss.wanglei@huawei.com>2017-07-07 15:06:29 +0800
committergrakiss <grakiss.wanglei@huawei.com>2017-07-20 09:51:50 +0800
commitcf402a2a6888ade5c57165dc978a59d2330307a7 (patch)
tree64031db8f9b231867ab2466679b23eb6ade79b37 /testapi/3rd_party
parent0c684cf169699a48570cb96c565d40007d4f006f (diff)
role based access control and result upload
1. add role for user 2. user can upload test results Change-Id: I1c5370be7818edb0394f05e8b81f975deb98b286 Signed-off-by: grakiss <grakiss.wanglei@huawei.com>
Diffstat (limited to 'testapi/3rd_party')
-rw-r--r--testapi/3rd_party/static/testapi-ui/components/results/results.html20
-rw-r--r--testapi/3rd_party/static/testapi-ui/components/results/resultsController.js58
-rw-r--r--testapi/3rd_party/static/testapi-ui/shared/header/header.html2
3 files changed, 77 insertions, 3 deletions
diff --git a/testapi/3rd_party/static/testapi-ui/components/results/results.html b/testapi/3rd_party/static/testapi-ui/components/results/results.html
index 3056e1d..2ae5339 100644
--- a/testapi/3rd_party/static/testapi-ui/components/results/results.html
+++ b/testapi/3rd_party/static/testapi-ui/components/results/results.html
@@ -1,6 +1,23 @@
<h3>{{ctrl.pageHeader}}</h3>
<p>{{ctrl.pageParagraph}}</p>
-
+<form class="form-inline" ng-show="ctrl.isUserResults">
+<h4>Upload Results</h4>
+<div class="form-group col-m-3">
+ <input class="form-contrl btn btn-default" type = "file" file-model = "resultFile"/>
+</div>
+<div class="checkbox col-m-1">
+ <label>
+ <input type="checkbox" ng-model="ctrl.isPublic">public
+ </label>
+</div>
+<div class="form-group col-m-3">
+ <button class="btn btn-primary" ng-click = "ctrl.uploadFile()">upload result</button>
+</div>
+<div>
+<lable>{{ctrl.uploadState}}</label>
+</div>
+</form>
+<div class="row" style="margin-bottom:24px;"></div>
<div class="result-filters">
<h4>Filters</h4>
<div class="row">
@@ -41,7 +58,6 @@
<div cg-busy="{promise:ctrl.authRequest,message:'Loading'}"></div>
<div cg-busy="{promise:ctrl.resultsRequest,message:'Loading'}"></div>
-
<div ng-show="ctrl.data" class="results-table">
<table ng-data="ctrl.data.result" ng-show="ctrl.data" class="table table-striped table-hover">
<thead>
diff --git a/testapi/3rd_party/static/testapi-ui/components/results/resultsController.js b/testapi/3rd_party/static/testapi-ui/components/results/resultsController.js
index 9e3540d..cc6cc0b 100644
--- a/testapi/3rd_party/static/testapi-ui/components/results/resultsController.js
+++ b/testapi/3rd_party/static/testapi-ui/components/results/resultsController.js
@@ -19,6 +19,24 @@
.module('testapiApp')
.controller('ResultsController', ResultsController);
+ angular
+ .module('testapiApp')
+ .directive('fileModel', ['$parse', function ($parse) {
+ return {
+ restrict: 'A',
+ link: function(scope, element, attrs) {
+ var model = $parse(attrs.fileModel);
+ var modelSetter = model.assign;
+
+ element.bind('change', function(){
+ scope.$apply(function(){
+ modelSetter(scope, element[0].files[0]);
+ });
+ });
+ }
+ };
+ }]);
+
ResultsController.$inject = [
'$scope', '$http', '$filter', '$state', 'testapiApiUrl','raiseAlert'
];
@@ -32,6 +50,7 @@
raiseAlert) {
var ctrl = this;
+ ctrl.uploadFile=uploadFile;
ctrl.update = update;
ctrl.open = open;
ctrl.clearFilters = clearFilters;
@@ -76,6 +95,8 @@
ctrl.format = 'yyyy-MM-dd';
/** Check to see if this page should display user-specific results. */
+ // ctrl.isUserResults = $state.current.name === 'userResults';
+ // need auth to browse
ctrl.isUserResults = $state.current.name === 'userResults';
// Should only be on user-results-page if authenticated.
@@ -91,14 +112,49 @@
'The most recently uploaded community test results are listed ' +
'here.';
+ ctrl.uploadState = '';
+
+ ctrl.isPublic = false;
+
if (ctrl.isUserResults) {
ctrl.authRequest = $scope.auth.doSignCheck()
.then(ctrl.update);
- ctrl.getUserProducts();
+ // ctrl.getUserProducts();
} else {
ctrl.update();
}
+
+ function uploadFileToUrl(file, uploadUrl){
+ var fd = new FormData();
+ fd.append('file', file);
+ fd.append('public', ctrl.isPublic)
+
+ $http.post(uploadUrl, fd, {
+ transformRequest: angular.identity,
+ headers: {'Content-Type': undefined}
+ })
+
+ .success(function(data){
+ var id = data.href.substr(data.href.lastIndexOf('/')+1);
+ ctrl.uploadState = "Upload succeed. Result id is " + id;
+ ctrl.update();
+ })
+
+ .error(function(data, status){
+ ctrl.uploadState = "Upload failed. Error code is " + status;
+ });
+ }
+
+ function uploadFile(){
+ var file = $scope.resultFile;
+ console.log('file is ' );
+ console.dir(file);
+
+ var uploadUrl = testapiApiUrl + "/results/upload";
+ uploadFileToUrl(file, uploadUrl);
+ };
+
/**
* This will contact the TestAPI API to get a listing of test run
* results.
diff --git a/testapi/3rd_party/static/testapi-ui/shared/header/header.html b/testapi/3rd_party/static/testapi-ui/shared/header/header.html
index f2c49e8..85c33b6 100644
--- a/testapi/3rd_party/static/testapi-ui/shared/header/header.html
+++ b/testapi/3rd_party/static/testapi-ui/shared/header/header.html
@@ -33,6 +33,7 @@ TestAPI
</ul>
<ul class="nav navbar-nav navbar-right">
<li ng-class="{ active: header.isActive('/user_results')}" ng-if="auth.isAuthenticated"><a ui-sref="userResults">My Results</a></li>
+ <!--
<li ng-if="auth.isAuthenticated" ng-class="{ active: header.isCatalogActive('user')}" class="dropdown" uib-dropdown>
<a role="button" class="dropdown-toggle" uib-dropdown-toggle>
My Catalog <strong class="caret"></strong>
@@ -42,6 +43,7 @@ TestAPI
<li><a ui-sref="userProducts">My Products</a></li>
</ul>
</li>
+ -->
<li ng-class="{ active: header.isActive('/profile')}" ng-if="auth.isAuthenticated"><a ui-sref="profile">Profile</a></li>
<li ng-if="auth.isAuthenticated"><a href="" ng-click="auth.doSignOut()">Sign Out</a></li>
<li ng-if="!auth.isAuthenticated"><a href="" ng-click="auth.doSignIn()">Sign In / Sign Up</a></li>