Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit 3ab070c

Browse files
committed
fixed #6
1 parent 7dac142 commit 3ab070c

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

djnotifier/templates/djnotifier/core.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,23 @@
55
<script src="{% static 'djnotifier/notify/jquery.min.js' %}"></script>
66
<script src="{% static 'djnotifier/notify/notify.js' %}"></script>
77

8+
<!--dj_notifier: add custom style-->
9+
{% block dj_notifier_notification_custom_style %}{% endblock dj_notifier_notification_custom_style %}
10+
811

912
<!--dj_notifier: notification javascript-->
1013
{% block dj_notifier_notification_js %}
11-
<script src="{% static 'djnotifier/notification.js' %}"></script>
14+
<script src="{% static 'djnotifier/notification.js' %}"></script>
1215
{% endblock dj_notifier_notification_js %}
1316

14-
<!--dj_notifier -> override: notification javascript-->
15-
{% block dj_notifier_notification_js_override %}{% endblock dj_notifier_notification_js_override %}
16-
1717

1818
<!--dj_notifier: web socket javascript-->
1919
{% block dj_notifier_websocket_js %}
20-
<script src="{% static 'djnotifier/socket.js' %}"></script>
20+
<script src="{% static 'djnotifier/socket.js' %}"></script>
2121
{% endblock dj_notifier_websocket_js %}
2222

23-
<!--dj_notifier -> override: web socket javascript-->
24-
{% block dj_notifier_websocket_js_override %}{% endblock dj_notifier_websocket_js_override %}
25-
2623

2724
<!--dj_notifier: notification audio file-->
2825
{% block dj_notifier_notification_audio %}
29-
<audio id="djNotifyAudio" data-src="{% static 'djnotifier/notify.mp3' %}"></audio>
26+
<audio id="djNotifyAudio" data-src="{% static 'djnotifier/notify.mp3' %}"></audio>
3027
{% endblock dj_notifier_notification_audio %}

docs/CUSTOMIZATION.md

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
> The `djnotifier` app is almost 100% customizable
33
44

5-
## Customize notification frontend
5+
# Table of contents
6+
1. [Frontend notification customization](#customize-notification-frontend)
7+
- [Adding own notification class/style](#adding-own-notification-classstyle)
8+
- [Registering new style as default](#registering-new-style-as-default)
9+
2. [Frontend websocket customization](#frontend-websocket-customization)
10+
3. [Backend customization](#backend-customization)
11+
12+
## Frontend notification customization
613
> Customize the notification style and other functionalities
714
815
### Adding own notification class/style
@@ -59,12 +66,15 @@ $.notify.addStyle("metro", {
5966
{% include 'djnotifier/dj_notifier.html' %}
6067
```
6168

62-
**Adding new style as one of notification styles
69+
**Adding new style as one of notification styles**
6370
```html
6471
<!--dj_notifier: add custom style-->
65-
{% block dj_notifier_notification_custom_style_js %}
66-
<script src="{% static 'path/to/djnotifier-custom-style.js' %}"></script>
67-
{% endblock dj_notifier_notification_custom_style_js %}
72+
{% block dj_notifier_notification_custom_style %}
73+
<script src="{% static 'path/to/djnotifier-custom-style.js' %}"></script>
74+
75+
<!--optional-->
76+
<link href="{% static 'path/to/djnotifier-custom-style.css' %}" rel="stylesheet">
77+
{% endblock dj_notifier_notification_custom_style %}
6878
```
6979

7080
### Registering new style as default
@@ -125,5 +135,47 @@ function playNotifyAudio(){
125135
<audio id="djNotifyAudio" data-src="{% static 'path/to/notify.mp3' %}"></audio>
126136
{% endblock dj_notifier_notification_audio %}
127137
```
128-
## Notification (backend)
138+
139+
## Frontend websocket customization
140+
> Customize the websocket frontend
141+
142+
**Writing own websocket client**
143+
```javascript
144+
// socket.js example
145+
var protocol = (window.location.protocol == 'http:') ? 'ws://' : 'wss://';
146+
var endpoint = "djnotifier"
147+
var webSocketEndpoint = protocol + window.location.host + '/' + endpoint + '/';
148+
var socket = new ReconnectingWebSocket(webSocketEndpoint);
149+
150+
socket.onmessage = function(e){
151+
let data = JSON.parse(e.data);
152+
// triggering push notification here...
153+
DJNotifier(style=data.type || 'info', text=data.message, audio=true)
154+
}
155+
156+
// Socket Connet Functionality
157+
socket.onopen = function(e){
158+
// more logic here...
159+
}
160+
161+
// Socket Error Functionality
162+
socket.onerror = function(e){
163+
// more logic here...
164+
}
165+
166+
// Socket close Functionality
167+
socket.onclose = function(e){
168+
console.log('Disconnected from djnotifier')
169+
}
170+
```
171+
172+
**Replacing default frontend websocket client**
173+
```html
174+
<!--web socket javascript client-->
175+
{% block dj_notifier_websocket_js %}
176+
<script src="{% static 'path/to/custom-socket.js' %}"></script>
177+
{% endblock dj_notifier_websocket_js %}
178+
```
179+
180+
## Backend customization
129181
> Customize the notification consumer, add more websocket routes etc.

example/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from django.contrib.auth import logout, authenticate, login
99
from django.contrib.auth.decorators import login_required
1010

11-
1211
User = get_user_model()
1312

1413

0 commit comments

Comments
 (0)