فهرست منبع

Completed the administrative interface to configure other Tripal sites

Chun-Huai Cheng 8 سال پیش
والد
کامیت
a2dc7d09a2
4فایلهای تغییر یافته به همراه281 افزوده شده و 46 حذف شده
  1. 1 6
      tripal_chado/includes/tripal_chado.semweb.inc
  2. 248 34
      tripal_ws/includes/tripal_ws.admin.inc
  3. 7 3
      tripal_ws/tripal_ws.install
  4. 25 3
      tripal_ws/tripal_ws.module

+ 1 - 6
tripal_chado/includes/tripal_chado.semweb.inc

@@ -521,12 +521,7 @@ function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
       'rows' => $rows,
     ));
     $form['table'] = array(
-      '#markup' => $output,
-      '#title' => 'Table',
-      '#description' => t('Please provide any filters for limiting
-        the records. Only those that match the filters specified
-        below will be published.  To publish all records of this
-        type, leave all filters blank.'),
+      '#markup' => $output
     );
   }
 

+ 248 - 34
tripal_ws/includes/tripal_ws.admin.inc

@@ -6,55 +6,269 @@
  * @param unknown $form_state
  */
 function tripal_ws_tripal_sites_form($form, &$form_state) {
+
   $form = array();
   $values = key_exists('values', $form_state) ? $form_state['values'] : NULL;
   $tripal_site = $values ? $values['tripal_site'] : 0;
   
-  $sites = array('Select a Tripal site', 'Add a Tripal site');
-  $form['tripal_site'] = array(
-    '#type' => 'select',
-    '#description' => 'Make change to an existing Tripal site',
-    '#options' => $sites,
-    '#default_value' => $tripal_site,
-    '#ajax' => array(
-      'callback' => "tripal_ws_tripal_sites_form_ajax_callback",
-      'wrapper' => "tripal-ws-tripal_sites-form",
-      'effect' => 'fade',
-      'method' => 'replace'
-    ),
-  );
-  
-  // Add/Edit a new tripal site
-  if ($tripal_site != 0) {
-    $form['tripal_site_info']['name'] = array(
-      '#title' => t('Name of Site'),
-      '#type' => 'textfield'
-    );
-    $form['tripal_site_info']['url'] = array(
-      '#title' => t('URL'),
-      '#type' => 'textfield'
-    );
-    $form['tripal_site_info']['description'] = array(
-      '#title' => t('Description'),
-      '#type' => 'textfield'
+  $results = 
+    db_select('tripal_sites', 'ts')
+      ->fields('ts')
+      ->execute();
+  $headers = array('Name', 'URL', 'Version', 'Description', 'Action');
+  $rows = array();
+  while ($site = $results->fetchObject()) {
+    $rows[] = array(
+      $site->name,
+      $site->url,
+      $site->version,
+      $site->description,
+      array(
+        'data' => l('Edit', '/admin/tripal/storage/ws/tripal_sites/edit/' . $site->id) . ' | ' .
+        l('Remove', '/admin/tripal/storage/ws/tripal_sites/remove/' . $site->id),
+        'nowrap' => TRUE,
+      ),
     );
-    $form['submit_button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Save'),
-      '#name' => 'save'
+  }
+  if (count($rows) == 0) {
+    $rows[] = array('No configured Tripal site.', array('colspan' => 5));
+  }
+  $output = theme('table', array(
+      'header' => $headers,
+      'rows' => $rows,
+    ));
+    $form['table'] = array(
+      '#markup' => $output
     );
+  
+  return $form;
+}
+
+/**
+ * Provide form to add/edit a Tripal site
+ *
+ * @param unknown $form
+ * @param unknown $form_state
+ */
+function tripal_ws_tripal_sites_edit_form($form, &$form_state, $tripal_site_id = NULL) {
+  $id = NULL;
+  $name = '';
+  $url = '';
+  $version = '';
+  $description = '';
+  if ($tripal_site_id) {
+    $site = db_select('tripal_sites', 'ts')
+      ->fields('ts')
+      ->condition('id', $tripal_site_id)
+      ->execute()
+      ->fetchObject();
+    if (is_object($site)) {
+      $id = $site->id;
+      $name = $site->name;
+      $url = $site->url;
+      $version = $site->version;
+      $description = $site->description;
+    }
   }
+  $form = array();
+  $form['tripal_site_info']['id'] = array(
+    '#type' => 'hidden',
+    '#value' => $id,
+  );
+  $form['tripal_site_info']['name'] = array(
+    '#title' => t('Name'),
+    '#type' => 'textfield',
+    '#description' => t('Full name of the Tripal site.'),
+    '#default_value' => $name,
+    '#required' => TRUE
+  );
+  $form['tripal_site_info']['url'] = array(
+    '#title' => t('URL'),
+    '#type' => 'textfield',
+    '#description' => t('The URL of the Tripal site.'),
+    '#default_value' => $url,
+    '#required' => TRUE
+  );
+  $form['tripal_site_info']['version'] = array(
+    '#title' => t('Version'),
+    '#type' => 'textfield',
+    '#description' => t('Web services version used by the Tripal site.'),
+    '#default_value' => $version,
+  );
+  $form['tripal_site_info']['description'] = array(
+    '#title' => t('Description'),
+    '#type' => 'textarea',
+    '#default_value' => $description,
+  );
+
+  $form['submit_button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#name' => 'save'
+  );
+  $form['cancel_button'] = array(
+    '#type' => 'button',
+    '#value' => t('Cancel'),
+    '#name' => 'cancel_button',
+    '#limit_validation_errors' => array()
+  );
   
-  $form['#prefix'] = '<div id="tripal-ws-tripal_sites-form">';
-  $form['#suffix'] = '</div>';
   return $form;
 }
 
+/**
+ * Implements hook_validate()
+ *
+ * @param unknown $form
+ * @param unknown $form_state
+ */
+function tripal_ws_tripal_sites_edit_form_validate($form, &$form_state) {
+  if (array_key_exists('clicked_button', $form_state)) {
+    if ($form_state['clicked_button']['#name'] =='cancel_button') {
+      drupal_goto('/admin/tripal/storage/ws/tripal_sites');
+    }
+    // Make sure URL does not already exist when adding a new site (which has no 'id')
+    else if ($form_state['clicked_button']['#name'] =='save' && !$form_state['values']['id']) {
+      $url = $form_state['values']['url'];
+      $check =
+      db_select('tripal_sites', 'ts')
+      ->fields('ts', array('id'))
+      ->condition('url', $url)
+      ->execute()
+      ->fetchField();
+      if ($check) {
+        form_set_error('url', t('The URL already exists.'));
+      }
+    }
+  }
+}
 
+/**
+ * Implements hook_submit()
+ *
+ * @param unknown $form
+ * @param unknown $form_state
+ */
+function tripal_ws_tripal_sites_edit_form_submit($form, &$form_state) {
+  $id = $form_state['values']['id'];
+  $name = $form_state['values']['name'];
+  $url = $form_state['values']['url'];
+  $version = $form_state['values']['version'];
+  $description = $form_state['values']['description'];
+  // If there is an 'id' do an update, otherwise do an insert
+  if ($id) {
+    db_update('tripal_sites')
+    ->fields(array(
+      'name' => $name,
+      'url' => $url,
+      'version' => $version,
+      'description' => $description
+    ))
+    ->condition('id', $id)
+    ->execute();
+    drupal_set_message(t('Tripal site \'' . $name . '\' has been updated.'));
+  }
+  else {
+    db_insert('tripal_sites')
+      ->fields(array(
+          'name' => $name,
+          'url' => $url,
+          'version' => $version,
+          'description' => $description
+        ))
+        ->execute();
+    drupal_set_message(t('Tripal site \'' . $name . '\' has been added.'));
+  }
+  drupal_goto('/admin/tripal/storage/ws/tripal_sites');
+}
 
 /**
+ * Implements hook_form()
+ * Reset term used by semantic web
  *
+ * @param $form
+ * @param $form_state
+ * @param $table
+ * @param $column
+ * @return $form
  */
-function tripal_ws_tripal_sites_form_ajax_callback($form, $form_state) {
+function tripal_ws_tripal_sites_remove_form($form, &$form_state, $id = NULL) {
+  $name = '';
+  $record_id = '';
+  if ($id) {
+    $site = db_select('tripal_sites', 'ts')
+    ->fields('ts')
+    ->condition('id', $id)
+    ->execute()
+    ->fetchObject();
+    if (is_object($site)) {
+      $record_id = $site->id;
+      $name = $site->name;
+    }
+  }
+  $form['confirmation'] = array(
+    '#markup' => 'Really remove the \'' . $name . '\' Tripal site? ',
+  );
+  $form['tripal_site_id'] = array(
+    '#type' => 'value',
+    '#value' => $record_id
+  );
+  $form['tripal_site_name'] = array(
+    '#type' => 'value',
+    '#value' => $name
+  );
+
+  $form['submit_button'] = array(
+    '#type' => 'submit',
+    '#value' => t('Remove'),
+    '#name' => 'remove'
+  );
+
+  $form['cancel_button'] = array(
+    '#type' => 'button',
+    '#value' => t('Cancel'),
+    '#name' => 'cancel_button',
+    '#limit_validation_errors' => array()
+  );
+
   return $form;
+}
+
+/**
+ * Implements hook_form_validate()
+ *
+ * Validate function for resetting the semantic web term
+ *
+ * @param unknown $form
+ * @param unknown $form_state
+ */
+function tripal_ws_tripal_sites_remove_form_validate($form, &$form_state) {
+  if (array_key_exists('clicked_button', $form_state)) {
+    if ($form_state['clicked_button']['#name'] =='cancel_button') {
+      drupal_goto('/admin/tripal/storage/ws/tripal_sites');
+    }
+    else if (!$form_state['values']['tripal_site_id']) {
+      drupal_set_message(t('Invalid Tripal site id'), 'error');
+    }
+  }
+}
+
+/**
+ * Implements hook_form_submit()
+ *
+ * Submit function for editing the semantic web term
+ *
+ * @param unknown $form
+ * @param unknown $form_state
+ */
+function tripal_ws_tripal_sites_remove_form_submit($form, &$form_state) {
+  $id = $form_state['values']['tripal_site_id'];
+  $name = $form_state['values']['tripal_site_name'];
+  if ($id) {
+    db_delete('tripal_sites')
+      ->condition('id', $id)
+      ->execute();
+    drupal_set_message('The Tripal site \'' .$name . '\' has been removed.');
+  }    
+  drupal_goto('/admin/tripal/storage/ws/tripal_sites');
 }

+ 7 - 3
tripal_ws/tripal_ws.install

@@ -38,18 +38,22 @@ function tripal_ws_tripal_sites_schema() {
         'length' => 255,
         'not null' => TRUE,
       ),
-      'description' => array(
-        'description' => 'The description of the Tripal site.',
+      'version' => array(
+        'description' => 'The web services version of the Tripal site.',
         'type' => 'varchar',
         'length' => 255,
       ),
+      'description' => array(
+        'description' => 'The description of the Tripal site.',
+        'type' => 'text'
+      ),
     ),
     'indexes' => array(
       'name' => array('name'),
       'url' => array('url'),
       'description' => array('description'),
     ),
-    'unique keys' => array('name' => array('name')),
+    'unique keys' => array('url' => array('url')),
     'primary key' => array('id'),
   );
   return $schema;

+ 25 - 3
tripal_ws/tripal_ws.module

@@ -38,16 +38,16 @@ function tripal_ws_menu() {
   );
 
   // Tripal Web Services setting groups
-  $items['admin/tripal/ws'] = array(
+  $items['admin/tripal/storage/ws'] = array(
     'title' => 'Web Services',
-    'description' => t("Exchange data between Tripal sites using the web services."),
+    'description' => t("Import data from other Tripal sites using the web services."),
     'weight' => 20,
     'page callback' => 'system_admin_menu_block_page',
     'access arguments' => array('administer tripal'),
     'file' => 'system.admin.inc',
     'file path' => drupal_get_path('module', 'system'),
   );
-  $items['admin/tripal/ws/tripal_sites'] = array(
+  $items['admin/tripal/storage/ws/tripal_sites'] = array(
     'title' => 'Other Tripal Sites',
     'description' => t('Provides information about other Tripal sites.
         This allows data exchange and communication betwen Tripal
@@ -60,6 +60,28 @@ function tripal_ws_menu() {
     'file' => 'includes/tripal_ws.admin.inc',
     'file path' => drupal_get_path('module', 'tripal_ws'),
   );
+  $items['admin/tripal/storage/ws/tripal_sites/edit'] = array(
+    'title' => 'Add Tripal Site',
+    'description' => 'Add a Tripal site',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_ws_tripal_sites_edit_form'),
+    'access arguments' => array('administer tripal'),
+    'file' =>  'includes/tripal_ws.admin.inc',
+    'file path' => drupal_get_path('module', 'tripal_ws'),
+    'type' => MENU_LOCAL_ACTION,
+    'weight' => 2
+  );
+  $items['admin/tripal/storage/ws/tripal_sites/remove/%'] = array(
+    'title' => 'Remove Tripal Site',
+    'description' => 'Remove a Tripal site',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_ws_tripal_sites_remove_form', 6),
+    'access arguments' => array('administer tripal'),
+    'file' =>  'includes/tripal_ws.admin.inc',
+    'file path' => drupal_get_path('module', 'tripal_ws'),
+    'type' => MENU_CALLBACK,
+    'weight' => 2
+  );
   return $items;
 }