mw.Upload.BookletLayout/Dialog: Add determinate progress bar
authorPrateek Saxena <prtksxna@gmail.com>
Thu, 11 Feb 2016 15:21:39 +0000 (20:51 +0530)
committerPrateek Saxena <prtksxna@gmail.com>
Wed, 17 Feb 2016 03:03:58 +0000 (08:33 +0530)
The BookletLayout now emits events during the upload file phase. It
uses these events to update a progress bar at the top of infoForm.

Bug: T115861
Change-Id: I0fd7f21f3fc1ef042330b7571c247e09c24d1a5c

resources/Resources.php
resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js
resources/src/mediawiki/mediawiki.Upload.BookletLayout.css
resources/src/mediawiki/mediawiki.Upload.BookletLayout.js

index b9dd3fa..bb88414 100644 (file)
@@ -1189,6 +1189,7 @@ return array(
                        'oojs-ui',
                        'oojs-ui.styles.icons-content',
                        'oojs-ui.styles.icons-editing-advanced',
+                       'moment',
                        'mediawiki.Title',
                        'mediawiki.user',
                        'mediawiki.Upload',
index 23e80b9..1fabe17 100644 (file)
                this.filePreview = new OO.ui.Widget( {
                        classes: [ 'mw-upload-bookletLayout-filePreview' ]
                } );
+               this.progressBarWidget = new OO.ui.ProgressBarWidget( {
+                       progress: 0
+               } );
+               this.filePreview.$element.append( this.progressBarWidget.$element );
+
                this.filenameWidget = new OO.ui.TextInputWidget( {
                        required: true,
                        validate: /.+/
                this.descriptionWidget.on( 'change', this.onInfoFormChange.bind( this ) );
                this.dateWidget.on( 'change', this.onInfoFormChange.bind( this ) );
 
+               this.on( 'fileUploadProgress', function ( progress ) {
+                       this.progressBarWidget.setProgress( progress * 100 );
+               }.bind( this ) );
+
                return this.infoForm;
        };
 
index 11bad8c..68062d0 100644 (file)
@@ -7,6 +7,7 @@
        padding: 1.5em;
        margin: -1.5em;
        margin-bottom: 1.5em;
+       position: relative;
 }
 
 .mw-upload-bookletLayout-infoForm.mw-upload-bookletLayout-hasThumbnail .mw-upload-bookletLayout-filePreview {
 .mw-upload-bookletLayout-filePreview p {
        line-height: 1em;
        margin: 0;
+}
+
+.mw-upload-bookletLayout-filePreview .oo-ui-progressBarWidget {
+       border: none;
+       border-radius: 0;
+       background-color: transparent;
+       position: absolute;
+       bottom: 0;
+       left: 0;
+       right: 0;
+}
+
+.mw-upload-bookletLayout-filePreview .oo-ui-progressBarWidget-bar {
+       background-color: #347bff;
+       height: 0.5em;
 }
\ No newline at end of file
index eaab8c7..33b10bd 100644 (file)
@@ -1,4 +1,5 @@
-( function ( $, mw ) {
+/*global moment*/
+( function ( $, mw, moment ) {
 
        /**
         * mw.Upload.BookletLayout encapsulates the process of uploading a file
 
        /* Events */
 
+       /**
+        * Progress events for the uploaded file
+        *
+        * @event fileUploadProgress
+        * @param {number} progress In percentage
+        * @param {Object} duration Duration object from `moment.duration()`
+        */
+
        /**
         * The file has finished uploading
         *
         * file object.
         *
         * @protected
+        * @fires fileUploadProgress
         * @fires fileUploaded
         * @return {jQuery.Promise}
         */
        mw.Upload.BookletLayout.prototype.uploadFile = function () {
                var deferred = $.Deferred(),
+                       startTime = new Date(),
                        layout = this,
                        file = this.getFile();
 
                        // really be an error...
                        var errorMessage = layout.getErrorMessageForStateDetails();
                        deferred.reject( errorMessage );
+               }, function ( progress ) {
+                       var elapsedTime = new Date() - startTime,
+                               estimatedTotalTime = ( 1 / progress ) * elapsedTime,
+                               estimatedRemainingTime = moment.duration( estimatedTotalTime - elapsedTime );
+                       layout.emit( 'fileUploadProgress', progress, estimatedRemainingTime );
                } );
 
                // If there is an error in uploading, come back to the upload page
                this.filePreview = new OO.ui.Widget( {
                        classes: [ 'mw-upload-bookletLayout-filePreview' ]
                } );
+               this.progressBarWidget = new OO.ui.ProgressBarWidget( {
+                       progress: 0
+               } );
+               this.filePreview.$element.append( this.progressBarWidget.$element );
+
                this.filenameWidget = new OO.ui.TextInputWidget( {
                        indicator: 'required',
                        required: true,
                        items: [ this.filePreview, fieldset ]
                } );
 
+               this.on( 'fileUploadProgress', function ( progress ) {
+                       this.progressBarWidget.setProgress( progress * 100 );
+               }.bind( this ) );
+
                this.filenameWidget.on( 'change', this.onInfoFormChange.bind( this ) );
                this.descriptionWidget.on( 'change', this.onInfoFormChange.bind( this ) );
 
         */
        mw.Upload.BookletLayout.prototype.clear = function () {
                this.selectFileWidget.setValue( null );
+               this.progressBarWidget.setProgress( 0 );
                this.filenameWidget.setValue( null ).setValidityFlag( true );
                this.descriptionWidget.setValue( null ).setValidityFlag( true );
                this.filenameUsageWidget.setValue( null );
        };
 
-}( jQuery, mediaWiki ) );
+}( jQuery, mediaWiki, moment ) );