airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject [01/11] airavata-php-gateway git commit: AIRAVATA-2228 Experiment summary: update sharing via AJAX
Date Wed, 23 Nov 2016 15:49:37 GMT
Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop 1b5314697 -> 76bb9dae7


AIRAVATA-2228 Experiment summary: update sharing via AJAX


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/a1143c1e
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/a1143c1e
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/a1143c1e

Branch: refs/heads/develop
Commit: a1143c1e856afc9047c6f56e505e76f481a45b62
Parents: 1811d76
Author: Marcus Christie <machrist@iu.edu>
Authored: Fri Nov 18 16:47:16 2016 -0500
Committer: Marcus Christie <machrist@iu.edu>
Committed: Fri Nov 18 16:47:16 2016 -0500

----------------------------------------------------------------------
 app/controllers/ExperimentController.php        |  22 +++-
 app/routes.php                                  |   1 +
 app/views/partials/experiment-info.blade.php    |  17 ++-
 .../partials/sharing-display-body.blade.php     |   1 +
 app/views/partials/sharing-form-modal.blade.php |   2 +
 public/css/sharing.css                          |   4 +
 public/js/sharing/share.js                      | 114 ++++++++++++++-----
 7 files changed, 128 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a1143c1e/app/controllers/ExperimentController.php
----------------------------------------------------------------------
diff --git a/app/controllers/ExperimentController.php b/app/controllers/ExperimentController.php
index 83586e0..734b60b 100755
--- a/app/controllers/ExperimentController.php
+++ b/app/controllers/ExperimentController.php
@@ -79,7 +79,7 @@ class ExperimentController extends BaseController
 
                 return View::make("experiment/create-complete", array("expInputs" => $experimentInputs,
                     "users" => json_encode($users), "owner" => json_encode($owner),
-                    "canEditSharing" => true));
+                    "canEditSharing" => true, "updateSharingViaAjax" => false));
             }else{
                 return View::make("experiment/no-sharing-create-complete", array("expInputs"
=> $experimentInputs));
             }
@@ -174,6 +174,8 @@ class ExperimentController extends BaseController
                 $data["users"] = json_encode($users);
                 $data["owner"] = json_encode($owner);
                 $data["canEditSharing"] = $canEditSharing;
+                // The summary page has it's own Update Sharing button
+                $data["updateSharingViaAjax"] = true;
             }
 
             if( Input::has("dashboard"))
@@ -285,7 +287,9 @@ class ExperimentController extends BaseController
 
                 return View::make("experiment/edit", array("expInputs" => $experimentInputs,
                     "users" => json_encode($users), "owner" => json_encode($owner),
-                    "canEditSharing" => $canEditSharing));
+                    "canEditSharing" => $canEditSharing,
+                    "updateSharingViaAjax" => false
+                ));
             }
             else {
                 Redirect::to("experiment/summary?expId=" . $experiment->experimentId)->with("error",
"You do not have permission to edit this experiment");
@@ -439,6 +443,20 @@ class ExperimentController extends BaseController
         }
     }
 
