This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
/
greeter-card.html
110 lines (100 loc) · 3.14 KB
/
greeter-card.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!--
@license
Copyright 2017 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../tf-backend/tf-backend.html">
<link rel="import" href="../tf-card-heading/tf-card-heading.html">
<link rel="import" href="../tf-color-scale/tf-color-scale.html">
<link rel="import" href="../tf-imports/lodash.html">
<!--
greeter-card loads greeting data from the greeter_plugin backend, and renders it.
-->
<dom-module id="greeter-card">
<template>
<tf-card-heading title="[[tag]]" color="[[_runColor]]">
[[run]]
</tf-card-heading>
<template is="dom-repeat" items="[[greetings]]">
<div>[[item.text]]</div>
</template>
<style>
:host {
display: flex;
flex-direction: column;
width: 330px;
height: 235px;
margin-right: 10px;
margin-bottom: 15px;
}
:host[_expanded] {
width: 700px;
height: 500px;
}
</style>
</template>
<script>
"use strict";
Polymer({
is: "greeter-card",
properties: {
run: String,
tag: String,
/** @type {Function} */
_colorScaleFunction: {
type: Object, // function: string => string
value: () => tf_color_scale.runsColorScale,
},
_runColor: {
type: String,
computed: "_computeRunColor(run)",
},
requestManager: Object,
_canceller: {
type: Object,
value: () => new tf_backend.Canceller(),
},
},
observers: ["_fetchNewData(run, tag)"],
_computeRunColor(run) {
return this._colorScaleFunction(run);
},
attached() {
// Defer reloading until after we're attached, because that ensures that
// the requestManager has been set from above. (Polymer is tricky
// sometimes)
this._attached = true;
this.reload();
},
reload() {
this._fetchNewData(this.run, this.tag);
},
_fetchNewData(run, tag) {
if (!this._attached) {
return;
}
this._canceller.cancelAll();
const url = tf_backend.addParams(
tf_backend.getRouter().pluginRoute('greeter', '/greetings'), {tag, run});
const updateData = this._canceller.cancellable(result => {
if (result.cancelled) {
return;
}
const backendData = result.value;
this.greetings = backendData;
});
this.requestManager.request(url).then(updateData);
},
});
</script>
</dom-module>