You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2016/11/04 17:55:26 UTC

[4/7] airavata-php-gateway git commit: AIRAVATA-2190 Select project when cloning experiment

AIRAVATA-2190 Select project when cloning experiment


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

Branch: refs/heads/develop
Commit: f76343df20524fcf8e8595f519555c0de33f4df4
Parents: 0d58af5
Author: Marcus Christie <ma...@iu.edu>
Authored: Fri Nov 4 12:12:47 2016 -0400
Committer: Marcus Christie <ma...@iu.edu>
Committed: Fri Nov 4 12:12:47 2016 -0400

----------------------------------------------------------------------
 app/controllers/ExperimentController.php     | 17 +++-----
 app/libraries/ExperimentUtilities.php        |  4 +-
 app/libraries/ProjectUtilities.php           | 15 +++++++
 app/routes.php                               |  2 +-
 app/views/partials/experiment-info.blade.php | 51 ++++++++++++++++-------
 5 files changed, 60 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f76343df/app/controllers/ExperimentController.php
----------------------------------------------------------------------
diff --git a/app/controllers/ExperimentController.php b/app/controllers/ExperimentController.php
index e6803a9..7b8e101 100755
--- a/app/controllers/ExperimentController.php
+++ b/app/controllers/ExperimentController.php
@@ -141,7 +141,7 @@ class ExperimentController extends BaseController
             }
             $expVal["jobDetails"] = $jobDetails;
 
