Skip to content

Commit 2cad11b

Browse files
committed
Update elements based on feedback and to use published property reflection.
1 parent 151aad6 commit 2cad11b

File tree

6 files changed

+86
-117
lines changed

6 files changed

+86
-117
lines changed

demo.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ google-analytics-chart {
7777
position: relative;
7878
transition: opacity .2s ease;
7979
}
80-
google-analytics-chart[unrendered] {
80+
google-analytics-chart:not([rendered]) {
8181
display: none;
8282
}
8383

google-analytics-base.html

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
(function() {
2525

26-
var isLoaded = false;
27-
var isAuthorized = false;
28-
2926
/**
3027
* A promise that is resolved when the underlying client libraries are
3128
* loaded. It is rejected if there are any load errors.
@@ -34,7 +31,6 @@
3431
document.addEventListener('google-api-load', function fn(event) {
3532
var lib = event.detail;
3633
if (lib.name == 'analytics' && lib.version == 'v3') {
37-
isLoaded = true;
3834
resolve(event.detail);
3935
document.removeEventListener('google-api-load', fn);
4036
}
@@ -56,60 +52,50 @@
5652

5753
Polymer('google-analytics-base', {
5854

59-
/**
60-
* The `isLoaded` attribute is true when the underlying analytics
61-
* library is fully loaded.
62-
*
63-
* @attribute isLoaded
64-
* @type boolean
65-
*/
66-
get isLoaded() {
67-
return isLoaded;
68-
},
69-
70-
/**
71-
* The `isAuthorized` attribute is true once the user successfully
72-
* signs in <em>and</em> the libraries have been loaded. If the user
73-
* signs out this will be false.
74-
*
75-
* @attribute isAuthorized
76-
* @type boolean
77-
*/
78-
get isAuthorized() {
79-
return isAuthorized;
55+
publish: {
56+
/**
57+
* The `authorized` attribute is true when the user has signed-in and
58+
* the underlying analytics library is fully loaded.
59+
*
60+
* @attribute authorized
61+
* @type boolean
62+
*/
63+
authorized: {
64+
value: false,
65+
reflect: true
66+
}
8067
},
8168

8269
created: function() {
8370
document.addEventListener('google-signin-success', function(event) {
84-
isAuthorized = true;
85-
loadPromise.then(this.authorized.bind(this, event.detail.result));
71+
loadPromise
72+
.then(this.userAuthorized.bind(this,event.detail.result));
8673
}.bind(this));
8774
document.addEventListener('google-signed-out', function(event) {
88-
isAuthorized = false;
89-
this.unauthorized();
75+
this.userUnauthorized();
9076
}.bind(this));
9177
},
9278

9379
/**
94-
* The `authorized` method will be invoked when the user has
80+
* The `userAuthorized` method will be invoked when the user has
9581
* successfully signed in and all the underlying client libraries
9682
* have been loaded.
9783
*
98-
* @method authorized
84+
* @method userAuthorized
9985
* @param {Object} data - The auth data information.
10086
*/
101-
authorized: function(data) {
102-
// Override in a subclass.
87+
userAuthorized: function(data) {
88+
this.authorized = true;
10389
},
10490

10591
/**
106-
* The `unauthorized` method will be invoked when the user has
92+
* The `userUnauthorized` method will be invoked when the user has
10793
* successfully signed out.
10894
*
109-
* @method unauthorized
95+
* @method userUnauthorized
11096
*/
111-
unauthorized: function() {
112-
// Override in a subclass.
97+
userUnauthorized: function() {
98+
this.authorized = false;
11399
}
114100

115101
});

google-analytics-chart.html

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
* for the options available to each chart type.
9090
*
9191
* @attribute options
92+
* @default null
9293
* @type object
9394
*/
9495
options: null,
@@ -97,19 +98,43 @@
9798

9899
data: null,
99100

101+
publish: {
102+
/**
103+
* True after the chart has been rendered for the first time.
104+
*
105+
* @attribute rendered
106+
* @type boolean
107+
*/
108+
rendered: {
109+
value: false,
110+
reflect: true
111+
},
112+
/**
113+
* True if the chart is currently loading data.
114+
*
115+
* @attribute loading
116+
* @type boolean
117+
*/
118+
loading: {
119+
value: false,
120+
reflect: true
121+
}
122+
},
123+
100124
ready: function() {
101-
this.setAttribute('unrendered', '');
102125
merge(this.$.chart.options, getChartOptions(this.type), this.options);
103126
},
104127

105-
authorized: function() {
128+
userAuthorized: function() {
129+
this.super();
130+
106131
// Get metadata as soon as possible so we don't have to wait later.
107132
metadata.get();
108133
},
109134

110135
getData: function() {
111136
if (this.super()) {
112-
this.setAttribute('pending', '');
137+
this.loading = true;
113138
}
114139
},
115140

@@ -118,8 +143,8 @@
118143
this.fire('analytics-query-error', response.error);
119144
}
120145
else {
121-
this.removeAttribute('unrendered');
122-
this.removeAttribute('pending');
146+
this.loading = false;
147+
this.rendered = true;
123148

124149
metadata.get().then(function(map) {
125150
switchApiNamesToDisplayNames(response.dataTable, map);
@@ -286,7 +311,7 @@
286311
* @return {Object} The merged target object.
287312
*/
288313
function merge(target) {
289-
var sources = [].slice.call(arguments, 1);
314+
var sources = Array.prototype.slice.call(arguments, 1);
290315
sources.forEach(function(source) {
291316
// Only merge objects.
292317
if (!(source && typeof sources == 'object')) return;

google-analytics-dashboard.html

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,20 @@
4444

4545
Polymer('google-analytics-dashboard', {
4646

47-
/**
48-
* The `query` attribute represents the internal query object of this
49-
* dashboard. It is updated when control elements fire the
50-
* `analytics-dashboard-control-change` event and pass along query data.
51-
*
52-
* @attribute query
53-
* @type object
54-
*/
55-
query: {},
56-
5747
ready: function() {
58-
this.unauthorized(); // Assume unauthorized state at first.
59-
},
48+
/**
49+
* The `query` attribute represents the internal query object of this
50+
* dashboard. It is updated when control elements fire the
51+
* `analytics-dashboard-control-change` event and pass along query data.
52+
*
53+
* @attribute query
54+
* @type object
55+
*/
56+
this.query = {};
6057

61-
authorized: function() {
62-
this.removeAttribute('unauthorized');
63-
this.setAttribute('authorized', '');
6458
this.updateChildren();
6559
},
6660

67-
unauthorized: function() {
68-
this.removeAttribute('authorized');
69-
this.setAttribute('unauthorized', '');
70-
},
71-
7261
/**
7362
* The `queryUpdated` method is the callback for whenever the
7463
* `analytics-dashboard-control-change` event is fired. It updates the
@@ -83,7 +72,7 @@
8372
this.query[key] = event.detail[key];
8473
}.bind(this))
8574

86-
if (this.isAuthorized) this.updateChildren();
75+
this.updateChildren();
8776
},
8877

8978
/**

google-analytics-query.html

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
* @attribute data
6565
* @type object
6666
*/
67-
data: null,
6867

6968
/**
7069
* The `ids` attribute is the unique table ID of the form ga:XXXX,
@@ -78,7 +77,6 @@
7877
* @attribute ids
7978
* @type string
8079
*/
81-
ids: null,
8280

8381
/**
8482
* The `startDate` attribute is the start date for fetching Analytics
@@ -117,7 +115,6 @@
117115
* @attribute metrics
118116
* @type string
119117
*/
120-
metrics: null,
121118

122119
/**
123120
* The `dimensions` attribute is a list of comma-separated dimensions
@@ -128,7 +125,6 @@
128125
* @attribute dimensions
129126
* @type string
130127
*/
131-
dimensions: null,
132128

133129
/**
134130
* The `sort` attribute is a list of comma-separated dimensions
@@ -140,7 +136,6 @@
140136
* @attribute sort
141137
* @type string
142138
*/
143-
sort: null,
144139

145140
/**
146141
* The `filters` attribute is dimension or metric filters that restrict
@@ -151,7 +146,6 @@
151146
* @attribute filters
152147
* @type string
153148
*/
154-
filters: null,
155149

156150
/**
157151
* The `segment` attribute segments the data returned for your
@@ -162,7 +156,6 @@
162156
* @attribute segment
163157
* @type string
164158
*/
165-
segment: null,
166159

167160
/**
168161
* The `samplingLevel` attribute sets the desired sampling level.
@@ -173,7 +166,6 @@
173166
* @attribute samplingLevel
174167
* @type string
175168
*/
176-
samplingLevel: null,
177169

178170
/**
179171
* The `startIndex` attribute sets the first row of data to retrieve,
@@ -185,7 +177,6 @@
185177
* @attribute startIndex
186178
* @type integer
187179
*/
188-
startIndex: null,
189180

190181
/**
191182
* The `maxResults` attribute is the maximum number of rows to include
@@ -196,7 +187,6 @@
196187
* @attribute maxResults
197188
* @type integer
198189
*/
199-
maxResults: null,
200190

201191
/**
202192
* The `output` attribute sets the desired output type for the
@@ -208,7 +198,6 @@
208198
* @attribute output
209199
* @type string
210200
*/
211-
output: null,
212201

213202
/**
214203
* The `fields` attribute is a selector specifying a subset of
@@ -219,7 +208,6 @@
219208
* @attribute fields
220209
* @type string
221210
*/
222-
fields: null,
223211

224212
observe: {
225213
ids: 'getData',
@@ -237,15 +225,13 @@
237225
fields: 'getData'
238226
},
239227

240-
get isValid() {
241-
return !!(this.ids && this.metrics && this.startDate && this.endDate);
242-
},
243-
244-
authorized: function() {
228+
userAuthorized: function() {
229+
this.super();
245230
this.getData();
246231
},
247232

248-
unauthorized: function() {
233+
userUnauthorized: function() {
234+
this.super();
249235
this.data = null;
250236
},
251237

@@ -255,8 +241,7 @@
255241
* @method getData
256242
*/
257243
getData: function() {
258-
259-
if (this.isAuthorized && this.isValid) {
244+
if (this.authorized && this.hasRequiredParams) {
260245

261246
// Required paramters.
262247
var query = {
@@ -298,7 +283,11 @@
298283
this.data = response;
299284
this.fire('analytics-query-success', response);
300285
}
301-
}
286+
},
287+
288+
get hasRequiredParams() {
289+
return !!(this.ids && this.metrics && this.startDate && this.endDate);
290+
},
302291

303292
});
304293

0 commit comments

Comments
 (0)