Make WordPress Core

Changeset 24732


Ignore:
Timestamp:
07/18/2013 04:35:19 PM (11 years ago)
Author:
markjaquith
Message:

Revisions: Better error handling.

  • Shows an error message if the current diff can't be loaded.
  • For bulk pre-loading, catches errors, and cuts subsequent requests in half, until eventually giving up.
  • Some CSS fixes related to this, and the loading spinner.
  • wp.revisions.loadAll() now returns a promise representing whether or not all revisions could be loaded.

Fixes #24758.

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/wp-admin.css

    r24695 r24732  
    35553555}
    35563556
     3557.revisions .diff-error {
     3558    position: absolute;
     3559    text-align: center;
     3560    margin: 0 auto;
     3561    width: 100%;
     3562    display: none;
     3563}
     3564
     3565.revisions.diff-error .diff-error {
     3566    display: block;
     3567}
     3568
    35573569.revisions .loading-indicator {
    35583570    position: absolute;
    3559     text-align: center;
    35603571    vertical-align: middle;
    35613572    opacity: 0;
    3562     margin: 0 auto;
    35633573    width: 100%;
    3564     height: 32px;
    35653574    top: 3em;
    3566     background: #fff url(../images/wpspin_light-2x.gif) no-repeat center top;
    35673575    -webkit-transition: opacity 0.5s;
    35683576    -moz-transition:    opacity 0.5s;
     
    35703578    -o-transition:      opacity 0.5s;
    35713579    transition:         opacity 0.5s;
     3580}
     3581
     3582.revisions .loading-indicator span.spinner {
     3583    display: block;
     3584    margin: 0 auto;
     3585    float: none;
    35723586}
    35733587
     
    35863600.revisions.loading .diff {
    35873601    opacity: 0.5;
     3602}
     3603
     3604.revisions.diff-error .diff {
     3605    visibility: hidden;
    35883606}
    35893607
  • trunk/wp-admin/js/revisions.js

    r24699 r24732  
    234234                request.done( _.bind( function() {
    235235                    deferred.resolveWith( context, [ this.get( id ) ] );
    236                 }, this ) );
     236                }, this ) ).fail( _.bind( function() {
     237                    deferred.reject();
     238                }) );
    237239            }
    238240
     
    257259            if ( _.size( diffs ) > 0 ) {
    258260                this.load( diffs ).done( function() {
    259                     deferred.resolve();
    260                     self._loadAll( allRevisionIds, centerId, num );
     261                    self._loadAll( allRevisionIds, centerId, num ).done( function() {
     262                        deferred.resolve();
     263                    });
     264                }).fail( function() {
     265                    if ( 1 === num ) { // Already tried 1. This just isn't working. Give up.
     266                        deferred.reject();
     267                    } else { // Request fewer diffs this time
     268                        self._loadAll( allRevisionIds, centerId, Math.ceil( num / 2 ) ).done( function() {
     269                            deferred.resolve();
     270                        });
     271                    }
    261272                });
    262                 return deferred.promise();
    263273            } else {
    264                 return deferred.reject().promise();
    265             }
     274                deferred.resolve();
     275            }
     276            return deferred;
    266277        },
    267278
     
    315326        defaults: {
    316327            loading: false,
     328            error: false,
    317329            compareTwoMode: false
    318330        },
     
    321333            var properties = {};
    322334
     335            _.bindAll( this, 'receiveDiff' );
    323336            this._debouncedEnsureDiff = _.debounce( this._ensureDiff, 200 );
    324337
     
    352365
    353366        updateLoadingStatus: function() {
     367            this.set( 'error', false );
    354368            this.set( 'loading', ! this.diff() );
    355369        },
     
    400414            // If we already have the diff, then immediately trigger the update.
    401415            if ( diff ) {
    402                 this.trigger( 'update:diff', diff );
     416                this.receiveDiff( diff );
    403417                return $.Deferred().resolve().promise();
    404418            // Otherwise, fetch the diff.
     
    419433        },
    420434
     435        receiveDiff: function( diff ) {
     436            // Did we actually get a diff?
     437            if ( _.isUndefined( diff ) || _.isUndefined( diff.id ) ) {
     438                this.set({
     439                    loading: false,
     440                    error: true
     441                });
     442            } else if ( this._diffId === diff.id ) { // Make sure the current diff didn't change
     443                this.trigger( 'update:diff', diff );
     444            }
     445        },
     446
    421447        _ensureDiff: function() {
    422             return this.diffs.ensure( this._diffId, this ).done( function( diff ) {
    423                 // Make sure the current diff didn't change while the request was in flight.
    424                 if ( this._diffId === diff.id )
    425                     this.trigger( 'update:diff', diff );
    426             });
     448            return this.diffs.ensure( this._diffId, this ).always( this.receiveDiff );
    427449        }
    428450    });
     
    444466            this.listenTo( this.model, 'change:compareTwoMode', this.updateCompareTwoMode );
    445467            this.listenTo( this.model, 'change:loading', this.updateLoadingStatus );
     468            this.listenTo( this.model, 'change:error', this.updateErrorStatus );
    446469
    447470            this.views.set( '.revisions-control-frame', new revisions.view.Controls({
     
    469492        updateLoadingStatus: function() {
    470493            this.$el.toggleClass( 'loading', this.model.get('loading') );
     494        },
     495
     496        updateErrorStatus: function() {
     497            this.$el.toggleClass( 'diff-error', this.model.get('error') );
    471498        },
    472499
  • trunk/wp-admin/revision.php

    r24729 r24732  
    187187
    188188<script id="tmpl-revisions-diff" type="text/html">
    189     <div class="loading-indicator"></div>
     189    <div class="loading-indicator"><span class="spinner"></span></div>
     190    <div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
    190191    <div class="diff">
    191192    <# _.each( data.fields, function( field ) { #>
Note: See TracChangeset for help on using the changeset viewer.