Skip to content

Commit a46186b

Browse files
committed
Revert: Revert 'Add Notifications'
1 parent ab1a03a commit a46186b

File tree

26 files changed

+381
-7
lines changed

26 files changed

+381
-7
lines changed

app/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/codingblocks-online.css">
1414
<link href="https://fonts.googleapis.com/css?family=Cabin" rel="stylesheet">
1515
<link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet">
16+
<link rel="manifest" href="/manifest.json" />
17+
18+
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
19+
<script>
20+
var OneSignal = window.OneSignal || [];
21+
OneSignal.push(function() {
22+
OneSignal.init({
23+
allowLocalhostAsSecureOrigin: true,
24+
appId: "29d9df1d-85cf-4d41-b504-c6b166b91261",
25+
});
26+
});
27+
28+
OneSignal.on ('register', function () { console.log ("*hacker voice*: I'm in") })
29+
</script>
1630

1731
{{content-for "head-footer"}}
1832
</head>

app/models/notification.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import DS from 'ember-data';
2+
3+
export default DS.Model.extend ({
4+
title: DS.attr (),
5+
message: DS.attr (),
6+
url: DS.attr (),
7+
triggerID: DS.attr (),
8+
triggerType: DS.attr (),
9+
run: DS.belongsTo ('run'),
10+
course: DS.belongsTo ('course'),
11+
user: DS.belongsTo ('user')
12+
});

app/models/user.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export default DS.Model.extend({
66
firstname: DS.attr(),
77
lastname: DS.attr(),
88
email: DS.attr(),
9-
hackJwt: DS.attr()
9+
hackJwt: DS.attr(),
10+
lastReadNotification: DS.attr (),
1011
//contents: DS.hasMany('content'),
1112
//courseRuns: DS.hasMany('run'),
1213
//runAttempt: DS.belongsTo('run-attempt')
13-
});
14+
});

app/pods/application/route.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export default Route.extend(ApplicationRouteMixin, {
3232
},
3333
model () {
3434
if (this.get('session.isAuthenticated')) {
35-
return this.get('currentUser').load()
35+
return this.get('currentUser').load().then (user => {
36+
OneSignal.sendTag ('user_id', user.get ('id'))
37+
.then (result => console.log ('OneSignal user_id set!'))
38+
.catch (result => console.error ('OneSignal user_id not set!'))
39+
})
3640
}
3741
}
3842
})

app/pods/components/accordian-head/component.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ export default class AccordianHeadComponent extends Component {
88
toggle () {
99
this.toggleProperty("collapsed")
1010
}
11-
1211
}

