airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sma...@apache.org
Subject [14/18] airavata-php-gateway git commit: AIRAVATA-2152 User Storage Preference management views
Date Fri, 28 Oct 2016 20:05:00 GMT
AIRAVATA-2152 User Storage Preference management views

Also beginning work on loading a user's SSH credential summary info


Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/10e9f42d
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/10e9f42d
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/10e9f42d

Branch: refs/heads/develop
Commit: 10e9f42d10df0246117c9c7a27650fb49ff6a21c
Parents: 8f0cc36
Author: Marcus Christie <machrist@iu.edu>
Authored: Fri Oct 21 13:52:31 2016 -0400
Committer: Marcus Christie <machrist@iu.edu>
Committed: Fri Oct 28 15:05:14 2016 -0400

----------------------------------------------------------------------
 app/controllers/AccountController.php           |  57 ++++++++
 app/libraries/URPUtilities.php                  |  31 +++++
 app/routes.php                                  |   5 +
 app/views/account/dashboard.blade.php           |   2 +-
 .../account/user-compute-resources.blade.php    |   2 +-
 .../account/user-storage-resources.blade.php    | 139 +++++++++++++++++++
 .../user-storage-resource-preferences.blade.php |  58 ++++++++
 7 files changed, 292 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/10e9f42d/app/controllers/AccountController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index 8e88e90..7b5e4cb 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -554,6 +554,7 @@ class AccountController extends BaseController
         $unselectedCRs = array_values($allCRsById);
 
         // TODO: actually get all of the user's credential store tokens, including description
+        URPUtilities::get_all_ssh_pub_keys_summary_for_user();
         $tokens = array(
             $userResourceProfile->credentialStoreToken => "Default SSH Key"
         );
@@ -590,4 +591,60 @@ class AccountController extends BaseController
             return Redirect::to("account/user-compute-resources")->with("message","Compute
Resource Account Settings have been deleted.");
         }
     }
