Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Notifications app #2967

Closed
wants to merge 48 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
20eea61
add inbox app
octavioamu Nov 27, 2018
7ab6e9b
Merge branch 'master' into new-notifications
Nov 28, 2018
287b3c4
add initial markup
octavioamu Nov 28, 2018
97b2a72
improve dropdown
octavioamu Nov 29, 2018
e2d315f
dynamic shadow
octavioamu Nov 30, 2018
3e2f9a7
change styles
octavioamu Nov 30, 2018
49594fd
backend init
octavioamu Dec 2, 2018
a6a8f05
small style changes
octavioamu Dec 3, 2018
e28a42d
mockup data
octavioamu Dec 4, 2018
3e6aa8f
fix request logic
octavioamu Dec 5, 2018
3080253
fix login and updates
octavioamu Dec 5, 2018
b4972d7
fix loop
octavioamu Dec 6, 2018
b6be53b
Changes to backend
Dec 5, 2018
be85747
Added username
Dec 6, 2018
fd08458
Get data from db
Dec 6, 2018
7cbb857
Added created time to data returned
Dec 6, 2018
d0b3330
Cleanup
Dec 6, 2018
710efeb
Merge pull request #3083 from usmanmuhd/notifs-backend
octavioamu Dec 6, 2018
dfb235c
fix shadow safari bug
octavioamu Dec 6, 2018
fad9fb9
Changes to notifs backend
Dec 7, 2018
6e958e1
Sort the notifs
Dec 7, 2018
cfd0469
Fix lint error
Dec 7, 2018
195e6ac
more changes
Dec 7, 2018
cfe8504
Added delete notification
Dec 8, 2018
a2c6716
Lint fixes
Dec 8, 2018
c31bd59
Mark read and unread
Dec 8, 2018
73640f4
Lint errors fix
Dec 8, 2018
74b8bd3
Minor fix
Dec 8, 2018
2d50b12
Helper function added
Dec 8, 2018
f33c079
Lint fixes
Dec 8, 2018
81b246b
Lint fixes
Dec 8, 2018
5021197
Lint fixes
Dec 8, 2018
0b3e682
Cleanup migrations
Dec 8, 2018
f01d9b9
add inbox and changes functions names
octavioamu Dec 8, 2018
2475d7f
url versioning and function name changes
Dec 8, 2018
80d93cf
Lint fixes
Dec 8, 2018
f6ef416
Merge branch 'new-notifications' into notif-backend
Dec 8, 2018
b67d6e9
Merge pull request #3119 from usmanmuhd/notif-backend
octavioamu Dec 8, 2018
abdbf37
change url version
octavioamu Dec 8, 2018
403a278
add mark as read
octavioamu Dec 9, 2018
e47ac1d
Handled json execptions
Dec 9, 2018
15064e8
Added pagination for notifications
Dec 9, 2018
476cb70
Merge pull request #3149 from usmanmuhd/notif-pagination
octavioamu Dec 9, 2018
5d25b33
Fix AttributeError in inbox.views
Dec 10, 2018
4def040
Merge pull request #3155 from usmanmuhd/notif-fixes
octavioamu Dec 10, 2018
80acc0e
change add read
octavioamu Dec 10, 2018
1dc59cc
Fix in inbox.views
Dec 10, 2018
a01df33
Merge pull request #3156 from usmanmuhd/new-notifications
octavioamu Dec 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mockup data
octavioamu committed Dec 4, 2018
commit e28a42decfe287b10d33b3df39d5cbabcaf1d0c9
85 changes: 85 additions & 0 deletions app/assets/v2/js/notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var notifications = []
const isHidden = false
const container = $('.notifications__list')

function requestNotifications() {
var getNotifications = fetchData ('/notification/','GET')

$.when( getNotifications ).then(function(response) {

// if (notifications.length) {
// newNotifications = filterNewData(response);
// } else {
// }
// newNotifications = response;
// console.log(newNotifications)
var flag = compareJson(response, notifications)
if (flag === false) {
console.log('updating')
console.log(notifications, response)
notifications = response;
templateSuggestions(response)
}
// return response
})
}

