OLD | NEW |
---|---|
1 <!-- Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 <!-- Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 Use of this source code is governed by a BSD-style license that can be | 2 Use of this source code is governed by a BSD-style license that can be |
3 found in the LICENSE file. --> | 3 found in the LICENSE file. --> |
4 | 4 |
5 <script src="../lib/sugar.js"></script> | 5 <script src="../lib/sugar.js"></script> |
6 <script src="../bower_components/gif.js/dist/gif.js"></script> | 6 <script src="../bower_components/gif.js/dist/gif.js"></script> |
7 | 7 |
8 <link rel="import" href="../bower_components/polymer/polymer.html"> | 8 <link rel="import" href="../bower_components/polymer/polymer.html"> |
9 <link rel="import" href="../bower_components/app-router/app-router.html"> | 9 <link rel="import" href="../bower_components/app-router/app-router.html"> |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 } | 100 } |
101 | 101 |
102 app-router, | 102 app-router, |
103 active-route { | 103 active-route { |
104 display: block; | 104 display: block; |
105 } | 105 } |
106 | 106 |
107 app-route { | 107 app-route { |
108 display: none; | 108 display: none; |
109 } | 109 } |
110 | |
111 .view-links .login-link, | |
112 .view-links .settings-link { | |
113 display: none; | |
114 } | |
115 | |
116 :host-context(.login) .settings-link { | |
117 display: block; | |
118 } | |
119 | |
120 :host-context(.no-login) .login-link { | |
121 display: block; | |
122 } | |
123 </style> | 110 </style> |
124 <header> | 111 <header> |
125 <div class="title"> | 112 <div class="title"> |
126 <a href="/"> | 113 <a href="/"> |
127 <img src="../images/chromium-logo.png"> | 114 <img src="../images/chromium-logo.png"> |
128 <span>Chromium Code Review</span> | 115 <span>Chromium Code Review</span> |
129 </a> | 116 </a> |
130 </div> | 117 </div> |
131 <div class="view-links"> | 118 <div class="view-links"> |
132 <a class="bug-report" | 119 <a class="bug-report" |
133 href="https://code.google.com/p/chromium/issues/entry?labels= Type-Bug,Pri-2,Infra-Area-Rietveld" | 120 href="https://code.google.com/p/chromium/issues/entry?labels= Type-Bug,Pri-2,Infra-Area-Rietveld" |
134 target="_blank">Report a bug</a> | 121 target="_blank">Report a bug</a> |
135 <a href="/search" class="search-link">Search</a> | 122 <a href="/search" class="search-link">Search</a> |
136 <a href="/settings" class="settings-link">Settings</a> | 123 <template if="{{ user }}"> |
137 <cr-action on-tap="{{ handleLogin }}" class="login-link" white>L ogin</cr-action> | 124 <a href="/settings">Settings</a> |
125 </template> | |
126 <cr-action on-tap="{{ handleLogin }}" white> | |
127 <template if="{{ user }}"> | |
128 Logout | |
129 </template> | |
130 <template if="{{ !user }}"> | |
131 Login | |
132 </template> | |
133 </cr-action> | |
138 </div> | 134 </div> |
139 </header> | 135 </header> |
140 <app-router id="router" trailingSlash="ignore"> | 136 <app-router id="router" trailingSlash="ignore"> |
141 <app-route path="/" element="cr-inbox-view"></app-route> | 137 <app-route path="/" element="cr-inbox-view"></app-route> |
142 <app-route path="/search" element="cr-search-view"></app-route> | 138 <app-route path="/search" element="cr-search-view"></app-route> |
143 <app-route path="/settings" element="cr-settings-view"></app-route> | 139 <app-route path="/settings" element="cr-settings-view"></app-route> |
144 <app-route path="/user/:username" element="cr-user-view"></app-route > | 140 <app-route path="/user/:username" element="cr-user-view"></app-route > |
145 <app-route path="/:issueId" element="cr-issue-view"></app-route> | 141 <app-route path="/:issueId" element="cr-issue-view"></app-route> |
146 </cr-view> | 142 </cr-view> |
147 </template> | 143 </template> |
148 <script> | 144 <script> |
149 Polymer({ | 145 Polymer({ |
146 created: function() { | |
147 this.user = User.current; | |
148 }, | |
150 attached: function() { | 149 attached: function() { |
151 var self = this; | 150 var self = this; |
152 User.loadCurrentUser({cached:true}).then(function() { | 151 User.loadCurrentUser({cached:true}).then(function() { |
153 self.classList.add("login"); | 152 self.classList.add("login"); |
154 }).catch(function(e) { | 153 }).catch(function(e) { |
155 self.classList.add("no-login"); | 154 self.classList.add("no-login"); |
156 }); | 155 }); |
157 }, | 156 }, |
158 handleNavigate: function(event) { | 157 handleNavigate: function(event) { |
159 var currentUrl = window.location.pathname + window.location.sear ch + window.location.hash; | 158 var currentUrl = window.location.pathname + window.location.sear ch + window.location.hash; |
160 if (currentUrl != event.detail.url) | 159 if (currentUrl != event.detail.url) |
161 window.history.pushState(null, null, event.detail.url); | 160 window.history.pushState(null, null, event.detail.url); |
162 this.$.router.go(); | 161 this.$.router.go(); |
163 }, | 162 }, |
164 handleLogin: function() { | 163 handleLogin: function() { |
165 window.location.href = User.getLoginUrl(); | 164 if (this.user) |
165 location.href = User.getLogoutUrl(); | |
ojan
2015/02/08 05:49:08
It's kinda funny to recreate links here. I would j
| |
166 else | |
167 location.href = User.getLoginUrl(); | |
166 }, | 168 }, |
167 }); | 169 }); |
168 </script> | 170 </script> |
169 </polymer-element> | 171 </polymer-element> |
OLD | NEW |