Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358938 )

Change subject: Use QueryTemplate class in VisualEditor
......................................................................

Use QueryTemplate class in VisualEditor

Throw out most template-related code in VisualEditor and instead use the
new QueryTemplate class (which inherited a lot of the now deleted code).

Bug: T167868
Change-Id: Idf56559ba3fe8a42ea6f05b9d479784eb0ce9df0
---
M wikibase/queryService/ui/visualEditor/VisualEditor.js
1 file changed, 17 insertions(+), 72 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui 
refs/changes/38/358938/1

diff --git a/wikibase/queryService/ui/visualEditor/VisualEditor.js 
b/wikibase/queryService/ui/visualEditor/VisualEditor.js
index e7c1a21..15f9b78 100644
--- a/wikibase/queryService/ui/visualEditor/VisualEditor.js
+++ b/wikibase/queryService/ui/visualEditor/VisualEditor.js
@@ -146,11 +146,26 @@
         * @param {jQuery} $element
         */
        SELF.prototype.draw = function( $element ) {
-               var template = this._getQueryTemplateDefinition();
+               var template = 
wikibase.queryService.ui.visualEditor.QueryTemplate.parse( this._query ),
+                       self = this,
+                       bindings = this._query.getBindings();
 
                if ( template !== null ) {
                        try {
-                               return $element.html( 
this._getQueryTemplateHtml( template ) );
+                               return $element.html( template.getHtml(
+                                       function( variable ) {
+                                               return self._getLabel( 
bindings[ variable ].expression );
+                                       },
+                                       this._selectorBox,
+                                       function( variable, oldId, newId ) {
+                                               bindings[ variable ].expression 
= bindings[ variable ].expression
+                                                       .replace( new RegExp( 
oldId + '$' ), '' )
+                                                       + newId;
+                                               if ( self._changeListener ) {
+                                                       self._changeListener( 
self );
+                                               }
+                                       }
+                               ) );
                        } catch ( e ) {
                                window.console.error( e );
                        }
@@ -167,76 +182,6 @@
 
                this._isSimpleMode = this._isSimpleQuery();
                $element.html( this._getHtml() );
-       };
-
-       /**
-        * Get the template definition from query comments
-        *
-        * @return {object}|null
-        */
-       SELF.prototype._getQueryTemplateDefinition = function() {
-               var templateComment = null,
-                       template = null;
-
-               try {
-                       templateComment = this._query.getCommentContent( 
'TEMPLATE=' );
-                       if ( templateComment ) {
-                               template = JSON.parse( templateComment );
-                       }
-               } catch ( e ) {
-               }
-
-               return template;
-       };
-
-       /**
-        * Get the template definition or null
-        *
-        * @param {object} definition
-        */
-       SELF.prototype._getQueryTemplateHtml = function( definition ) {
-               var self = this,
-                       template = $( '<span>' ).text( definition.template 
)[0].outerHTML,
-                       $html = $( '<div>' ),
-                       bindings = this._query.getBindings();
-
-               $.each( definition.variables, function( variable, varDef ) {
-                       var $label = $( '<span>' );
-
-                       self._getLabel( bindings[variable].expression ).done(
-                                       function( label, id, description, type 
) {
-                                               var $link = $( '<a>' ).text( 
label ).attr( {
-                                                       'data-id': id,
-                                                       'data-type': type,
-                                                       href: '#'
-                                               } ).appendTo( $label );
-
-                                               if ( varDef.query ) {
-                                                       $link.attr( 
'data-sparql', varDef.query );
-                                               }
-
-                                               self._selectorBox.add( $link, 
null, function( selectedId, name ) {
-                                                       
bindings[variable].expression = bindings[variable].expression.replace(
-                                                                       new 
RegExp( id + '$' ), '' ) +
-                                                                       
selectedId;// TODO: technical debt
-                                                       $link.attr( {
-                                                               'data-id': 
selectedId
-                                                       } );
-                                                       $link.text( name );
-
-                                                       if ( 
self._changeListener ) {
-                                                               
self._changeListener( self );
-                                                       }
-                                                       id = selectedId;
-                                               } );
-
-                                               $html.find( '[data-variable="' 
+ variable + '"]' ).append( $label );
-                                       } );
-
-                       template = template.replace( variable, $( '<span>' 
).attr( 'data-variable', variable )[0].outerHTML );
-               } );
-
-               return $html.append( $( template ) );
        };
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/358938
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idf56559ba3fe8a42ea6f05b9d479784eb0ce9df0
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to