Chromium Code Reviews| Index: web/inc/logdog-query-view/view.ts |
| diff --git a/web/inc/logdog-query-view/view.ts b/web/inc/logdog-query-view/view.ts |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3bfe12d91e8524c4b311d7052257f9b21555f036 |
| --- /dev/null |
| +++ b/web/inc/logdog-query-view/view.ts |
| @@ -0,0 +1,105 @@ |
| +/* |
| + Copyright 2017 The LUCI Authors. All rights reserved. |
| + Use of this source code is governed under the Apache License, Version 2.0 |
| + that can be found in the LICENSE file. |
| +*/ |
| + |
| +///<reference path="../logdog-stream/logdog.ts" /> |
| +///<reference path="../logdog-stream/client.ts" /> |
| +///<reference path="../luci-operation/operation.ts" /> |
| +///<reference path="../luci-sleep-promise/promise.ts" /> |
| +///<reference path="../rpc/client.ts" /> |
| + |
| +namespace LogDog { |
| + |
| + type QueryEntry = {fullPath: string; title: string;}; |
| + |
| + type QueryComponent = { |
| + $: { |
| + client: luci.PolymerClient; |
| + queryPanel: {project: string; path: string; streamType: string;}, |
| + } |
| + |
| + _setSharedPrefix(prefix: string|null): void; |
| + _setQueryResults(results: QueryEntry[]): void; |
| + }; |
| + |
| + const QUERY_LIMIT = 50; |
| + |
| + export class QueryView { |
|
Ryan Tseng
2017/08/02 23:34:09
In general, more comments please, namely on export
dnj
2017/08/03 00:07:37
Done.
|
| + private currentQuery: luci.Operation|null; |
| + private client: LogDog.Client; |
| + |
| + constructor(readonly comp: QueryComponent) {} |
| + |
| + reset() { |
| + this._cancelCurrentQuery(); |
| + this.client = new LogDog.Client(new luci.Client(this.comp.$.client)); |
| + |
| + this.comp._setSharedPrefix(null); |
| + this.comp._setQueryResults([]); |
| + } |
| + |
| + doQuery() { |
| + this._cancelCurrentQuery(); |
| + |
| + let qp = this.comp.$.queryPanel; |
| + let project = qp.project; |
| + let params: LogDog.QueryRequest = { |
| + project: project, |
| + path: qp.path, |
| + }; |
| + switch (qp.streamType) { |
| + case 'Text': |
| + params.streamType = LogDog.StreamType.TEXT; |
| + break; |
| + |
| + case 'Binary': |
| + params.streamType = LogDog.StreamType.BINARY; |
| + break; |
| + |
| + case 'Datagram': |
| + params.streamType = LogDog.StreamType.DATAGRAM; |
| + break; |
| + |
| + case 'Any': |
| + default: |
| + break; |
| + } |
| + |
| + let op = new luci.Operation(); |
| + this.client.query(op, params, '', QUERY_LIMIT).then((result) => { |
| + // Do all of the results have the same prefix? |
| + let streams = result[0] || []; |
| + let sharedPrefix: string|null = null; |
| + if (streams.length > 0) { |
| + sharedPrefix = streams[0].stream.prefix; |
| + for (let i = 1; i < streams.length; i++) { |
| + if (streams[i].stream.prefix !== sharedPrefix) { |
| + sharedPrefix = null; |
| + break; |
| + } |
| + } |
| + } |
| + this.comp._setSharedPrefix(sharedPrefix); |
| + |
| + let queryResults = result[0].map((v): QueryEntry => { |
| + return { |
| + fullPath: v.stream.fullName(), |
| + title: |
| + ((sharedPrefix) ? ('.../+/' + v.stream.name) : v.stream.path), |
| + }; |
| + }); |
| + this.comp._setQueryResults(queryResults); |
| + }); |
| + this.currentQuery = op; |
| + } |
| + |
| + private _cancelCurrentQuery() { |
| + if (this.currentQuery) { |
| + this.currentQuery.cancel(); |
| + this.currentQuery = null; |
| + } |
| + } |
| + } |
| +} |