Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1374)

Unified Diff: server/static/rpcexplorer/rpc-method.html

Issue 1695893004: RPC Explorer (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@rpcepxlorer-deps
Patch Set: refactoring and tests Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: server/static/rpcexplorer/rpc-method.html
diff --git a/server/static/rpcexplorer/rpc-method.html b/server/static/rpcexplorer/rpc-method.html
new file mode 100644
index 0000000000000000000000000000000000000000..057119b9144b77d09aaa065b47a36d310790dea8
--- /dev/null
+++ b/server/static/rpcexplorer/rpc-method.html
@@ -0,0 +1,208 @@
+<!--
+ Copyright 2016 The Chromium Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style license that can be
+ found in the LICENSE file.
+ -->
+
+<link rel="import" href="../bower_components/polymer/polymer.html">
+
+<link rel="import" href="/static/common/rpc/rpc-client.html">
+
+<link rel="import" href="rpc-descriptor-util.html">
+<link rel="import" href="rpc-editor.html">
+
+<!-- The `rpc-method` is a service method page -->
+<dom-module id="rpc-method">
+ <template>
+ <style>
+ rpc-editor {
+ height: 300px;
+ }
+ button {
+ margin: 5px;
+ }
+ </style>
+
+ <div on-keypress="_onKeypress">
+ <rpc-client
+ id="client"
+ service="[[service]]"
+ method="[[method]]"
+ request="[[requestObject]]"
+ on-response="_onCallComplete"
+ on-error="_onCallComplete">
+ </rpc-client>
+ <div>[[methodDesc.source_code_info.leading_comments]]</div>
+ <hr>
+
+ <p>Request:</p>
+ <div class="row">
+ <div class="col-md-7">
+ <rpc-editor value="{{requestText}}"
+ description="[[description]]"
+ root-type-name="[[requestTypeName]]"></rpc-editor>
+ </div>
+ <div class="col-md-3">
+ <p>Ctrl+Space for Autocomplete</p>
+ <p>Shift+Enter for Send</p>
+ </div>
+ </div>
+
+ <div>
+ <button on-click="send">Send</button>
Bons 2016/02/23 15:52:29 replace with on-tap from https://www.polymer-proj
nodir 2016/02/23 18:32:26 Done.
+ </div>
+
+ <div class="alert alert-danger" role="alert" hidden="[[!error]]">
+ <template is="dom-if" if="[[error.isGrpcError]]">
+ <div>
+ Code: [[error.code]]
+ <template is="dom-if" if="[[error.codeName]]">
+ ([[error.codeName]])
+ </template>
+ </div>
+ <div>Description: [[error.description]]</div>
+ </template>
+
+ <template is="dom-if" if="[[!error.isGrpcError]]">
+ [[error]]
+ </template>
+ </div>
+
+ <div class="row">
+ <div class="col-md-7">
+ <rpc-editor value="[[responseText]]"></rpc-editor>
+ </div>
+ </div>
+ </div>
+ </template>
+
+ <script>
+ 'use strict';
+
+ Polymer({
+ is: 'rpc-method',
+
+ properties: {
+ /** @type {FileDescriptorSet} */
+ description: Object,
+
+ service: String,
+
+ method: String,
+
+ /** @type {MethodDescriptorProto} */
+ methodDesc: {
+ type: Object,
+ computed: '_resolveMethod(description, service, method)'
+ },
+
+ requestTypeName: {
+ type: String,
+ computed: '_getRequestTypeName(methodDesc)'
+ },
+
+ /** "request" query string parameter. */
+ request: {
+ type: String,
+ value: '{}',
+ observer: '_onRequestChanged',
+ notify: true
+ },
+
+ /** Request editor text. */
+ requestText: String,
+
+ /** Parsed from requestText. */
+ requestObject: Object,
+
+ /** Response editor text. */
+ responseText: String,
+
+ error: {
+ type: Object,
+ value: null
+ }
+ },
+
+ _resolveMethod: function(desc, service, method) {
+ if (!desc || !service || !method) {
+ return null;
+ }
+ var methodDesc = rpcExplorer.descUtil.resolve(
+ desc, service + '.' + method);
+ return methodDesc && methodDesc.type === 'method' && methodDesc.desc;
+ },
+
+ _getRequestTypeName: function(methodDesc) {
+ return (methodDesc &&
+ rpcExplorer.descUtil.trimPrefixDot(methodDesc.input_type));
+ },
+
+ _onRequestChanged: function() {
+ try {
+ this.requestObject = JSON.parse(this.request);
+ } catch (e) {
+ console.error('Invalid request: ' + this.request);
+ this.requestText = this.request;
+ return;
+ }
+
+ // Reformat the request read from query string parameter
+ // because it gets corrupted there.
+ this.requestText = JSON.stringify(this.requestObject, null, 4);
+ },
+
+ _onKeypress: function(e) {
+ if (e.key === 'Enter' && e.shiftKey) {
+ this.send();
+ e.preventDefault();
+ }
+ },
+
+ send: function() {
+ this.error = null;
+ try {
+ this.requestObject = JSON.parse(this.requestText);
+
+ // Reformat request
+ this.requestText = JSON.stringify(this.requestObject, null, 4);
+
+ // Update URL without a refresh.
+ var newHash = (
+ '#/services/' + this.service + '/' + this.method +
+ '?request=' + this.requestText);
+ history.replaceState(history.state, document.title, newHash);
+
+ // Actually send the request.
+ this.$.client.call();
+ } catch (e) {
+ this.error = e;
+ console.error(this.error)
+ }
+ },
+
+ _onCallComplete: function() {
+ var client = this.$.client;
+ if (client.lastError) {
+ console.error(client.lastError);
+ }
+
+ if (client.lastResponse) {
+ this.responseText = JSON.stringify(client.lastResponse, null, 4);
+ } else {
+ this.responseText = '';
+ }
+
+ this.error = client.lastError;
+ if (this.error instanceof luci.rpc.GrpcError) {
+ this.error = {
+ isGrpcError: true,
+ code: this.error.code,
+ codeName: luci.rpc.CodeName(this.error.code),
+ description: this.error.description
+ };
+ }
+ }
+ });
+ </script>
+</dom-module>

Powered by Google App Engine
This is Rietveld 408576698