GeezerVison is showing github.com — Merge pull request #81 from axeptio/feat/82780_error_plugins_api_tmp · axeptio/wordpress-plugin@bbcb19a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions - Display the source diff
- Display the rich diff
Collapse file Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions - Display the source diff
- Display the rich diff
Collapse file Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions - Display the source diff
- Display the rich diff
Collapse file Copy file name to clipboardExpand all lines: assets/js/backend/app.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ import selectComponent from './components/selectComponent'; | 9 | 9 | import noticeComponent from './components/noticeComponent'; | 10 | 10 | import tabsPill from './components/tabsPill'; | 11 | 11 | import advancedSettings from './components/advancedSettings'; | | 12 | +import notifications from './store/notifications'; | 12 | 13 |
| 13 | 14 | window.Alpine = Alpine; | 14 | 15 |
| @@ -22,6 +23,8 @@ Alpine.data('SelectComponent', selectComponent); | 22 | 23 | Alpine.data('tabsPill', tabsPill); | 23 | 24 | Alpine.data('advancedSettings', advancedSettings); | 24 | 25 |
| | 26 | +Alpine.store('notifications', notifications); | | 27 | + | 25 | 28 | Alpine.plugin( persist ); | 26 | 29 | Alpine.plugin( collapse ); | 27 | 30 |
| |
Collapse file Copy file name to clipboardExpand all lines: assets/js/backend/components/noticeComponent.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ const instance = function( args ) { | 3 | 3 | timeoutButton: null, | 4 | 4 | disableButton: null, | 5 | 5 | nonce: args.nonce, | | 6 | + restRoot: args.rest_root, | 6 | 7 |
| 7 | 8 | init() { | 8 | 9 | this.timeoutButton = this.$el.querySelector( '#axeptio-timeout-button' ); | @@ -32,15 +33,15 @@ const instance = function( args ) { | 32 | 33 | }, | 33 | 34 |
| 34 | 35 | fetchAPI( route ) { | 35 | | - const apiUrl = `/wp-json/axeptio/v1/${ route }`; | | 36 | + const apiUrl = `${ this.restRoot }${ route }/`; | 36 | 37 |
| 37 | 38 | fetch( apiUrl, { | 38 | 39 | method: 'POST', | 39 | 40 | headers: { | 40 | 41 | 'Content-Type': 'application/json', | 41 | 42 | 'X-WP-Nonce': this.nonce, | 42 | 43 | }, | 43 | | - } ).then( ( response ) => response.json() ); | | 44 | + } ).catch( () => {} ); | 44 | 45 | }, | 45 | 46 | }; | 46 | 47 | }; | |
Collapse file Copy file name to clipboardExpand all lines: assets/js/backend/components/pluginList.js +60-16Lines changed: 60 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,26 +78,40 @@ const instance = function( args ) { | 78 | 78 | }; | 79 | 79 |
| 80 | 80 | const pluginMethods = { | | 81 | + readResponse( response ) { | | 82 | + if ( ! response.ok ) { | | 83 | + throw new Error( `Unexpected response status: ${ response.status }` ); | | 84 | + } | | 85 | + return response.json(); | | 86 | + }, | | 87 | + | 81 | 88 | fetchPlugins() { | 82 | 89 | this.isGetting = true; | 83 | | - const apiUrl = `/wp-json/axeptio/v1/plugins/${ this.configurationId }`; | | 90 | + | | 91 | + const apiUrl = `${ this.restRoot }plugins/${ this.configurationId }/`; | 84 | 92 | fetch( apiUrl, { | 85 | 93 | method: 'GET', | 86 | 94 | headers: { | 87 | 95 | 'Content-Type': 'application/json', | 88 | | - 'X-WP-Nonce': args.nonce, | | 96 | + 'X-WP-Nonce': this.nonce, | 89 | 97 | }, | 90 | 98 | } ) | 91 | | - .then( ( response ) => response.json() ) | | 99 | + .then( this.readResponse ) | 92 | 100 | .then( ( data ) => { | 93 | 101 | this.plugins = data; | 94 | 102 | this.isGetting = false; | | 103 | + } ) | | 104 | + .catch( () => { | | 105 | + this.plugins = []; | | 106 | + this.isGetting = false; | | 107 | + window.Alpine.store( 'notifications' ).push( args.messages.load_error ); | 95 | 108 | } ); | 96 | 109 | }, | 97 | 110 |
| 98 | 111 | deletePlugin( plugin ) { | 99 | 112 | this.isSaving = true; | 100 | | - const apiUrl = `/wp-json/axeptio/v1/plugins/${ this.configurationId }/${ plugin.Metas.plugin }`; | | 113 | + | | 114 | + const apiUrl = `${ this.restRoot }plugins/${ this.configurationId }/${ plugin.Metas.plugin }/`; | 101 | 115 | fetch( apiUrl, { | 102 | 116 | method: 'DELETE', | 103 | 117 | headers: { | @@ -106,14 +120,19 @@ const instance = function( args ) { | 106 | 120 | }, | 107 | 121 | body: JSON.stringify( plugin.Metas ), | 108 | 122 | } ) | 109 | | - .then( ( response ) => response.json() ) | | 123 | + .then( this.readResponse ) | 110 | 124 | .then( () => { | 111 | 125 | this.isSaving = false; | 112 | 126 | this.editOpen = false; | 113 | 127 | this.closeDeleteModal(); | 114 | 128 | this.fetchPlugins(); | 115 | 129 | this.editedPlugin.Metas.enabled = false; | 116 | 130 | this.setForceEditOpen( false ); | | 131 | + } ) | | 132 | + .catch( () => { | | 133 | + this.isSaving = false; | | 134 | + this.closeDeleteModal(); | | 135 | + window.Alpine.store( 'notifications' ).push( args.messages.delete_error ); | 117 | 136 | } ); | 118 | 137 | }, | 119 | 138 |
| @@ -141,26 +160,41 @@ const instance = function( args ) { | 141 | 160 | this.refreshRepeaterFields(); | 142 | 161 | }, | 143 | 162 |
| 144 | | - updatePlugin( plugin ) { | | 163 | + updatePlugin( plugin, metas = plugin.Metas ) { | 145 | 164 | this.isSaving = true; | 146 | 165 |
| 147 | | - const apiUrl = `/wp-json/axeptio/v1/plugins/${ this.configurationId }/${ plugin.Metas.plugin }`; | 148 | | - fetch( apiUrl, { | | 166 | + const apiUrl = `${ this.restRoot }plugins/${ this.configurationId }/${ plugin.Metas.plugin }/`; | | 167 | + return fetch( apiUrl, { | 149 | 168 | method: 'PUT', | 150 | 169 | headers: { | 151 | 170 | 'Content-Type': 'application/json', | 152 | 171 | 'X-WP-Nonce': this.nonce, | 153 | 172 | }, | 154 | | - body: JSON.stringify( plugin.Metas ), | | 173 | + body: JSON.stringify( metas ), | 155 | 174 | } ) | 156 | | - .then( ( response ) => response.json() ) | | 175 | + .then( this.readResponse ) | 157 | 176 | .then( () => { | 158 | 177 | this.refreshRepeaterFields(); | 159 | 178 | this.isSaving = false; | 160 | 179 | this.editedPluginHasChanged = false; | | 180 | + return true; | | 181 | + } ) | | 182 | + .catch( () => { | | 183 | + this.isSaving = false; | | 184 | + window.Alpine.store( 'notifications' ).push( args.messages.save_error ); | | 185 | + return false; | 161 | 186 | } ); | 162 | 187 | }, | 163 | 188 |
| | 189 | + saveEditedPlugin() { | | 190 | + this.updatePlugin( this.editedPlugin ).then( ( saved ) => { | | 191 | + if ( saved ) { | | 192 | + window.Alpine.store( 'notifications' ).push( args.messages.save_success, 'success' ); | | 193 | + this.editOpen = false; | | 194 | + } | | 195 | + } ); | | 196 | + }, | | 197 | + | 164 | 198 | openMediaSelector() { | 165 | 199 | this.setForceEditOpen( true ); | 166 | 200 | const self = this; | @@ -192,12 +226,23 @@ const instance = function( args ) { | 192 | 226 | }, | 193 | 227 |
| 194 | 228 | enableControl( plugin ) { | | 229 | + if ( this.isSaving ) { | | 230 | + return; | | 231 | + } | | 232 | + | 195 | 233 | const { Metas } = plugin; | | 234 | + const metas = { | | 235 | + ...Metas, | | 236 | + enabled: ! Boolean( Metas.enabled ) ? 1 : 0, | | 237 | + cookie_widget_step: 'wordpress', | | 238 | + }; | 196 | 239 |
| 197 | 240 | this.editedPlugin = plugin; | 198 | | - Metas.enabled = ! Boolean( Metas.enabled ) ? 1 : 0; | 199 | | - Metas.cookie_widget_step = 'wordpress'; | 200 | | - this.updatePlugin( plugin ); | | 241 | + this.updatePlugin( plugin, metas ).then( ( saved ) => { | | 242 | + if ( saved ) { | | 243 | + Object.assign( Metas, metas ); | | 244 | + } | | 245 | + } ); | 201 | 246 | }, | 202 | 247 |
| 203 | 248 | initEditedPlugin() { | @@ -303,19 +348,18 @@ const instance = function( args ) { | 303 | 348 | editedPluginHasChanged: false, | 304 | 349 | configurationId: 'all', | 305 | 350 | activeTab: 1, | 306 | | - currentPage: 1, | 307 | 351 | forceEditOpen: false, | 308 | 352 | activePlugins: args.active_plugins, | 309 | | - totalPages: 1, | 310 | 353 | nonce: args.nonce, | | 354 | + restRoot: args.rest_root, | | 355 | + | 311 | 356 | isSaving: false, | 312 | 357 | isGetting: false, | 313 | 358 | hookModes: [], | 314 | 359 | projectVersions: args.project_versions, | 315 | 360 | shortcodeTagsModes: [], | 316 | 361 | editOpen: false, | 317 | 362 | showDeleteModal: false, | 318 | | - pluginToDelete: null, | 319 | 363 | inputRefs: [], | 320 | 364 | fields: [], | 321 | 365 |
| |
Collapse file Copy file name to clipboard +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +const ENTER_DELAY = 30; | | 2 | +const LEAVE_DURATION = 300; | | 3 | + | | 4 | +export default { | | 5 | + items: [], | | 6 | + nextId: 1, | | 7 | + autoClose: true, | | 8 | + autoCloseDelay: 5000, | | 9 | + | | 10 | + push( message, type = 'error' ) { | | 11 | + const id = this.nextId++; | | 12 | + this.items.push( { id, message, type, visible: false } ); | | 13 | + | | 14 | + setTimeout( () => { | | 15 | + const item = this.items.find( ( notification ) => notification.id === id ); | | 16 | + if ( item ) { | | 17 | + item.visible = true; | | 18 | + } | | 19 | + }, ENTER_DELAY ); | | 20 | + | | 21 | + if ( this.autoClose ) { | | 22 | + setTimeout( () => this.dismiss( id ), this.autoCloseDelay ); | | 23 | + } | | 24 | + }, | | 25 | + | | 26 | + dismiss( id ) { | | 27 | + const item = this.items.find( ( notification ) => notification.id === id ); | | 28 | + if ( ! item ) { | | 29 | + return; | | 30 | + } | | 31 | + | | 32 | + item.visible = false; | | 33 | + setTimeout( () => { | | 34 | + this.items = this.items.filter( ( notification ) => notification.id !== id ); | | 35 | + }, LEAVE_DURATION ); | | 36 | + }, | | 37 | +}; |
Collapse file Copy file name to clipboardExpand all lines: includes/classes/admin/pages/class-admin-callbacks.php +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,9 +33,16 @@ public function admin_dashboard() { | 33 | 33 | */ | 34 | 34 | public function plugin_manager() { | 35 | 35 | $settings = array( | | 36 | + 'rest_root' => \Axeptio\Plugin\get_rest_root(), | 36 | 37 | 'nonce' => wp_create_nonce( 'wp_rest' ), | 37 | 38 | 'active_plugins' => Plugins::get_active_plugins(), | 38 | 39 | 'project_versions' => Project_Versions::all(), | | 40 | + 'messages' => array( | | 41 | + 'load_error' => __( 'The extension list could not be loaded. Please try again, and contact your host if the problem persists.', 'axeptio-sdk-integration' ), | | 42 | + 'save_error' => __( 'Your changes have not been saved. Please try again, and contact your host if the problem persists.', 'axeptio-sdk-integration' ), | | 43 | + 'delete_error' => __( 'These settings have not been deleted. Please try again, and contact your host if the problem persists.', 'axeptio-sdk-integration' ), | | 44 | + 'save_success' => __( 'Your changes have been saved.', 'axeptio-sdk-integration' ), | | 45 | + ), | 39 | 46 | ); | 40 | 47 | return require_once XPWP_PATH . 'templates' . DS . 'admin' . DS . 'plugin-manager.php'; | 41 | 48 | } | |
Collapse file Copy file name to clipboardExpand all lines: includes/classes/frontend/class-axeptio-sdk.php +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | use function Axeptio\Plugin\get_sdk_settings; | 23 | 23 | use function Axeptio\Plugin\script_url; | 24 | 24 | use function Axeptio\Plugin\style_url; | 25 | | -use function Axeptio\Plugin\Utility\get_asset_info; | 26 | 25 |
| 27 | 26 | class Axeptio_Sdk extends Module { | 28 | 27 |
| @@ -104,7 +103,7 @@ public function enqueue_scripts() { | 104 | 103 | 'axeptio/main', | 105 | 104 | style_url( 'frontend/main', 'frontend' ), | 106 | 105 | array(), | 107 | | - get_asset_info( 'shared', 'version' ), | | 106 | + XPWP_VERSION, | 108 | 107 | ); | 109 | 108 |
| 110 | 109 | $cookies_version = Settings::get_option( 'version', false ); | |
Collapse file Copy file name to clipboardExpand all lines: includes/classes/utils/class-search-callback-file-location.php -2Lines changed: 0 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | namespace Axeptio\Plugin\Utils; | 4 | 4 |
| 5 | | -use function Axeptio\Plugin\wp_memory_limit_in_bytes; | 6 | | - | 7 | 5 | class Search_Callback_File_Location { | 8 | 6 | /** | 9 | 7 | * Cache expiration time in seconds (1 week) | |
|