jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/394664 )

Change subject: Urls direct to boards
......................................................................


Urls direct to boards

Bug: T120000
Change-Id: Ifb4b580e54f501efc51ad4e98d17a4d3295d43b4
---
M src/components/app-content/app-content.html
M src/components/app-content/app-content.js
M src/components/nav-bar/nav-bar.html
M src/components/nav-bar/nav-bar.js
4 files changed, 61 insertions(+), 32 deletions(-)

Approvals:
  jenkins-bot: Verified
  Ejegg: Looks good to me, approved



diff --git a/src/components/app-content/app-content.html 
b/src/components/app-content/app-content.html
index 653c70a..935179b 100644
--- a/src/components/app-content/app-content.html
+++ b/src/components/app-content/app-content.html
@@ -1,8 +1,8 @@
 <section id="navbar">
-       <nav-bar params="welcome: welcome, loggedIn: loggedIn, userBoards: 
userBoards, displayPage: displayPage"></nav-bar>
+       <nav-bar params="welcome: welcome, loggedIn: loggedIn, userBoards: 
userBoards, displayedPage: displayedPage"></nav-bar>
 </section>
 
-<section id="appContent" data-bind="if: displayPage() === 'Home'">
+<section id="appContent" data-bind="if: displayedPage() === 'Home'">
 
        <div class="container-fluid" data-bind='if: loggedIn'>
                <div class="row" data-bind='if:displayedBoard'>
@@ -20,7 +20,7 @@
 
 </section>
 
-<section id="appContent" data-bind="if: displayPage() === 'Library'">
+<section id="appContent" data-bind="if: displayedPage() === 'Library'">
 
        <div class="container-fluid" data-bind='if: loggedIn()'>
                <div class="row">
@@ -40,7 +40,7 @@
 
 </section>
 
-<section id="appContent" data-bind="if: displayPage() === 'Profile'">
+<section id="appContent" data-bind="if: displayedPage() === 'Profile'">
 
        <div class="container-fluid" data-bind='if: loggedIn()'>
                <div class="row">
