فهرست منبع

working on edit function, working out the bugs

alexgl 13 سال پیش
والد
کامیت
ba88f6c58c
3فایلهای تغییر یافته به همراه116 افزوده شده و 94 حذف شده
  1. 2 1
      base/tripal_core/tripal_core.info
  2. 57 56
      base/tripal_core/tripal_core.module
  3. 57 37
      base/tripal_core/tripal_views_integration.inc

+ 2 - 1
base/tripal_core/tripal_core.info

@@ -6,4 +6,5 @@ project = tripal_core
 package = Tripal
 version = 6.x-0.3.1b
 
-dependencies = views
+dependencies[] = views
+dependencies[] = ahah_helper

+ 57 - 56
base/tripal_core/tripal_core.module

@@ -31,7 +31,7 @@ function tripal_core_init(){
    // variable is always set.  In the case where a view needs to query the
    // chado schema when it is local to the Drupal database.  Otherwise the
    // search_path isn't set.  When tripal_db_set_active is called it
-   // automatically sets the serach path if chado is local to the 
+   // automatically sets the serach path if chado is local to the
    // Drupal database
    $previous = tripal_db_set_active('chado');
    tripal_db_set_active($previous);
@@ -43,11 +43,11 @@ function tripal_core_init(){
       if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
          $results = db_query("INSERT INTO {cv} (name,definition) ".
     	                     "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
-      } 
+      }
       if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
-         $results = db_query("INSERT INTO {db} (name,description) ". 
+         $results = db_query("INSERT INTO {db} (name,description) ".
 	                        "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
-      }  
+      }
       tripal_db_set_active($previous_db);  // now use drupal database
    }
 
