Jonas Kress (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/283191

Change subject: Rdf cleanup
......................................................................

Rdf cleanup

move ENTITY_TYPES to RdfNamespaces
Rdf tooltip use debounce and modify styling

Change-Id: I4a3a7c97e43d14bc02436229cf3eef89b50912df
---
M wikibase/queryService/RdfNamespaces.js
M wikibase/queryService/ui/editor/hint/Rdf.js
M wikibase/queryService/ui/editor/tooltip/Rdf.js
3 files changed, 56 insertions(+), 56 deletions(-)


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

diff --git a/wikibase/queryService/RdfNamespaces.js 
b/wikibase/queryService/RdfNamespaces.js
index ba794f8..367954a 100644
--- a/wikibase/queryService/RdfNamespaces.js
+++ b/wikibase/queryService/RdfNamespaces.js
@@ -42,6 +42,20 @@
                }
        };
 
+       RdfNamespaces.ENTITY_TYPES = {
+                       'http://www.wikidata.org/prop/direct/': 'property',
+                       'http://www.wikidata.org/prop/': 'property',
+                       'http://www.wikidata.org/prop/novalue/': 'property',
+                       'http://www.wikidata.org/prop/statement/': 'property',
+                       'http://www.wikidata.org/prop/statement/value/': 
'property',
+                       'http://www.wikidata.org/prop/qualifier/': 'property',
+                       'http://www.wikidata.org/prop/qualifier/value/': 
'property',
+                       'http://www.wikidata.org/prop/reference/': 'property',
+                       'http://www.wikidata.org/prop/reference/value/': 
'property',
+                       'http://www.wikidata.org/wiki/Special:EntityData/': 
'item',
+                       'http://www.wikidata.org/entity/': 'item'
+               };
+
        RdfNamespaces.ALL_PREFIXES = $.map(RdfNamespaces.NAMESPACE_SHORTCUTS,
                        function(n) { return n; }
        ).reduce(function(p, v, i) { return $.extend(p, v); }, {});
diff --git a/wikibase/queryService/ui/editor/hint/Rdf.js 
b/wikibase/queryService/ui/editor/hint/Rdf.js
index 0039a48..77b17b2 100755
--- a/wikibase/queryService/ui/editor/hint/Rdf.js
+++ b/wikibase/queryService/ui/editor/hint/Rdf.js
@@ -9,20 +9,6 @@
 
        var MODULE = wb.queryService.ui.editor.hint;
 