+
+    public function getStorageResources(){
+
+        $userResourceProfile = URPUtilities::get_or_create_user_resource_profile();
+
+        $allSRs = SRUtilities::getAllSRObjects();
+        foreach( $allSRs as $index => $srObject )
+        {
+            $allSRsById[$srObject->storageResourceId] = $srObject;
+        }
+        // Add srDetails to each UserStoragePreference
+        foreach ($userResourceProfile->userStoragePreferences as $index => $userStoragePreference)
{
+            $userStoragePreference->srDetails = $allSRsById[$userStoragePreference->storageResourceId];
+            // To figure out the unselectedSRs, remove this storage resource from allSRsById
+            unset($allSRsById[$userStoragePreference->storageResourceId]);
+        }
+        $unselectedSRs = array_values($allSRsById);
+
+        // TODO: actually get all of the user's credential store tokens, including description
+        URPUtilities::get_all_ssh_pub_keys_summary_for_user();
+        $tokens = array(
+            $userResourceProfile->credentialStoreToken => "Default SSH Key"
+        );
+
+        return View::make("account/user-storage-resources", array(
+            "userResourceProfile" => $userResourceProfile,
+            "storageResources" => $allSRs,
+            "unselectedSRs" => $unselectedSRs,
+            "tokens" => $tokens
+        ));
+    }
+
+    public function addUserStorageResourcePreference() {
+
+        if( URPUtilities::add_or_update_user_SRP( Input::all()) )
+        {
+            return Redirect::to("account/user-storage-resources")->with("message","Storage
Resource Account Settings have been saved.");
+        }
+    }
+
+    public function updateUserStorageResourcePreference() {
+
+        if( URPUtilities::add_or_update_user_SRP( Input::all(), true ) )
+        {
+            return Redirect::to("account/user-storage-resources")->with("message","Storage
Resource Account Settings have been updated.");
+        }
+    }
+
+    public function deleteUserStorageResourcePreference() {
+        $storageResourceId = Input::get("rem-user-srId");
+        $result = URPUtilities::delete_user_SRP( $storageResourceId );
+        if( $result )
+        {
+            return Redirect::to("account/user-storage-resources")->with("message","Storage
Resource Account Settings have been deleted.");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/10e9f42d/app/libraries/URPUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/URPUtilities.php b/app/libraries/URPUtilities.php
index ad5c79a..b4ceba6 100644
--- a/app/libraries/URPUtilities.php
+++ b/app/libraries/URPUtilities.php
@@ -3,6 +3,7 @@
 use Airavata\API\Error\AiravataSystemException;
 use Airavata\Model\AppCatalog\UserResourceProfile\UserResourceProfile;
 use Airavata\Model\AppCatalog\UserResourceProfile\UserComputeResourcePreference;
+use Airavata\Model\AppCatalog\UserResourceProfile\UserStoragePreference;
 
 class URPUtilities
 {
@@ -79,6 +80,7 @@ class URPUtilities
             $inputs["reservationEndTime"] = CommonUtilities::convertLocalToUTC(strtotime($inputs["reservationEndTime"]))
* 1000;
 
         $userComputeResourcePreference = new UserComputeResourcePreference($inputs);
+        // Log::debug("add_or_update_user_CRP: ", array($userComputeResourcePreference));
         $userId = Session::get('username');
         if ($update)
         {
@@ -94,6 +96,35 @@ class URPUtilities
         $userId = Session::get('username');
         $gatewayId = Session::get('gateway_id');
         $result = Airavata::deleteUserComputeResourcePreference(Session::get('authz-token'),
$userId, $gatewayId, $computeResourceId);
+        // Log::debug("deleteUserComputeResourcePreference($userId, $gatewayId, $computeResourceId)
=> $result");
+        return $result;
+    }
+
+    public static function add_or_update_user_SRP($inputs, $update = false)
+    {
+        $inputs = Input::all();
+
+        $userStoragePreference = new UserStoragePreference($inputs);
+        $userId = Session::get('username');
+        $gatewayId = Session::get('gateway_id');
+        $storageResourceId = $inputs["storageResourceId"];
+        if ($update)
+        {
+            return Airavata::updateUserStoragePreference(Session::get('authz-token'), $userId,
$inputs["gatewayId"], $inputs["storageResourceId"], $userStoragePreference);
+        } else
+        {
+            // Log::debug("addUserStoragePreference($userId, $gatewayId, $storageResourceId)",
array($userStoragePreference));
+            $result = Airavata::addUserStoragePreference(Session::get('authz-token'), $userId,
$gatewayId, $storageResourceId, $userStoragePreference);
+            return $result;
+        }
+    }
+
+    public static function delete_user_SRP($storageResourceId)
+    {
+        $userId = Session::get('username');
+        $gatewayId = Session::get('gateway_id');
+        $result = Airavata::deleteUserStoragePreference(Session::get('authz-token'), $userId,
$gatewayId, $storageResourceId);
+        // Log::debug("deleteUserStoragePreference($userId, $gatewayId, $storageResourceId)
=> $result");
         return $result;
     }
 

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/10e9f42d/app/routes.php
----------------------------------------------------------------------
diff --git a/app/routes.php b/app/routes.php
index ffb6850..a087339 100755
--- a/app/routes.php
+++ b/app/routes.php
@@ -58,6 +58,11 @@ Route::post("account/add-user-crp", "AccountController@addUserComputeResourcePre
 Route::post("account/update-user-crp", "AccountController@updateUserComputeResourcePreference");
 Route::post("account/delete-user-crp", "AccountController@deleteUserComputeResourcePreference");
 
+Route::get("account/user-storage-resources", "AccountController@getStorageResources");
+Route::post("account/add-user-srp", "AccountController@addUserStorageResourcePreference");
+Route::post("account/update-user-srp", "AccountController@updateUserStorageResourcePreference");
+Route::post("account/delete-user-srp", "AccountController@deleteUserStorageResourcePreference");
+
 /*
  * The following routes will not work without logging in.
  *

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/10e9f42d/app/views/account/dashboard.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/dashboard.blade.php b/app/views/account/dashboard.blade.php
index 038dbbb..58c4c7b 100644
--- a/app/views/account/dashboard.blade.php
+++ b/app/views/account/dashboard.blade.php
@@ -402,7 +402,7 @@
                     </div>
                 </a>
 
-                <a href="{{URL::to('/')}}/account/storageResources">
+                <a href="{{URL::to('/')}}/account/user-storage-resources">
                     <div class=" col-md-4 well">
                         <div class="col-md-12">
                             <span class="glyphicon glyphicon-folder-open console-icon"></span>

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/10e9f42d/app/views/account/user-compute-resources.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/user-compute-resources.blade.php b/app/views/account/user-compute-resources.blade.php
index 4b9330a..bc81f37 100644
--- a/app/views/account/user-compute-resources.blade.php
+++ b/app/views/account/user-compute-resources.blade.php
@@ -53,7 +53,7 @@ button.add-user-cr {
                         <input type="hidden" name="gatewayId" id="gatewayId"
                                value="{{$userResourceProfile->gatewayID}}">
                         <input type="hidden" name="computeResourceId"
-                               id="gatewayId"
+                               id="computeResourceId"
                                value="{{$user_crp->computeResourceId}}">
 
                         <div class="form-horizontal">

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/10e9f42d/app/views/account/user-storage-resources.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/user-storage-resources.blade.php b/app/views/account/user-storage-resources.blade.php
new file mode 100644
index 0000000..e38ef96
--- /dev/null
+++ b/app/views/account/user-storage-resources.blade.php
@@ -0,0 +1,139 @@
+@extends('layout.basic')
+
+@section('page-header')
+@parent
+<style>
+button.add-user-sr {
+    margin-top: 10px;
+    margin-bottom: 10px;
+}
+#user-sr-select-input-group {
+    margin-bottom: 10px;
+}
+</style>
+@stop
+
+@section('content')
+@foreach( (array)$storageResources as $index => $sr)
+@include('partials/user-storage-resource-preferences', array('storageResource' => $sr))
+@endforeach
+<div class="container">
+    @if( Session::has("message"))
+        <div class="alert alert-success alert-dismissible" role="alert">
+            <button type="button" class="close" data-dismiss="alert"><span
+                    aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
+            {{ Session::get("message") }}
+        </div>
+    {{ Session::forget("message") }}
+    @endif
+    <h1>Storage Resource Accounts</h1>
+    <button class="btn btn-default add-user-sr">
+        <span class="glyphicon glyphicon-plus"></span> Add a Storage Resource
Account
+    </button>
+    <div id="add-user-storage-resource-block-container">
+    </div>
+    <div class="panel-group" id="accordion">
+        @foreach( (array)$userResourceProfile->userStoragePreferences as $indexUserSRP
=> $user_srp )
+        <div class="panel panel-default">
+            <div class="panel-heading">
+                <h4 class="panel-title">
+                    <a class="accordion-toggle collapsed"
+                       data-toggle="collapse" data-parent="#accordion"
+                       href="#collapse-user-srp-{{$indexUserSRP}}">
+                        {{$user_srp->srDetails->hostName}}
+                    </a>
+                </h4>
+            </div>
+            <div id="collapse-user-srp-{{$indexUserSRP}}"
+                 class="panel-collapse collapse">
+                <div class="panel-body">
+                    <form class="set-sr-preference" action="{{URL::to('/')}}/account/update-user-srp"
+                          method="POST">
+                        <input type="hidden" name="gatewayId" id="gatewayId"
+                               value="{{$userResourceProfile->gatewayID}}">
+                        <input type="hidden" name="storageResourceId"
+                               id="storageResourceId"
+                               value="{{$user_srp->storageResourceId}}">
+
+                        <div class="form-horizontal">
+                            @include('partials/user-storage-resource-preferences',
+                            array('storageResource' => $user_srp->srDetails,
+                            'preferences'=>$user_srp, 'show'=>true,
+                            'allowDelete'=>true))
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+        @endforeach
+    </div>
+</div>
+<div class="add-user-storage-resource-block hide">
+    <div class="well">
+        <form action="{{URL::to('/')}}/account/add-user-srp" method="POST">
+            <input type="hidden" name="gatewayId" id="gatewayId" value="{{$userResourceProfile->gatewayID}}">
+
+            <div id="user-sr-select-input-group" class="input-group">
+                <select id="user-sr-select" name="storageResourceId" class="form-control">
+                    <option value="">Select a Storage Resource and configure your account</option>
+                    @foreach( (array)$unselectedSRs as $index => $sr)
+                    <option value="{{ $sr->storageResourceId}}">{{ $sr->hostName
}}</option>
+                    @endforeach
+                </select>
+                <span class="input-group-addon remove-user-sr" style="cursor:pointer;">x</span>
+            </div>
+            <div class="user-sr-pref-space form-horizontal"></div>
+        </form>
+    </div>
+</div>
+
+<div class="modal fade" id="remove-user-storage-resource-block" tabindex="-1" role="dialog"
aria-labelledby="add-modal"
+     aria-hidden="true">
+    <div class="modal-dialog">
+
+        <form action="{{URL::to('/')}}/account/delete-user-srp" method="POST">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h3 class="text-center">Remove Storage Resource Account Confirmation</h3>
+                </div>
+                <div class="modal-body">
+                    <input type="hidden" class="form-control remove-user-srId" name="rem-user-srId"/>
+
+                    Do you really want to remove your Storage Resource Account settings for
<span class="remove-user-sr-name"> </span>?
+                </div>
+                <div class="modal-footer">
+                    <div class="form-group">
+                        <input type="submit" class="btn btn-danger" value="Remove"/>
+                        <input type="button" class="btn btn-default" data-dismiss="modal"
value="Cancel"/>
+                    </div>
+                </div>
+            </div>
+
+        </form>
+    </div>
+</div>
+@stop
+
+@section('scripts')
+@parent
+<script>
+
+$('.add-user-sr').on('click', function(){
+
+    $('#add-user-storage-resource-block-container').append( $(".add-user-storage-resource-block").html()
);
+});
+$(".remove-user-storage-resource").click( function(){
+	$(".remove-user-sr-name").html( $(this).data("sr-name") );
+	$(".remove-user-srId").val( $(this).data("sr-id") );
+});
+$("#add-user-storage-resource-block-container").on("change", "#user-sr-select", function(){
+    srId = $(this).val();
+    //This is done as Jquery creates problems when using period(.) in id or class.
+    srId = srId.replace(/\./g,"_");
+    $("#add-user-storage-resource-block-container .user-sr-pref-space").html($("#sr-" + srId).html());
+});
+$("#add-user-storage-resource-block-container").on("click", ".remove-user-sr", function(){
+    $("#add-user-storage-resource-block-container").empty();
+});
+</script>
+@stop
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/10e9f42d/app/views/partials/user-storage-resource-preferences.blade.php
----------------------------------------------------------------------
diff --git a/app/views/partials/user-storage-resource-preferences.blade.php b/app/views/partials/user-storage-resource-preferences.blade.php
new file mode 100644
index 0000000..b70d48e
--- /dev/null
+++ b/app/views/partials/user-storage-resource-preferences.blade.php
@@ -0,0 +1,58 @@
+<!-- partial template variables:
+    storageResource - (required, StorageResourceDescription) the storage resource object
+    preferences - (optional, UserStoragePreference) the saved preference data
+    show - (optional, boolean)
+    allowDelete - (optional, boolean)
+-->
+<!-- String replace is done as Jquery creates problems when using period(.) in id or class.
-->
+<div id="sr-{{ str_replace( '.', "_", $storageResource->storageResourceId) }}" class="@if(isset(
$show) ) @if( !$show) hide @endif @else hide @endif">
+<div class="form-group">
+    <label class="control-label col-md-3">Login Username</label>
+
+    <div class="col-md-9">
+        <input type="text" name="loginUserName" class="form-control"
+               value="@if( isset( $preferences) ){{$preferences->loginUserName}}@endif"/>
+    </div>
+</div>
+
+<div class="form-group">
+    <label class="control-label col-md-3">File System Root Location</label>
+
+    <div class="col-md-9">
+        <input type="text" name="fileSystemRootLocation" class="form-control"
+               value="@if( isset( $preferences) ){{$preferences->fileSystemRootLocation}}@endif"/>
+    </div>
+</div>
+
+<div class="form-group">
+    <label class="control-label col-md-3">Resource Specific Credential Store Token</label>
+
+    <div class="col-md-9">
+        <select class="form-control gateway-credential-store-token" name="resourceSpecificCredentialStoreToken"
>
+            <option value="">Select a Credential Token from Store</option>
+            @foreach( $tokens as $token => $description )
+                <option value="{{$token}}" @if( isset( $preferences) ) @if( $token ==
$preferences->resourceSpecificCredentialStoreToken) selected @endif @endif>{{$description}}</option>
+            @endforeach
+            <option value="">DO-NO-SET</option>
+        </select>
+        <!--
+        <input type="text" name="resourceSpecificCredentialStoreToken" class="form-control"
+               value="@if( isset( $preferences) ){{$preferences->resourceSpecificCredentialStoreToken}}@endif"/>
+        -->
+    </div>
+</div>
+
+<div class="row">
+    <div class="form-group col-md-12 text-center">
+        <input type="submit" class="btn btn-primary" value="Save"/>
+        <button type="button" class="btn btn-danger remove-user-storage-resource @if(isset(
$allowDelete ) ) @if( !$allowDelete) hide @endif @else hide @endif"
+            data-toggle="modal"
+            data-target="#remove-user-storage-resource-block"
+            data-cr-name="{{$storageResource->hostName}}"
+            data-cr-id="{{$storageResource->storageResourceId}}">
+            Remove
+        </button>
+    </div>
+</div>
+
+</div>


Mime
View raw message