Repository: airavata-php-gateway
Updated Branches:
  refs/heads/master b993f7dc7 -> 363264005


fixing AIRAVATA-1748


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

Branch: refs/heads/master
Commit: 363264005e2bc7feee7b31f3d162681db0462402
Parents: b993f7d
Author: Supun Nakandala <[email protected]>
Authored: Thu Jul 9 01:04:23 2015 +0530
Committer: Supun Nakandala <[email protected]>
Committed: Thu Jul 9 01:04:23 2015 +0530

----------------------------------------------------------------------
 app/controllers/AdminController.php            |  28 +++
 app/routes.php                                 |   2 +
 app/views/admin/manage-users.blade.php         | 192 +++++++++++++-------
 app/views/partials/experiment-inputs.blade.php |   2 +-
 4 files changed, 161 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/36326400/app/controllers/AdminController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AdminController.php 
b/app/controllers/AdminController.php
index 3993838..dab564d 100644
--- a/app/controllers/AdminController.php
+++ b/app/controllers/AdminController.php
@@ -88,6 +88,34 @@ class AdminController extends BaseController {
                return Redirect::to("admin/dashboard/roles")->with( "message", 
"Role has been added.");
        }
 
+    public function addRolesToUser(){
+        $currentRoles = (array)WSIS::getUserRoles(Input::get("username"));
+        $roles["new"] = array_diff(Input::all()["roles"], $currentRoles);
+        $roles["deleted"] = array_diff($currentRoles, Input::all()["roles"]);
+
+        $index = array_search('Internal/everyone',$roles["new"]);
+        if($index !== FALSE){
+            unset($roles["new"][$index]);
+        }
+
+        $index = array_search('Internal/everyone',$roles["deleted"]);
+        if($index !== FALSE){
+            unset($roles["deleted"][$index]);
+        }
+
+        $username = Input::all()["username"];
+        WSIS::updateUserRoles($username, $roles);
+        return Redirect::to("admin/dashboard/roles")->with( "message", "Roles 
has been added.");
+    }
+
+    public function removeRoleFromUser(){
+        $roles["deleted"] = array(Input::all()["roleName"]);
+        $roles["new"] = array();
+        $username = Input::all()["username"];
+        WSIS::updateUserRoles($username, $roles);
+        return Redirect::to("admin/dashboard/roles")->with( "message", "Role 
has been deleted.");
+    }
+
        public function getRoles(){
                return 
json_encode((array)WSIS::getUserRoles(Input::get("username")));
        }

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/36326400/app/routes.php
----------------------------------------------------------------------
diff --git a/app/routes.php b/app/routes.php
index 8e1493e..c3c3b66 100755
--- a/app/routes.php
+++ b/app/routes.php
@@ -186,6 +186,8 @@ Route::post("admin/delete-role", 
"AdminController@deleteRole");
 
 Route::post("admin/add-roles-to-user", "AdminController@addRolesToUser");
 
+Route::post("admin/remove-role-from-user", 
"AdminController@removeRoleFromUser");
+
 //Super Admin Specific calls
 
 Route::post("admin/add-gateway", "AdminController@addGateway");

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/36326400/app/views/admin/manage-users.blade.php
----------------------------------------------------------------------
diff --git a/app/views/admin/manage-users.blade.php 
b/app/views/admin/manage-users.blade.php
index 872acaf..444ff21 100644
--- a/app/views/admin/manage-users.blade.php
+++ b/app/views/admin/manage-users.blade.php
@@ -37,7 +37,13 @@
                                 <option>Select a role</option>
                                 <option 
value="{{URL::to('/')}}/admin/dashboard/users">All</option>
                                 @foreach( (array)$roles as $role)
-                                <option 
value="{{URL::to('/')}}/admin/dashboard/users?role={{$role}}">{{$role}}</option>
+                                <option 
value="{{URL::to('/')}}/admin/dashboard/users?role={{$role}}"
+                                <?php
+                                    if(isset(Input::all()["role"]) && 
Input::all()["role"] == $role){
+                                        echo "selected";
+                                    }
+                                ?>
+                                >{{$role}}</option>
                                 @endforeach
                             </select>
                         </th>
@@ -46,7 +52,7 @@
                     <tr class="user-row">
                         <td>{{ $user }}</td>
                         <td>
-                            <button class="button btn btn-default check-roles 
fade" type="button"
+                            <button class="button btn btn-default check-roles" 
type="button"
                                     data-username="{{$user}}">Check All Roles
                             </button>
                             <div class="user-roles"></div>
@@ -77,9 +83,9 @@
                 </div>
                 <div class="add-roles-block hide">
                     <div class="form-group well">
-                        <label class="control-label">Add a new role to the 
user</label>
+                        <label class="control-label">Add a new roles to the 
user</label>
                         <select multiple name="new-role" 
class="new-roles-select" class="form-control">
-                            <option>Select a role</option>
+<!--                            <option>Select a role</option>-->
                             @foreach( (array)$roles as $role)
                             <option value="{{$role}}">{{$role}}</option>
                             @endforeach
@@ -90,6 +96,7 @@
                 </div>
             </div>
             <div class="modal-footer">
+                <div class="success-message"></div>
                 <div class="form-group">
                     <input type="submit" class="btn" data-dismiss="modal" 
value="Close"/>
                 </div>
@@ -102,7 +109,7 @@
 <div class="role-block hide">
     <div class="btn-group" role="group">
         <button type="button" class="btn btn-default role-name" 
disabled>Role</button>
-        <button type="button" class="btn btn-default"><span class="glyphicon 
glyphicon-remove"></span></button>
+        <button type="button" class="btn btn-default 
existing-role-button"><span class="glyphicon glyphicon-remove"></span></button>
     </div>
 </div>
 @stop
@@ -111,29 +118,23 @@
 @parent
 <script>
 
-    $(".user-row").hover(
-        function () {
-            $(this).find(".check-roles").addClass("in");
-        },
-        function () {
-            $(this).find(".check-roles").removeClass("in");
-        }
-    );
-    $(".check-roles").click(function () {
-
-        //remove disabled roles from previous actions.
-        $(".new-roles-select option").each(function () {
-            $(this).removeAttr("disabled");
-        });
+//    $(".user-row").hover(
+//        function () {
+//            $(this).find(".check-roles").addClass("in");
+//        },
+//        function () {
+//            $(this).find(".check-roles").removeClass("in");
+//        }
+//    );
 
-        var userName = $(this).data("username");
+    function update_users_existing_roles(that){
+        userName = $(that).data("username");
         $("#check-role-block").modal("show");
         $(".roles-of-user").html("User : " + userName);
         $(".roles-load").removeClass("hide");
         $(".roles-list").addClass("hide");
         $(".add-roles-submit").data("username", userName);
-        $(this).find(".alert-success").remove();
-
+        $(that).find(".alert-success").remove();
 
         //getting user's existing roles
         $.ajax({
@@ -142,57 +143,124 @@
             data: {
                 username: userName
             }
-        })
-            .complete(function (data) {
-                roles = JSON.parse(data.responseText);
-                roleBlocks = "";
-                for (var i = 0; i < roles.length; i++) {
-                    //disable roles which user already has.
-                    $(".new-roles-select option").each(function () {
-                        if ($(this).val() == roles[i])
-                            $(this).attr("disabled", "disabled");
-                        else
+        }).complete(function (data) {
+            roles = JSON.parse(data.responseText);
+            roleBlocks = "";
+            $(".new-roles-select option").each(function () {
+                $(this).removeAttr("disabled");
+            });
+            for (var i = 0; i < roles.length; i++) {
+                //disable roles which user already has.
+                $(".new-roles-select option").each(function () {
+                    if ($(this).val().trim() == roles[i].trim()){
+                        $(this).attr("disabled", "disabled");
+                    }
+                });
+                $(".role-block").find(".role-name").html(roles[i]);
+                
$(".role-block").find(".existing-role-button").attr("roleName", roles[i]);
+                var newRoleBlock = $(".role-block").html();
+                roleBlocks += newRoleBlock;
+                $(".roles-list").html(roleBlocks);
+                $(".add-roles-block").removeClass("hide");
+            }
+            $(".roles-load").addClass("hide");
+            $(".roles-list").removeClass("hide");
+        });
+
+        $(document).on("click",".existing-role-button",function(e) {
+            e.preventDefault();
+            that = this;
+            if($(this).attr("roleName") != "Internal/everyone"){
+                $.ajax({
+                    type: "POST",
+                    url: $(".base-url").val() + "/admin/remove-role-from-user",
+                    data: {
+                        username: userName,
+                        roleName:$(this).attr("roleName")
+                    }
+                }).complete(function (data) {
+                    $("#check-role-block").modal("show");
+                    $(".roles-of-user").html("User : " + userName);
+                    $(".roles-load").removeClass("hide");
+                    $(".roles-list").addClass("hide");
+                    $(".add-roles-submit").data("username", userName);
+                    $(document).find(".alert-success").remove();
+
+                    //getting user's existing roles
+                    $.ajax({
+                        type: "POST",
+                        url: $(".base-url").val() + "/admin/check-roles",
+                        data: {
+                            username: userName
+                        }
+                    }).complete(function (data) {
+                        roles = JSON.parse(data.responseText);
+                        roleBlocks = "";
+                        $(".new-roles-select option").each(function () {
                             $(this).removeAttr("disabled");
+                        });
+                        for (var i = 0; i < roles.length; i++) {
+                            //disable roles which user already has.
+                            $(".new-roles-select option").each(function () {
+                                if ($(this).val().trim() == roles[i].trim()){
+                                    $(this).attr("disabled", "disabled");
+                                }
+                            });
+                            $(".role-block").find(".role-name").html(roles[i]);
+                            
$(".role-block").find(".existing-role-button").attr("roleName", roles[i]);
+                            var newRoleBlock = $(".role-block").html();
+                            roleBlocks += newRoleBlock;
+                            $(".roles-list").html(roleBlocks);
+                            $(".add-roles-block").removeClass("hide");
+                        }
+                        $(".roles-load").addClass("hide");
+                        $(".roles-list").removeClass("hide");
                     });
-                    $(".role-block").find(".role-name").html(roles[i]);
-                    var newRoleBlock = $(".role-block").html();
-                    roleBlocks += newRoleBlock;
-                    $(".roles-list").html(roleBlocks);
-
-                    $(".add-roles-block").removeClass("hide");
-                }
-                $(".roles-load").addClass("hide");
-                $(".roles-list").removeClass("hide");
+                    $(".success-message").html("<span class='alert 
alert-success col-md-12'>Role has been removed</span>");
+                });
+            }
+        });
+    }
 
+    $(".check-roles").click(function () {
+        //remove disabled roles from previous actions.
+        $(".new-roles-select option").each(function () {
+            $(this).removeAttr("disabled");
+        });
 
-            });
+        update_users_existing_roles(this);
 
         $(".add-roles-submit").click(function () {
+            that = this;
+            $(".success-message").html("");
             $(this).attr("disabled", "disabled");
-            $(this).html("<img src='" + $(".base-url").val() + 
"/ajax-loader.gif'/>");
+            $(this).html("<img src='" + $(".base-url").val() + 
"/assets/ajax-loader.gif'/>");
             userName = $(this).data("username");
             var rolesToAdd = $(".new-roles-select").val();
-            $(".roles-list").find(".role-name").each(function () {
-                rolesToAdd.push($(this).html());
-            })
-            $.ajax({
-                type: "POST",
-                url: $(".base-url").val() + "/admin/add-roles-to-user",
-                data: {
-                    add: true,
-                    username: userName,
-                    roles: rolesToAdd
-                },
-                success( data)
-            {
-                console.log(data);
+            if(rolesToAdd != null){
+                $(".roles-list").find(".role-name").each(function () {
+                    rolesToAdd.push($(this).html());
+                });
+                $.ajax({
+                    type: "POST",
+                    url: $(".base-url").val() + "/admin/add-roles-to-user",
+                    data: {
+                        add: true,
+                        username: userName,
+                        roles: rolesToAdd
+                    },
+                    success : function(data)
+                    {
+                        $(".roles-load").removeClass("hide");
+                        $(".roles-list").addClass("hide");
+                        $(".success-message").html("<span class='alert 
alert-success col-md-12'>Roles have been added</span>");
+                        update_users_existing_roles(that);
+                    }
+                });
             }
+            $(".add-roles-submit").html("Add Roles");
+            $(this).removeAttr("disabled");
         });
-        $(".add-roles-submit").html("Add Roles");
-        $(".add-roles-submit").after("<span class='alert alert-success 
col-md-12'>Roles have been added</span>");
     });
-
-    })
-    ;
 </script>
 @stop
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/36326400/app/views/partials/experiment-inputs.blade.php
----------------------------------------------------------------------
diff --git a/app/views/partials/experiment-inputs.blade.php 
b/app/views/partials/experiment-inputs.blade.php
index 7d09106..f60ae1d 100644
--- a/app/views/partials/experiment-inputs.blade.php
+++ b/app/views/partials/experiment-inputs.blade.php
@@ -58,7 +58,7 @@
                 @endforeach
             </select>
             @else
-            <h4>Application deployed Computational resources are currently 
available
+            <h4>Application deployed Computational resources are currently 
unavailable
                 @endif
         </div>
         <div class="queue-block">

Reply via email to