function templateSuggestions(notifications) {
var tmp = `
${notifications.map((notify, index) => `
<li class="notifications__item">
<span class="notifications__item-readed">
<b class="notification__dot-small"></b>
</span>
<div>
${notify.message_html}
</div>
<time class="notifications__time" datetime="${notify.created_on}" title="${notify.created_on}">
${notify.created_on}
</time>
</li>`
).join(' ')}
`;

container.html(tmp);
}

function checkHidden() {
if (typeof document.hidden !== "undefined") {
return isHidden = document.hidden
} else {
return isHidden = false
}
}

function filterNewData(data) {

return notifications.filter(
function(item) {

return data.indexOf(item) < 0;
}
);
}

function compareJson(obj1, obj2) {
var flag = true
if (Object.keys(obj1).length==Object.keys(obj2).length){
for(key in obj1) {
if(obj1[key] == obj2[key]) {
continue;
}
else {
return flag=false;
break;
}
}
}
else {
return flag=false;
}
}

requestNotifications()

var intervalNotifications = window.setInterval(requestNotifications, 5000);
28 changes: 14 additions & 14 deletions app/dashboard/templates/shared/notifications.html
Original file line number Diff line number Diff line change
@@ -29,75 +29,75 @@
</div> <a href="">{% trans 'Mark All as Read' %}</a>
</div>
<ul class="notifications__list">
<li class="notifications__item">
<!-- <li class="notifications__item">
<span class="notifications__item-readed">
<b class="notification__dot-small"></b>
</span>
You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…
<time class="notifications__time" datetime="{{'7:30 PM'|date:'c'}}" title="{{'7:30 PM'}}">
{{'7:30 PM'|naturaltime}}
</time>
</li>
</li> -->

<li class="notifications__item">
<!-- <li class="notifications__item">
<span class="notifications__item-readed">
<b class="notification__dot-small"></b>
</span>
You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…
<time class="notifications__time" datetime="{{'7:30 PM'|date:'c'}}" title="{{'7:30 PM'}}">
{{'7:30 PM'|naturaltime}}
</time>
</li>
</li> -->

<li class="notifications__item">
<!-- <li class="notifications__item">
<span class="notifications__item-readed">
<b class="notification__dot-small"></b>
</span>
You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…
<time class="notifications__time" datetime="{{'7:30 PM'|date:'c'}}" title="{{'7:30 PM'}}">
{{'7:30 PM'|naturaltime}}
</time>
</li>
</li> -->

<li class="notifications__item">
<!-- <li class="notifications__item">
<span class="notifications__item-readed">
<b class="notification__dot-small"></b>
</span>
You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…
<time class="notifications__time" datetime="{{'7:30 PM'|date:'c'}}" title="{{'7:30 PM'}}">
{{'7:30 PM'|naturaltime}}
</time>
</li>
</li> -->

<li class="notifications__item">
<!-- <li class="notifications__item">
<span class="notifications__item-readed">
<b class="notification__dot-small"></b>
</span>
You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…
<time class="notifications__time" datetime="{{'7:30 PM'|date:'c'}}" title="{{'7:30 PM'}}">
{{'7:30 PM'|naturaltime}}
</time>
</li>
</li> -->

<li class="notifications__item">
<!-- <li class="notifications__item">
<span class="notifications__item-readed">
<b class="notification__dot-small"></b>
</span>
You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…
<time class="notifications__time" datetime="{{'7:30 PM'|date:'c'}}" title="{{'7:30 PM'}}">
{{'7:30 PM'|naturaltime}}
</time>
</li>
</li> -->

<li class="notifications__item">
<!-- <li class="notifications__item">
<span class="notifications__item-readed">
<b class="notification__dot-small"></b>
</span>
You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…
<time class="notifications__time" datetime="{{'7:30 PM'|date:'c'}}" title="{{'7:30 PM'}}">
{{'7:30 PM'|naturaltime}}
</time>
</li>
</li> -->
</ul>
<a href="" class="notifications__button-all">{% trans 'See all' %}</a>
</div>
32 changes: 32 additions & 0 deletions app/inbox/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 2.1.2 on 2018-12-03 22:38

