Thiemo Mättig (WMDE) has uploaded a new change for review.

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

Change subject: Add inline documentation to gui.js and fix some style issues
......................................................................

Add inline documentation to gui.js and fix some style issues

The other files (other than gui.js) do have a lot more issues but I
did not wanted to make this patch to big. Will continue working on
them in later patches.

Change-Id: I2e049e6bac30538e5e14230816b278789223ecfb
---
M gui/gui.js
M gui/index.html
M gui/style.css
M gui/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js
M gui/wikibase/codemirror/addon/hint/wikibase-sparql-hint.js
M gui/wikibase/codemirror/addon/tooltip/WikibaseRDFTooltip.js
6 files changed, 128 insertions(+), 79 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/rdf 
refs/changes/82/251482/1

diff --git a/gui/gui.js b/gui/gui.js
index 355a383..f941b8d 100644
--- a/gui/gui.js
+++ b/gui/gui.js
@@ -41,7 +41,7 @@
                                'hint': 'http://www.bigdata.com/queryHints#'
                        }
                },
-               STANDARD_PREFIXES =[
+               STANDARD_PREFIXES = [
                        'PREFIX wd: <http://www.wikidata.org/entity/>',
                        'PREFIX wdt: <http://www.wikidata.org/prop/direct/>',
                        'PREFIX wikibase: <http://wikiba.se/ontology#>',
@@ -63,24 +63,24 @@
                LAST_RESULT = null,
                DOWNLOAD_FORMATS = {
                        'CSV': {
-                               handler: getCSVData,
+                               handler: getCsvData,
                                mimetype: 'text/csv;charset=utf-8'
                        },
                        'JSON': {
-                               handler: getJSONData,
+                               handler: getJsonData,
                                mimetype: 'application/json;charset=utf-8'
                        },
                        'TSV': {
-                               handler: getSparqlTSVData,
+                               handler: getSparqlTsvData,
                                mimetype: 
'text/tab-separated-values;charset=utf-8'
                        },
                        'Simple TSV': {
-                               handler: getSimpleTSVData,
+                               handler: getSimpleTsvData,
                                mimetype: 
'text/tab-separated-values;charset=utf-8',
                                ext: 'tsv'
                        },
                        'Full JSON': {
-                               handler: getAllJSONData,
+                               handler: getAllJsonData,
                                mimetype: 'application/json;charset=utf-8',
                                ext: 'json'
                        }
@@ -88,6 +88,8 @@
 
        /**
         * Submit SPARQL query.
+        *
+        * @param {Event} e
         */
        function submitQuery( e ) {
                e.preventDefault();
@@ -119,6 +121,10 @@
 
        /**
         * Handle SPARQL error.
+        *
+        * @param {Object} jqXHR
+        * @param {string} textStatus
+        * @param {string} errorThrown
         */
        function queryResultsError( jqXHR, textStatus, errorThrown ) {
                var response,
@@ -139,6 +145,8 @@
 
        /**
         * Show results of the query.
+        *
+        * @param {Object} data
         */
        function showQueryResults( data ) {
                var results, thead, i, tr, td, linkText, j, binding,
@@ -175,7 +183,7 @@
                                td = $( '<td>' ) ;
                                if ( data.head.vars[j] in 
data.results.bindings[i] ) {
                                        binding = 
data.results.bindings[i][data.head.vars[j]];
-                                       text = binding.value;
+                                       var text = binding.value;
                                        if ( binding.type === 'uri' ) {
                                                text = abbreviate( text );
                                        }
@@ -195,7 +203,7 @@
                                                        if ( 
binding.value.match( EXPLORE_URL ) ) {
                                                                td.append( $( 
'<a>' )
                                                                        .attr( 
'href', '#' )
-                                                                       .bind( 
'click', exploreURL.bind( undefined, binding.value ) )
+                                                                       .bind( 
'click', exploreUrl.bind( undefined, binding.value ) )
                                                                        .text( 
'*' )
                                                                );
                                                        }
@@ -222,6 +230,9 @@
 
        /**
         * Produce abbreviation of the URI.
+        *
+        * @param {string} uri
+        * @returns {string}
         */
        function abbreviate( uri ) {
                var nsGroup, ns;
@@ -288,6 +299,8 @@
 
        /**
         * Show/hide help text.
+        *
+        * @param {Event} e
         */
        function showHideHelp( e ) {
                var $seeAlso = $( '#seealso' );
@@ -330,6 +343,8 @@
 
        /**
         * Highlight SPARQL error in editor window.
+        *
+        * @param {string} description
         */
        function highlightError( description ) {
                var line, character,
@@ -353,8 +368,10 @@
 
        /**
         * Show explorer window for given URL.
+        *
+        * @param {string} url
         */
-       function exploreURL( url ) {
+       function exploreUrl( url ) {
                var id,
                        match = url.match( EXPLORE_URL + '(.+)' );
                if ( !match ) {
@@ -376,8 +393,10 @@
 
        /**
         * Hide explorer window.
+        *
+        * @param {Event} e
         */
-       function hideExlorer( e ) {
+       function hideExplorer( e ) {
                e.preventDefault();
                $( '#explore' ).empty( '' );
                $( '#hide-explorer' ).hide();
@@ -445,7 +464,7 @@
                $( '.exampleQueries' ).on( 'change', pasteExample );
                $( '.addPrefixes' ).click( addPrefixes );
                $( '#showhide' ).click( showHideHelp );
-               $( '#hide-explorer' ).click( hideExlorer );
+               $( '#hide-explorer' ).click( hideExplorer );
                $( '#clear-button' ).click( function () {
                        EDITOR.setValue( '' );
                } );
@@ -460,6 +479,11 @@
 
        /**
         * Create download handler function.
+        *
+        * @param {string} filename
+        * @param {Function} handler
+        * @param {string} mimetype
+        * @return {Function}
         */
        function downloadHandler( filename, handler, mimetype ) {
                return function ( e ) {
@@ -483,13 +507,15 @@
                                        'Accept': 
'application/sparql-results+json'
                                },
                                success: showDbQueryResults,
-                               error: DbQueryResultsError
+                               error: dbQueryResultsError
                        };
                $.ajax( url, settings );
        }
 
        /**
         * Show results for last DB update time.
+        *
+        * @param {Object} data
         */
        function showDbQueryResults( data ) {
                try {
@@ -508,15 +534,19 @@
 
        /**
         * Show error for last DB update time.
+        *
+        * @param {Object} jqXHR
+        * @param {string} textStatus
+        * @param {string} errorThrown
         */
-       function DbQueryResultsError( jqXHR, textStatus, errorThrown ) {
+       function dbQueryResultsError( jqXHR, textStatus, errorThrown ) {
                $( '#dbUpdated' ).text( '[unable to connect]' );
        }
 
        /**
         * Initialize GUI
         */
-       function startGUI() {
+       function startGui() {
                setupEditor();
                setupExamples();
                populateNamespaceShortcuts();
@@ -527,12 +557,17 @@
 
        /**
         * Process SPARQL query result.
+        *
+        * @param {Object} data
+        * @param {Function} rowHandler
+        * @param {*} context
+        * @return {*} The provided context, modified by the rowHandler.
         */
        function processData( data, rowHandler, context ) {
-               results = data.results.bindings.length;
-               for ( i = 0; i < results; i++ ) {
-                       rowBindings = {};
-                       for ( j = 0; j < data.head.vars.length; j++ ) {
+               var results = data.results.bindings.length;
+               for ( var i = 0; i < results; i++ ) {
+                       var rowBindings = {};
+                       for ( var j = 0; j < data.head.vars.length; j++ ) {
                                if ( data.head.vars[j] in 
data.results.bindings[i] ) {
                                        rowBindings[data.head.vars[j]] = 
data.results.bindings[i][data.head.vars[j]];
                                }
@@ -544,8 +579,11 @@
 
        /**
         * Encode string as CSV.
+        *
+        * @param {string} string
+        * @return {string}
         */
-       function encodeCSV( string ) {
+       function encodeCsv( string ) {
                var result = string.replace( /"/g, '""' );
                if ( result.search( /("|,|\n)/g ) >= 0 ) {
                        result = '"' + result + '"';
@@ -555,13 +593,16 @@
 
        /**
         * Get CSV rendering of the result data.
+        *
+        * @param {Object} data
+        * @return {string}
         */
-       function getCSVData( data ) {
-               out = data.head.vars.map( encodeCSV ).join( ',' ) + '\n';
+       function getCsvData( data ) {
+               var out = data.head.vars.map( encodeCsv ).join( ',' ) + '\n';
                out = processData( data, function ( row, out ) {
-                       rowOut = '';
+                       var rowOut = '';
                        for ( rowVar in row ) {
-                               var rowCSV = encodeCSV( row[rowVar].value );
+                               var rowCSV = encodeCsv( row[rowVar].value );
                                if ( rowOut.length > 0 ) {
                                        rowOut += ',';
                                }
@@ -577,11 +618,14 @@
 
        /**
         * Get TSV rendering of the result data.
+        *
+        * @param {Object} data
+        * @return {string}
         */
-       function getSimpleTSVData( data ) {
-               out = data.head.vars.join( '\t' ) + '\n';
+       function getSimpleTsvData( data ) {
+               var out = data.head.vars.join( '\t' ) + '\n';
                out = processData( data, function ( row, out ) {
-                       rowOut = '';
+                       var rowOut = '';
                        for ( rowVar in row ) {
                                var rowTSV = row[rowVar].value.replace( /\t/g, 
'' );
                                if ( rowOut.length > 0 ) {
@@ -599,6 +643,9 @@
 
        /**
         * Render value as per 
http://www.w3.org/TR/sparql11-results-csv-tsv/#tsv
+        *
+        * @param {Object} binding
+        * @return {string}
         */
        function renderValueTSV( binding ) {
                var value = binding.value.replace( /\t/g, '' );
@@ -629,13 +676,16 @@
        /**
         * Get TSV rendering of the result data according to SPARQL standard.
         * See: http://www.w3.org/TR/sparql11-results-csv-tsv/#tsv
+        *
+        * @param {Object} data
+        * @return {string}
         */
-       function getSparqlTSVData( data ) {
-               out = data.head.vars.map( function ( vname ) {
+       function getSparqlTsvData( data ) {
+               var out = data.head.vars.map( function ( vname ) {
                        return '?' + vname;
                } ).join( '\t' ) + '\n';
                out = processData( data, function ( row, out ) {
-                       rowOut = '';
+                       var rowOut = '';
                        for ( rowVar in row ) {
                                var rowTSV = renderValueTSV( row[rowVar] );
                                if ( rowOut.length > 0 ) {
@@ -650,13 +700,17 @@
                }, out );
                return out;
        }
+
        /**
         * Get JSON rendering of the result data.
+        *
+        * @param {Object} data
+        * @return {string}
         */
-       function getJSONData( data ) {
-               out = [];
+       function getJsonData( data ) {
+               var out = [];
                out = processData( data, function ( row, out ) {
-                       extractRow = {};
+                       var extractRow = {};
                        for ( rowVar in row ) {
                                extractRow[rowVar] = row[rowVar].value;
                        }
@@ -666,12 +720,20 @@
                return JSON.stringify( out );
        }
 
-       function getAllJSONData( data ) {
+       /**
+        * @param {Object} data
+        * @returns {string}
+        */
+       function getAllJsonData( data ) {
                return JSON.stringify( data );
        }
 
        /**
         * Produce file download.
+        *
+        * @param {string} filename
+        * @param {string} text
+        * @param {string} contentType
         */
        function download( filename, text, contentType ) {
                if ( !text ) {
@@ -688,7 +750,7 @@
        }
 
        $( document ).ready( function () {
-               startGUI();
+               startGui();
        } );
        $( window ).on( 'popstate', initQuery );
 } )( jQuery, mediaWiki );
diff --git a/gui/index.html b/gui/index.html
index 43b15b6..c98cf70 100644
--- a/gui/index.html
+++ b/gui/index.html
@@ -19,8 +19,7 @@
 <link rel="stylesheet" href="vendor/codemirror/addon/hint/show-hint.css">
 <link rel="stylesheet" href="style.css">
 
-<link rel="shortcut icon"
-       href="//www.wikidata.org/static/favicon/testwikidata.ico">
+<link rel="shortcut icon" 
href="//www.wikidata.org/static/favicon/testwikidata.ico">
 
 <title>Wikidata Query Service (Beta)</title>
 </head>
@@ -56,7 +55,7 @@
                                                                <li><a 
target="_blank" 
href="https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format";>RDF 
Data Model</a></li>
                                                                <li><a 
target="_blank" 
href="https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format#Full_list_of_prefixes";>List
 of prefixes</a></li>
                                                        </ul></li>
-                                               <li><select id="exampleQueries" 
class="exampleQueries form-control navbar-btn""><option value="">Query 
Examples</option></select></li>
+                                               <li><select id="exampleQueries" 
class="exampleQueries form-control navbar-btn"><option value="">Query 
Examples</option></select></li>
                                        </ul>
                                </div>
                        </nav>
diff --git a/gui/style.css b/gui/style.css
index 31373e0..039611c 100644
--- a/gui/style.css
+++ b/gui/style.css
@@ -1,45 +1,48 @@
 .error {
-   margin: 20px;
-   overflow-x: scroll;
-   font-family: monospace;
-   white-space: pre;
+       margin: 20px;
+       overflow-x: scroll;
+       font-family: monospace;
+       white-space: pre;
 }
 
-#total, #query-result,  #hide-explorer {
-   display: none;
+#total,
+#query-result,
+#hide-explorer {
+       display: none;
 }
+
 #query-error {
-   display: none;
+       display: none;
 }
 
 .error-line {
-   background: red;
+       background: red;
 }
 
 .error-character {
-   background: green;
+       background: green;
 }
 
 #query-result pre {
-  display: inline;
-  font-family: serif;
-  border: none;
-  background-color: inherit;
+       display: inline;
+       font-family: serif;
+       border: none;
+       background-color: inherit;
 }
 
 .cm-s-default .cm-bracket {
-  color: #000;
+       color: #000;
 }
 
 .CodeMirror {
-  border: 1px solid #ccc;
-  height: auto!important;
+       border: 1px solid #ccc;
+       height: auto !important;
 }
 
 .CodeMirror-scroll {
-  min-height: 300px; 
+       min-height: 300px;
 }
 
-.exampleQueries{
-       width:160px;
-}
\ No newline at end of file
+.exampleQueries {
+       width: 160px;
+}
diff --git a/gui/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js 
b/gui/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js
index 83dbdc5..2086092 100755
--- a/gui/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js
+++ b/gui/wikibase/codemirror/addon/hint/wikibase-rdf-hint.js
@@ -36,7 +36,6 @@
                ENTITY_SEARCH_API_ENDPOINT = 
'https://www.wikidata.org/w/api.php?action=wbsearchentities&search={term}&format=json&language=en&uselang=en&type={entityType}&continue=0';
 
        CodeMirror.registerHelper( 'hint', 'sparql', function ( editor, 
callback, options ) {
-
                if( wikibase_sparqlhint ){
                        wikibase_sparqlhint( editor, callback, options );
                }
@@ -70,15 +69,12 @@
                                callback( getHintCompletion( editor, 
currentWord, prefix, list ) );
                        } );
                }
-
        } );
 
        CodeMirror.hint.sparql.async = true;
        CodeMirror.defaults.hintOptions = {};
        CodeMirror.defaults.hintOptions.closeCharacters = /[]/;
        CodeMirror.defaults.hintOptions.completeSingle = false;
-
-
 
        function getPrefixFromWord( word ) {
                return word.split( ':' ).shift();
@@ -97,7 +93,6 @@
        }
 
        function getHintCompletion( editor, currentWord, prefix , list) {
-
                var completion = { list: [] };
                completion.from = CodeMirror.Pos( editor.getCursor().line, 
currentWord.start + prefix.length + 1 );
                completion.to = CodeMirror.Pos( editor.getCursor().line, 
currentWord.end );
@@ -114,9 +109,12 @@
                        url: ENTITY_SEARCH_API_ENDPOINT.replace( '{term}', term 
).replace( '{entityType}', type ),
                        dataType: 'jsonp'
                } ).done( function ( data ) {
-
                        $.each( data.search, function ( key, value ) {
-                               entityList.push( { className: 
'wikibase-rdf-hint', text: value.id, displayText: value.label + ' (' + value.id 
+ ') ' + value.description + '\n' } );
+                               entityList.push( {
+                                       className: 'wikibase-rdf-hint',
+                                       text: value.id,
+                                       displayText: value.label + ' (' + 
value.id + ') ' + value.description + '\n'
+                               } );
                        } );
 
                        deferred.resolve( entityList );
@@ -164,7 +162,7 @@
                                        prefixes[ matches[ 2 ] ] = 
ENTITY_TYPES[ matches[ 3 ] ];
                                }
                        }
-               } )
+               } );
 
                return prefixes;
        }
diff --git a/gui/wikibase/codemirror/addon/hint/wikibase-sparql-hint.js 
b/gui/wikibase/codemirror/addon/hint/wikibase-sparql-hint.js
index 0fe974a..d16e7fe 100755
--- a/gui/wikibase/codemirror/addon/hint/wikibase-sparql-hint.js
+++ b/gui/wikibase/codemirror/addon/hint/wikibase-sparql-hint.js
@@ -27,7 +27,6 @@
                var currentWord = getCurrentWord( getCurrentLine( editor ), 
getCurrentCurserPosition( editor ) ),
                        hintList = [];
 
-
                if ( currentWord.word.indexOf('?') === 0 ) {
                        hintList = hintList.concat( getVariableHints( 
currentWord.word,
                                                                                
getDefinedVariables( editor.doc.getValue() ) ) );
@@ -38,8 +37,7 @@
                if(hintList.length > 0){
                        callback( getHintCompletion( editor, currentWord, 
hintList ) );
                }
-
-       }
+       };
 
        CodeMirror.hint.sparql.async = true;
        CodeMirror.defaults.hintOptions = {};
@@ -71,7 +69,6 @@
        }
 
        function getVariableHints( term, variables ) {
-
                var list = [];
 
                if(!term || term === '?'){
@@ -88,7 +85,6 @@
        }
 
        function getHintCompletion( editor, currentWord , list) {
-
                var completion = { list: [] };
                completion.from = CodeMirror.Pos( editor.getCursor().line, 
currentWord.start );
                completion.to = CodeMirror.Pos( editor.getCursor().line, 
currentWord.end );
@@ -97,12 +93,10 @@
                return completion;
        }
 
-
        function getCurrentWord(line, position) {
                var words = line.split(' '), matchedWord = "", scannedPostion = 
0;
 
                $.each(words, function(key, word) {
-
                        scannedPostion += word.length;
 
                        if (key > 0) {// add spaces to position
diff --git a/gui/wikibase/codemirror/addon/tooltip/WikibaseRDFTooltip.js 
b/gui/wikibase/codemirror/addon/tooltip/WikibaseRDFTooltip.js
index f389808..254bc09 100644
--- a/gui/wikibase/codemirror/addon/tooltip/WikibaseRDFTooltip.js
+++ b/gui/wikibase/codemirror/addon/tooltip/WikibaseRDFTooltip.js
@@ -1,7 +1,6 @@
 var WikibaseRDFTooltip = ( function( CodeMirror, $ ) {
        "use strict";
 
-
        /**
         * Wikibase RDF tooltip for codemirror editor
         *
@@ -11,14 +10,12 @@
         * @constructor
         */
        function SELF( editor ) {
-
                this.editor = editor;
                this._registerHandler();
        }
 
        SELF.prototype.editor = null;
        SELF.prototype.tooltipTimeoutHandler = null;
-
 
        var ENTITY_TYPES = { "http://www.wikidata.org/prop/direct/": "property",
                        "http://www.wikidata.org/prop/": "property",
@@ -33,7 +30,6 @@
                        "http://www.wikidata.org/entity/": "item" };
 
        var ENTITY_SEARCH_API_ENDPOINT = 
"https://www.wikidata.org/w/api.php?action=wbsearchentities&search={term}&format=json&language=en&uselang=en&type={entityType}&continue=0";;
-
 
        SELF.prototype._registerHandler = function(){
                CodeMirror.on(this.editor.getWrapperElement(), "mouseover", 
$.proxy(this._triggerTooltip, this));
@@ -50,9 +46,7 @@
                }, 500);
        };
 
-
        SELF.prototype._createTooltip = function( e ){
-
                var posX = e.clientX, posY = (e.clientY +  
$(window).scrollTop());
 
                var token = 
this.editor.getTokenAt(this.editor.coordsChar({left: posX, top: posY})).string;
@@ -97,7 +91,6 @@
                .appendTo( "body" )
                .fadeIn( "slow" );
        };
-
 
        SELF.prototype._extractPrefixes = function( text ) {
                var prefixes = {},

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2e049e6bac30538e5e14230816b278789223ecfb
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/rdf
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to