Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9012bf31
authored
Apr 15, 2016
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: improve and make switchable desktop notifications
parent
cf9e0077
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
7 deletions
+37
-7
circle/dashboard/forms.py
+1
-1
circle/dashboard/migrations/0004_profile_desktop_notifications.py
+19
-0
circle/dashboard/models.py
+4
-0
circle/dashboard/static/dashboard/activity.js
+11
-6
circle/dashboard/templates/dashboard/_display-name.html
+2
-0
No files found.
circle/dashboard/forms.py
View file @
9012bf31
...
@@ -1223,7 +1223,7 @@ class MyProfileForm(forms.ModelForm):
...
@@ -1223,7 +1223,7 @@ class MyProfileForm(forms.ModelForm):
class
Meta
:
class
Meta
:
fields
=
(
'preferred_language'
,
'email_notifications'
,
fields
=
(
'preferred_language'
,
'email_notifications'
,
'use_gravatar'
,
)
'
desktop_notifications'
,
'
use_gravatar'
,
)
model
=
Profile
model
=
Profile
@property
@property
...
...
circle/dashboard/migrations/0004_profile_desktop_notifications.py
0 → 100644
View file @
9012bf31
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'dashboard'
,
'0003_message'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'profile'
,
name
=
'desktop_notifications'
,
field
=
models
.
BooleanField
(
default
=
False
,
help_text
=
'Whether user wants to get desktop notification when an activity has finished and the window not in focus.'
,
verbose_name
=
'Desktop notifications'
),
),
]
circle/dashboard/models.py
View file @
9012bf31
...
@@ -184,6 +184,10 @@ class Profile(Model):
...
@@ -184,6 +184,10 @@ class Profile(Model):
email_notifications
=
BooleanField
(
email_notifications
=
BooleanField
(
verbose_name
=
_
(
"Email notifications"
),
default
=
True
,
verbose_name
=
_
(
"Email notifications"
),
default
=
True
,
help_text
=
_
(
'Whether user wants to get digested email notifications.'
))
help_text
=
_
(
'Whether user wants to get digested email notifications.'
))
desktop_notifications
=
BooleanField
(
verbose_name
=
_
(
"Desktop notifications"
),
default
=
False
,
help_text
=
_
(
'Whether user wants to get desktop notification when '
'an activity has finished and the window not in focus.'
))
smb_password
=
CharField
(
smb_password
=
CharField
(
max_length
=
20
,
max_length
=
20
,
verbose_name
=
_
(
'Samba password'
),
verbose_name
=
_
(
'Samba password'
),
...
...
circle/dashboard/static/dashboard/activity.js
View file @
9012bf31
...
@@ -169,7 +169,7 @@ $(function() {
...
@@ -169,7 +169,7 @@ $(function() {
);
);
}
else
{
}
else
{
in_progress
=
false
;
in_progress
=
false
;
if
(
windowHasFocus
===
false
){
if
(
windowHasFocus
===
false
&&
userWantNotifications
()
){
sendNotification
(
generateMessageFromLastActivity
());
sendNotification
(
generateMessageFromLastActivity
());
}
}
if
(
reload_vm_detail
)
location
.
reload
();
if
(
reload_vm_detail
)
location
.
reload
();
...
@@ -186,7 +186,8 @@ $(function() {
...
@@ -186,7 +186,8 @@ $(function() {
// Notification init
// Notification init
$
(
function
(){
$
(
function
(){
Notification
.
requestPermission
();
if
(
userWantNotifications
())
Notification
.
requestPermission
();
});
});
// Detect window has focus
// Detect window has focus
...
@@ -200,10 +201,10 @@ $(window).focus(function(){
...
@@ -200,10 +201,10 @@ $(window).focus(function(){
function
generateMessageFromLastActivity
(){
function
generateMessageFromLastActivity
(){
var
ac
=
$
(
'div.activity'
).
first
();
var
ac
=
$
(
'div.activity'
).
first
();
if
(
ac
.
length
===
0
)
return
""
;
var
error
=
ac
.
children
(
".timeline-icon-failed"
).
length
;
var
error
=
$
(
ac
[
0
]).
children
(
".timeline-icon-failed"
).
length
;
var
sign
=
(
error
===
1
)
?
"❌ "
:
"✓ "
;
var
sign
=
(
error
===
1
)
?
"❌ "
:
"✓ "
;
return
sign
+
ac
[
0
].
innerText
.
split
(
","
)[
0
];
var
msg
=
ac
.
children
(
"strong"
).
text
().
trim
();
return
sign
+
msg
;
}
}
function
sendNotification
(
message
)
{
function
sendNotification
(
message
)
{
...
@@ -219,6 +220,11 @@ function sendNotification(message) {
...
@@ -219,6 +220,11 @@ function sendNotification(message) {
}
}
}
}
function
userWantNotifications
(){
var
dn
=
$
(
"#user-options"
).
data
(
"desktop_notifications"
);
return
dn
===
"True"
;
}
function
addConnectText
()
{
function
addConnectText
()
{
var
activities
=
$
(
".timeline .activity"
);
var
activities
=
$
(
".timeline .activity"
);
if
(
activities
.
length
>
1
)
{
if
(
activities
.
length
>
1
)
{
...
@@ -229,7 +235,6 @@ function addConnectText() {
...
@@ -229,7 +235,6 @@ function addConnectText() {
}
}
}
}
String
.
prototype
.
hashCode
=
function
()
{
String
.
prototype
.
hashCode
=
function
()
{
var
hash
=
0
,
i
,
chr
,
len
;
var
hash
=
0
,
i
,
chr
,
len
;
if
(
this
.
length
===
0
)
return
hash
;
if
(
this
.
length
===
0
)
return
hash
;
...
...
circle/dashboard/templates/dashboard/_display-name.html
View file @
9012bf31
...
@@ -15,4 +15,6 @@
...
@@ -15,4 +15,6 @@
{% endif %}
{% endif %}
{% endif %}
{% endif %}
<span
id=
"user-options"
data-desktop_notifications=
"{{ user.profile.desktop_notifications }}"
><span>
{% endif %}
{% endif %}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment