Skip to content

Commit fdb0164

Browse files
Carolyn GalvinCarolyn Galvin
authored andcommitted
Merge branch 'master' of github.com:cmcgalvin/puppy-schedule
2 parents b6db232 + c74a452 commit fdb0164

File tree

4 files changed

+98
-33
lines changed

4 files changed

+98
-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: 7 additions & 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

@@ -15,6 +16,7 @@
1516
</style>
1617

1718
<paper-button raised on-tap="_handlePeedEvent">Peed</paper-button>
19+
<paper-button raised on-tap="_handlePoopedEvent">Pooped</paper-button>
1820
<firebase-document
1921
id="document"
2022
app-name="puppyscheduler"
@@ -28,10 +30,14 @@
2830
static get is() { return 'data-entry'; }
2931

3032
_handlePeedEvent(e) {
31-
console.log('clicked peed button!');
3233
this.eventPath = '/events/' + Date.now().toString();
3334
this.eventData = {action: "peed"};
3435
}
36+
37+
_handlePoopedEvent(e) {
38+
this.eventPath = '/events/' + Date.now().toString();
39+
this.eventData = {action: "pooped"};
40+
}
3541
}
3642

3743
window.customElements.define(DataEntry.is, DataEntry);

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: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
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">
4+
<link rel="import" href="../bower_components/app-storage/app-indexeddb-mirror/app-indexeddb-mirror.html">
125
<link rel="import" href="shared-styles.html">
136

147
<dom-module id="stats-page">
@@ -21,18 +14,95 @@
2114
}
2215
</style>
2316

17+
<!--<firebase-document
18+
id="doc2"
19+
app-name="puppyscheduler"
20+
path="/events"
21+
data="{{events}}">
22+
</firebase-document> -->
23+
<firebase-query
24+
id="query"
25+
app-name="puppyscheduler"
26+
path="/events"
27+
data="{{events}}"
28+
limit-to-last=[[queryLimit]]
29+
</firebase-query>
30+
31+
<!--<app-indexeddb-mirror
32+
session="1"
33+
key="events"
34+
data="{{events}}"
35+
persisted-data="{{persistedEvents}}">
36+
</app-indexeddb-mirror>-->
37+
2438
<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>
39+
Last time Peed: [[lastTimePeed]]
2940
</div>
3041
</template>
3142

3243
<script>
3344
class StatsPage extends Polymer.Element {
3445
static get is() { return 'stats-page'; }
35-
}
46+
47+
static get observers() {
48+
return [
49+
'dataChanged(events.splices)'
50+
]
51+
}
52+
53+
static get properties() {
54+
return {
55+
events: Object,
56+
lastTimePeed: String,
57+
queryLimit: {
58+
type: Number,
59+
value: 10
60+
}
61+
}
62+
}
63+
64+
dataChanged(changeSet) {
65+
var self = this;
66+
if(changeSet) {
67+
changeSet.indexSplices.forEach(function(s) {
68+
if(s.object.length < self.queryLimit) {
69+
return;
70+
} else {
71+
self.lastTimePeed = self._findLastEvent("peed", s.object);
72+
}
73+
});
74+
}
75+
}
76+
77+
_findLastEvent(eventName, eventList) {
78+
var self = this;
79+
for(var i = self.queryLimit - 1; i > 0; i--) {
80+
if(eventList[i].action === eventName) {
81+
return self._formatDateReadable(eventList[i].$key);
82+
}
83+
}
84+
console.log('error');
85+
return '';
86+
}
87+
88+
_formatDateReadable(ts) {
89+
// how long ago in ms
90+
var diff = Date.now() - ts;
91+
// convert to a readable time
92+
var secs = Math.floor(diff / 1000);
93+
var mins = Math.floor(secs / 60 );
94+
var hours = Math.floor(mins / 60);
95+
96+
if(hours >= 1) {
97+
return hours + ' hours ago';
98+
} else if (mins >= 1){
99+
return mins + ' minutes ago';
100+
} else {
101+
return secs + ' seconds ago';
102+
}
103+
}
104+
}
105+
36106

37107
window.customElements.define(StatsPage.is, StatsPage);
38108
</script>

0 commit comments

Comments
 (0)