jenkins-bot has submitted this change and it was merged.
Change subject: Link steps together less painfully
......................................................................
Link steps together less painfully
Bug: T93099
Change-Id: I62b17ccd4e8a0fbe06075550b6a77b5f185788e9
---
M resources/controller/uw.controller.Deed.js
M resources/controller/uw.controller.Details.js
M resources/controller/uw.controller.Step.js
M resources/controller/uw.controller.Thanks.js
M resources/controller/uw.controller.Tutorial.js
M resources/controller/uw.controller.Upload.js
M resources/mw.UploadWizard.js
M resources/ui/uw.ui.Step.js
M resources/ui/uw.ui.Thanks.js
M resources/ui/uw.ui.Wizard.js
M tests/qunit/controller/uw.controller.Step.test.js
11 files changed, 167 insertions(+), 159 deletions(-)
Approvals:
Gilles: Looks good to me, approved
jenkins-bot: Verified
diff --git a/resources/controller/uw.controller.Deed.js
b/resources/controller/uw.controller.Deed.js
index 8394d0e..4dd6536 100644
--- a/resources/controller/uw.controller.Deed.js
+++ b/resources/controller/uw.controller.Deed.js
@@ -34,6 +34,8 @@
} ),
config
);
+
+ this.stepName = 'deeds';
}
oo.inheritClass( Deed, uw.controller.Step );
@@ -53,10 +55,25 @@
*/
DP.moveTo = function ( uploads ) {
var customDeed, deeds,
+ showDeed = false,
step = this;
uw.controller.Step.prototype.moveTo.call( this, uploads );
+ $.each( this.uploads, function ( i, upload ) {
+ if ( !upload.fromURL ) {
+ showDeed = true;
+ return false;
+ }
+ } );
+
+ // If all of the uploads are from URLs, then we know the
licenses
+ // already, we don't need this step.
+ if ( !showDeed ) {
+ this.moveFrom();
+ return;
+ }
+
deeds = mw.UploadWizard.getLicensingDeeds( this.uploads.length,
this.config );
// if we have multiple uploads, also give them the option to set
diff --git a/resources/controller/uw.controller.Details.js
b/resources/controller/uw.controller.Details.js
index 39887ca..a9ac6fa 100644
--- a/resources/controller/uw.controller.Details.js
+++ b/resources/controller/uw.controller.Details.js
@@ -34,6 +34,8 @@
} ),
config
);
+
+ this.stepName = 'details';
}
oo.inheritClass( Details, uw.controller.Step );
diff --git a/resources/controller/uw.controller.Step.js
b/resources/controller/uw.controller.Step.js
index 462170f..f2b861b 100644
--- a/resources/controller/uw.controller.Step.js
+++ b/resources/controller/uw.controller.Step.js
@@ -28,6 +28,8 @@
* @param {Object} config The UW config object, or relevant subset.
*/
function Step( ui, config ) {
+ var step = this;
+
oo.EventEmitter.call( this );
/**
@@ -41,6 +43,16 @@
this.uploadsTransitioning = 0;
this.ui = ui;
+
+ this.ui.on( 'next-step', function () {
+ step.moveFrom();
+ } );
+
+ /**
+ * @property {mw.uw.controller.Step} nextStep
+ * The next step in the process.
+ */
+ this.nextStep = null;
}
oo.mixinClass( Step, oo.EventEmitter );
@@ -55,20 +67,53 @@
};
/**
+ * Set the next step in the process.
+ * @param {mw.uw.controller.Step} step
+ */
+ SP.setNextStep = function ( step ) {
+ this.nextStep = step;
+ };
+
+ /**
* Move to this step.
* @param {mw.UploadWizardUpload[]} uploads List of uploads being
carried forward.
*/
SP.moveTo = function ( uploads ) {
- this.uploads = uploads;
+ var step = this;
+
+ this.uploads = uploads || [];
+
+ $.each( this.uploads, function ( i, upload ) {
+ if ( upload !== undefined ) {
+ upload.state = step.stepName;
+ }
+ } );
+
this.ui.moveTo( uploads );
+ ( new mw.UploadWizardTutorialEvent( 'load' ) ).dispatch();
+ uw.eventFlowLogger.logStep( this.stepName );
+ this.emit( 'load' );
+
+ this.updateFileCounts( this.uploads );
};
/**
* Move out of this step.
- * @param {mw.UploadWizardUpload[]} uploads List of uploads being
carried forward.
*/
SP.moveFrom = function () {
- this.ui.moveFrom();
+ this.ui.moveFrom( this.uploads );
+
+ if ( this.nextStep ) {
+ this.nextStep.moveTo( this.uploads );
+ }
+ };
+
+ /**
+ * Skip this step.
+ */
+ SP.skip = function () {
+ uw.eventFlowLogger.logSkippedStep( this.stepName );
+ this.moveFrom();
};
/**
diff --git a/resources/controller/uw.controller.Thanks.js
b/resources/controller/uw.controller.Thanks.js
index 7f2ec07..6d7fb10 100644
--- a/resources/controller/uw.controller.Thanks.js
+++ b/resources/controller/uw.controller.Thanks.js
@@ -28,6 +28,8 @@
this,
new uw.ui.Thanks()
);
+
+ this.stepName = 'thanks';
}
oo.inheritClass( Thanks, uw.controller.Step );
@@ -37,11 +39,13 @@
TP.moveTo = function ( uploads ) {
var thanks = this;
+ uw.controller.Step.prototype.moveTo.call( this );
+
$.each( uploads, function ( i, upload ) {
thanks.ui.addUpload( upload );
} );
- uw.controller.Step.prototype.moveTo.call( this );
+ this.uploads = undefined;
};
uw.controller.Thanks = Thanks;
diff --git a/resources/controller/uw.controller.Tutorial.js
b/resources/controller/uw.controller.Tutorial.js
index 05577c9..4aaab91 100644
--- a/resources/controller/uw.controller.Tutorial.js
+++ b/resources/controller/uw.controller.Tutorial.js
@@ -19,8 +19,6 @@
var TP;
function Tutorial( api ) {
- var tutorial = this;
-
this.api = api;
uw.controller.Step.call(
@@ -37,19 +35,9 @@
.on( 'helpdesk-click', function () {
( new mw.UploadWizardTutorialEvent(
'helpdesk-click' ) ).dispatch();
} )
-
- .on( 'next-step', function () {
- ( new mw.UploadWizardTutorialEvent(
'continue' ) ).dispatch();
-
- // if the skip checkbox is checked, set
the skip user preference
- if ( $( '#mwe-upwiz-skip' ).is(
':checked' ) ) {
- $( '#mwe-upwiz-skip' ).tipsy(
'hide' );
- tutorial.setSkipPreference();
- }
-
- tutorial.emit( 'next-step' );
- } )
);
+
+ this.stepName = 'tutorial';
}
oo.inheritClass( Tutorial, uw.controller.Step );
@@ -79,5 +67,30 @@
} );
};
+ TP.moveTo = function () {
+ var tconf = mw.config.get( 'UploadWizardConfig' ).tutorial;
+
+ if (
+ mw.user.options.get( 'upwiz_skiptutorial' ) ||
+ ( tconf && tconf.skip )
+ ) {
+ this.skip();
+ } else {
+ uw.controller.Step.prototype.moveTo.call( this );
+ }
+ };
+
+ TP.moveFrom = function () {
+ ( new mw.UploadWizardTutorialEvent( 'continue' ) ).dispatch();
+
+ // if the skip checkbox is checked, set the skip user preference
+ if ( $( '#mwe-upwiz-skip' ).is( ':checked' ) ) {
+ $( '#mwe-upwiz-skip' ).tipsy( 'hide' );
+ this.setSkipPreference();
+ }
+
+ uw.controller.Step.prototype.moveFrom.call( this );
+ };
+
uw.controller.Tutorial = Tutorial;
}( mediaWiki, mediaWiki.uploadWizard, jQuery, OO ) );
diff --git a/resources/controller/uw.controller.Upload.js
b/resources/controller/uw.controller.Upload.js
index 642caf8..05f2581 100644
--- a/resources/controller/uw.controller.Upload.js
+++ b/resources/controller/uw.controller.Upload.js
@@ -31,11 +31,12 @@
new uw.ui.Upload( config )
.connect( this, {
retry: [ 'emit', 'retry' ],
- 'next-step': [ 'emit', 'next-step' ],
'flickr-ui-init': [ 'emit',
'flickr-ui-init' ]
} ),
config
);
+
+ this.stepName = 'file';
}
oo.inheritClass( Upload, uw.controller.Step );
@@ -58,7 +59,7 @@
this.ui.updateFileCounts( haveUploads, fewerThanMax );
if ( !haveUploads ) {
- this.emit( 'reset' );
+ this.emit( 'no-uploads' );
}
};
diff --git a/resources/mw.UploadWizard.js b/resources/mw.UploadWizard.js
index a2a7695..3a9d17e 100644
--- a/resources/mw.UploadWizard.js
+++ b/resources/mw.UploadWizard.js
@@ -17,13 +17,6 @@
var maxSimPref = mw.user.options.get( 'upwiz_maxsimultaneous' ),
wizard = this;
- function finalizeDetails() {
- if ( wizard.allowCloseWindow !== undefined ) {
- wizard.allowCloseWindow();
- }
- wizard.moveToStep( 'thanks' );
- }
-
if ( maxSimPref !== 'default' ) {
if ( maxSimPref > 0 ) {
config.maxSimultaneousConnections = maxSimPref;
@@ -34,13 +27,9 @@
this.maxSimultaneousConnections =
config.maxSimultaneousConnections;
- this.showDeed = false;
-
this.steps = {
- tutorial: new uw.controller.Tutorial( this.api )
- .on( 'next-step', function () {
- wizard.moveToStep( 'file' );
- } ),
+ tutorial: new uw.controller.Tutorial( this.api ),
+
file: new uw.controller.Upload( config )
.on( 'retry', function () {
uw.eventFlowLogger.logEvent(
'retry-uploads-button-clicked' );
@@ -60,32 +49,21 @@
uw.eventFlowLogger.logEvent(
'flickr-upload-button-clicked' );
} )
- .on( 'next-step', function () {
- wizard.removeErrorUploads();
-
- if ( wizard.showDeed ) {
- wizard.moveToStep( 'deeds' );
- } else {
- wizard.moveToStep( 'details' );
- }
- } )
-
- .on( 'reset', function () {
- wizard.bailAndMoveToFile();
+ .on( 'load', function () {
+ wizard.reset();
+ wizard.resetFileStepUploads();
} ),
deeds: new uw.controller.Deed( this.api, config )
- .on( 'next-step', function () {
- wizard.moveToStep( 'details' );
- } )
-
- .on( 'no-uploads', function () {
- wizard.bailAndMoveToFile();
+ .on( 'load', function () {
+ wizard.removeErrorUploads();
} ),
details: new uw.controller.Details( config )
.on( 'details-submitted', function () {
- wizard.showNext( 'details', 'complete',
finalizeDetails );
+ wizard.showNext( 'details', 'complete',
function () {
+ wizard.steps.details.moveFrom();
+ } );
} )
.on( 'details-error', function () {
@@ -94,15 +72,29 @@
.on( 'finalize-details-after-removal', function
() {
wizard.removeErrorUploads();
- finalizeDetails();
- } )
-
- .on( 'no-uploads', function () {
- wizard.bailAndMoveToFile();
+ wizard.steps.details.moveFrom();
} ),
thanks: new uw.controller.Thanks()
+ .on( 'load', function () {
+ if ( wizard.allowCloseWindow !==
undefined ) {
+ wizard.allowCloseWindow();
+ }
+ } )
};
+
+ $.each( this.steps, function ( name, step ) {
+ step
+ .on( 'no-uploads', function () {
+ wizard.bailAndMoveToFile();
+ } );
+ } );
+
+ this.steps.tutorial.setNextStep( this.steps.file );
+ this.steps.file.setNextStep( this.steps.deeds );
+ this.steps.deeds.setNextStep( this.steps.details );
+ this.steps.details.setNextStep( this.steps.thanks );
+ this.steps.thanks.setNextStep( this.steps.file );
if ( mw.UploadWizard.config.enableFirefogg &&
mw.Firefogg.isInstalled() ) {
// update the "valid" extension to include firefogg
transcode extensions:
@@ -119,7 +111,6 @@
mw.UploadWizard.prototype = {
stepNames: [ 'tutorial', 'file', 'deeds', 'details', 'thanks' ],
- currentStepName: undefined,
/**
* Reset the entire interface so we can upload more stuff
@@ -127,12 +118,16 @@
* Depending on whether we split uploading / detailing, it may
actually always be as simple as loading a URL
*/
reset: function () {
- mw.UploadWizardUpload.prototype.count = -1; // this is
counterintuitive, but the count needs to start at -1 to allow for the empty
upload created on the first step.
+ if ( this.hasLoadedBefore ) {
+ // this is counterintuitive, but the count
needs to start at -1 to allow for the empty upload created on the first step.
+ mw.UploadWizardUpload.prototype.count = -1;
+ }
+
this.showDeed = false;
$.purgeReadyEvents();
$.purgeSubscriptions();
this.removeMatchingUploads( function () { return true;
} );
- this.moveToStep( 'file' );
+ this.hasLoadedBefore = true;
},
/**
@@ -151,33 +146,16 @@
if ( this.allowCloseWindow !== undefined ) {
this.allowCloseWindow();
}
-
- this.moveToStep( 'file' );
},
/**
* create the basic interface to make an upload in this div
*/
createInterface: function () {
- var wizard = this;
+ this.ui = new uw.ui.Wizard( this );
- this.ui = new uw.ui.Wizard( this )
- .on( 'reset-wizard', function () {
- wizard.reset();
- } );
-
- // check to see if the the skip tutorial preference or
global setting is set
- if (
- mw.user.options.get( 'upwiz_skiptutorial' ) ||
- ( mw.config.get( 'UploadWizardConfig'
).tutorial && mw.config.get( 'UploadWizardConfig' ).tutorial.skip )
- ) {
- // "select" the second step - highlight, make
it visible, hide all others
- this.moveToStep( 'file' );
- } else {
- // "select" the first step - highlight, make it
visible, hide all others
- this.moveToStep( 'tutorial' );
- ( new mw.UploadWizardTutorialEvent( 'load' )
).dispatch();
- }
+ // "select" the first step - highlight, make it
visible, hide all others
+ this.steps.tutorial.moveTo();
},
/**
@@ -263,64 +241,6 @@
},
/**
- * Advance one "step" in the wizard interface.
- * It is assumed that the previous step to the current one was
selected.
- * We do not hide the tabs because this messes up certain
calculations we'd like to make about dimensions, while elements are not
- * on screen. So instead we make the tabs zero height and, in
CSS, they are already overflow hidden
- * @param selectedStepName
- * @param callback to do after layout is ready?
- */
- moveToStep: function ( selectedStepName, callback ) {
- if ( this.currentStepName === selectedStepName ) {
- // already there!
- return;
- }
-
- // scroll to the top of the page (the current step
might have been very long, vertically)
- var headScroll = $( 'h1:first' ).offset(),
- fromStep = this.steps[this.currentStepName],
- targetStep = this.steps[selectedStepName];
-
- if ( fromStep ) {
- fromStep.moveFrom( this.uploads );
- }
-
- targetStep.moveTo( this.uploads );
-
- $( 'html, body' ).animate( { scrollTop: headScroll.top,
scrollLeft: headScroll.left }, 'slow' );
-
- if (
- selectedStepName === 'file' &&
- ( !this.currentStepName || this.currentStepName
=== 'thanks' )
- ) { // tutorial was skipped
- uw.eventFlowLogger.logSkippedStep( 'tutorial' );
- }
-
- uw.eventFlowLogger.logStep( selectedStepName );
-
- this.currentStepName = selectedStepName;
-
- if ( selectedStepName === 'file' ) {
- this.resetFileStepUploads();
- }
-
- $.each( this.uploads, function (i, upload) {
- if ( upload === undefined ) {
- return;
- }
- upload.state = selectedStepName;
- } );
-
- this.currentStepObject = targetStep;
-
- this.currentStepObject.updateFileCounts( this.uploads );
-
- if ( callback ) {
- callback();
- }
- },
-
- /**
* If there are no uploads, make a new one
*/
resetFileStepUploads: function () {
@@ -389,11 +309,11 @@
// Add a new upload to cover the button
wizard.newUpload();
-
wizard.currentStepObject.updateFileCounts( wizard.uploads );
+ wizard.steps.file.updateFileCounts(
wizard.uploads );
} )
.on( 'filename-accepted', function () {
-
wizard.currentStepObject.updateFileCounts( wizard.uploads );
+ wizard.steps.file.updateFileCounts(
wizard.uploads );
} )
.on( 'error', function ( code, message ) {
@@ -420,12 +340,7 @@
this.uploads.push( upload );
- //If upload is through a local file, then we need to
show the Deeds step of the wizard
- if ( !upload.fromURL ) {
- this.showDeed = true;
- }
-
- this.currentStepObject.updateFileCounts( this.uploads );
+ this.steps.file.updateFileCounts( this.uploads );
// Start uploads now, no reason to wait--leave the
remove button alone
this.steps.file.transitionAll().done( function () {
@@ -455,7 +370,7 @@
}
);
- this.currentStepObject.updateFileCounts( this.uploads );
+ this.steps.file.updateFileCounts( this.uploads );
if ( this.uploads && this.uploads.length !== 0 ) {
// check all uploads, if they're complete, show
the next button
diff --git a/resources/ui/uw.ui.Step.js b/resources/ui/uw.ui.Step.js
index 99cf30a..0d5c10d 100644
--- a/resources/ui/uw.ui.Step.js
+++ b/resources/ui/uw.ui.Step.js
@@ -42,11 +42,18 @@
* @param {mw.UploadWizardUpload[]} uploads
*/
SP.moveTo = function ( uploads ) {
+ var offset = $( 'h1:first' ).offset();
+
this.uploads = uploads;
// Remove the initial spinner if it's still present
$( '#mwe-first-spinner' ).remove();
this.$div.show();
$( '#mwe-upwiz-steps' ).arrowStepsHighlight( this.$arrow );
+
+ $( 'html, body' ).animate( {
+ scrollTop: offset.top,
+ scrollLeft: offset.left
+ }, 'slow' );
};
/**
diff --git a/resources/ui/uw.ui.Thanks.js b/resources/ui/uw.ui.Thanks.js
index 7dd6b0c..f7aee13 100644
--- a/resources/ui/uw.ui.Thanks.js
+++ b/resources/ui/uw.ui.Thanks.js
@@ -25,7 +25,8 @@
* @constructor
*/
function Thanks() {
- var $header;
+ var $header,
+ thanks = this;
ui.Step.call(
this,
@@ -47,6 +48,18 @@
} else {
$header.html(
mw.UploadWizard.config.display.thanksLabel );
}
+
+ // "Upload more files" button
+ this.$div.find( '.mwe-upwiz-button-begin' )
+ .click( function () {
+ thanks.emit( 'next-step' );
+ } );
+
+ // "Go to wiki home" button
+ $( '.mwe-upwiz-button-home' )
+ .click( function () {
+ window.location.href = mw.config.get(
'wgArticlePath' ).replace( '$1', '' );
+ } );
}
oo.inheritClass( Thanks, ui.Step );
diff --git a/resources/ui/uw.ui.Wizard.js b/resources/ui/uw.ui.Wizard.js
index e270305..2602038 100644
--- a/resources/ui/uw.ui.Wizard.js
+++ b/resources/ui/uw.ui.Wizard.js
@@ -143,19 +143,10 @@
* Initialize all of the buttons in the interface.
*/
UWIP.initButtons = function () {
- var ui = this;
-
// make all stepdiv proceed buttons into jquery buttons
$( '.mwe-upwiz-stepdiv .mwe-upwiz-buttons button' )
.button()
.css( { 'margin-left': '1em' } );
-
- $( '.mwe-upwiz-button-begin' )
- .click( function () { ui.emit( 'reset-wizard' ); } );
-
- $( '.mwe-upwiz-button-home' )
- .click( function () { window.location.href =
mw.config.get( 'wgArticlePath' ).replace( '$1', '' ); } );
-
};
ui.Wizard = UploadWizardInterface;
diff --git a/tests/qunit/controller/uw.controller.Step.test.js
b/tests/qunit/controller/uw.controller.Step.test.js
index 059bc3e..5251a81 100644
--- a/tests/qunit/controller/uw.controller.Step.test.js
+++ b/tests/qunit/controller/uw.controller.Step.test.js
@@ -19,7 +19,7 @@
QUnit.module( 'mw.uw.controller.Step', QUnit.newMwEnvironment() );
QUnit.test( 'Constructor sanity test', 2, function ( assert ) {
- var step = new uw.controller.Step( {}, {} );
+ var step = new uw.controller.Step( { on: $.noop }, {} );
assert.ok( step );
assert.ok( step.ui );
} );
@@ -30,7 +30,7 @@
ds = [ $.Deferred(), $.Deferred(), $.Deferred() ],
ps = [ ds[0].promise(), ds[1].promise(),
ds[2].promise() ],
calls = [],
- step = new uw.controller.Step( {}, {
+ step = new uw.controller.Step( { on: $.noop }, {
maxSimultaneousConnections: 3
} );
--
To view, visit https://gerrit.wikimedia.org/r/199314
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I62b17ccd4e8a0fbe06075550b6a77b5f185788e9
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits