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

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

Change subject: Short URL for queries
......................................................................

Short URL for queries

Created short URL for queries inside of query box.
Changed existing short URL link to show results only.

Bug: T125867
Change-Id: If3ef75ad13294cc18461552c86627b45a79308df
---
M index.html
M style.css
M wikibase/queryService/ui/App.js
3 files changed, 103 insertions(+), 21 deletions(-)


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

diff --git a/index.html b/index.html
index 35535ff..0dd30c6 100644
--- a/index.html
+++ b/index.html
@@ -96,13 +96,14 @@
                                                                    <span 
class="glyphicon glyphicon-link" aria-hidden="true">Link</span><span 
class="caret"></span>
                                                                  </a>
                                                                  <ul 
class="dropdown-menu">
-                                                                       <li><a 
href="#" target="_blank" title="Short URL to this page" data-toggle="popover" 
id="shorturl">Create Short URL</a></li>
+                                                                       <li><a 
href="#" class="shortUrlTrigger result" target="_blank" title="Short URL to 
this query result" data-toggle="popover">Share Result</a></li>
                                                                        <li><a 
target="_blank" title="SPARQL endpoint REST request" class="queryUri">SPARQL 
Query</a></li>
                                                                  </ul>
                                                        </li>
                                                </ul>
                                        </nav>
                                </form>
+                               <a href="#" class="shareQuery shortUrlTrigger 
query" target="_blank" title="Short URL to this page" data-toggle="popover"> 
<span class="glyphicon glyphicon-link" aria-hidden="true"></span></a>
                        </div>
                </div>
                <div class="row">
diff --git a/style.css b/style.css
index 5f54b42..9b13963 100644
--- a/style.css
+++ b/style.css
@@ -61,6 +61,18 @@
        visibility: hidden;
        padding: 0;
 }
+
+#query-box {
+       position: relative;
+}
+.shareQuery {
+       z-index: 100;
+       position: absolute;
+       top: 10px;
+       right: 10px;
+       font-size: 25px;
+}
+
 /**
        Bootstrap Styles
 **/
diff --git a/wikibase/queryService/ui/App.js b/wikibase/queryService/ui/App.js
index fed47ab..8438f12 100644
--- a/wikibase/queryService/ui/App.js
+++ b/wikibase/queryService/ui/App.js
@@ -60,6 +60,12 @@
        SELF.prototype._editor = null;
 
        /**
+        * @property {bool}
+        * @private
+        **/
+       SELF.prototype._autoExecuteQuery = false;
+
+       /**
         * Initialize private members and call delegate to specific init methods
         * @private
         **/
@@ -77,6 +83,7 @@
                        this._editor = new wikibase.queryService.ui.Editor();
                }
 
+               this._initApp();
                this._initEditor();
                this._initExamples();
                this._initDataUpdated();
@@ -84,6 +91,19 @@
                this._initRdfNamespaces();
                this._initHandlers();
 
+               if( this._autoExecuteQuery ){
+                       $( '#execute-button' ).click();
+               }
+       };
+
+       /**
+        * @private
+        **/
+       SELF.prototype._initApp = function() {
+               if( location.hash.indexOf( '#result#' ) === 0 ){
+                       this._toggleCollapse( true );
+                       this._autoExecuteQuery = true;
+               }
        };
 
        /**
@@ -142,6 +162,11 @@
         **/
        SELF.prototype._initQuery = function() {
                if ( window.location.hash !== '' ) {
+
+                       if( location.hash.indexOf( '#result#' ) === 0 ){
+                               location.hash = location.hash.replace( 
'#result#', '#' );
+                       }
+
                        this._editor.setValue( decodeURIComponent( 
window.location.hash.substr( 1 ) ) );
                        this._editor.refresh();
                }
@@ -186,6 +211,17 @@
 
                $( window ).on( 'popstate', $.proxy( this._initQuery, this ) );
 
+               this._initPopovers();
+               this._initHandlersDownloads();
+       };
+
+       /**
+        * @private
+        **/
+       SELF.prototype._initPopovers= function() {
+               var self = this;
+
+               //Closes popover when clicked somewhere else
                $('body').on('click', function (e) {
                    if ($(e.target).data('toggle') !== 'popover'
                        && $(e.target).parents('.popover.in').length === 0) {
@@ -193,7 +229,28 @@
                    }
                });
 
-               this._initHandlersDownloads();
+
+               $( '.shortUrlTrigger' ).click( function( e ){
+                       var $target = $( e.target );
+                       self._updateQueryUrl();
+                       $target.attr( 'href', SHORTURL + encodeURIComponent( 
window.location ) );
+
+                       var sharedLocation = new URL( window.location );
+                       if( $target.hasClass( 'result' ) ){
+                               sharedLocation.hash =  '#result' + 
sharedLocation.hash;
+                       }
+
+                       $target.popover({
+                       placement : 'left',
+                       'html':true,
+                       'content':function(){
+                               return '<iframe class="shortUrl" src="' + 
SHORTURL_API + encodeURIComponent( sharedLocation.toString() ) +   '">';
+                       }
+               });
+                       $target.popover('show');
+
+                       return false;
+               } );
        };
 
        /**
@@ -259,25 +316,7 @@
 
                e.preventDefault();
                this._editor.save();
-
-               var hash = encodeURIComponent( this._editor.getValue() );
-               if ( window.location.hash !== hash ) {
-                       window.location.hash = hash;
-               }
-               $( '#shorturl' ).attr( 'href', SHORTURL + encodeURIComponent( 
window.location ) );
-
-               $( '#shorturl' ).click( function(){
-
-               $( '#shorturl' ).popover({
-                       placement : 'left',
-                       'html':true,
-                       'content':function(){
-                               return '<iframe class="shortUrl" src="' + 
SHORTURL_API + encodeURIComponent( window.location )  +   '">';
-                       }
-               });
-               $( '#shorturl' ).popover('show');
-                       return false;
-               } );
+               this._updateQueryUrl();
 
                $( '#query-result' ).empty( '' );
                $( '#query-result' ).hide();
@@ -359,5 +398,35 @@
                return false;
        };
 
+       /**
+        * @private
+        */
+       SELF.prototype._updateQueryUrl = function() {
+               var hash = encodeURIComponent( this._editor.getValue() );
+               if ( window.location.hash !== hash ) {
+                       window.location.hash = hash;
+               }
+       };
+
+       /**
+        * @private
+        */
+       SELF.prototype._toggleCollapse = function( collapse ) {
+               if( collapse === true ){
+                       $( '#query-box' ).hide();
+                       $( '#header-navbar-collapse' ).css('visibility', 
'hidden');
+                       $( '.navbar-toggle' ).show();
+
+                       $( '.navbar-toggle' ).click( 
$.proxy(this._toggleCollapse, this) );
+               }else{
+                       $( '#query-box' ).show();
+                       this._editor.refresh();
+                       $( '#header-navbar-collapse' ).css('visibility', 
'visible');
+                       if ( $( '#header-navbar-collapse' ).is(':visible') ) {
+                               $( '.navbar-toggle.collapsed ' ).hide();
+                       }
+               }
+       };
+
        return SELF;
 }( jQuery, mediaWiki ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If3ef75ad13294cc18461552c86627b45a79308df
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/gui
Gerrit-Branch: master
Gerrit-Owner: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de>

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

Reply via email to