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

Unified Diff: server/static/rpcexplorer/rpc-editor.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-editor.html
diff --git a/server/static/rpcexplorer/rpc-editor.html b/server/static/rpcexplorer/rpc-editor.html
new file mode 100644
index 0000000000000000000000000000000000000000..26cb6f30c8445a84f61b584cc9c629d79726a23b
--- /dev/null
+++ b/server/static/rpcexplorer/rpc-editor.html
@@ -0,0 +1,103 @@
+<!--
+ 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">
+
+<script src="third_party/ace/ace.js"></script>
+<script src="third_party/ace/ext-language_tools.js"></script>
+<script src="third_party/ace/mode-json.js"></script>
+
+<link rel="import" href="rpc-completer.html">
+
+<!-- The `rpc-editor` is an Ace editor for JSON with optional autocomplete -->
+<dom-module id="rpc-editor">
+ <template>
+ <style>
+ :host, pre {
+ display: block;
+ height: 100%;
+ }
+ </style>
+ <pre id="editor" class="editor"></pre>
+ <rpc-completer id="completer"
+ description="[[description]]" root-type-name="[[rootTypeName]]">
+ </rpc-completer>
+ </template>
+
+ <script>
+ 'use strict';
Bons 2016/02/23 15:52:29 sometimes you indent the script block and sometime
nodir 2016/02/23 18:32:25 Done.
+
+ Polymer({
+ is: 'rpc-editor',
+
+ properties: {
+ value: {
+ type: String,
+ notify: true,
+ observer: 'onValueChanged'
+ },
+
+ editor: {
+ type: Object,
+ readOnly: true
+ },
+
+ /** @type {FileDescriptorSet} */
+ description: Object,
+
+ rootTypeName: String
+ },
+
+ ready: function() {
+ var self = this;
+ this._setEditor(ace.edit(this.$.editor));
+ this.editor.session.setMode('ace/mode/json');
+
+ // Set and sync text;
+ this.editor.session.setValue(this.value || '');
+ this.editor.session.on('change', function() {
+ var text = self.editor.session.getValue();
+ if (text !== self.value) {
+ self._maybeSync(function() {
+ self.value = text;
+ });
+ }
+ });
+
+ this.editor.commands.removeCommands(['gotoline', 'find']);
+
+ this.editor.setOptions({
+ enableBasicAutocompletion: [this.$.completer],
+ });
+ },
+
+ onValueChanged: function(newVal) {
Bons 2016/02/23 15:52:29 why is this a public method (no underscore)?
nodir 2016/02/23 18:32:25 Done.
+ var newText = newVal || '';
+ if (this.editor && this.editor.session.getValue() != newText) {
+ this._maybeSync(function() {
+ var selection = this.editor.selection;
+ var origRange = selection.getRange();
+ this.editor.session.setValue(newText);
+ // Restore cursor position, in a lame way, best effort.
+ selection.setSelectionRange(origRange);
+ })
+ }
+ },
+
+ _maybeSync: function(action) {
+ if (this._syncing) {
+ return;
+ }
+ this._syncing = true;
+ try {
+ action.call(this);
+ } finally {
+ this._syncing = false;
+ }
+ }
+ });
+ </script>
+</dom-module>

Powered by Google App Engine
This is Rietveld 408576698