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

Side by Side Diff: appengine/swarming/elements/res/imp/botlist/bot-list-shared-behavior.html

Issue 2408743002: Move elements/ to ui/ (Closed)
Patch Set: rebase again Created 4 years, 2 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 2016 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 window.SwarmingBehaviors.BotListBehavior contains any shared functions and
7 constants used by the bot-list and its sub-elements.
8
9 To use it, include
10 behaviors: [SwarmingBehaviors.BotListBehavior]
11 in the creation of your Polymer element.
12 -->
13 <link rel="import" href="/res/imp/common/common-behavior.html">
14 <script>
15 (function(){
16 var UNKNOWN = "unknown";
17
18 // This behavior wraps up all the shared bot-list functionality by
19 // extending SwarmingBehaviors.CommonBehavior
20 SwarmingBehaviors.BotListBehavior = [SwarmingBehaviors.CommonBehavior, {
21
22 properties: {
23 BOT_PROPERTIES: {
24 type: Array,
25 value: function() {
26 // TODO(kjlubick): Add more of these things from state, as they
27 // needed/useful/requested.
28 return ["disk_space", "uptime", "running_time", "task", "status", "v ersion", "external_ip", "cloud_console_link", "mp_lease_id", "mp_lease_expires", "last_seen", "first_seen", "battery_level", "battery_voltage", "battery_tempera ture", "battery_status", "battery_health", "bot_temperature", "device_temperatur e"];
29 }
30 },
31 },
32
33 // _attribute looks first in dimension and then in state for the
34 // specified attribute. This will always return an array. If there is
35 // no matching attribute, ["unknown"] will be returned.
36 _attribute: function(bot, attr, none) {
37 none = none || UNKNOWN;
38 return this._dimension(bot, attr) || this._state(bot, attr) || [none];
39 },
40
41 _devices: function(bot) {
42 return bot.state.devices;
43 },
44
45 // _deviceType returns the codename of a given Android device.
46 _deviceType: function(device) {
47 return device.device_type.toLowerCase();
48 },
49
50 // _dimension returns the given dimension of a bot. If it is defined, it
51 // is an array of strings.
52 _dimension: function(bot, dim) {
53 if (!bot || !bot.dimensions || !dim) {
54 return undefined;
55 }
56 for (var i = 0; i < bot.dimensions.length; i++) {
57 if (bot.dimensions[i].key === dim) {
58 return bot.dimensions[i].value;
59 }
60 }
61 return undefined;
62 },
63
64 // _state returns the requested attribute from a bot's state.
65 // For consistency with _dimension, if the attribute is not an array,
66 // it is put as the only element in an array.
67 _state: function(bot, attr) {
68 if (!bot || !bot.state || !bot.state[attr]) {
69 return undefined
70 }
71 var state = bot.state[attr];
72 if (Array.isArray(state)) {
73 return state;
74 }
75 return [state];
76 },
77
78 _taskId: function(bot) {
79 if (bot && bot.task_id) {
80 return bot.task_id;
81 }
82 return "idle";
83 },
84
85 }];
86 })()
87 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698