diff --git a/breccia_mapper/settings.py b/breccia_mapper/settings.py index 4ddf406..cdade2c 100644 --- a/breccia_mapper/settings.py +++ b/breccia_mapper/settings.py @@ -146,6 +146,7 @@ THIRD_PARTY_APPS = [ 'post_office', 'bootstrap_datepicker_plus', 'hijack', + 'pwa', ] FIRST_PARTY_APPS = [ @@ -348,9 +349,17 @@ CONSTANCE_CONFIG = { 'RELATIONSHIP_FORM_HELP': ( '', 'Help text to display at the top of relationship forms.'), - 'DEPLOYMENT_URL': ( + 'SITE_URL': ( 'http://localhost', 'URL at which this mapper tool is accessible - do NOT include a trailing forward slash'), + 'SITE_ICON': ( + 'icon.png', + 'Site icon', + 'image_field'), + 'SITE_ICON_192x192': ( + 'icon-192x192.png', + 'Site icon', + 'image_field'), 'PARENT_PROJECT_NAME': ( '', 'Parent project name'), @@ -449,7 +458,9 @@ CONSTANCE_CONFIG_FIELDSETS = { 'RELATIONSHIP_FORM_HELP', ), 'Deployment': ( - 'DEPLOYMENT_URL', + 'SITE_URL', + 'SITE_ICON', + 'SITE_ICON_192x192', ), } # yapf: disable @@ -503,6 +514,40 @@ BOOTSTRAP_DATEPICKER_PLUS = { } } +# PWA settings + +PWA_SERVICE_WORKER_PATH = BASE_DIR.joinpath('static/js', 'serviceworker.js') + +PWA_APP_NAME = 'networkmapper' +PWA_APP_DESCRIPTION = "Network Mapper" +PWA_APP_THEME_COLOR = '#000000' +PWA_APP_BACKGROUND_COLOR = '#ffffff' +PWA_APP_DISPLAY = 'standalone' +PWA_APP_SCOPE = '/' +PWA_APP_ORIENTATION = 'any' +PWA_APP_START_URL = '/' +PWA_APP_STATUS_BAR_COLOR = 'default' +PWA_APP_ICONS = [ + { + 'src': 'media/icon-192x192.png', + 'sizes': '160x160' + } +] +PWA_APP_ICONS_APPLE = [ + { + 'src': 'media/icon-192x192.png', + 'sizes': '160x160' + } +] +PWA_APP_SPLASH_SCREEN = [ + { + 'src': 'media/icon.png', + 'media': '(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)' + } +] +PWA_APP_DIR = 'ltr' +PWA_APP_LANG = 'en-GB' + # Database default automatic primary key DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/breccia_mapper/static/js/serviceworker.js b/breccia_mapper/static/js/serviceworker.js new file mode 100644 index 0000000..9ed99a2 --- /dev/null +++ b/breccia_mapper/static/js/serviceworker.js @@ -0,0 +1,24 @@ +var staticCacheName = "djangopwa-v1"; + +self.addEventListener("install", function (event) { + event.waitUntil( + caches.open(staticCacheName).then(function (cache) { + return cache.addAll([""]); + }) + ); +}); + +self.addEventListener("fetch", function (event) { + var requestUrl = new URL(event.request.url); + if (requestUrl.origin === location.origin) { + if (requestUrl.pathname === "/") { + event.respondWith(caches.match("")); + return; + } + } + event.respondWith( + caches.match(event.request).then(function (response) { + return response || fetch(event.request); + }) + ); +}); diff --git a/breccia_mapper/templates/base.html b/breccia_mapper/templates/base.html index a7ef1fc..49cc7de 100755 --- a/breccia_mapper/templates/base.html +++ b/breccia_mapper/templates/base.html @@ -6,6 +6,11 @@ {% endif %} +{% load pwa %} +{% progressive_web_app_meta %} + + + diff --git a/breccia_mapper/urls.py b/breccia_mapper/urls.py index c5d5b9f..915b373 100644 --- a/breccia_mapper/urls.py +++ b/breccia_mapper/urls.py @@ -54,4 +54,7 @@ urlpatterns = [ path('', include('activities.urls')), + + path('', + include('pwa.urls')), ] # yapf: disable diff --git a/media/icon-192x192.png b/media/icon-192x192.png new file mode 100644 index 0000000..311b68f Binary files /dev/null and b/media/icon-192x192.png differ diff --git a/media/icon.png b/media/icon.png new file mode 100644 index 0000000..586b855 Binary files /dev/null and b/media/icon.png differ diff --git a/people/fixtures/email_templates.json b/people/fixtures/email_templates.json index ceacc07..77bcdf4 100644 --- a/people/fixtures/email_templates.json +++ b/people/fixtures/email_templates.json @@ -7,8 +7,8 @@ "created": "2020-04-27T12:13:30.448Z", "last_updated": "2020-04-27T14:45:27.152Z", "subject": "Welcome to {{config.PROJECT_LONG_NAME}}", - "content": "Dear user,\r\n\r\nWelcome to {{ config.PROJECT_LONG_NAME }}. You can set your password at {{ config.DEPLOYMENT_URL }}/password_reset/.\r\n\r\nThanks,\r\n\r\nThe {{ config.PROJECT_SHORT_NAME }} team", - "html_content": "

{{ config.PROJECT_LONG_NAME }}


Dear user,


Welcome to {{ config.PROJECT_LONG_NAME }}. You can set your password here.


Thanks,

The {{ config.PROJECT_SHORT_NAME }} team

", + "content": "Dear user,\r\n\r\nWelcome to {{ config.PROJECT_LONG_NAME }}. You can set your password at {{ config.SITE_URL }}/password_reset/.\r\n\r\nThanks,\r\n\r\nThe {{ config.PROJECT_SHORT_NAME }} team", + "html_content": "

{{ config.PROJECT_LONG_NAME }}


Dear user,


Welcome to {{ config.PROJECT_LONG_NAME }}. You can set your password here.


Thanks,

The {{ config.PROJECT_SHORT_NAME }} team

", "language": "", "default_template": null } diff --git a/requirements.txt b/requirements.txt index 33d0c1f..4c53580 100755 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ django-filter==22.1 django-hijack==3.2.6 django-picklefield==3.1 django-post-office==3.6.3 +django-pwa==1.1.0 django-select2==8.0.0 django-settings-export==1.2.1 djangorestframework==3.14.0