Update tables
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 17 Oct 2019 20:40:03 +0000 (16:40 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 17 Oct 2019 20:40:03 +0000 (16:40 -0400)
Worked on the tables for each section.
Adding functionality to the plugin detail page.
Plugin detail page can now edit the prod_version and dev_version
columns. They'll update the actual database record.

models/admin/ajax/pluginListSites.php
models/admin/ajax/sitePluginUpdate.php [new file with mode: 0644]
models/admin/plugins/plugins.php
setup/validActions.php
views/admin/plugins/index.html
views/admin/plugins/plugin-detail.html
views/admin/plugins/plugins.html
views/admin/plugins/sites.html

index 23b6a45..d5c7235 100644 (file)
@@ -73,12 +73,12 @@ class GlmMembersAdmin_ajax_pluginListSites extends GlmDataSites
 
     public function modelAction( $actionData = false ) {
 
-        // $where  = "T.prod_server = 2"; // norax
-        $where  = "T.prod_server = 1"; // eleusis
+        $where  = "T.prod_server = 2"; // norax
+        // $where  = "T.prod_server = 1"; // eleusis
         $where .= "
             AND T.id IN (SELECT site
                            FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "site_plugins
-                          WHERE plugin = 7)
+                          WHERE plugin = 15)
         ";
 
         $config = array(
diff --git a/models/admin/ajax/sitePluginUpdate.php b/models/admin/ajax/sitePluginUpdate.php
new file mode 100644 (file)
index 0000000..7aeb654
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * PDF Output by admin-ajax
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+require_once GLM_MEMBERS_PLUGINS_PLUGIN_CLASS_PATH.'/data/dataSitePlugins.php';
+/**
+ * Steve Note
+ *
+ * You can get to this using the following URL.
+ *
+ *
+ {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax&glm_action=runQueue
+ *
+ * You should be able to do this as POST or GET and should be able to add and read additional parameters.
+ * I added a "mystuff" parameter to the URL above and it does output from the code in the
+ * modelAction() function below.
+ *
+ * To add another model under models/admin/ajax all you need to do is create it and add it to the
+ * setup/validActions.php file.
+ *
+ */
+
+// Load Members data abstract
+// require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataImages.php';
+
+/**
+ * This class performs the work of handling images passed to it via
+ * an AJAX call that goes through the WorPress AJAX Handler.
+ *
+ */
+class GlmMembersAdmin_ajax_sitePluginUpdate extends GlmDataSitePlugin
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        // Run constructor for members data class
+        parent::__construct( false, false );
+
+    }
+
+    public function modelAction( $actionData = false ) {
+        if ( isset( $_REQUEST['id'] ) && $id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ) ) {
+
+            $return = array(
+                'prodStatus' => false,
+                'devStatus'  => false,
+                'id'         => $id,
+            );
+
+            $this->wpdb->update(
+                $this->table,
+                array(
+                    'prod_version' => $_REQUEST['prodVersion'],
+                    'dev_version'  => $_REQUEST['devVersion']
+                ),
+                array( 'id' => $id ),
+                array( '%s', '%s' ),
+                array( '%d' )
+            );
+            // Get entry.
+            $sitePlugin = $this->getEntry( $id );
+            if ( $sitePlugin ) {
+
+                // Now check to see prod and dev version status are ok or not and return.
+                $latestVersion = $this->wpdb->get_var(
+                    $this->wpdb->prepare(
+                        "SELECT latest_version
+                           FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "plugins
+                          WHERE id = %d",
+                        $sitePlugin['plugin']['value']
+                    )
+                );
+                if ( $latestVersion ) {
+                    if ( $sitePlugin['prod_version'] && version_compare( $latestVersion, $sitePlugin['prod_version'], '>' ) ) {
+                        $return['prodStatus'] = false;
+                    } elseif ( $sitePlugin['prod_version'] )  {
+                        $return['prodStatus'] = true;
+                    }
+                    if ( $sitePlugin['dev_version'] && version_compare( $latestVersion, $sitePlugin['dev_version'], '>' ) ) {
+                        $return['devStatus'] = false;
+                    } elseif ( $sitePlugin['dev_version'] ) {
+                        $return['devStatus'] = true;
+                    }
+                }
+            }
+        }
+
+        echo json_encode( $return );
+
+        exit;
+    }
+}
index 74166f3..9040b68 100644 (file)
@@ -215,7 +215,7 @@ class GlmMembersAdmin_plugins_plugins extends GlmDataPlugins
                 // Find all sites for this plugin.
                 $tData['sites'] = $this->wpdb->get_results(
                     $this->wpdb->prepare(
-                        "SELECT S.name as site_name,S.id,SP.prod_version,SP.dev_version,PS.name as prod_server,DS.name as dev_server
+                        "SELECT S.name as site_name,S.id,SP.id as site_plugin_id,SP.prod_version,SP.dev_version,PS.name as prod_server,DS.name as dev_server
                            FROM " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "site_plugins SP
                                 LEFT OUTER JOIN " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "sites S ON (S.id = SP.site)
                                 LEFT OUTER JOIN " . GLM_MEMBERS_PLUGINS_PLUGIN_DB_PREFIX . "servers PS ON (PS.id = S.prod_server)
index 7798060..fd1f4e7 100644 (file)
 $glmMemberPluginsAddOnValidActions = array(
     'adminActions' => array(
         'ajax' => array(
-            'pluginListSites' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
+            'pluginListSites'  => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
+            'sitePluginUpdate' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
         ),
         'plugins' => array(
-            'index' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
+            'index'   => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
             'plugins' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
             'sites'   => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
             'servers' => GLM_MEMBERS_PLUGINS_PLUGIN_SLUG,
index f996296..7b348df 100644 (file)
     </div>
 </div>
 
+<div class="grid-x grid-margin-x">
+    <div class="cell small-12 medium-3">
+        <input type="text" id="filter-value" placeholder="Search">
+    </div>
+    <div class="cell small-12 medium-4">
+        <button id="filter-clear" class="button primary">Clear</button>
+    </div>
+</div>
 <div id="dashboard-plugins"></div>
 
 <script>
         ];
 
         {literal}
+
+        function updateFilter(){
+            table.setFilter( 'name', 'like', $('#filter-value').val() );
+        }
+
+        $('#filter-value').keyup(updateFilter);
+
+        // Clear filter on "Clear" button click
+        $('#filter-clear').on( 'click', function(){
+            $('#filter-value').val('');
+            table.clearFilter();
+        } );
+
         var table = new Tabulator("#dashboard-plugins",{
             height: "350px",
             data: tabledata,
index fdec3bf..d8f5ef1 100644 (file)
 
 {* Grid End *}
 {include file='ui/f6/grid-end.html'}
-
+{debug}
 <script>
     jQuery(document).ready(function($){
         $(document).foundation();
         var tabledata = [
             {foreach $sites as $site}
-                { id:"{$site.id}", name:"{$site.site_name|escape:'quotes'}",
+                { id:"{$site.site_plugin_id}", siteId: "{$site.id}", name:"{$site.site_name|escape:'quotes'}",
                 prodServer: "{$site.prod_server}", prodVersion: "{$site.prod_version}",
                 prodUpToDate: {if !empty($site.prod_version) && version_compare( $plugin.fieldData.latest_version, $site.prod_version, '>' )}false{elseif !empty($site.prod_version)}true{else}null{/if},
                 devServer: "{$site.dev_server}", devVersion: "{$site.dev_version}",
         ];
 
         {literal}
+        function updateVersion( cell ) {
+            if ( cell == undefined ) {
+                console.log('ERROR');
+                return false;
+            }
+            // Get data from row.
+            var data = cell.getRow().getData();
+            // Call ajax page to update the sitePlugin record.
+            $.ajax({
+                cache: false,
+                url: '{/literal}{$ajaxUrl}{literal}?action=glm_members_admin_ajax&glm_action=sitePluginUpdate',
+                data: data,
+                dataType: 'json',
+            }).done(function( rsp ){
+                console.log( 'return: ', rsp );
+                table.updateData([{id: rsp.id, prodUpToDate: rsp.prodStatus, devUpToDate: rsp.devStatus}]);
+            });
+        }
+
         var table = new Tabulator("#siteList",{
             height: "350px",
             data: tabledata,
             columns:[
                 {title:"Site Name", field:"name", width:"250"},
                 {title:"Prod Server", field:"prodServer", align:"left"},
-                {title:"Prod Version", field:"prodVersion", align:"left", editor:true, cellEdited: function(cell){
-                    console.log('Edit: ', cell );
-                }},
+                {title:"Prod Version", field:"prodVersion", align:"left", editor:true, cellEdited: updateVersion },
                 {title:"Status", field:"prodUpToDate", formatter:"tickCross"},
                 {title:"Dev Server", field:"devServer", align:"left"},
-                {title:"Dev Version", field:"devVersion", align:"left", editor: true},
+                {title:"Dev Version", field:"devVersion", align:"left", editor: true, cellEdited: updateVersion },
                 {title:"Status", field:"devUpToDate", formatter:"tickCross"},
             ],
             rowClick:function(e, row){
                 console.log('Row ' + row.getData().id + ' Clicked!!!');
-                window.location.href="{/literal}{$baseUrl}&option=pluginSite{if !empty($smarty.request.order)}&order={$smarty.request.order}{/if}&site_id={literal}" + row.getData().id;
+                window.location.href="{/literal}{$baseUrl}&option=pluginSite{if !empty($smarty.request.order)}&order={$smarty.request.order}{/if}&site_id={literal}" + row.getData().siteId;
             }
         });
         {/literal}
index 06b0e4d..28e4ce8 100644 (file)
 
 </table>
 
+<div class="grid-x grid-margin-x">
+    <div class="cell small-12 medium-4">
+        <input type="text" id="filter-value" placeholder="Search">
+    </div>
+    <div class="cell small-12 medium-4">
+        <button id="filter-clear" class="button primary">Clear</button>
+    </div>
+</div>
 <div id="pluginList"></div>
 
 <script>
             {/foreach}
         ];
         {literal}
+
+        function updateFilter(){
+            table.setFilter( 'name', 'like', $('#filter-value').val() );
+        }
+
+        $('#filter-value').keyup(updateFilter);
+
+        // Clear filter on "Clear" button click
+        $('#filter-clear').on( 'click', function(){
+            $('#filter-value').val('');
+            table.clearFilter();
+        } );
+
         var table = new Tabulator("#pluginList",{
             height: "350px",
             data: tabledata,
index 9909bf0..d413530 100644 (file)
 
 </table>
 
+<div class="grid-x grid-margin-x">
+    <div class="cell small-12 medium-3">
+        <input type="text" id="filter-value" placeholder="Search">
+    </div>
+    <div class="cell small-12 medium-4">
+        <button id="filter-clear" class="button primary">Clear</button>
+    </div>
+</div>
 <div id="siteList"></div>
 
 <script>
         ];
 
         {literal}
+
+        function updateFilter(){
+            table.setFilter( 'name', 'like', $('#filter-value').val() );
+        }
+
+        $('#filter-value').keyup(updateFilter);
+
+        // Clear filter on "Clear" button click
+        $('#filter-clear').on( 'click', function(){
+            $('#filter-value').val('');
+            table.clearFilter();
+        } );
+
         var table = new Tabulator("#siteList",{
             height: "350px",
             data: tabledata,
             addRowPos: "top",
             initialSort: [ {column: "name", dir: "asc"} ],
             columns:[
-                {title:"Site Name", field:"name", width:"350", headerFilter: true},
+                {title:"Site Name", field:"name", width:"350"},
                 {title:"Prod Url", field:"prodUrl", align:"left"},
                 {title:"Dev Url", field:"devUrl", align:"left"},
             ],
             rowClick:function(e, row){
                 console.log('Row ' + row.getData().id + ' Clicked!!!');
                 window.location.href="{/literal}{$thisUrl}?page={$thisPage}&glm_action={$thisAction}&option=view&site_id={literal}" + row.getData().id;
-            }
+            },
+            initialFilter: [
+                {field:"name", type:"like", value:""}
+            ]
         });
         {/literal}
     });