-       var ENTITY_TYPES = {
-                       'http://www.wikidata.org/prop/direct/': 'property',
-                       'http://www.wikidata.org/prop/': 'property',
-                       'http://www.wikidata.org/prop/novalue/': 'property',
-                       'http://www.wikidata.org/prop/statement/': 'property',
-                       'http://www.wikidata.org/prop/statement/value/': 
'property',
-                       'http://www.wikidata.org/prop/qualifier/': 'property',
-                       'http://www.wikidata.org/prop/qualifier/value/': 
'property',
-                       'http://www.wikidata.org/prop/reference/': 'property',
-                       'http://www.wikidata.org/prop/reference/value/': 
'property',
-                       'http://www.wikidata.org/wiki/Special:EntityData/': 
'item',
-                       'http://www.wikidata.org/entity/': 'item'
-       };
-
        /**
         * Code completion for Wikibase entities RDF prefixes in SPARQL
         * completes SPARQL keywords and ?variables
@@ -173,15 +159,16 @@
        };
 
        SELF.prototype._extractPrefixes = function( text ) {
-               var prefixes = this._rdfNamespaces.getPrefixMap(ENTITY_TYPES),
+               var prefixes = this._rdfNamespaces.getPrefixMap( 
this._rdfNamespaces.ENTITY_TYPES),
+                       types = this._rdfNamespaces.ENTITY_TYPES,
                        lines = text.split( '\n' ),
                        matches;
 
                $.each( lines, function ( index, line ) {
                        // PREFIX wd: <http://www.wikidata.org/entity/>
                        if ( ( matches = line.match( /(PREFIX) (\S+): 
<([^>]+)>/ ) ) ) {
-                               if ( ENTITY_TYPES[ matches[ 3 ] ] ) {
-                                       prefixes[ matches[ 2 ] ] = 
ENTITY_TYPES[ matches[ 3 ] ];
+                               if ( types[ matches[ 3 ] ] ) {
+                                       prefixes[ matches[ 2 ] ] =  types[ 
matches[ 3 ] ];
                                }
                        }
                } );
diff --git a/wikibase/queryService/ui/editor/tooltip/Rdf.js 
b/wikibase/queryService/ui/editor/tooltip/Rdf.js
index 4f900d2..4adbbcb 100644
--- a/wikibase/queryService/ui/editor/tooltip/Rdf.js
+++ b/wikibase/queryService/ui/editor/tooltip/Rdf.js
@@ -4,7 +4,7 @@
 wikibase.queryService.ui.editor = wikibase.queryService.ui.editor || {};
 wikibase.queryService.ui.editor.tooltip = 
wikibase.queryService.ui.editor.tooltip || {};
 
-wikibase.queryService.ui.editor.tooltip.Rdf = ( function ( CodeMirror, $ ) {
+wikibase.queryService.ui.editor.tooltip.Rdf = ( function ( CodeMirror, $, _ ) {
        'use strict';
 
        /**
@@ -17,65 +17,65 @@
         * @constructor
         * @param {wikibase.queryService.api.Wikibase} api
         */
