Plugin Directory

Changeset 1524886


Ignore:
Timestamp:
10/30/2016 04:48:01 PM (9 years ago)
Author:
AeonOfTime
Message:
  • Fixed an error when importing an EFT XML file
  • Made the EFT fitting visibility toggle-able in the list by double-clicking the icon
  • Improved the internal handling of Ajax calls for future features
Location:
eve-shipinfo/trunk
Files:
8 added
11 edited

Legend:

Unmodified
Added
Removed
  • eve-shipinfo/trunk/classes/EVEShipInfo.php

    r1515401 r1524886  
    4242    const ERROR_COULD_NOT_CREATE_SQL_STRUCTURE = 1303;
    4343   
     44    const ERROR_CANNOT_FIND_CLASS_FILE = 1304;
     45   
    4446   /**
    4547    * The name of the request variable which is used to
     
    9799         
    98100        add_action('init', array($this, 'handle_init'));
    99         add_action('wp_ajax_eveshipinfo_checkforupdate', array($this, 'ajax_checkForUpdate'));
     101
     102        $this->handle_initAJAXMethods();
     103       
    100104        add_action('admin_init', array($this, 'handle_initPluginSettings'));
    101105        add_action('admin_menu', array($this, 'handle_initAdminMenu'));
     
    106110   
    107111   /**
    108     * Ajax handler for fetching the database version from the project homepage.
    109     */
    110     public function ajax_checkForUpdate()
    111     {
    112         $url = $this->getHomepageURL().'/api/getDataVersion.php';
    113        
    114         $result = wp_remote_get($url);
    115        
    116         $state = 'success';
    117         if(is_wp_error($result)) {
    118             $state = 'error';
    119             $data = $result->get_error_message();
    120         } else {
    121             $code = wp_remote_retrieve_response_code($result);
    122             if($code != 200) {
    123                 $state = 'error';
    124                 $data = wp_remote_retrieve_response_message($result);
    125             } else {
    126                 $infoRemote = EVEShipInfo::parseVersion(trim($result['body']));
    127                 $infoLocal = EVEShipInfo::parseVersion($this->getDataVersion());
    128                 $update = false;
    129                 if($infoRemote['date'] > $infoLocal['date']) {
    130                     $update = true;
    131                 }
    132                
    133                 $data = array(
    134                     'remoteVersion' => $infoRemote['version'],
    135                     'updateAvailable' => $update,
    136                 );
    137             }
    138         }
    139 
    140         $response = array(
    141             'url' => $url,
    142             'state' => $state,
    143             'data' => $data
    144         );
    145        
    146         echo json_encode($response);
    147         wp_die();
     112    * Sets up all AJAX methods available for the plugin,
     113    * by checking which are available in the AjaxMethod
     114    * classes folder. Adds each as a plugin-specific
     115    * AJAX method.
     116    */
     117    protected function handle_initAJAXMethods()
     118    {
     119        $this->loadClass('EVEShipInfo_AjaxHandler');
     120       
     121        $names = $this->getClassNamesFromFolder($this->getClassesFolder().'/EVEShipInfo/AjaxMethod');
     122       
     123        foreach($names as $name) {
     124            // to avoid having to load the entire ajax class for each method on each request,
     125            // we use the lightweight handler, which loads the class on demand.
     126            $handler = new EVEShipInfo_AjaxHandler($this, $name);
     127            add_action('wp_ajax_eveshipinfo_'.strtolower($name), array($handler, 'execute'));
     128        }
    148129    }
    149130   
     
    582563        $this->shortcodeIDs = array();
    583564       
    584         $folder = $this->getDir().'/classes/EVEShipInfo/Shortcode';
     565        $folder = $this->getClassesFolder().'/EVEShipInfo/Shortcode';
    585566        if(!file_exists($folder)) {
    586567            return $this->shortcodeIDs;
    587568        }
    588569       
     570        $this->shortcodeIDs = $this->getClassNamesFromFolder($folder);
     571
     572        return $this->shortcodeIDs;
     573    }
     574   
     575   /**
     576    * Retrieves all PHP file names from the specified folder,
     577    * without their extensions.
     578    *
     579    * @param string $folder
     580    * @return string[]
     581    */
     582    public function getClassNamesFromFolder($folder)
     583    {
     584        $names = array();
    589585        $d = new DirectoryIterator($folder);
    590586        foreach($d as $item) {
    591             $file = $item->getFilename();
    592             $ext = pathinfo($file, PATHINFO_EXTENSION);
    593             if($ext != 'php') {
    594                 continue;
    595             }
    596            
    597             $this->shortcodeIDs[] = str_replace('.php', '', $file);
    598         }
    599 
    600         return $this->shortcodeIDs;
     587            $file = $item->getFilename();
     588            $ext = pathinfo($file, PATHINFO_EXTENSION);
     589            if($ext != 'php') {
     590                continue;
     591            }
     592           
     593            $names[] = str_replace('.php', '', $file);
     594        }
     595       
     596        return $names;
    601597    }
    602598   
     
    667663    {
    668664        if(is_admin()) {
    669             $this->addScript('admin/FittingsList.js', array('jquery'));
     665            $this->addScript('admin/Admin.js', array('jquery'));
     666            $this->addScript('admin/FittingsList.js', array('jquery'));
    670667            $this->addScript('admin/Themes.js', array('jquery'));
    671668            $this->addStyle('admin.css');
     
    10151012        }
    10161013       
    1017         $file = $this->dir.'/classes/'.str_replace('_', '/', $className).'.php';
     1014        $file = $this->getClassesFolder().'/'.str_replace('_', '/', $className).'.php';
     1015        if(!file_exists($file)) {
     1016            throw new EVEShipInfo_Exception(
     1017                'Class file not found',
     1018                sprintf(
     1019                    'Tried loading the class [%s] from file [%s].',
     1020                    $className,
     1021                    $file
     1022                ),
     1023                self::ERROR_CANNOT_FIND_CLASS_FILE
     1024            );
     1025        }
     1026       
    10181027        require_once $file;
     1028    }
     1029   
     1030   /**
     1031    * Retrieves the full path to the plugin's "classes" folder.
     1032    * @return string
     1033    */
     1034    public function getClassesFolder()
     1035    {
     1036        return $this->dir.'/classes';
    10191037    }
    10201038   
  • eve-shipinfo/trunk/classes/EVEShipInfo/Admin/Page.php

    r1296717 r1524886  
    195195                $content.
    196196            '</div>'.
    197         '</div>';
    198        
     197        '</div>'.
     198        $this->ui->renderJS();
     199               
    199200        return $html;
    200201    }
  • eve-shipinfo/trunk/classes/EVEShipInfo/Admin/Page/Main/EFTFittings.php

    r1512895 r1524886  
    139139                        '</tr>';   
    140140                    } else {
    141                         foreach($fits as $fit) {
    142                             $public = $this->ui->icon()->visibilityPrivate()->makeDangerous().' '.__('Private', 'eve-shipinfo');
    143                             if($fit->isPublic()) {
    144                                 $public = $this->ui->icon()->visibilityPublic()->makeSuccess().' '.__('Public', 'eve-shipinfo');
    145                             }
     141                        foreach($fits as $fit)
     142                        {
     143                            $jsID = EVEShipInfo::nextJSID();
     144                            $displayPrivate = 'none';
     145                            $displayPublic = 'none';
     146                           
     147                            $this->ui->addJSOnload(sprintf(
     148                                "jQuery('#%s-private, #%s-public').dblclick(function() {FittingsList.ToggleVisibility('%s', '%s');}).addClass('shipinfo-clickable')",
     149                                $jsID,
     150                                $jsID,
     151                                $fit->getID(),
     152                                $jsID
     153                            ));
     154                           
     155                            if($fit->isPublic()) { $displayPublic = 'block'; }
     156                            if($fit->isPrivate()) { $displayPrivate = 'block'; }
     157                           
     158                            $public =
     159                            '<div id="'.$jsID.'-private" class="fit-visibility-toggle" style="display:'.$displayPrivate.'" title="'.__('Double-click to toggle.', 'eve-shipinfo').'">'.
     160                                $this->ui->icon()->visibilityPrivate()
     161                                ->makeDangerous().
     162                                ' '.
     163                                __('Private', 'eve-shipinfo').
     164                            '</div>'.
     165                            '<div id="'.$jsID.'-public" class="fit-visibility-toggle" style="display:'.$displayPublic.'" title="'.__('Double-click to toggle.', 'eve-shipinfo').'">'.
     166                                $this->ui->icon()->visibilityPublic()
     167                                ->makeSuccess().
     168                                ' '.
     169                                __('Public', 'eve-shipinfo').
     170                            '</div>'.
     171                            '<div id="'.$jsID.'-loading" style="display:none">'.
     172                                $this->ui->icon()->spinner()
     173                                ->addClass('spinner-datagrid').
     174                                ' '.
     175                                __('Updating...', 'eve-shipinfo').
     176                            '</div>';
    146177                           
    147178                            $invalid = '';
  • eve-shipinfo/trunk/classes/EVEShipInfo/Admin/UI.php

    r1236586 r1524886  
    9797        return new EVEShipInfo_Admin_UI_Icon();
    9898    }
     99   
     100    protected $jsOnload = array();
     101    protected $jsHead = array();
     102   
     103   /**
     104    * Adds a javascript statement intended to be executed on page load.
     105    *
     106    * @param string $statement
     107    * @return EVEShipInfo_Admin_UI
     108    */
     109    public function addJSOnload($statement)
     110    {
     111        $this->jsOnload[] = rtrim(trim($statement), ';');
     112        return $this;
     113    }
     114   
     115   /**
     116    * Adds a javascript statement intended to to be executed before the page loads.
     117    *
     118    * @param string $statement
     119    * @return EVEShipInfo_Admin_UI
     120    */
     121    public function addJSHead($statement)
     122    {
     123        $this->jsHead[] = rtrim(trim($statement), ';');
     124        return $this;
     125    }
     126   
     127    public function renderJS()
     128    {
     129        if(empty($this->jsOnload) && empty($this->jsHead)) {
     130            return '';
     131        }
     132       
     133        $head = $this->jsHead;
     134        if(!empty($this->jsOnload)) {
     135            $head[] = 'jQuery(document).ready(function() {'.implode(';', $this->jsOnload).';})';
     136        }
     137       
     138        return '<script>'.implode(';', $head).';</script>';
     139    }
    99140}
  • eve-shipinfo/trunk/classes/EVEShipInfo/Admin/UI/Icon.php

    r1417468 r1524886  
    2525        'LIST_VIEW' => 'list-view',
    2626        'THEME' => 'admin-appearance',
    27         'UPDATE' => 'update'
     27        'UPDATE' => 'update',
     28        'SPINNER' => '_spinner'
    2829    );
    2930
     
    5960    public function visibilityPublic() { return $this->setType('VISIBILITY_PUBLIC'); }
    6061    public function visibilityPrivate() { return $this->setType('VISIBILITY_PRIVATE'); }
     62    public function spinner() { return $this->setType('SPINNER'); }
    6163   
    6264    /**
     
    138140    public function render()
    139141    {
    140         $this->setAttribute('class', 'dashicons dashicons-' . self::$types[$this->type] . ' ' . implode(' ', $this->classes));
     142        if($this->type == 'SPINNER') {
     143            $this->setAttribute('class', 'shipinfo-spinner');
     144        } else {
     145            $this->setAttribute('class', 'dashicons dashicons-' . self::$types[$this->type] . ' ' . implode(' ', $this->classes));
     146        }
    141147
    142148        if(!empty($this->styles)) {
  • eve-shipinfo/trunk/classes/EVEShipInfo/EFTManager.php

    r1411207 r1524886  
    276276        $label = trim($result[2][0]);
    277277       
    278         $this->loadModules();
     278        $this->load();
    279279       
    280280        $modules = array();
  • eve-shipinfo/trunk/css/admin.css

    r1417468 r1524886  
    196196cursor:zoom-out;
    197197}
     198
     199.shipinfo-spinner{
     200display:inline-block;
     201background:url(../images/spinner.gif) no-repeat center center;
     202min-width:20px;
     203min-height:20px;
     204line-height:1;
     205vertical-align:top;
     206}
     207
     208.shipinfo-clickable{
     209cursor:pointer;
     210}
     211
     212.fit-visibility-toggle.shipinfo-clickable:hover{
     213color:#0073aa;
     214}
  • eve-shipinfo/trunk/errorcodes.txt

    r1417468 r1524886  
    1 18001
     119001
  • eve-shipinfo/trunk/js/admin/Dashboard.js

    r1515401 r1524886  
    99        jQuery('#updatecheck-available').hide();
    1010       
    11         jQuery.ajax({
    12             'url':ajaxurl,
    13             'data':{
    14                 'action':'eveshipinfo_checkforupdate'
    15             },
    16             'success':function(data) {
     11        EVEShipInfo_Admin.AJAX(
     12            'CheckForUpdate',
     13            null,
     14            function(data) {
    1715                EVEShipInfo_Dashboard.Handle_UpdateCheckSuccess(data);
    1816            },
    19             'error':function(jqXHR, textStatus, errorThrown) {
    20                 EVEShipInfo_Dashboard.Handle_UpdateCheckFailure(errorThrown);
    21             },
    22             'dataType':'json'
    23         });
     17            function(errorMessage) {
     18                EVEShipInfo_Dashboard.Handle_UpdateCheckFailure(errorMessage);
     19            }
     20        );
    2421    },
    2522   
  • eve-shipinfo/trunk/js/admin/FittingsList.js

    r1112684 r1524886  
    1515        jQuery('.fit-checkbox').prop('checked', true);
    1616        this.allSelected = true;
     17    },
     18   
     19    ToggleVisibility:function(fitID, jsID)
     20    {
     21        // avoid the text being selected after the doubleclick
     22        var sel = window.getSelection();
     23        if(sel) { sel.removeAllRanges(); }
     24       
     25        var elPublic = jQuery('#'+jsID+'-public');
     26        var elPrivate = jQuery('#'+jsID+'-private');
     27        var elLoader = jQuery('#'+jsID+'-loading');
     28
     29        var payload = {
     30            'fitID':fitID,
     31            'changeTo':'private'
     32        };
     33       
     34        if(elPrivate.is(':visible')) {
     35            payload.changeTo = 'public';
     36        }
     37
     38        elPublic.hide();
     39        elPrivate.hide();
     40        elLoader.show();
     41       
     42        EVEShipInfo_Admin.AJAX(
     43            'FittingSetVisibility',
     44            payload,
     45            function(data) {
     46                FittingsList.Handle_ToggleVisibilitySuccess(data, jsID);
     47            },
     48            function(errorMessage) {
     49                FittingsList.Handle_ToggleVisibilityFailure(errorMessage, payload, jsID);
     50            }
     51        );
     52    },
     53   
     54    Handle_ToggleVisibilityFailure:function(errorMessage, payload, jsID)
     55    {
     56        console.log('ERROR | Could not update visibility | '+errorMessage);
     57       
     58        jQuery('#'+jsID+'-loading').hide();
     59       
     60        if(payload.changeTo == 'public') {
     61            jQuery('#'+jsID+'-private').show();
     62        } else {
     63            jQuery('#'+jsID+'-public').show();
     64        }
     65    },
     66   
     67    Handle_ToggleVisibilitySuccess:function(response, jsID)
     68    {
     69        jQuery('#'+jsID+'-loading').hide();
     70       
     71        if(response.visibility == 'private') {
     72            jQuery('#'+jsID+'-private').show();
     73        } else {
     74            jQuery('#'+jsID+'-public').show();
     75        }
    1776    }
    1877};
  • eve-shipinfo/trunk/readme.txt

    r1515807 r1524886  
    5454
    5555= 2.1 =
     56* Added the "mass" filter to the list shortcodes to limit the list by ship mass
    5657* Added the "ships" filter to the list shortcodes to display specific ships by name or id
    57 * Added the "mass" filter to the list shortcodes to limit the list by ship mass
     58* Fixed an error when importing an EFT XML file
     59* Made the EFT fitting visibility toggle-able in the list by double-clicking the icon
     60* Improved the internal handling of Ajax calls for future features
    5861
    5962= 2.0 =
Note: See TracChangeset for help on using the changeset viewer.