-
+            $writeableProjects = ProjectUtilities::get_all_user_writeable_projects(Session::get("gateway_id"), Session::get("username"));
 
             $data = array(
                 "expId" => Input::get("expId"),
@@ -149,7 +149,8 @@ class ExperimentController extends BaseController
                 "project" => $project,
                 "jobDetails" => $jobDetails,
                 "expVal" => $expVal,
-                "autoRefresh"=> $autoRefresh
+                "autoRefresh"=> $autoRefresh,
+                "writeableProjects" => $writeableProjects
             );
             if(Config::get('pga_config.airavata')["data-sharing-enabled"]){
                 $users = SharingUtilities::getProfilesForSharedUsers(Input::get("expId"), ResourceType::EXPERIMENT);
@@ -288,16 +289,10 @@ class ExperimentController extends BaseController
 
     public function cloneExperiment()
     {
-        if (isset($_GET['expId'])) {
-            $cloneId = ExperimentUtilities::clone_experiment($_GET['expId']);
-            $experiment = ExperimentUtilities::get_experiment($cloneId);
-            $project = ProjectUtilities::get_project($experiment->projectId);
-
-            $expVal = ExperimentUtilities::get_experiment_values($experiment);
-            $expVal["jobState"] = ExperimentUtilities::get_job_status($experiment);
+        // TODO: catch and handle errors when cloning fails
+        $cloneId = ExperimentUtilities::clone_experiment(Input::get('expId'), Input::get('projectId'));
 
-            return Redirect::to('experiment/edit?expId=' . $cloneId . "&clonedExp=true");
-        }
+        return Redirect::to('experiment/edit?expId=' . $cloneId . "&clonedExp=true");
     }
 
     public function editSubmit()

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f76343df/app/libraries/ExperimentUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/ExperimentUtilities.php b/app/libraries/ExperimentUtilities.php
index 3b803b5..fb0d363 100755
--- a/app/libraries/ExperimentUtilities.php
+++ b/app/libraries/ExperimentUtilities.php
@@ -581,12 +581,12 @@ class ExperimentUtilities
      * Clone the experiment with the given ID
      * @param $expId
      */
-    public static function clone_experiment($expId)
+    public static function clone_experiment($expId, $projectId)
     {
         try {
             //create new experiment to receive the clone
             $experiment = Airavata::getExperiment(Session::get('authz-token'), $expId);
-            $cloneId = Airavata::cloneExperiment(Session::get('authz-token'), $expId, 'Clone of ' . $experiment->experimentName);
+            $cloneId = Airavata::cloneExperiment(Session::get('authz-token'), $expId, 'Clone of ' . $experiment->experimentName, $projectId);
             //updating the experiment inputs and output path
             $experiment = Airavata::getExperiment(Session::get('authz-token'), $cloneId);
             $experimentInputs = $experiment->experimentInputs;

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f76343df/app/libraries/ProjectUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/ProjectUtilities.php b/app/libraries/ProjectUtilities.php
index 1a58c61..d1d7600 100755
--- a/app/libraries/ProjectUtilities.php
+++ b/app/libraries/ProjectUtilities.php
@@ -46,6 +46,19 @@ class ProjectUtilities
         return $userProjects;
     }
 
+    public static function get_all_user_writeable_projects($gatewayId, $username)
+    {
+        $writeableProjects = array();
+        $userProjects = ProjectUtilities::get_all_user_projects($gatewayId, $username);
+        foreach($userProjects as $project) {
+            if (SharingUtilities::userCanWrite($username, $project->projectID, ResourceType::PROJECT)) {
+                $writeableProjects[] = $project;
+            }
+        }
+
+        return $writeableProjects;
+    }
+
     /**
      * Get the project with the given ID
      * @param $projectId
@@ -78,6 +91,7 @@ class ProjectUtilities
     public static function create_project_select($projectId = null, $editable = true)
     {
         $editable ? $disabled = '' : $disabled = 'disabled';
+        // TODO: this should only return projects the user can write
         $userProjects = ProjectUtilities::get_all_user_projects(Session::get("gateway_id"), Session::get('username'));
 
         echo '<select class="form-control" name="project" id="project" required ' . $disabled . '>';
@@ -338,6 +352,7 @@ class ProjectUtilities
         GrouperUtilities::shareResourceWithUsers($projectId, ResourceType::PROJECT, $radd);
         GrouperUtilities::revokeSharingOfResourceFromUsers($projectId, ResourceType::PROJECT, $rrevoke);
 
+        // TODO: get rid of the experiment revocation stuff
         $experiments = ProjectUtilities::get_experiments_in_project($projectId);
 
         foreach ($experiments as $exp) {

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f76343df/app/routes.php
----------------------------------------------------------------------
diff --git a/app/routes.php b/app/routes.php
index a087339..6fc817b 100755
--- a/app/routes.php
+++ b/app/routes.php
@@ -102,7 +102,7 @@ Route::get("experiment/summary", "ExperimentController@summary");
 
 Route::post("experiment/summary", "ExperimentController@expChange");
 
-Route::get("experiment/clone", "ExperimentController@cloneExperiment");
+Route::post("experiment/clone", "ExperimentController@cloneExperiment");
 
 Route::get("experiment/edit", "ExperimentController@editView");
 

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f76343df/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 8236a49..0d7b621 100644
--- a/app/views/partials/experiment-info.blade.php
+++ b/app/views/partials/experiment-info.blade.php
@@ -1,4 +1,9 @@
 {{ HTML::style('css/sharing.css') }}
+<style>
+#experiment-form {
+    margin-bottom: 20px;
+}
+</style>
 <div class="container" style="max-width: 750px;">
     <!--
     @if(isset( $invalidExperimentId ) )
@@ -213,7 +218,7 @@
 
     @if( !isset( $dashboard))
 
-    <form action="{{URL::to('/') }}/experiment/summary" method="post" role="form">
+    <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"])
@@ -238,20 +243,6 @@
                 <span class="glyphicon glyphicon-remove"></span>
                 Cancel
             </a>
-<!--            <input name="clone"-->
-<!--                   type="submit"-->
-<!--                   class="btn btn-primary"-->
-<!--                   value="Clone"-->
-<!--                   title="Create a clone of the experiment. Cloning is the only way to change an experiment's settings-->
-<!--                    after it has been launched.">-->
-            <a href="{{URL::to('/') }}/experiment/clone?expId={{ $experiment->experimentId }}"
-               class="btn btn-primary"
-               role="button"
-               title="Create a clone of the experiment. Cloning is the only way to change an experiment's settings
-                    after it has been launched." target="_blank">
-                <span class="glyphicon glyphicon-pencil"></span>
-                Clone
-            </a>
             <input type="hidden" name="expId" value="{{ Input::get('expId') }}"/>
             <a href="{{URL::to('/') }}/experiment/edit?expId={{ $experiment->experimentId }}&savedExp=true"
                class="btn btn-default"
@@ -272,6 +263,36 @@
             @endif
         </div>
     </form>
+    <div class="panel panel-default">
+        <div class="panel-heading">
+            <h3 class="panel-title">Clone Experiment</h3>
+        </div>
+        <div class="panel-body">
+            <form class="form-inline" action="{{ URL::to('/') }}/experiment/clone" method="post">
+                <input type="hidden" name="expId" value="{{ Input::get('expId') }}"/>
+                <div class="form-group">
+                    <label for="projectId">Project</label>
+                    <select class="form-control" name="projectId" required>
+                        @foreach($writeableProjects as $project)
+                        <option value="{{{ $project->projectID }}}"
+                            @if( $project->projectID == $experiment->projectId)
+                            selected
+                            @endif
+                        >{{{ $project->name }}}</option>
+                        @endforeach
+                    </select>
+                </div>
+
+                <button type="submit"
+                   class="btn btn-primary"
+                   role="button"
+                   title="Create a clone of the experiment. Cloning is the only way to change an experiment's settings after it has been launched.">
+                    <span class="glyphicon glyphicon-pencil"></span>
+                    Clone
+                </a>
+            </form>
+        </div>
+    </div>
     @endif
     <input type="hidden" id="lastModifiedTime" value="{{ $expVal['experimentTimeOfStateChange'] }}"/>