-       function SELF( api ) {
+       function SELF( api, rdfNamespaces ) {
                this._api = api;
+               this._rdfNamespaces = rdfNamespaces;
 
                if ( !this._api ){
                        this._api = new wikibase.queryService.api.Wikibase();
                }
+
+               if( !this._rdfNamespaces ){
+                       this._rdfNamespaces = 
wikibase.queryService.RdfNamespaces;
+               }
        }
 
-       SELF.prototype.editor = null;
-       SELF.prototype.tooltipTimeoutHandler = null;
+       /**
+        * @property {wikibase.queryService.RdfNamespace}
+        * @private
+        **/
+       SELF.prototype._rdfNamespaces = null;
 
-       var ENTITY_TYPES = {
-               'http://www.wikidata.org/prop/direct/': 'property',
-               'http://www.wikidata.org/prop/': 'property',
-               'http://www.wikidata.org/prop/novalue/': 'property',
-               'http://www.wikidata.org/prop/statement/': 'property',
-               'http://www.wikidata.org/prop/statement/value/': 'property',
-               'http://www.wikidata.org/prop/qualifier/': 'property',
-               'http://www.wikidata.org/prop/qualifier/value/': 'property',
-               'http://www.wikidata.org/prop/reference/': 'property',
-               'http://www.wikidata.org/prop/reference/value/': 'property',
-               'http://www.wikidata.org/wiki/Special:EntityData/': 'item',
-               'http://www.wikidata.org/entity/': 'item'
-       };
+       /**
+        * @property {CodeMirror}
+        * @private
+        */
+       SELF.prototype._editor = null;
+
 
        /**
         * Set the editor the onmouseover callback is registered to
         *
-        * @param {wikibase.queryService.ui.editor.Editor} editor
+        * @param {CodeMirror} editor
         */
        SELF.prototype.setEditor = function ( editor ) {
-               this.editor = editor;
+               this._editor = editor;
                this._registerHandler();
        };
 
        SELF.prototype._registerHandler = function () {
-               CodeMirror.on( this.editor.getWrapperElement(), 'mouseover', 
$.proxy( this._triggerTooltip, this ) );
+               var self = this;
+
+               CodeMirror.on( this._editor.getWrapperElement(), 'mouseover', 
_.debounce( function( e ){
+                       self._triggerTooltip( e );
+               }, 300) );
        };//TODO: Remove CodeMirror dependency
 
        SELF.prototype._triggerTooltip = function ( e ) {
-               clearTimeout( this.tooltipTimeoutHandler );
                this._removeToolTip();
-
-               var self = this;
-               this.tooltipTimeoutHandler = setTimeout( function () {
-                       self._createTooltip( e );
-               }, 500 );
+               this._createTooltip( e );
        };
 
        SELF.prototype._createTooltip = function ( e ) {
                var posX = e.clientX,
                        posY = e.clientY + $( window ).scrollTop(),
-                       token = this.editor.getTokenAt( this.editor.coordsChar( 
{ left: posX, top: posY } ) ).string;
+                       token = this._editor.getTokenAt( 
this._editor.coordsChar( { left: posX, top: posY } ) ).string;
 
                if ( !token.match( /.+\:(Q|P)[0-9]*/ ) ) {
                        return;
                }
 
-               var prefixes = this._extractPrefixes( 
this.editor.doc.getValue() );
+               var prefixes = this._extractPrefixes( 
this._editor.doc.getValue() );
                var prefix = token.split( ':' ).shift();
                var entityId = token.split( ':' ).pop();
 
@@ -97,30 +97,29 @@
                if ( !text || !pos ) {
                        return;
                }
-               $( '<div/>' )
-               .text( text )
+
+               $( '<div class="panel panel-info">' )
                .css( 'position', 'absolute' )
-               .css( 'background-color', 'white' )
                .css( 'z-index', '100' )
-               .css( 'border', '1px solid grey' )
                .css( 'max-width', '200px' )
-               .css( 'padding', '5px' )
                .css( { top: pos.y + 2, left: pos.x + 2 } )
                .addClass( 'wikibaseRDFtoolTip' )
+               .append( $( '<div class="panel-body">' ).html( text ).css( 
'padding', '10px' ) )
                .appendTo( 'body' )
                .fadeIn( 'slow' );
        };
 
        SELF.prototype._extractPrefixes = function ( text ) {
-               var prefixes = 
wikibase.queryService.RdfNamespaces.getPrefixMap(ENTITY_TYPES),
+               var prefixes = this._rdfNamespaces.getPrefixMap( 
this._rdfNamespaces.ENTITY_TYPES ),
                        lines = text.split( '\n' ),
                        matches;
 
+               var self = this;
                $.each( lines, function ( index, line ) {
                        // PREFIX wd: <http://www.wikidata.org/entity/>
                        if ( ( matches = line.match( /(PREFIX) (\S+): 
<([^>]+)>/ ) ) ) {
-                               if ( ENTITY_TYPES[ matches[ 3 ] ] ) {
-                                       prefixes[ matches[ 2 ] ] = 
ENTITY_TYPES[ matches[ 3 ] ];
+                               if ( self._rdfNamespaces.ENTITY_TYPES[ matches[ 
3 ] ] ) {
+                                       prefixes[ matches[ 2 ] ] =  
self._rdfNamespaces.ENTITY_TYPES[ matches[ 3 ] ];
                                }
                        }
                } );
@@ -135,8 +134,8 @@
                this._api.searchEntities( term, type ).done( function ( data ) {
 
                        $.each( data.search, function ( key, value ) {
-                               entityList.push( value.label + ' (' + value.id 
+ ')\n' +
-                                                               ( 
value.description ? value.description: '' ) );
+                               entityList.push( value.label + ' ('+ value.id 
+')<br/><small>' +
+                                                               ( 
value.description ? value.description: '' ) + '</small>');
                        } );
 
                        deferred.resolve( entityList );
@@ -147,4 +146,4 @@
 
        return SELF;
 
-}( CodeMirror, jQuery ) );
+}( CodeMirror, jQuery, _ ) );

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

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

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

Reply via email to