Skip to content

Commit

Permalink
Support Del key to remove a bad record in the studio
Browse files Browse the repository at this point in the history
  • Loading branch information
0x010C committed Oct 28, 2018
1 parent 8fc3c57 commit a0e71c4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 22 deletions.
4 changes: 3 additions & 1 deletion modules/controller/mw.recordWizard.controller.Step.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@
if ( prevState !== 'up' ) {
rw.metadatas.statesCount[ prevState ]--;
}
rw.metadatas.statesCount[ state ]++;
if ( state !== 'up' ) {
rw.metadatas.statesCount[ state ]++;
}
this.ui.setItemState( word, state );
};

Expand Down
16 changes: 16 additions & 0 deletions modules/controller/mw.recordWizard.controller.Studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
}
}
} );

this.ui.on( 'delete-record', this.onDelete.bind( this ) );
};

/**
Expand Down Expand Up @@ -159,6 +161,20 @@
}
};

/**
* Event handler called when the user want to delete a record.
*/
rw.controller.Studio.prototype.onDelete = function () {
// Reset the selected word
rw.records[ this.currentWord ].reset();
this.ui.setItemState( this.currentWord, 'up', '' );

// If a record is pending, cancel it
if ( this.isRecording ) {
this.selectWord( this.currentWord );
}
};

/**
* Event handler called when an audio record got saturated.
*
Expand Down
51 changes: 32 additions & 19 deletions modules/mw.recordWizard.Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,28 @@
* Clear locally the audio record file.
*/
rw.Record.prototype.remove = function () {
// TODO: abort request if uploading
// this.offStateChange();
this.file = null;

// Cancel any pending request
if ( this.deferred !== undefined ) {
this.deferred.reject( 'cancel' );
}
};

/**
* Reset the object
*/
rw.Record.prototype.reset = function () {
// TODO: abort request if uploading
// this.offStateChange();
this.file = null;
this.filekey = null;
this.imageInfo = null;
this.error = false;
this.state = 'up';
this.setState( 'up' );

// Cancel any pending request
if ( this.deferred !== undefined ) {
this.deferred.reject( 'cancel' );
}
};

/**
Expand All @@ -338,15 +344,19 @@
if ( this.state === 'ready' || this.state === 'error' ) {
this.setState( 'stashing' );

this.deferred = deferred;

api.upload( this.file, {
stash: true,
filename: this.getFilename()
} ).then( function ( result ) {
} ).then( deferred.resolve.bind( deferred ), deferred.reject.bind( deferred ) );

this.deferred.then( function ( result ) {
record.setFilekey( result.upload.filekey );
deferred.resolve( result );
} ).fail( function ( errorCode, result ) {
deferred.reject( errorCode, result );
record.setError( errorCode );
}, function ( errorCode ) {
if ( errorCode !== 'cancel' ) {
record.setError( errorCode );
}
} );
}
};
Expand All @@ -364,25 +374,28 @@

if ( this.state === 'error' && this.imageInfo !== null ) {
deferred.resolve();
return;
}

this.setState( 'uploading' );

// TODO: switch from upload to upload-to-commons, if available
// use the config to detect it
this.deferred = deferred;

api.postWithToken( 'csrf', {
action: 'upload-to-commons',
format: 'json',
filekey: this.getFilekey(),
filename: this.getFilename(),
text: this.getText(),
ignorewarnings: true // TODO: manage warnings !important
} ).then( function ( result ) {
} ).then( deferred.resolve.bind( deferred ), deferred.reject.bind( deferred ) );

this.deferred.then( function ( result ) {
record.uploaded( result[ 'upload-to-commons' ].oauth.upload.imageinfo );
deferred.resolve();
} ).fail( function ( code, result ) {
record.setError( code );
deferred.reject( code, result );
}, function ( errorCode ) {
if ( errorCode !== 'cancel' ) {
record.setError( errorCode );
}
} );
};

Expand Down Expand Up @@ -418,13 +431,13 @@

this.wbItem.labels = { en: this.word };

lang = rw.config.languages[ rw.metadatas.language ]
lang = rw.config.languages[ rw.metadatas.language ];
this.wbItem.descriptions = { en: 'audio record - ' + ( lang.iso3 !== null ? lang.iso3 : lang.wikidataId ) + ' - ' + rw.metadatas.locutor.name + ' (' + mw.config.get( 'wgUserName' ) + ')' };

this.wbItem.addOrReplaceStatements( new rw.wikibase.Statement( rw.config.properties.instanceOf ).setType( 'wikibase-item' ).setValue( rw.config.items.record ), true ); // InstanceOf
this.wbItem.addOrReplaceStatements( new rw.wikibase.Statement( rw.config.properties.subclassOf ).setType( 'wikibase-item' ).setValue( rw.config.items.word ), true ); // SubclassOf
if ( mw.Debug === undefined ) { // Disable media on the dev environment
this.wbItem.addOrReplaceStatements( new rw.wikibase.Statement( rw.config.properties.audioRecord ).setType( 'commonsMedia' ).setValue( this.getFilename() ), true ); //Audio file
this.wbItem.addOrReplaceStatements( new rw.wikibase.Statement( rw.config.properties.audioRecord ).setType( 'commonsMedia' ).setValue( this.getFilename() ), true ); // Audio file
}
this.wbItem.addOrReplaceStatements( new rw.wikibase.Statement( rw.config.properties.spokenLanguages ).setType( 'wikibase-item' ).setValue( rw.metadatas.language ), true ); // Language
this.wbItem.addOrReplaceStatements( new rw.wikibase.Statement( rw.config.properties.locutor ).setType( 'wikibase-item' ).setValue( rw.metadatas.locutor.qid ), true ); // Locutor
Expand Down
3 changes: 3 additions & 0 deletions modules/ui/mw.recordWizard.ui.Publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
};

rw.ui.Publish.prototype.setItemState = function ( word, state ) {
if ( !( word in this.recordItems ) ) {
return;
}
// TODO: use a correlation table to asociate state and HTML class
if ( [ 'done', 'error' ].indexOf( state ) > -1 ) {
$( 'html, body' ).stop( true );
Expand Down
10 changes: 8 additions & 2 deletions modules/ui/mw.recordWizard.ui.Studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
* @inheritDoc
*/
rw.ui.Studio.prototype.load = function () {
var word,
ui = this;
var word;
rw.ui.Step.prototype.load.call( this );

this.isRecording = false;
Expand Down Expand Up @@ -124,6 +123,11 @@
ui.emit( 'next-item-click' );
break;

case 46: // del
case 8: // backspace
ui.emit( 'delete-record' );
break;

default: return;
}
event.preventDefault();
Expand Down Expand Up @@ -278,6 +282,8 @@
if ( total > 0 ) {
this.$recordCounter.text( mw.message( 'mwe-recwiz-studio-uploadcount', count.stashed, total ).text() );
this.$recordCounter.show();
} else {
this.$recordCounter.hide();
}
};

Expand Down

0 comments on commit a0e71c4

Please sign in to comment.