Chromium Code Reviews| 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 | |
| 8 <link rel="import" href="/static/common/third_party/polymer/polymer.html"> | |
| 9 | |
| 10 <link rel="import" href="rpc-descriptor-util.html"> | |
| 11 <link rel="import" href="rpc-editor.html"> | |
| 12 <link rel="import" href="rpc-error.html"> | |
| 13 | |
| 14 <!-- The `rpc-method` is a service method page --> | |
| 15 <dom-module id="rpc-method"> | |
| 16 <template> | |
| 17 <style> | |
| 18 rpc-editor { | |
| 19 height: 300px; | |
| 20 } | |
| 21 button { | |
| 22 margin: 5px; | |
| 23 } | |
| 24 </style> | |
| 25 | |
| 26 <div on-keypress="_onKeypress"> | |
| 27 <rpc-call id="call" service="[[service]]" method="[[method]]" | |
| 28 request="[[requestObject]]" | |
| 29 on-response="_onResponse"></rpc-call> | |
| 30 | |
| 31 <div>[[methodDesc.source_code_info.leading_comments]]</div> | |
| 32 <hr> | |
| 33 | |
| 34 <p>Request:</p> | |
| 35 <div class="row"> | |
| 36 <div class="col-md-7"> | |
| 37 <rpc-editor value="{{requestText}}" | |
| 38 description="[[description]]" | |
| 39 root-type-name="[[requestTypeName]]"></rpc-editor> | |
| 40 </div> | |
| 41 <div class="col-md-3"> | |
| 42 <p>Ctrl+Space for Autocomplete</p> | |
| 43 <p>Shift+Enter for Send</p> | |
| 44 </div> | |
| 45 </div> | |
| 46 | |
| 47 <div> | |
| 48 <button on-click="send">Send</button> | |
| 49 </div> | |
| 50 | |
| 51 <div class="alert alert-danger" role="alert" hidden="[[!error]]"> | |
| 52 <template is="dom-if" if="[[error.isGrpcError]]"> | |
| 53 Code: [[error.code]] | |
| 54 <template is="dom-if" if="[[error.codeName]]"> | |
| 55 ([[error.codeName]]) | |
| 56 </template> | |
| 57 <div>[[error.description]]</div> | |
| 58 </template> | |
| 59 | |
| 60 <template is="dom-if" if="[[!error.isGrpcError]]"> | |
| 61 [[error]] | |
| 62 </template> | |
| 63 </div> | |
| 64 | |
| 65 <div class="row"> | |
| 66 <div class="col-md-7"> | |
| 67 <rpc-editor value="[[responseText]]"></rpc-editor> | |
| 68 </div> | |
| 69 </div> | |
| 70 </div> | |
| 71 </template> | |
| 72 | |
| 73 <script> | |
| 74 'use strict'; | |
| 75 | |
| 76 Polymer({ | |
| 77 is: 'rpc-method', | |
| 78 properties: { | |
| 79 description: Object, // FileDescriptorSet message | |
| 80 service: String, | |
| 81 method: String, | |
| 82 | |
| 83 methodDesc: { | |
| 84 type: Object, | |
| 85 computed: '_resolveMethod(description, service, method)' | |
| 86 }, | |
| 87 requestTypeName: { | |
| 88 type: String, | |
| 89 computed: '_getRequestTypeName(methodDesc)' | |
| 90 }, | |
| 91 | |
| 92 request: { | |
| 93 // "request" query string parameter. | |
| 94 type: String, | |
| 95 value: '{}', | |
| 96 observer: 'onRequestChanged', | |
| 97 notify: true | |
| 98 }, | |
| 99 requestText: String, // request editor text. | |
| 100 requestObject: Object, // parsed from requestText | |
| 101 | |
| 102 responseText: String, // response editor text. | |
| 103 error: { | |
| 104 type: Object, | |
| 105 value: null | |
| 106 } | |
| 107 }, | |
| 108 | |
| 109 _resolveMethod: function(desc, service, method) { | |
| 110 if (!desc || !service || !method) { | |
| 111 return null; | |
| 112 } | |
| 113 var methodDesc = rpcExplorer.descUtil.resolve( | |
| 114 desc, service + '.' + method); | |
| 115 return methodDesc && methodDesc.type == 'method' && methodDesc.desc; | |
| 116 }, | |
| 117 _getRequestTypeName: function(methodDesc) { | |
| 118 return methodDesc && rpcExplorer.descUtil.trimPrefixDot(methodDesc.input _type); | |
|
Bons
2016/02/13 17:18:28
80 chars
nodir
2016/02/17 02:02:13
Done.
| |
| 119 }, | |
| 120 | |
| 121 onRequestChanged: function() { | |
| 122 // "request" query string parameter changed. | |
|
Bons
2016/02/13 17:18:27
superfluous comment.
nodir
2016/02/17 02:02:13
Done.
| |
| 123 try { | |
| 124 this.requestObject = JSON.parse(this.request); | |
| 125 } catch (e) { | |
| 126 console.log('Invalid request: ' + this.request); | |
| 127 this.requestText = this.request; | |
| 128 return; | |
| 129 } | |
| 130 | |
| 131 // Reformat the request read from query string parameter | |
| 132 // because it gets corrupted there. | |
| 133 this.requestText = JSON.stringify(this.requestObject, null, 4); | |
| 134 }, | |
| 135 | |
| 136 _onKeypress: function(e) { | |
| 137 if (e.key == 'Enter' && e.shiftKey) { | |
| 138 this.send(); | |
| 139 e.preventDefault(); | |
| 140 } | |
| 141 }, | |
| 142 | |
| 143 send: function() { | |
| 144 this.error = null; | |
| 145 try { | |
| 146 this.requestObject = JSON.parse(this.requestText); | |
| 147 console.log('Request: ', this.requestObject); | |
|
Bons
2016/02/13 17:18:27
do you mean to keep this?
nodir
2016/02/17 02:02:13
Removed, because network tab provides enough info
| |
| 148 | |
| 149 // Reformat request | |
| 150 this.requestText = JSON.stringify(this.requestObject, null, 4); | |
| 151 | |
| 152 // Update URL without a refresh. | |
| 153 var newHash = ( | |
| 154 '#/services/' + this.service + '/' + this.method + | |
|
Bons
2016/02/13 17:18:27
four-space indent on continuing lines.
nodir
2016/02/17 02:02:13
Done.
| |
| 155 '?request=' + this.requestText); | |
| 156 history.replaceState(history.state, document.title, newHash); | |
| 157 | |
| 158 // Actually send the request. | |
| 159 this.$.call.send(); | |
| 160 } catch (e) { | |
| 161 this.error = e; | |
| 162 console.log('Error: ', this.error) | |
|
Bons
2016/02/13 17:18:27
use console.error
nodir
2016/02/17 02:02:13
Done.
| |
| 163 } | |
| 164 }, | |
| 165 | |
| 166 _onResponse: function() { | |
| 167 var call = this.$.call; | |
| 168 console.log('Response: ', call.lastResponse, 'Error: ', call.lastError); | |
|
Bons
2016/02/13 17:18:27
remove?
nodir
2016/02/17 02:02:13
Done
| |
| 169 | |
| 170 if (call.lastResponse) { | |
| 171 this.responseText = JSON.stringify(call.lastResponse, null, 4); | |
| 172 } else { | |
| 173 this.responseText = ''; | |
| 174 } | |
| 175 | |
| 176 this.error = call.lastError; | |
| 177 if (this.error instanceof rpcExplorer.GrpcError) { | |
| 178 this.error = { | |
| 179 isGrpcError: true, | |
| 180 code: this.error.code, | |
| 181 codeName: rpcExplorer.CodeName(this.error.code), | |
| 182 description: this.error.description | |
| 183 }; | |
| 184 } | |
| 185 } | |
| 186 }); | |
| 187 </script> | |
| 188 </dom-module> | |
| OLD | NEW |