diff --git a/src/components/app-content/app-content.js 
b/src/components/app-content/app-content.js
index c7471e6..239460f 100644
--- a/src/components/app-content/app-content.js
+++ b/src/components/app-content/app-content.js
@@ -1,16 +1,20 @@
 define( [
+       'hasher',
        'jquery',
        'knockout',
        'text!./app-content.html'
-], function ( $, ko, templateMarkup ) {
-
+], function ( hasher, $, ko, templateMarkup ) {
        function AppContent() {
-               var self = this;
+               var self = this,
+                       pages = [ 'Library', 'Profile', 'Home' ];
+
+               hasher.prependHash = '';
 
                self.displayedBoard = ko.observable();
+               self.hashValue = location.hash.substring( 1 );
                self.userBoards = ko.observableArray();
                self.userdata = ko.observable();
-               self.displayPage = ko.observable( 'Home' );
+               self.displayedPage = ko.observable( 'Home' );
                self.loggedIn = ko.observable( false );
                self.welcome = ko.observable( '' );
                self.widgetTemplates = ko.observableArray();
@@ -25,16 +29,28 @@
                        return widgets;
                } );
 
+               self.displayPage = function ( view ) {
+                       if ( pages.indexOf( view ) > -1 ) {
+                               self.displayedPage( view );
+                       } else if ( !isNaN( parseInt( view, 10 ) ) ) {
+                               $.get( 'board/' + view, function ( bdata ) {
+                                       self.displayedPage( 'Home' );
+                                       self.displayedBoard( bdata );
+                               } );
+                       } else {
+                               return false;
+                       }
+               };
+
                $.get( '/user/info', function ( userInfo ) {
                        if ( userInfo && !userInfo.error ) {
                                self.userdata( userInfo );
                                self.welcome( userInfo.name.charAt( 0 
).toUpperCase() + userInfo.name.slice( 1 ) );
                                self.loggedIn( true );
-
                                $.get( 'board/' + self.userdata().defaultBoard, 
function ( moredata ) {
                                        self.displayedBoard( moredata );
+                                       self.displayPage( self.hashValue );
                                } );
-
                                $.get( 'board/', function ( boards ) {
                                        self.userBoards( boards );
                                } );
@@ -86,18 +102,10 @@
                };
 
                self.setDisplayPage = function ( e, data ) {
-                       var pages = [ 'Library', 'Profile', 'Home' ],
-                               view = data.target.id;
-
-                       if ( pages.indexOf( data.target.id ) > -1 ) {
-                               self.displayPage( view );
-                       } else if ( isNaN( parseInt( view, 10 ) ) ) {
-                               self.displayPage( $.trim( $( data.target 
).text() ) );
-                       } else {
-                               $.get( 'board/' + view, function ( bdata ) {
-                                       self.displayPage( 'Home' );
-                                       self.displayedBoard( bdata );
-                               } );
+                       var view = data.target.id;
+                       hasher.setHash( view );
+                       if ( !self.displayPage( view ) ) {
+                               self.displayedPage( $.trim( $( data.target 
).text() ) );
                        }
                };
 
@@ -125,6 +133,12 @@
                };
                self.getUsersWidgetInstances();
 
+               self.handleChanges = function ( newHash ) {
+                       self.displayPage( newHash );
+               };
+
+               hasher.changed.add( self.handleChanges );
+               hasher.init();
        }
 
        return { viewModel: AppContent, template: templateMarkup };
diff --git a/src/components/nav-bar/nav-bar.html 
b/src/components/nav-bar/nav-bar.html
index a0485f8..7d82735 100644
--- a/src/components/nav-bar/nav-bar.html
+++ b/src/components/nav-bar/nav-bar.html
@@ -48,7 +48,7 @@
                                                </div>
                                        </div>
 
-                                       <div class="mainNavButton" id="Library" 
data-bind="click: $parent.setDisplayPage"><i class="fa fa-plug"></i><span 
id="LibraryLink"> Library</span>
+                                       <div class="mainNavButton" id="Library" 
data-bind="click: $parent.setDisplayPage"><i class="fa fa-plug"></i> Library
                                        </div>
                                </span>
 
diff --git a/src/components/nav-bar/nav-bar.js 
b/src/components/nav-bar/nav-bar.js
index d4e82bb..9a60d35 100644
--- a/src/components/nav-bar/nav-bar.js
+++ b/src/components/nav-bar/nav-bar.js
@@ -1,15 +1,17 @@
 define( [
-       'knockout',
+       'hasher',
        'jquery',
+       'knockout',
        'text!components/nav-bar/nav-bar.html'
-], function ( ko, $, template ) {
+], function ( hasher, $, ko, template ) {
 
        function NavBarViewModel( params ) {
                var self = this;
+
                self.loggedIn = params.loggedIn;
                self.welcome = params.welcome;
                self.userBoards = params.userBoards;
-               self.displayPage = ko.observable( 'filler' );
+               self.displayedPage = ko.observable( 'filler' );
                self.newBoardName = ko.observable( '' );
                self.boardError = ko.observable( '' );
 
@@ -28,13 +30,18 @@
                };
 
                $( '.mainNavButton' ).click( function ( e ) {
-                       $( '.mainNavButton' ).removeClass( 'selectedSubNav' );
-                       if ( $( e.target ).hasClass( 'mainNavButton' ) ) {
-                               $( e.target ).addClass( 'selectedSubNav' );
-                       } else {
-                               $( e.target.parentElement ).addClass( 
'selectedSubNav' );
-                       }
+                       self.button = e.target;
+                       self.toggleNav( self.button );
                } );
+
+               self.toggleNav = function ( button ) {
+                       $( '.mainNavButton' ).removeClass( 'selectedSubNav' );
+                       if ( $( button ).hasClass( 'mainNavButton' ) ) {
+                               $( button ).addClass( 'selectedSubNav' );
+                       } else {
+                               $( button.parentElement ).addClass( 
'selectedSubNav' );
+                       }
+               };
 
                self.toggleBoardList = function ( e, data ) {
                        $( '#boards.subNavBoardOpts' ).slideDown( 200, 'swing', 
function () {
@@ -77,6 +84,14 @@
                                }
                        } );
                };
+               self.readHashValue = function ( hashValue ) {
+                       if ( hashValue.length ) {
+                               self.button = '#' + hashValue;
+                               self.toggleNav( self.button );
+                       }
+               };
+               hasher.initialized.add( self.readHashValue );
+               hasher.changed.add( self.readHashValue );
        }
 
        return { viewModel: NavBarViewModel, template: template };

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifb4b580e54f501efc51ad4e98d17a4d3295d43b4
Gerrit-PatchSet: 19
Gerrit-Project: wikimedia/fundraising/dash
Gerrit-Branch: master
Gerrit-Owner: Mepps <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Mepps <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to