from django.db import migrations, models
import economy.models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Notification',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('created_on', models.DateTimeField(auto_now_add=True, null=True)),
('to_user_id', models.IntegerField()),
('from_user_id', models.IntegerField()),
('CTA_URL', models.URLField(max_length=255, null=True)),
('CTA_Text', models.CharField(max_length=255)),
('message_html', models.CharField(help_text='Html message', max_length=255, null=True)),
('is_read', models.BooleanField(default=False)),
],
options={
'abstract': False,
},
),
]
3 changes: 2 additions & 1 deletion app/inbox/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.db import models

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F401 'django.db.models' imported but unused

from django.utils.translation import gettext_lazy as _
from economy.models import SuperModel

# Create your models here.

class Notification(models.Model):
class Notification(SuperModel):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E302 expected 2 blank lines, found 1

created_on = models.DateTimeField(auto_now_add=True, blank=True, null=True)
to_user_id = models.IntegerField()
from_user_id = models.IntegerField()
61 changes: 53 additions & 8 deletions app/inbox/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
from django.shortcuts import render

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F401 'django.shortcuts.render' imported but unused

from django.core.paginator import Paginator
from inbox.models import Notification

from django.http import Http404, JsonResponse

# Create your views here.

def inbox(request, notification):
try:
notification = Notification.get(notification=notification)
return notification
except Exception as e:
print(e)
raise Http404
return JsonResponse("Hello, world. You're at the polls index.")
# def inbox(request):
# profile = request.user.profile if request.user.is_authenticated and request.user.profile else None

# try:
# grant = Notification.objects.prefetch_related('subscriptions', 'milestones').get(pk=grant_id, slug=grant_slug)
# notification = Notification.get(notification=notification)
# return notification
# except Exception as e:
# print(e)
# raise Http404
# return JsonResponse("Hello, world. You're at the polls index.")



def inbox(request):
"""Handle grants explorer."""
profile = request.user.profile if request.user.is_authenticated and request.user.profile else None
limit = request.GET.get('limit', 25)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F841 local variable 'limit' is assigned to but never used

page = request.GET.get('page', 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F841 local variable 'page' is assigned to but never used

sort = request.GET.get('sort_option', '-created_on')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F841 local variable 'sort' is assigned to but never used


_notifications = Notification.objects.filter(to_user_id=profile.id).order_by(sort)

if request.method == 'POST':
sort = request.POST.get('sort_option', '-created_on')
_notifications = Notification.objects.order_by(sort)

paginator = Paginator(_notifications, limit)
notifications = paginator.get_page(page)

params = [{
'is_read': 'false',
'created_on': '2018-11-15T19:59:08.081864Z',
'to_user_id': '7',
'from_user_id': '1',
'CTA_URL': 'http://localhost:8000/issue/owocki/pytrader/142/1555',
'CTA_Text': 'You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…',
'message_html': 'You haven’t responded to <b>#2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…</b>',
},
{
'is_read': 'false',
'created_on': '2018-11-15T19:59:08.081864Z',
'to_user_id': '7',
'from_user_id': '1',
'CTA_URL': 'http://localhost:8000/issue/owocki/pytrader/142/1555',
'CTA_Text': 'You haven’t responded to #2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…',
'message_html': 'You haven’t responded to <b>#2186: [Design] Show Remarketed Issues… in 3 days. Please submit a WIP…</b>',
},

]
return JsonResponse(params, status=200, safe=False)
1 change: 1 addition & 0 deletions app/retail/templates/shared/footer_scripts.html
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
<script src="{% static "v2/js/note.js" %}"></script>
<script src="{% static "v2/js/ajax-helper.js" %}"></script>
<script src="{% static "v2/js/pages/carousel.js" %}"></script>
<script src="{% static "v2/js/notifications.js"" %}"></script>
<script src="{% static "cookielaw/js/cl.js" %}"></script>

<script>