app/pods/components/nav-bar/template.hbs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
{{#link-to 'classroom'}}My Courses{{/link-to}}
2121
</li>
2222
{{/if}}
23+
<li class="nav-items pointer">
24+
{{notification-dropdown}}
25+
</li>
2326
<li class="nav-items pointer">
2427
<div class="button-solid">
2528
{{login-button}}
@@ -53,4 +56,4 @@
5356
</div>
5457
</div>
5558
</div>
56-
</header>
59+
</header>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import Component from '@ember/component';
2+
import { action } from 'ember-decorators/object'
3+
import { task } from 'ember-concurrency';
4+
import { service } from 'ember-decorators/service';
5+
6+
// Notifications Dropdown
7+
// - Highlight unread
8+
// - Mark all as read
9+
// - Poll periodically and update UI
10+
// - There are no more notifications to display
11+
export default class NotificationDropdownComponent extends Component {
12+
@service store
13+
@service currentUser
14+
15+
active = false
16+
notifications = []
17+
unreadNotifications = false
18+
19+
refreshInterval = 60000
20+
21+
offset = 0
22+
limit = 3
23+
page = 1
24+
25+
constructor () {
26+
super (...arguments)
27+
28+
this.get('loadNotifications').perform ()
29+
30+
setInterval (() =>
31+
this.get ('loadNotifications').perform (),
32+
this.get('refreshInterval')
33+
)
34+
}
35+
36+
loadNotifications = task(function * () {
37+
const notifications = yield this.get ('store').query ('notification', {
38+
page: {
39+
offset: this.get ('offset'),
40+
limit: this.get ('limit')
41+
},
42+
sort: '-id',
43+
custom: {
44+
ext: 'url',
45+
url: 'me'
46+
}
47+
})
48+
.then (notifications => {
49+
notifications.forEach (notification => {
50+
notification.set ('isUnread', this.isUnread (notification))
51+
})
52+
53+
return notifications
54+
})
55+
56+
this.set ('notifications', notifications)
57+
})
58+
59+
isUnread (notification) {
60+
let id = notification.get ('id'),
61+
currentUser = this.get ('currentUser'),
62+
lastReadNotificationID = currentUser.get ('user.lastReadNotification')
63+
;
64+
65+
return (lastReadNotificationID < id)
66+
}
67+
68+
@action
69+
toggle () {
70+
return this.toggleProperty ("active")
71+
}
72+
73+
@action
74+
nextPage () {
75+
let offset = this.get ('offset'),
76+
limit = this.get ('limit'),
77+
page = this.get ('page'),
78+
notificationCount = this.get ('notifications.meta.pagination.count')
79+
;
80+
81+
let maxPageCount = Math.ceil (notificationCount / limit)
82+
83+
if (page >= maxPageCount)
84+
return
85+
86+
this.set ('page', page + 1)
87+
this.set ('offset', offset + limit)
88+
this.get ('loadNotifications').perform ()
89+
}
90+
91+
@action
92+
previousPage () {
93+
let offset = this.get ('offset'),
94+
limit = this.get ('limit'),
95+
page = this.get ('page')
96+
;
97+
98+
if (offset <= 0)
99+
return
100+
101+
this.set ('offset', offset - limit)
102+
this.set ('page', page - 1)
103+
this.get ('loadNotifications').perform ()
104+
}
105+
106+
@action
107+
markAsRead () {
108+
let currentUser = this.get ('currentUser.user'),
109+
notificationIds = this.get ('notifications').mapBy ('id').map (id => parseInt (id)),
110+
maxNotificationId = Math.max (...notificationIds),
111+
notifications = this.get ('notifications')
112+
;
113+
114+
if (currentUser.get ('lastReadNotification') < maxNotificationId) {
115+
currentUser.set ('lastReadNotification', maxNotificationId)
116+
currentUser.save ()
117+
118+
notifications.forEach (notification => {
119+
notification.set ('isUnread', this.isUnread (notification))
120+
})
121+
}
122+
}
123+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div class="notify-icon" {{action 'toggle'}}>
2+
{{#if unreadNotifications}}
3+
<span class="notify-dot new"></span>
4+
{{/if}}
5+
<img src="images/notif-icon.png" alt="">
6+
</div>
7+
8+
<div class="dropdown-ul o-notification {{if active 'display-block'}}">
9+
{{#each notifications as |notification|}}
10+
<div class="dropdown-li row no-gutters">
11+
<div class="notify-type col-2 ">
12+
<div class="notify-icon">
13+
{{#if notification.isUnread}}
14+
<span class="notify-dot new"></span>
15+
{{/if}}
16+
<img src="images/announcement.png" alt="">
17+
</div>
18+
</div>
19+
<div class="notify-text col-10">{{notification.message}}</div>
20+
</div>
21+
{{/each}}
22+
<button onclick={{action 'previousPage'}}>Previous</button>
23+
<button onclick={{action 'nextPage'}}>Next</button>
24+
<button onclick={{action 'markAsRead'}}>Mark As Read</button>
25+
</div>

app/pods/notifications/index/route.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default Route.extend({
4+
model () {
5+
return this.store.query ('notification', {
6+
custom: {
7+
ext: 'url',
8+
url: 'me'
9+
}
10+
})
11+
}
12+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<div class="notify-icon" {{action 'toggle'}}>
2+
<span class="notify-dot new"></span>
3+
<img src="images/notif-icon.png" alt="">
4+
</div>
5+
<div class="dropdown-ul o-notification {{if show display-block}}">
6+
<div class="dropdown-li row no-gutters">
7+
<div class="notify-type col-2 ">
8+
<div class="notify-icon">
9+
<span class="notify-dot new"></span>
10+
<img src="images/announcement.png" alt="">
11+
</div>
12+
</div>
13+
<div class="notify-text col-10">Please hard refresh (Ctrl + Shift + R) your web app to make sure that you are on latest version of the app. We just deployed some major changes so that might be causing
14+
issues for you.</div>
15+
</div>
16+
17+
<div class="dropdown-li row no-gutters">
18+
<div class="notify-type col-2 ">
19+
<div class="notify-icon">
20+
<span class="notify-dot new"></span>
21+
<img src="images/announcement.png" alt="">
22+
</div>
23+
</div>
24+
<div class="notify-text col-10">Please hard refresh (Ctrl + Shift + R) your web app to make sure that you are on latest version of the app. We just deployed some major changes so that might be causing
25+
issues for you.</div>
26+
</div>
27+
28+
<div class="dropdown-li row no-gutters">
29+
<div class="notify-type col-2 ">
30+
<div class="notify-icon">
31+
<span class="notify-dot new"></span>
32+
<img src="images/announcement.png" alt="">
33+
</div>
34+
</div>
35+
<div class="notify-text col-10">Please hard refresh (Ctrl + Shift + R) your web app to make sure that you are on latest version of the app. We just deployed some major changes so that might be causing
36+
issues for you.</div>
37+
</div>
38+
39+
<div class="dropdown-li row no-gutters">
40+
<div class="notify-type col-2 ">
41+
<div class="notify-icon">
42+
<span class="notify-dot new"></span>
43+
<img src="images/announcement.png" alt="">
44+
</div>
45+
</div>
46+
<div class="notify-text col-10">Please hard refresh (Ctrl + Shift + R) your web app to make sure that you are on latest version of the app. We just deployed some major changes so that might be causing
47+
issues for you.</div>
48+
</div>
49+
</div>

app/pods/notifications/route.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Route from '@ember/routing/route';
2+
3+
export default Route.extend({
4+
});

app/pods/notifications/template.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{outlet}}

app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Router.map(function() {
2525
this.route('error');
2626
this.route('loading');
2727
this.route('application-loading');
28+
this.route('notifications', function() {});
2829
this.route('otp');
2930
});
3031

app/services/raven.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ export default RavenLogger.extend({
55
unhandledPromiseErrorMessage: '',
66

77
captureException(/* error */) {
8+
console.log ('lord')
89
console.error(...arguments)
9-
this._super(...arguments);
10+
// this._super(...arguments);
1011
},
1112

1213
captureMessage(/* message */) {

app/styles/_elements.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
@import "elements/element.loader";
2525
@import "elements/elements.dropdown";
2626
@import "elements/elements.color";
27-
@import "elements/elements.bg-color";
27+
@import "elements/elements.bg-color";

app/styles/objects/o-card-layout/card.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
margin-top: 25px;
2020
}
2121
}
22+
.grid-background {
23+
background-color: #f6f6f6;
24+
padding: 5%;
25+
}
2226

2327
.grid {
2428
margin: 0;

public/OneSignalSDKUpdaterWorker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');

public/OneSignalSDKWorker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');

public/images/notif-icon.png

3.8 KB
Loading

public/manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"gcm_sender_id": "482941778795",
3+
"gcm_sender_id_comment": "Do not change the GCM Sender ID"
4+
}

ssl/server.crt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDqjCCApICCQCdzqXQYU1rhzANBgkqhkiG9w0BAQsFADCBljELMAkGA1UEBhMC
3+
SU4xEjAQBgNVBAgMCU5ldyBEZWxoaTEOMAwGA1UEBwwFRGVsaGkxFjAUBgNVBAoM
4+
DUNvZGluZyBCbG9ja3MxETAPBgNVBAsMCERldiBUZWFtMRcwFQYDVQQDDA5sb2Nh
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A+QeTjA5cbYfVAxCUO1eMPxNHrd
21+
0AgJvRU3pxNHi+c0TPYQ6RwPc1s5feRCycthpv+s
22+
-----END CERTIFICATE-----

ssl/server.csr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-----BEGIN CERTIFICATE REQUEST-----
2+
MIIC3DCCAcQCAQAwgZYxCzAJBgNVBAYTAklOMRIwEAYDVQQIDAlOZXcgRGVsaGkx
3+
DjAMBgNVBAcMBURlbGhpMRYwFAYDVQQKDA1Db2RpbmcgQmxvY2tzMREwDwYDVQQL
4+
DAhEZXYgVGVhbTEXMBUGA1UEAwwObG9jYWxob3N0OjQyMDAxHzAdBgkqhkiG9w0B
5+
CQEWEHNpbkBwcmFqandhbC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
6+
AoIBAQDFtYYHay0ejal0LeKXJdVmy+ZVkWLCNn2qKf9N7hWUGQnxut+2UNaXl4Na
7+
EZe7SWdy3MuzA9CSAJmLutfBn94VEmZ8wslgIBgEDyYtlHASZk/FZVLEbEcnCogi
8+
GfPKQXGyC0wKj0n6GHKyBScCIPKLDnz5vujAA0RIlQAEHhx3A3xjDdS0BKRPjqDw
9+
GCMhKctV0cNF4ljDWTTfHwxv63DjAQC9P89IhEWBUs5c4L4ZXHXL4IHXpPRee689
10+
auaYJNfiodMjODA05FZAGHcuFNjU5Y/drpEds5OgE8AvCB9JG/LAN7KwxSkcO6+r
11+
sBQSBqLYnpZpo6uBAK4p+AF7xt1jAgMBAAGgADANBgkqhkiG9w0BAQsFAAOCAQEA
12+
xWg8FfBDBQoIt1vYeFAGKdgssvBB/ced9DVNeOIDxKx5DYRGkvmp8bxa+t3W8Nwp
13+
fYNILfwBsMDS1CsmjImi3XNIXQLIbHwR86JjUVRXc1OIIo4c7kHAezBuYHq5WQJg
14+
Bg6PdrxKJWef5orCIJZl8NvVLeYLVRcBlPp0nfU9OmymuhhsLpCSuXpwWywM23tr
15+
f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