OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. |
| 5 --> |
| 6 |
| 7 <link rel="import" href="../bower_components/app-router/app-router.html"> |
| 8 <link rel="import" href="../bower_components/polymer/polymer.html"> |
| 9 <link rel="import" |
| 10 href="../bower_components/html5-history-anchor/html5-history-anchor.html"> |
| 11 |
| 12 <link rel="import" href="/static/common/rpc/rpc-client.html"> |
| 13 |
| 14 <link rel="import" href="rpc-descriptor-util.html"> |
| 15 <link rel="import" href="rpc-method.html"> |
| 16 <link rel="import" href="rpc-service-list.html"> |
| 17 <link rel="import" href="rpc-service.html"> |
| 18 |
| 19 <!-- The `rpc-explorer` is the top-level element of RPC Explorer --> |
| 20 <dom-module id="rpc-explorer"> |
| 21 <template> |
| 22 <style> |
| 23 li[hidden] { |
| 24 display: none; |
| 25 } |
| 26 </style> |
| 27 |
| 28 <!-- Load server description --> |
| 29 <rpc-client |
| 30 auto |
| 31 service="discovery.Discovery" |
| 32 method="Describe" |
| 33 last-response="{{serverDescription}}"> |
| 34 </rpc-client> |
| 35 |
| 36 <div class="navbar navbar-default" role="navigation"> |
| 37 <div class="navbar-header"> |
| 38 <button |
| 39 class="navbar-toggle collapsed" |
| 40 data-toggle="collapse" |
| 41 aria-expanded="false"> |
| 42 <span class="sr-only">Toggle navigation</span> |
| 43 <span class="icon-bar"></span> |
| 44 <span class="icon-bar"></span> |
| 45 <span class="icon-bar"></span> |
| 46 </button> |
| 47 <span class="navbar-brand"> |
| 48 <span id="progress-spinner" class="not-spinning"> |
| 49 <a is="html5-history-anchor" pushstate popstate |
| 50 href="[[rootPath]]">RPC Explorer</a> |
| 51 </span> |
| 52 </span> |
| 53 </div> |
| 54 </div> |
| 55 |
| 56 <ol class="breadcrumb"> |
| 57 <li> |
| 58 <a is="html5-history-anchor" pushstate popstate |
| 59 href="[[rootPath]]/services/">Home</a> |
| 60 </li> |
| 61 <li hidden="[[!service]]"> |
| 62 <a is="html5-history-anchor" pushstate popstate |
| 63 href="[[rootPath]]/services/[[service]]/">[[service]]</a> |
| 64 </li> |
| 65 <li hidden="[[!method]]"> |
| 66 <a is="html5-history-anchor" pushstate popstate |
| 67 href="[[rootPath]]/services/[[service]]/[[method]"> |
| 68 [[method]] |
| 69 </a> |
| 70 </li> |
| 71 </ol> |
| 72 |
| 73 <app-router |
| 74 id="router" |
| 75 mode="pushstate" |
| 76 on-activate-route-end="_onRouted" |
| 77 on-before-data-binding="_onRouteBinding"> |
| 78 <!-- |
| 79 "path" attributes in <app-route> elements are set dynamically, but |
| 80 unless we set them to a string, app-router prints errors to the console. |
| 81 --> |
| 82 <app-route id="servicesRoute" path="" element="rpc-service-list"> |
| 83 </app-route> |
| 84 <app-route id="serviceRoute" path="" element="rpc-service"></app-route> |
| 85 <app-route id="methodRoute" path="" element="rpc-method"></app-route> |
| 86 <app-route id="catchAllRoute" path="*"></app-route> |
| 87 </app-router> |
| 88 </template> |
| 89 |
| 90 <script> |
| 91 'use strict'; |
| 92 |
| 93 Polymer({ |
| 94 is: 'rpc-explorer', |
| 95 |
| 96 properties: { |
| 97 rootPath: { |
| 98 type: String, |
| 99 value: '', |
| 100 observer: '_onRootPathChanged' |
| 101 }, |
| 102 |
| 103 service: String, |
| 104 |
| 105 method: String, |
| 106 |
| 107 /** @type {DescribeResponse} */ |
| 108 serverDescription: { |
| 109 type: Object, |
| 110 observer: '_onServerDescriptionChanged' |
| 111 } |
| 112 }, |
| 113 |
| 114 _onRootPathChanged: function (newVal) { |
| 115 // The app-router element does not like data-binding in its attributes |
| 116 // so we update their values manually. |
| 117 var rootPath = newVal || '', |
| 118 servicesPath = rootPath + '/services/', |
| 119 servicePath = servicesPath + ':service/', |
| 120 methodPath = servicePath + ':method'; |
| 121 this.$.servicesRoute.setAttribute('path', servicesPath); |
| 122 this.$.serviceRoute.setAttribute('path', servicePath); |
| 123 this.$.methodRoute.setAttribute('path', methodPath); |
| 124 this.$.catchAllRoute.setAttribute('redirect', servicesPath); |
| 125 }, |
| 126 |
| 127 _onRouteBinding: function(e) { |
| 128 if (this.serverDescription) { |
| 129 e.detail.model.description = this.serverDescription.description; |
| 130 e.detail.model.serviceNames = this.serverDescription.services; |
| 131 } |
| 132 }, |
| 133 |
| 134 _onServerDescriptionChanged: function(e) { |
| 135 if (this.serverDescription) { |
| 136 rpcExplorer.descUtil.annotateSet(this.serverDescription.description); |
| 137 // Recreate route model. |
| 138 this.$.router.go(document.location.toString()); |
| 139 } |
| 140 }, |
| 141 |
| 142 _onRouted: function(e) { |
| 143 var model = e.detail.model || {}; |
| 144 this.service = model.service || ''; |
| 145 this.method = model.method || ''; |
| 146 } |
| 147 }); |
| 148 </script> |
| 149 </dom-module> |
OLD | NEW |