summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/ui/profile
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-10-27 16:58:49 +0800
committerSerena Feng <feng.xiaowei@zte.com.cn>2017-10-31 01:00:35 +0000
commit10cfa68dc2a67890ffe822a9d4fbbb9f80fbd8a3 (patch)
treeec3016c76a24ce1a43695f6027423be75d2b9d24 /utils/test/testapi/opnfv_testapi/ui/profile
parent0e92805f1bfe597334e2a2f4414e460a8e811239 (diff)
remove components out side of 3rd_party
components are implemented by TestAPI team, they are not the third party code, put them under opnfv_testapi/ui directory Change-Id: Ia0f5e2afe4bcb12bcb74d3a8d78fb28fe1432bec Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/ui/profile')
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/profile/importPubKeyModal.html27
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/profile/profile.html44
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/profile/profileController.js219
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/profile/showPubKeyModal.html11
4 files changed, 301 insertions, 0 deletions
diff --git a/utils/test/testapi/opnfv_testapi/ui/profile/importPubKeyModal.html b/utils/test/testapi/opnfv_testapi/ui/profile/importPubKeyModal.html
new file mode 100644
index 000000000..0f55c27fd
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/ui/profile/importPubKeyModal.html
@@ -0,0 +1,27 @@
+<div class="modal-header">
+ <h4>Import Public Key</h4>
+ <p>Instructions for adding a public key and signature can be found
+ <a href="https://github.com/openstack/refstack/blob/master/doc/source/uploading_private_results.rst#generate-ssh-keys-locally"
+ target="_blank"
+ title="How to generate and upload SSH key and signature with testapi-client">here.
+ </a>
+ </p>
+</div>
+<div class="modal-body container-fluid">
+ <div class="row">
+ <div class="col-md-2">Public Key</div>
+ <div class="col-md-9 pull-right">
+ <textarea type="text" rows="10" cols="42" ng-model="modal.raw_key" required></textarea>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col-md-2">Signature</div>
+ <div class="col-md-9 pull-right">
+ <textarea type="text" rows="10" cols="42" ng-model="modal.self_signature" required></textarea>
+ </div>
+ </div>
+ <div class="modal-footer">
+ <button class="btn btn-warning btn-sm" ng-click="modal.cancel()">Cancel</button>
+ <button type="button" class="btn btn-default btn-sm" ng-click="modal.importPubKey()">Import Public Key</button>
+ </div>
+</div>
diff --git a/utils/test/testapi/opnfv_testapi/ui/profile/profile.html b/utils/test/testapi/opnfv_testapi/ui/profile/profile.html
new file mode 100644
index 000000000..763f5d120
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/ui/profile/profile.html
@@ -0,0 +1,44 @@
+<h3>User profile</h3>
+<div cg-busy="{promise:ctrl.authRequest,message:'Loading'}"></div>
+<div>
+ <table class="table table-striped table-hover">
+ <tbody>
+ <tr> <td>User</td> <td>{{auth.currentUser.user}}</td> </tr>
+ <tr> <td>Fullname</td> <td>{{auth.currentUser.fullname}}</td> </tr>
+ <tr> <td>Email</td> <td>{{auth.currentUser.email}}</td> </tr>
+ <tr> <td>Groups</td>
+ <td>
+ <div ng-repeat="group in auth.currentUser.groups">
+ {{group}}</br>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</div>
+<div ng-show="ctrl.pubkeys">
+ <div class="container-fluid">
+ <div class="row">
+ <div class="col-md-4">
+ <h4>User Public Keys</h4>
+ </div>
+ <div class="col-md-2 pull-right">
+ <button type="button" class="btn btn-default btn-sm" ng-click="ctrl.openImportPubKeyModal()">
+ <span class="glyphicon glyphicon-plus"></span> Import Public Key
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <div>
+ <table class="table table-striped table-hover">
+ <tbody>
+ <tr ng-repeat="pubKey in ctrl.pubkeys" ng-click="ctrl.openShowPubKeyModal(pubKey)">
+ <td>{{pubKey.format}}</td>
+ <td>{{pubKey.shortKey}}</td>
+ <td>{{pubKey.comment}}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+</div>
diff --git a/utils/test/testapi/opnfv_testapi/ui/profile/profileController.js b/utils/test/testapi/opnfv_testapi/ui/profile/profileController.js
new file mode 100644
index 000000000..5dbdf7b1a
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/ui/profile/profileController.js
@@ -0,0 +1,219 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function () {
+ 'use strict';
+
+ angular
+ .module('testapiApp')
+ .factory('PubKeys', PubKeys);
+
+ PubKeys.$inject = ['$resource', 'testapiApiUrl'];
+
+ /**
+ * This is a provider for the user's uploaded public keys.
+ */
+ function PubKeys($resource, testapiApiUrl) {
+ return $resource(testapiApiUrl + '/user/pubkeys/:id', null, null);
+ }
+
+ angular
+ .module('testapiApp')
+ .controller('ProfileController', ProfileController);
+
+ ProfileController.$inject = [
+ '$scope', '$http', 'testapiApiUrl', 'PubKeys',
+ '$uibModal', 'raiseAlert', '$state'
+ ];
+
+ /**
+ * TestAPI Profile Controller
+ * This controller handles user's profile page, where a user can view
+ * account-specific information.
+ */
+ function ProfileController($scope, $http, testapiApiUrl,
+ PubKeys, $uibModal, raiseAlert, $state) {
+
+ var ctrl = this;
+
+ ctrl.updatePubKeys = updatePubKeys;
+ ctrl.openImportPubKeyModal = openImportPubKeyModal;
+ ctrl.openShowPubKeyModal = openShowPubKeyModal;
+
+ // Must be authenticated to view this page.
+ if (!$scope.auth.isAuthenticated) {
+ $state.go('home');
+ }
+
+ /**
+ * This function will fetch all the user's public keys from the
+ * server and store them in an array.
+ */
+ function updatePubKeys() {
+ var keys = PubKeys.query(function() {
+ ctrl.pubkeys = [];
+ angular.forEach(keys, function (key) {
+ ctrl.pubkeys.push({
+ 'resource': key,
+ 'format': key.format,
+ 'shortKey': [
+ key.pubkey.slice(0, 10),
+ '.',
+ key.pubkey.slice(-10)
+ ].join('.'),
+ 'pubkey': key.pubkey,
+ 'comment': key.comment
+ });
+ });
+ });
+ }
+
+ /**
+ * This function will open the modal that will give the user a form
+ * for importing a public key.
+ */
+ function openImportPubKeyModal() {
+ $uibModal.open({
+ templateUrl: '/components/profile/importPubKeyModal.html',
+ backdrop: true,
+ windowClass: 'modal',
+ controller: 'ImportPubKeyModalController as modal'
+ }).result.finally(function() {
+ ctrl.updatePubKeys();
+ });
+ }
+
+ /**
+ * This function will open the modal that will give the full
+ * information regarding a specific public key.
+ * @param {Object} pubKey resource
+ */
+ function openShowPubKeyModal(pubKey) {
+ $uibModal.open({
+ templateUrl: '/components/profile/showPubKeyModal.html',
+ backdrop: true,
+ windowClass: 'modal',
+ controller: 'ShowPubKeyModalController as modal',
+ resolve: {
+ pubKey: function() {
+ return pubKey;
+ }
+ }
+ }).result.finally(function() {
+ ctrl.updatePubKeys();
+ });
+ }
+
+ ctrl.authRequest = $scope.auth.doSignCheck().then(ctrl.updatePubKeys);
+ }
+
+ angular
+ .module('testapiApp')
+ .controller('ImportPubKeyModalController', ImportPubKeyModalController);
+
+ ImportPubKeyModalController.$inject = [
+ '$uibModalInstance', 'PubKeys', 'raiseAlert'
+ ];
+
+ /**
+ * Import Pub Key Modal Controller
+ * This controller is for the modal that appears if a user wants to import
+ * a public key.
+ */
+ function ImportPubKeyModalController($uibModalInstance,
+ PubKeys, raiseAlert) {
+
+ var ctrl = this;
+
+ ctrl.importPubKey = importPubKey;
+ ctrl.cancel = cancel;
+
+ /**
+ * This function will save a new public key resource to the API server.
+ */
+ function importPubKey() {
+ var newPubKey = new PubKeys(
+ {raw_key: ctrl.raw_key, self_signature: ctrl.self_signature}
+ );
+ newPubKey.$save(
+ function(newPubKey_) {
+ raiseAlert('success', '', 'Public key saved successfully');
+ $uibModalInstance.close(newPubKey_);
+ },
+ function(httpResp) {
+ raiseAlert('danger',
+ httpResp.statusText, httpResp.data.title);
+ ctrl.cancel();
+ }
+ );
+ }
+
+ /**
+ * This function will dismiss the modal.
+ */
+ function cancel() {
+ $uibModalInstance.dismiss('cancel');
+ }
+ }
+
+ angular
+ .module('testapiApp')
+ .controller('ShowPubKeyModalController', ShowPubKeyModalController);
+
+ ShowPubKeyModalController.$inject = [
+ '$uibModalInstance', 'raiseAlert', 'pubKey'
+ ];
+
+ /**
+ * Show Pub Key Modal Controller
+ * This controller is for the modal that appears if a user wants to see the
+ * full details of one of their public keys.
+ */
+ function ShowPubKeyModalController($uibModalInstance, raiseAlert, pubKey) {
+ var ctrl = this;
+
+ ctrl.deletePubKey = deletePubKey;
+ ctrl.cancel = cancel;
+
+ ctrl.pubKey = pubKey.resource;
+ ctrl.rawKey = [pubKey.format, pubKey.pubkey, pubKey.comment].join('\n');
+
+ /**
+ * This function will delete a public key resource.
+ */
+ function deletePubKey() {
+ ctrl.pubKey.$remove(
+ {id: ctrl.pubKey.id},
+ function() {
+ raiseAlert('success',
+ '', 'Public key deleted successfully');
+ $uibModalInstance.close(ctrl.pubKey.id);
+ },
+ function(httpResp) {
+ raiseAlert('danger',
+ httpResp.statusText, httpResp.data.title);
+ ctrl.cancel();
+ }
+ );
+ }
+
+ /**
+ * This method will dismiss the modal.
+ */
+ function cancel() {
+ $uibModalInstance.dismiss('cancel');
+ }
+ }
+})();
diff --git a/utils/test/testapi/opnfv_testapi/ui/profile/showPubKeyModal.html b/utils/test/testapi/opnfv_testapi/ui/profile/showPubKeyModal.html
new file mode 100644
index 000000000..5f63a5ef6
--- /dev/null
+++ b/utils/test/testapi/opnfv_testapi/ui/profile/showPubKeyModal.html
@@ -0,0 +1,11 @@
+<div class="modal-header">
+ <h4>Public Key</h4>
+</div>
+<div class="modal-body container-fluid">
+ <textarea type="text" rows="10" cols="67" readonly="readonly">{{modal.rawKey}}</textarea>
+ <div class="modal-footer">
+ <button class="btn btn-warning" ng-click="modal.cancel()">Cancel</button>
+ <button type="button" class="btn btn-danger btn-sm" ng-click="modal.deletePubKey() "
+ confirm="Are you sure you want to delete this public key? You will lose management access to any test results signed with this key.">Delete</button>
+ </div>
+</div>