+    public function updateSharing()
+    {
+        try{
+            // Convert the JSON array to an object
+            $sharing_info = json_decode(json_encode(Input::json()->all()));
+            ExperimentUtilities::update_experiment_sharing(Input::get('expId'), $sharing_info);
+            return Response::json(array("success" => true));
+        }catch (Exception $ex){
+            Log::error("failed to update sharing for experiment", array(Input::all()));
+            Log::error($ex);
+            return Response::json(array("success" => false, "error" => "Error: failed
to update sharing: " . $ex->getMessage()));
+        }
+    }
+
     private function isExperimentOwner($experiment, $username)
     {
         return strcmp($username, $experiment->userName) === 0;

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a1143c1e/app/routes.php
----------------------------------------------------------------------
diff --git a/app/routes.php b/app/routes.php
index c331072..86ec2d8 100755
--- a/app/routes.php
+++ b/app/routes.php
@@ -118,6 +118,7 @@ Route::post("experiment/browse", "ExperimentController@browseView");
 Route::get("experiment/shared-users", "ExperimentController@sharedUsers");
 
 Route::get("experiment/unshared-users", "ExperimentController@unsharedUsers");
+Route::post("experiment/update-sharing", "ExperimentController@updateSharing");
 
 Route::get("download", function(){
     if(Input::has("path") && (0 == strpos(Input::get("path"), Session::get('username'))

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a1143c1e/app/views/partials/experiment-info.blade.php
----------------------------------------------------------------------
diff --git a/app/views/partials/experiment-info.blade.php b/app/views/partials/experiment-info.blade.php
index eec614d..cad9b33 100644
--- a/app/views/partials/experiment-info.blade.php
+++ b/app/views/partials/experiment-info.blade.php
@@ -229,8 +229,8 @@
     <form id="experiment-form" action="{{URL::to('/') }}/experiment/summary" method="post"
role="form">
 
         <div class="form-group">
-        @if(Config::get('pga_config.airavata')["data-sharing-enabled"] && isset($canEditSharing))
-            @include('partials/sharing-display-body', array("form" => $canEditSharing))
+        @if(Config::get('pga_config.airavata')["data-sharing-enabled"] && isset($updateSharingViaAjax))
+            @include('partials/sharing-display-body', array("form" => !$updateSharingViaAjax))
         @endif
         </div>
         <div class="btn-toolbar">
@@ -256,8 +256,8 @@
                 Edit
             </a>
             @if(Config::get('pga_config.airavata')["data-sharing-enabled"] && isset($canEditSharing)
&& $canEditSharing)
-            <button name="update-sharing"
-                   type="submit"
+            <button id="update-sharing" name="update-sharing"
+                   type="button"
                    class="btn btn-primary"
                    title="Update sharing settings">
                 <span class="glyphicon glyphicon-share"></span>
@@ -266,6 +266,10 @@
             @endif
         </div>
     </form>
+
+    {{-- This is a placeholder for the sharing modal to write share-settings to. --}}
+    <input id="share-settings" name="share-settings" type="hidden" value="{}" />
+
     <div id="clone-panel" class="panel panel-default">
         <div class="panel-heading">
             <h3 class="panel-title">Clone Experiment</h3>
@@ -398,7 +402,10 @@
     <script>
         var users = {{ $users }};
         var owner = {{ $owner }};
-        $('#project-share').data({url: "{{URL::to('/')}}/experiment/unshared-users", resourceId:
"{{Input::get('expId')}}"})
+        $('#update-sharing').data({url: "{{URL::to('/')}}/experiment/unshared-users", resourceId:
"{{Input::get('expId')}}"})
+        @if($updateSharingViaAjax)
+        $('#share-box-button').data({ajaxUpdateUrl: "{{URL::to('/')}}/experiment/update-sharing?expId={{Input::get('expId')}}",
resourceId: "{{Input::get('expId')}}"})
+        @endif
     </script>
     {{ HTML::script('js/sharing/sharing_utils.js') }}
     {{ HTML::script('js/sharing/share.js') }}

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a1143c1e/app/views/partials/sharing-display-body.blade.php
----------------------------------------------------------------------
diff --git a/app/views/partials/sharing-display-body.blade.php b/app/views/partials/sharing-display-body.blade.php
index dbb7b69..a92fe69 100644
--- a/app/views/partials/sharing-display-body.blade.php
+++ b/app/views/partials/sharing-display-body.blade.php
@@ -1,3 +1,4 @@
+<!-- TODO: this is used for other than projects. Need to update name -->
 @if($form)
 <label for="project-share">Sharing Settings</label><br />
 <button type="button" class="btn btn-default" name="project-share" id="project-share">Share
With Other Users</button><br />

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a1143c1e/app/views/partials/sharing-form-modal.blade.php
----------------------------------------------------------------------
diff --git a/app/views/partials/sharing-form-modal.blade.php b/app/views/partials/sharing-form-modal.blade.php
index dee2036..5622f16 100644
--- a/app/views/partials/sharing-form-modal.blade.php
+++ b/app/views/partials/sharing-form-modal.blade.php
@@ -10,6 +10,8 @@
                 @include('partials/sharing-form-body')
             </div>
             <div class="modal-footer">
+                <div id="share-box-error-message">
+                </div>
                 <button type="button" id="share-box-button" class="btn btn-primary">Update</button>
                 <button type="button" id="share-box-close" class="btn btn-default" data-dismiss="modal">Cancel</button>
             </div>

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a1143c1e/public/css/sharing.css
----------------------------------------------------------------------
diff --git a/public/css/sharing.css b/public/css/sharing.css
index 80f6b65..3c9c0b9 100755
--- a/public/css/sharing.css
+++ b/public/css/sharing.css
@@ -106,3 +106,7 @@
 #show-results-group .show-groups.btn-primary, #show-results-group .show-users.btn-primary
{
 	box-shadow: inset 0px 0px 1px rgba(0,0,0,1);/*.075);*/
 }
+
+.modal-footer .alert {
+	text-align: left;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a1143c1e/public/js/sharing/share.js
----------------------------------------------------------------------
diff --git a/public/js/sharing/share.js b/public/js/sharing/share.js
index 956cec3..8de122b 100755
--- a/public/js/sharing/share.js
+++ b/public/js/sharing/share.js
@@ -83,7 +83,7 @@ $(function() {
     /* Share box event handlers */
 
     // Create, populate, and show the share box
-    $('body').on('click', 'button#project-share, button#experiment-share', function(e) {
+    $('body').on('click', 'button#project-share, button#update-sharing', function(e) {
         var $share_list, ajax_data;
         e.stopPropagation();
         e.preventDefault();
@@ -208,56 +208,114 @@ $(function() {
         var data, resource_id, $share_list, $update_list, share_settings;
         e.stopPropagation();
         e.preventDefault();
+        $('#share-box-error-message').empty();
         data = $("#share-box").data();
         $share_list = $("#share-box-share").children();
         $update_list = $('.sharing-to-update');
         share_settings = JSON.parse($('#share-settings').val());
+        // TODO: is this used any longer?  I don't see where resource_id gets
+        // set and updateUserPrivileges doesn't seem to be defined
         if (data.hasOwnProperty('resource_id')) {
             resource_id = data.resource_id;
             updateUserPrivileges(resource_id, $share_list);
         }
         else {
-            $('#shared-users').empty();
             if ($update_list.length > 0) {
-                $share_list.sort(comparator_map.username);
                 $update_list.each(function(index, element) {
-                    var $e, data, settings;
+                    var $e, data, newaccess;
                     $e = $(element);
                     data = $e.data();
+                    newaccess = data.access;
                     if (data.hasOwnProperty('currentaccess')) {
-                        data.access = data.currentaccess;
-                        $e.data(data);
+                        newaccess = data.currentaccess;
                     }
-                    share_settings[data.username] = data.access;
+                    share_settings[data.username] = newaccess;
                 });
-                $('#share-settings').val(JSON.stringify(share_settings));
-                $('#shared-users').removeClass('text-align-center');
-            }
-            if ($share_list.length === 0) {
-                $('#shared-users').addClass('text-align-center');
-                $('#shared-users').prepend('<p>This has not been shared</p>');
-            }
-            else {
-                $share_list.each(function(index, element) {
-                    var $e, access;
-                    $e = $(element);
-                    access = parseInt($e.find('.sharing-thumbnail-access').prop('disabled',
true).hide().val(), 10);
-                    $e.find('.sharing-thumbnail-access-text').text(access_text[access]).show();
-                    $e.find('.sharing-thumbnail-unshare').hide();
-                });
-                $share_list.detach().appendTo($('#shared-users'));
+                if ($(this).data().hasOwnProperty('ajaxUpdateUrl')) {
+                    ajaxUpdateSharing($(this).data().ajaxUpdateUrl, share_settings, function(){
+                        updateSharingAndCloseModal(share_settings);
+                    });
+                } else {
+                    updateSharingAndCloseModal(share_settings);
+                }
+            } else {
+                updateSharingAndCloseModal(share_settings);
             }
-            $('#share-box').animate({top: '100%'});
         }
-        $update_list.removeClass('sharing-to-update');
-        $update_list.addClass('updated');
         return false;
     });
 
+    var updateSharingAndCloseModal = function(new_share_settings) {
+
+        var $share_list, $update_list;
+
+        $share_list = $("#share-box-share").children();
+        $update_list = $('.sharing-to-update');
+        $('#shared-users').empty();
+        if ($update_list.length > 0) {
+            $share_list.sort(comparator_map.username);
+            $update_list.each(function(index, element) {
+                var $e, data;
+                $e = $(element);
+                data = $e.data();
+                data.access = new_share_settings[data.username];
+            });
+            $('#share-settings').val(JSON.stringify(new_share_settings));
+            $('#shared-users').removeClass('text-align-center');
+        }
+        if ($share_list.length === 0) {
+            $('#shared-users').addClass('text-align-center');
+            $('#shared-users').prepend('<p>This has not been shared</p>');
+        }
+        else {
+            $share_list.each(function(index, element) {
+                var $e, access;
+                $e = $(element);
+                access = parseInt($e.find('.sharing-thumbnail-access').prop('disabled', true).hide().val(),
10);
+                $e.find('.sharing-thumbnail-access-text').text(access_text[access]).show();
+                $e.find('.sharing-thumbnail-unshare').hide();
+            });
+            $share_list.detach().appendTo($('#shared-users'));
+        }
+        $('#share-box').animate({top: '100%'});
+        $update_list.removeClass('sharing-to-update');
+        $update_list.addClass('updated');
+    };
+
+    var ajaxUpdateSharing = function(url, share_settings, callback) {
+        // TODO: add spinner to button and disable and remove when ajax request completes
+        $.ajax({
+            url: url,
+            method: 'post',
+            data: JSON.stringify(share_settings),
+            contentType: 'application/json',
+            dataType: "json",
+            success: function(data, status, xhr) {
+                if (data.success) {
+                    // TODO: add success message on page
+                    callback();
+                } else {
+                    $(    '<div id="share-box-error-alert" class="alert alert-danger">'
+                        +   data.error
+                        + '</div>'
+                    ).appendTo('#share-box-error-message');
+                }
+            },
+            error: function(xhr, status, error) {
+                console.log("Error while saving sharing settings", url, share_settings, status,
error);
+                $(    '<div id="share-box-error-alert" class="alert alert-danger">'
+                    +   'Error occurred: ' + status
+                    + '</div>'
+                ).appendTo('#share-box-error-message');
+            }
+        });
+    };
+
     // Close the share box
     $('body').on('click', '#share-box-close, #share-box-x', function(e) {
         e.stopPropagation();
         e.preventDefault();
+        $('#share-box-error-message').empty();
         $('#shared-users').empty();
         if ($original_shared_list.length > 0) {
             $original_shared_list.each(function(index, element) {
@@ -271,6 +329,7 @@ $(function() {
                 $e.find('.sharing-thumbnail-access').val(access).prop('disabled', true).hide();
                 $e.find('.sharing-thumbnail-access-text').text(access_text[access]).show();
                 $e.find('.sharing-thumbnail-unshare').hide();
+                $e.removeClass('sharing-to-update');
             });
             $('#shared-users').removeClass('text-align-center');
             $original_shared_list.detach().appendTo('#shared-users');
@@ -280,6 +339,9 @@ $(function() {
             $('#shared-users').prepend('<p>This has not been shared</p>');
         }
         $('.sharing-to-update').detach().appendTo($('#share-box-users'));
+        $('.sharing-to-update').find('.sharing-thumbnail-access').val(access_enum.NONE).prop('disabled',
true).hide();
+        $('.sharing-to-update').find('.sharing-thumbnail-access-text').text(access_text[access_enum.NONE]).show();
+        $('.sharing-to-update').find('.sharing-thumbnail-unshare').hide();
         $('.sharing-to-update').addClass('share-box-users-item').removeClass('sharing-to-update
share-box-share-item');
         $('#share-box').animate({top: "100%"});
         $('.order-results-selector').trigger('change');


Mime
View raw message