@@ -56,8 +56,8 @@ function tripal_core_init(){
    $theme_dir = drupal_get_path('theme', 'tripal');
    $clean_urls  = variable_get('clean_url', 0);
    drupal_add_js("
-      var baseurl = '$base_url'; 
-      var themedir = '$theme_dir'; 
+      var baseurl = '$base_url';
+      var themedir = '$theme_dir';
       var isClean = $clean_urls;",'inline');
 
    // make sure the date time settings are the way Tripal will insert them
@@ -123,7 +123,7 @@ function tripal_core_menu() {
      'page callback' => 'tripal_toggle_box_menu',
      'page arguments' => array(1,2,3),
      'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT 
+     'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
    );
    $items['admin/tripal/chado_1_11_install'] = array(
      'title' => 'Install Chado v1.11',
@@ -179,47 +179,39 @@ function tripal_core_menu() {
      'access arguments' => array('access administration pages'),
      'type' => MENU_CALLBACK,
    );
-	$items['admin/tripal/views/integration'] = array(
-    'title' => t('Drupal Views Integration'),
-    'description' => t('Allows you to select existing materialized views and provide details for integration with Drupal Views.'),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_core_views_integration_admin_form'),
-    'access arguments' => array('manage tripal_views_integration'),
-    'type' => MENU_NORMAL_ITEM,
-	);
-	$items['admin/tripal/views/integration/mviews'] = array(
-    'title' => t('Integrated MViews'),
-    'description' => t('Allows you to select existing materialized views and provide details for integration with Drupal Views.'),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_core_views_integration_admin_form'),
-    'access arguments' => array('manage tripal_views_integration'),
-    'type' => MENU_NORMAL_ITEM,
-	);
-	
-// 	$items['admin/tripal/views/integration/edit_form'] = array(
-//     'title' => 'My redirected path', 
-//     'page callback' => 'drupal_goto', 
-//     'page arguments' => array('tripal_core_views_integration_new_setup_form'), 
-//     'access arguments' => array('access administration pages'),
-//     'type' => MENU_CALLBACK, 
+// 	$items['admin/tripal/views/integration'] = array(
+//     'title' => t('Drupal Views Integration'),
+//     'description' => t('Allows you to select existing materialized views and provide details for integration with Drupal Views.'),
+//     'page callback' => 'drupal_get_form',
+//     'page arguments' => array('tripal_core_views_integration_admin_form'),
+//     'access arguments' => array('manage tripal_views_integration'),
+//     'type' => MENU_NORMAL_ITEM,
 // 	);
 
-	//page to actually create setup->mview->chado table relationships
-	$items['admin/tripal/views/integration/mviews/new'] = array(
-     'title' => 'Add an MView',
-     'page callback' => 'drupal_get_form',
-     'page arguments' => array('tripal_core_views_integration_new_setup_form'),
-     'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
-     'type' => MENU_NORMAL_ITEM,
-	);
+// 	$items['admin/tripal/views/integration/mviews'] = array(
+//     'title' => t('Integrated MViews'),
+//     'description' => t('Allows you to select existing materialized views and provide details for integration with Drupal Views.'),
+//     'page callback' => 'drupal_get_form',
+//     'page arguments' => array('tripal_core_views_integration_admin_form'),
+//     'access arguments' => array('manage tripal_views_integration'),
+//     'type' => MENU_NORMAL_ITEM,
+// 	);
 	
-	$items['admin/tripal/views/integration/mviews/edit/%'] = array(
-	     'title' => 'Add an MView',
-	     'page callback' => 'drupal_get_form',
-	     'page arguments' => array('tripal_core_views_integration_new_setup_form', 6),
-	     'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
-	     'type' => MENU_NORMAL_ITEM,
-	);
+// 	$items['admin/tripal/views/integration/mviews/new'] = array(
+//      'title' => 'Add an MView',
+//      'page callback' => 'drupal_get_form',
+//      'page arguments' => array('tripal_core_views_integration_new_setup_form'),
+//      'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
+//      'type' => MENU_NORMAL_ITEM,
+// 	);
+	
+// 	$items['admin/tripal/views/integration/mviews/edit/%'] = array(
+//      'title' => 'Edit MView Integration',
+//      'page callback' => 'drupal_get_form',
+//      'page arguments' => array('tripal_core_views_integration_new_setup_form', 6),
+//      'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
+//      'type' => MENU_NORMAL_ITEM,
+// 	);
 
 	$items['admin/tripal/views/integration/chado'] = array(
     'title' => t('Integrated Chado Table'),
@@ -233,9 +225,18 @@ function tripal_core_menu() {
      'title' => 'Add a Chado table',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('tripal_core_views_integration_new_setup_form'),
-     'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
+     'access arguments' => array('manage tripal_views_integration'), //TODO: What is this item supposed to be?
      'type' => MENU_NORMAL_ITEM,
 	);
+
+	$items['admin/tripal/views/integration/chado/edit/%'] = array(
+	     'title' => 'Edit MView Integration',
+	     'page callback' => 'drupal_get_form',
+	     'page arguments' => array('tripal_core_views_integration_new_setup_form', 6),
+	     'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
+	     'type' => MENU_NORMAL_ITEM,
+	);
+
   return $items;
 }
 
@@ -259,7 +260,7 @@ function tripal_core_perm(){
  *   The name of the database to switch to as indicated in settings.php
  *   Should be either default or chado
  *
- * @return 
+ * @return
  *   The name of the previously set database
  *
  * @ingroup tripal_chado_api
@@ -267,12 +268,12 @@ function tripal_core_perm(){
 function tripal_core_is_chado_installed(){
    global $db_url, $db_type;
 
-   // first check if chado is in the db_url of the 
+   // first check if chado is in the db_url of the
    // settings.php file
-   if(is_array($db_url)){ 
+   if(is_array($db_url)){
       if(isset($db_url['chado'])){
          return true;
-      } 
+      }
    }
    // check to make sure the chado schema exists
    $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
@@ -290,7 +291,7 @@ function tripal_core_is_chado_installed(){
  *  views integration code is
  *
  * @ingroup tripal_core
- */ 
+ */
 function tripal_core_views_api() {
    return array(
       'api' => 2.0,
@@ -303,7 +304,7 @@ function tripal_core_views_api() {
  * @ingroup tripal_core
  */
 function tripal_core_theme () {
-   return array(      
+   return array(
       'tripal_core_job_view' => array (
          'arguments' => array('job_id'=> null),
          'template' => 'tripal_core_job_view',
@@ -323,18 +324,18 @@ function tripal_core_job_describe_args($callback,$args){
    if($callback == 'tripal_update_mview'){
       // get this mview details
       $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
-      $mview = db_fetch_object(db_query($sql,$args[0]));     
+      $mview = db_fetch_object(db_query($sql,$args[0]));
       $new_args['View Name'] = $mview->name;
    }
    return $new_args;
 }
 
 // this is just a wrapper for backwards compatibility with a naming mistake.
-// it can go away in the future as it only is useful for jobs created by v0.3b 
-function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0, 
+// it can go away in the future as it only is useful for jobs created by v0.3b
+function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0,
    $update = 0, $refresh = 0, $remove = 0, $job = NULL)
 {
-   tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only, 
+   tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only,
       $update, $refresh, $remove, $job);
 }
 

+ 57 - 37
base/tripal_core/tripal_views_integration.inc

@@ -91,18 +91,12 @@ function tripal_core_views_integration_admin_form(){
     '#prefix' => theme('table', $header, $rows),
   );
 
-  $form['submit'] = array(
+  $form['button']['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Remove'),
   	'#submit' => array('tripal_core_views_integration_admin_form_submit'),
   );
   
-//   $form[''] = array(
-//     '#type' => 'submit',
-//     '#value' => 'Edit',
-//     '#submit' => array('tripal_core_views_integration_admin_edit_form_submit'),
-//   );
-  
   $form['button']['edit_form'] = array(
     '#type' => 'submit',
     '#value' => t('Edit'),
@@ -111,7 +105,7 @@ function tripal_core_views_integration_admin_form(){
 
   $form['new'] = array(
     '#type' => 'markup',
-    '#value' => l(t(' Add a New MView'), 'admin/tripal/views/integration/mviews/new'),
+    '#value' => l(t(' Add a New MView'), 'admin/tripal/views/integration/chado/new'),
   );
 
   return $form;
@@ -122,8 +116,9 @@ function tripal_core_views_integration_admin_form(){
 function tripal_core_views_integration_admin_edit_form_submit($form, &$form_state) {
 	$form_state['rebuild'] = FALSE;
 	unset($form_state['storage']);
-// 	$form_state['redirect'] = 'admin/tripal/views/integration/edit_form';
-	$form_state['redirect'] = 'admin/tripal/views/integration/mviews/edit/'. $form['existing_rows']['#options'][$form_state['values']['existing_rows']];
+	$form_state['redirect'] = 'admin/tripal/views/integration/chado/edit/'. $form['existing_rows']['#options'][$form_state['values']['existing_rows']];
+// 	$form_state['redirect'] = 'admin';
+// 	$form_state['redirect'] = 'admin/tripal/views/integration/mview/new';
 	return $form_state;
 }
 /**
@@ -142,18 +137,9 @@ function tripal_core_views_integration_admin_form_submit($form, &$form_state){
  */
 
 function tripal_core_views_integration_new_setup_form(&$form_state, $setup_id = NULL){
-	$setup_id = $setup_id['0'];
-	if(isset($setup_id)){
-		$setup_obj = db_fetch_object(db_query("SELECT * FROM {tripal_views_integration} WHERE setup_id = '$setup_id';"));
-		$mview_id = $setup_obj->mview_id;
-		$form_state['storage']['mview_id'] = $mview_id;
-		$column_query = db_query("SELECT * FROM {tripal_mviews_join} WHERE setup_id = '$setup_id';");
-		$mview_joins = array();
-		while ($mviews_join = db_fetch_object($column_query)){
-			$mview_joins[] = $mviews_join;
-		}
-
-	}
+  
+  
+
   $form = array();
 
   $data = array();
@@ -162,7 +148,37 @@ function tripal_core_views_integration_new_setup_form(&$form_state, $setup_id =
 
   //ahah_helper requires this to register the form with it's module
   ahah_helper_register($form, $form_state);
+  
+
+
+  $setup_id = $setup_id['0'];
+  if(isset($setup_id)){
 
+    
+    
+    
+    
+    $setup_obj = db_fetch_object(db_query("SELECT * FROM {tripal_views_integration} WHERE setup_id = '$setup_id';"));
+    $mview_id = $setup_obj->mview_id;
+    $form_state['storage']['mview_id'] = $mview_id;
+    $column_query = db_query("SELECT * FROM {tripal_mviews_join} WHERE setup_id = '$setup_id';");
+    $mview_joins = array();
+    while ($mviews_join = db_fetch_object($column_query)){
+      $mview_joins[] = $mviews_join;
+    }
+  
+    dpm($form_state,'formstate');
+    if(!isset($form_state['storage']['mview_id'])){
+      $form_state['storage']['mview_id'] = $setup_obj->mview_id;
+    }
+  }
+  else{
+    $form['hidden_edited'] = array(
+      '#type' => 'hidden',
+      '#value' => FALSE,
+    );
+  }
+  
   // field for the name of the
   $form['row_name'] = array(
     '#title' => t('Name'),
@@ -228,9 +244,7 @@ function tripal_core_views_integration_new_setup_form(&$form_state, $setup_id =
 
   if ($form_state['storage']['mview_id']){
 
-  	if(!isset($mview_id)){
     	$mview_id = $form_state['storage']['mview_id'];
-  	}
   	
     $form['view_setup_table'] = array(
      '#type' => 'fieldset',
@@ -262,7 +276,7 @@ function tripal_core_views_integration_new_setup_form(&$form_state, $setup_id =
     $handlers_fields = array();
     $handlers_filters = array();
     
-    $handlers_fields[] = "Select a Field Handler"; 
+    $handlers_fields[] = "Select a Field Handler";
     $handlers_filters[] = "Select a Filter Handler";
     foreach($all_handlers as $handler){
        if(preg_match("/views_handler_field/",$handler)){
@@ -332,12 +346,9 @@ function tripal_core_views_integration_new_setup_form(&$form_state, $setup_id =
         '#suffix' => "</div></div>",
         '#options' => $columns,
         '#required' => FALSE,
-      );      
-      $column_name = $mview_joins["$p"]->view_column;
-      $default_handlers = db_fetch_object(db_query("SELECT handler_filter, handler_field FROM {tripal_views_handlers} WHERE setup_id = '$setup_id' AND column_name = '$column_name';"));
-    	$default_field_handler = array_keys($handlers_fields, $default_handlers->handler_field, TRUE);
-    	$default_field_handler = $default_field_handler[0];
-    	
+      );
+      
+      
       $form['view_setup_table']["fields_field_handler_$mview_id-$i"] = array(
          '#type' => 'select',
          '#prefix' => "<div class=\"column-two\">".
@@ -345,20 +356,29 @@ function tripal_core_views_integration_new_setup_form(&$form_state, $setup_id =
          '#suffix' => "</div>",
          '#options' => $handlers_fields,
          '#required' => FALSE,
-         '#default_value' => $default_field_handler,
       );
       
-      $default_filter_handler = array_keys($handlers_filters, $default_handlers->handler_filter, TRUE);
-      $default_filter_handler = $default_filter_handler['0'];
+
       $form['view_setup_table']["fields_filter_handler_$mview_id-$i"] = array(
         '#type' => 'select',
         '#prefix' => "<div class=\"fields-filter-handler\">",
         '#suffix' => "</div></div>",
         '#options' => $handlers_filters,
         '#required' => FALSE,
-      	'#default_value' => $default_filter_handler,
       );
       
+      if(isset($setup_id)){
+        $column_name = $mview_joins["$p"]->view_column;
+        $default_handlers = db_fetch_object(db_query("SELECT handler_filter, handler_field FROM {tripal_views_handlers} WHERE setup_id = '$setup_id' AND column_name = '$column_name';"));
+        $default_field_handler = array_keys($handlers_fields, $default_handlers->handler_field, TRUE);
+        $default_field_handler = $default_field_handler[0];
+        $form['view_setup_table']["fields_field_handler_$mview_id-$i"]['#default_value'] = $default_field_handler;
+        
+        $default_filter_handler = array_keys($handlers_filters, $default_handlers->handler_filter, TRUE);
+        $default_filter_handler = $default_filter_handler['0'];
+        $form['view_setup_table']["fields_filter_handler_$mview_id-$i"]['#default_value'] = $default_filter_handler;
+      }
+      
       $form['view_setup_table']["fields_end_$i"] = array(
         '#type' => 'markup',
         '#value' => "</div></div>",
@@ -459,9 +479,9 @@ function tripal_core_views_integration_discover_handlers() {
      }
    }
 
-   // these handlers are hard coded because I could not 
+   // these handlers are hard coded because I could not
    // get the views_views_handlers() function to be called
-   // in the code above.  However, we will be creating 
+   // in the code above.  However, we will be creating
    // Chado wrappers for many of these and once that work
    // is done these will no longer be needed.