Skip to content

Commit 448ec33

Browse files
Carolyn GalvinCarolyn Galvin
authored andcommitted
attempt #1 at fetching and searching through firebase data
1 parent e4d3a2f commit 448ec33

File tree

4 files changed

+73
-33
lines changed

4 files changed

+73
-33
lines changed

index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
<script>
6464
// Register the base URL
6565
const baseUrl = document.querySelector('base').href;
66-
console.log('baseurl ' + baseUrl);
6766

6867
//don't care about service worker but I'll keep this around in case we want it later
6968
// Load and register pre-caching Service Worker

src/data-entry.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<link rel="import" href="../bower_components/polymer/polymer-element.html">
22
<link rel="import" href="../bower_components/paper-button/paper-button.html">
33
<link rel="import" href="../bower_components/polymerfire/polymerfire.html">
4+
<link rel="import" href="../bower_components/polymerfire/firebase-document.html">
45

56
<link rel="import" href="shared-styles.html">
67

@@ -28,7 +29,6 @@
2829
static get is() { return 'data-entry'; }
2930

3031
_handlePeedEvent(e) {
31-
console.log('clicked peed button!');
3232
this.eventPath = '/events/' + Date.now().toString();
3333
this.eventData = {action: "peed"};
3434
}

src/puppy-app.html

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
<!--
2-
@license
3-
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7-
Code distributed by Google as part of the polymer project is also
8-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9-
-->
10-
111
<link rel="import" href="../bower_components/polymer/polymer-element.html">
122
<link rel="import" href="../bower_components/app-layout/app-drawer/app-drawer.html">
133
<link rel="import" href="../bower_components/app-layout/app-drawer-layout/app-drawer-layout.html">
@@ -20,7 +10,10 @@
2010
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
2111
<link rel="import" href="../bower_components/iron-selector/iron-selector.html">
2212
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
23-
<link rel="import" href="../bower_components/polymerfire/polymerfire.html">
13+
14+
<link rel="import" href="../bower_components/polymerfire/firebase-app-script.html">
15+
<link rel="import" href="../bower_components/polymerfire/firebase-database-script.html">
16+
<link rel="import" href="../bower_components/polymerfire/firebase-app.html">
2417

2518
<link rel="lazy-import" href="data-entry.html">
2619
<link rel="lazy-import" href="stats-page.html">
@@ -72,6 +65,7 @@
7265
data="{{routeData}}"
7366
tail="{{subroute}}"></app-route>
7467

68+
7569
<app-drawer-layout fullbleed>
7670
<!-- Drawer content -->
7771
<app-drawer id="drawer" slot="drawer">
@@ -102,7 +96,7 @@
10296
</iron-pages>
10397
</app-header-layout>
10498
</app-drawer-layout>
105-
99+
106100
</template>
107101

108102
<script>
@@ -135,7 +129,6 @@
135129
// Get root pattern for app-route, for more info about `rootPath` see:
136130
// https://www.polymer-project.org/2.0/docs/upgrade#urls-in-templates
137131
this.rootPattern = (new URL(this.rootPath)).pathname;
138-
console.log('rootpattern ' + this.rootPattern);
139132
}
140133

141134

@@ -149,7 +142,6 @@
149142
// If no page was found in the route data, page will be an empty string.
150143
// Deault to 'view1' in that case.
151144
this.page = page || 'dataEntry';
152-
console.log('page ' + page);
153145

154146
// Close a non-persistent drawer when the page & route are changed.
155147
if (!this.$.drawer.persistent) {
@@ -158,7 +150,6 @@
158150
}
159151

160152
_pageChanged(page) {
161-
console.log(page + ' is loading');
162153
var loc = 'data-entry';
163154
if(page === 'statsPage') loc = 'stats-page';
164155
var resolvedPageUrl = this.resolveUrl(loc + '.html');
@@ -171,7 +162,6 @@
171162
}
172163

173164
_error() {
174-
console.log('there was an error!');
175165
this.page = 'dataEntry';
176166
}
177167
}

src/stats-page.html

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
<!--
2-
@license
3-
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7-
Code distributed by Google as part of the polymer project is also
8-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9-
-->
10-
111
<link rel="import" href="../bower_components/polymer/polymer-element.html">
2+
<link rel="import" href="../bower_components/polymerfire/polymerfire.html">
3+
<link rel="import" href="../bower_components/polymerfire/firebase-query.html">
124
<link rel="import" href="shared-styles.html">
135

146
<dom-module id="stats-page">
@@ -21,18 +13,77 @@
2113
}
2214
</style>
2315

16+
<!--<firebase-document
17+
id="doc2"
18+
app-name="puppyscheduler"
19+
path="/events"
20+
data="{{events}}">
21+
</firebase-document> -->
22+
<firebase-query
23+
id="query"
24+
app-name="puppyscheduler"
25+
path="/events"
26+
data="{{events}}"
27+
</firebase-query>
28+
2429
<div class="card">
25-
<div class="circle">2</div>
26-
<h1>View Two</h1>
27-
<p>Ea duis bonorum nec, falli paulo aliquid ei eum.</p>
28-
<p>Id nam odio natum malorum, tibique copiosae expetenda mel ea.Detracto suavitate repudiandae no eum. Id adhuc minim soluta nam.Id nam odio natum malorum, tibique copiosae expetenda mel ea.</p>
30+
Last time Peed: [[lastTimePeed]]
2931
</div>
3032
</template>
3133

3234
<script>
3335
class StatsPage extends Polymer.Element {
3436
static get is() { return 'stats-page'; }
35-
}
37+
38+
/*static get observers() {
39+
return [
40+
'dataChanged(events.*)'
41+
]
42+
}*/
43+
44+
static get properties() {
45+
return {
46+
events: {
47+
type: Object,
48+
observer: 'dataChanged'
49+
},
50+
lastTimePeed: String
51+
}
52+
}
53+
54+
dataChanged(newData, oldData) {
55+
console.log('data changed');
56+
console.log('newData is ');
57+
console.log(newData);
58+
console.log('oldData is ');
59+
console.log(oldData);
60+
this.lastTimePeed = this._findLastEvent("peed");
61+
}
62+
63+
_findLastEvent(eventName) {
64+
console.log('finding last event, events are...');
65+
console.log(this.events);
66+
return 'abc';
67+
}
68+
69+
_formatDateReadable(ts) {
70+
// how long ago in ms
71+
var diff = Date.now() - ts;
72+
// convert to a readable time
73+
var secs = Math.floor(diff / 1000);
74+
var mins = Math.floor(secs / 60 );
75+
var hours = Math.floor(mins / 60);
76+
77+
if(hours >= 1) {
78+
return hours + ' hours ago';
79+
} else if (mins >= 1){
80+
return mins + ' minutes ago';
81+
} else {
82+
return secs + ' seconds ago';
83+
}
84+
}
85+
}
86+
3687

3788
window.customElements.define(StatsPage.is, StatsPage);
3889
</script>

0 commit comments

Comments
 (0)