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

Side by Side Diff: web/inc/logdog-query-view/view.ts

Issue 2991253003: [logdog] Replace list view with query view. (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 Copyright 2017 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file.
5 */
6
7 ///<reference path="../logdog-stream/logdog.ts" />
8 ///<reference path="../logdog-stream/client.ts" />
9 ///<reference path="../luci-operation/operation.ts" />
10 ///<reference path="../luci-sleep-promise/promise.ts" />
11 ///<reference path="../rpc/client.ts" />
12
13 namespace LogDog {
14
15 type QueryEntry = {fullPath: string; title: string;};
16
17 type QueryComponent = {
18 $: {
19 client: luci.PolymerClient;
20 queryPanel: {project: string; path: string; streamType: string;},
21 }
22
23 _setSharedPrefix(prefix: string|null): void;
24 _setQueryResults(results: QueryEntry[]): void;
25 };
26
27 const QUERY_LIMIT = 50;
28
29 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.
30 private currentQuery: luci.Operation|null;
31 private client: LogDog.Client;
32
33 constructor(readonly comp: QueryComponent) {}
34
35 reset() {
36 this._cancelCurrentQuery();
37 this.client = new LogDog.Client(new luci.Client(this.comp.$.client));
38
39 this.comp._setSharedPrefix(null);
40 this.comp._setQueryResults([]);
41 }
42
43 doQuery() {
44 this._cancelCurrentQuery();
45
46 let qp = this.comp.$.queryPanel;
47 let project = qp.project;
48 let params: LogDog.QueryRequest = {
49 project: project,
50 path: qp.path,
51 };
52 switch (qp.streamType) {
53 case 'Text':
54 params.streamType = LogDog.StreamType.TEXT;
55 break;
56
57 case 'Binary':
58 params.streamType = LogDog.StreamType.BINARY;
59 break;
60
61 case 'Datagram':
62 params.streamType = LogDog.StreamType.DATAGRAM;
63 break;
64
65 case 'Any':
66 default:
67 break;
68 }
69
70 let op = new luci.Operation();
71 this.client.query(op, params, '', QUERY_LIMIT).then((result) => {
72 // Do all of the results have the same prefix?
73 let streams = result[0] || [];
74 let sharedPrefix: string|null = null;
75 if (streams.length > 0) {
76 sharedPrefix = streams[0].stream.prefix;
77 for (let i = 1; i < streams.length; i++) {
78 if (streams[i].stream.prefix !== sharedPrefix) {
79 sharedPrefix = null;
80 break;
81 }
82 }
83 }
84 this.comp._setSharedPrefix(sharedPrefix);
85
86 let queryResults = result[0].map((v): QueryEntry => {
87 return {
88 fullPath: v.stream.fullName(),
89 title:
90 ((sharedPrefix) ? ('.../+/' + v.stream.name) : v.stream.path),
91 };
92 });
93 this.comp._setQueryResults(queryResults);
94 });
95 this.currentQuery = op;
96 }
97
98 private _cancelCurrentQuery() {
99 if (this.currentQuery) {
100 this.currentQuery.cancel();
101 this.currentQuery = null;
102 }
103 }
104 }
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698