[MediaWiki-commits] [Gerrit] Auto-refresh graph on editing - change (mediawiki...Graph)
Yurik has uploaded a new change for review. https://gerrit.wikimedia.org/r/161894 Change subject: Auto-refresh graph on editing .. Auto-refresh graph on editing Requires https://gerrit.wikimedia.org/r/161893 Change-Id: I12f481c10576ffe53f60d820900dc0dd876902a1 --- M Graph.body.php M Graph.php A js/graph.editor.js M js/graph.js 4 files changed, 65 insertions(+), 46 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Graph refs/changes/94/161894/1 diff --git a/Graph.body.php b/Graph.body.php index 867ad71..9b89931 100644 --- a/Graph.body.php +++ b/Graph.body.php @@ -13,6 +13,7 @@ use Html; use JsonConfig\JCContent; use JsonConfig\JCContentView; +use JsonConfig\JCSingleton; use Parser; use ParserOptions; use ParserOutput; @@ -55,6 +56,21 @@ $parserOutput-addModules( 'ext.graph' ); return $parserOutput; } + + /** +* @param \EditPage $editpage +* @param \OutputPage $output +* @return bool +*/ + public static function editPageShowEditFormInitial( $editpage, $output ) { + // TODO: not sure if this is the best way to test + if ( $editpage-contentFormat === CONTENT_FORMAT_JSON +JCSingleton::getContentClass( $editpage-contentModel ) === __NAMESPACE__ . '\Content' + ) { + $output-addModules( 'ext.graph.editor' ); + } + return true; + } } /** diff --git a/Graph.php b/Graph.php index 34a3ec6..81aa27e 100644 --- a/Graph.php +++ b/Graph.php @@ -47,49 +47,17 @@ $wgGraphDataDomains = array(); $wgHooks['ParserFirstCallInit'][] = 'Graph\Singleton::onParserFirstCallInit'; +$wgHooks['EditPage::showEditForm:initial'][] = 'Graph\Singleton::editPageShowEditFormInitial'; - -// ResourceLoader modules -/** - * A boilerplate for resource loader modules - */ $extGraphBoilerplate = array( 'localBasePath' = __DIR__, 'remoteExtPath' = 'Graph', 'targets' = array( 'mobile', 'desktop' ), ); -$wgResourceModules['mediawiki.libs.d3'] = array( -'scripts' = array( -'lib/d3.js', -//'lib/d3.geo.projection.min.js', -), -) + $extGraphBoilerplate; -$wgResourceModules['mediawiki.libs.topojson'] = array( -'scripts' = array( -'lib/topojson.js', -), -) + $extGraphBoilerplate; -$wgResourceModules['mediawiki.libs.vega'] = array( -'dependencies' = array( -'mediawiki.libs.d3', -'mediawiki.libs.topojson', -), -'scripts' = array( -'lib/vega.js', -), -) + $extGraphBoilerplate; $wgResourceModules['ext.graph'] = array( -// TODO: dependencies don't work. Symptoms: -// * Firefox works -// * Chrome works in debug mode -// * Chrome does not work in production mode (debug=false) -//'dependencies' = array( -//'mediawiki.libs.vega', -//), 'scripts' = array( 'lib/d3.js', -// 'lib/d3.geo.projection.min.js', 'lib/topojson.js', 'lib/vega.js', 'js/graph.js', @@ -98,4 +66,11 @@ 'styles/common.less', ), ) + $extGraphBoilerplate; + +$wgResourceModules['ext.graph.editor'] = array( +'scripts' = array( +'js/graph.editor.js', +) +) + $extGraphBoilerplate; + unset( $extGraphBoilerplate ); diff --git a/js/graph.editor.js b/js/graph.editor.js new file mode 100644 index 000..7670cc4 --- /dev/null +++ b/js/graph.editor.js @@ -0,0 +1,30 @@ +( function( $ ) { + var oldContent = ''; + (function() { + $('.mw-wiki-graph').each(function () { + // This should not be a loop - there must be only one value with this class + var el = this, + textbox = $('#wpTextbox1'), + context = textbox textbox.data('wikiEditor-context'); + + if (!context || !context.evt || !context.evt.codeEditorSync || !context.fn) { + return; + } + context.evt.codeEditorSync(); + var content = context.fn.getContents(); + if (oldContent === content) { + return; + } + oldContent = content; + var annotations = context.codeEditor.getSession().getAnnotations(); + if (annotations.every(function(v) { return v.type !== 'error'; })) { + if (this.hasAttribute('spec')) + this.removeAttribute('spec'); + var spec = $.parseJSON(content); + vg.parse.spec(spec, function(chart) { chart({el:el}).update(); }) + } + }); + // FIXME: This should be
[MediaWiki-commits] [Gerrit] Auto-refresh graph on editing - change (mediawiki...Graph)
jenkins-bot has submitted this change and it was merged. Change subject: Auto-refresh graph on editing .. Auto-refresh graph on editing Requires https://gerrit.wikimedia.org/r/161893 Change-Id: I12f481c10576ffe53f60d820900dc0dd876902a1 --- M Graph.body.php M Graph.php A js/graph.editor.js M js/graph.js 4 files changed, 65 insertions(+), 46 deletions(-) Approvals: Yurik: Looks good to me, approved jenkins-bot: Verified diff --git a/Graph.body.php b/Graph.body.php index 867ad71..9b89931 100644 --- a/Graph.body.php +++ b/Graph.body.php @@ -13,6 +13,7 @@ use Html; use JsonConfig\JCContent; use JsonConfig\JCContentView; +use JsonConfig\JCSingleton; use Parser; use ParserOptions; use ParserOutput; @@ -55,6 +56,21 @@ $parserOutput-addModules( 'ext.graph' ); return $parserOutput; } + + /** +* @param \EditPage $editpage +* @param \OutputPage $output +* @return bool +*/ + public static function editPageShowEditFormInitial( $editpage, $output ) { + // TODO: not sure if this is the best way to test + if ( $editpage-contentFormat === CONTENT_FORMAT_JSON +JCSingleton::getContentClass( $editpage-contentModel ) === __NAMESPACE__ . '\Content' + ) { + $output-addModules( 'ext.graph.editor' ); + } + return true; + } } /** diff --git a/Graph.php b/Graph.php index 34a3ec6..81aa27e 100644 --- a/Graph.php +++ b/Graph.php @@ -47,49 +47,17 @@ $wgGraphDataDomains = array(); $wgHooks['ParserFirstCallInit'][] = 'Graph\Singleton::onParserFirstCallInit'; +$wgHooks['EditPage::showEditForm:initial'][] = 'Graph\Singleton::editPageShowEditFormInitial'; - -// ResourceLoader modules -/** - * A boilerplate for resource loader modules - */ $extGraphBoilerplate = array( 'localBasePath' = __DIR__, 'remoteExtPath' = 'Graph', 'targets' = array( 'mobile', 'desktop' ), ); -$wgResourceModules['mediawiki.libs.d3'] = array( -'scripts' = array( -'lib/d3.js', -//'lib/d3.geo.projection.min.js', -), -) + $extGraphBoilerplate; -$wgResourceModules['mediawiki.libs.topojson'] = array( -'scripts' = array( -'lib/topojson.js', -), -) + $extGraphBoilerplate; -$wgResourceModules['mediawiki.libs.vega'] = array( -'dependencies' = array( -'mediawiki.libs.d3', -'mediawiki.libs.topojson', -), -'scripts' = array( -'lib/vega.js', -), -) + $extGraphBoilerplate; $wgResourceModules['ext.graph'] = array( -// TODO: dependencies don't work. Symptoms: -// * Firefox works -// * Chrome works in debug mode -// * Chrome does not work in production mode (debug=false) -//'dependencies' = array( -//'mediawiki.libs.vega', -//), 'scripts' = array( 'lib/d3.js', -// 'lib/d3.geo.projection.min.js', 'lib/topojson.js', 'lib/vega.js', 'js/graph.js', @@ -98,4 +66,11 @@ 'styles/common.less', ), ) + $extGraphBoilerplate; + +$wgResourceModules['ext.graph.editor'] = array( +'scripts' = array( +'js/graph.editor.js', +) +) + $extGraphBoilerplate; + unset( $extGraphBoilerplate ); diff --git a/js/graph.editor.js b/js/graph.editor.js new file mode 100644 index 000..e3ec172 --- /dev/null +++ b/js/graph.editor.js @@ -0,0 +1,30 @@ +( function( $ ) { + var oldContent = ''; + (function() { + $('.mw-wiki-graph').each(function () { + // This should not be a loop - there must be only one value with this class + var el = this, + textbox = $('#wpTextbox1'), + context = textbox textbox.data('wikiEditor-context'); + + if (!context || !context.evt || !context.evt.codeEditorSync || !context.fn) { + return; + } + context.evt.codeEditorSync(); + var content = context.fn.getContents(); + if (oldContent === content) { + return; + } + oldContent = content; + var annotations = context.codeEditor.getSession().getAnnotations(); + if (annotations.every(function(v) { return v.type !== 'error'; })) { + if (this.hasAttribute('spec')) + this.removeAttribute('spec'); + var spec = $.parseJSON(content); + vg.parse.spec(spec, function(chart) { chart({el:el}).update(); }); + } + }); + // FIXME: This should be done on data modification, not on timer +