-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added delete activity - fixed broken tests
- Loading branch information
Showing
13 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//= require jquery/3.4.1/jquery-3.4.1.min.js | ||
//= require knockout/3.4.0/knockout-3.4.0.js | ||
//= require utils.js | ||
//= require dexiejs/dexie.js | ||
//= require bootstrap4/js/bootstrap.bundle.min.js | ||
//= require bootbox/bootbox.min.js | ||
//= require entities.js | ||
//= require pwa-settings.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
function StorageViewModel() { | ||
var self = this, | ||
deleteSteps = ['cache', 'db']; | ||
self.maximum = ko.observable(); | ||
self.used = ko.observable(); | ||
self.free = ko.observable(); | ||
self.percentage = ko.computed(function () { | ||
return Math.round(self.used() / self.maximum() * 100); | ||
}); | ||
self.isOffline = ko.observable(false); | ||
self.deleteProgress = ko.observable(0); | ||
self.deleteSteps = ko.observable(deleteSteps.length); | ||
self.deletePercentage = ko.computed(function () { | ||
return Math.round(self.deleteProgress() / self.deleteSteps() * 100); | ||
}); | ||
self.supported = ko.observable(true); | ||
self.refresh = function () { | ||
if (navigator.storage && navigator.storage.estimate) { | ||
navigator.storage.estimate().then( | ||
({ usage, quota }) => { | ||
var gbUnit = 1024 * 1024 * 1024; | ||
self.maximum(quota / gbUnit); | ||
self.used(usage / gbUnit); | ||
self.free(self.maximum() - self.used()); | ||
}, | ||
error => console.warn(`error estimating quota: ${error.name}: ${error.message}`) | ||
); | ||
} | ||
else { | ||
self.supported(false); | ||
} | ||
} | ||
|
||
self.clearAll = function () { | ||
self.deleteProgress(0); | ||
bootbox.confirm("This operation cannot be reversed. Are you sure you want to delete?", function (result) { | ||
if (result) { | ||
self.deleteCache().then(self.deleteDBEntries).then(function () { | ||
self.deleteProgress(self.deleteSteps()); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
self.deleteCache = function () { | ||
return caches.keys().then(function (cacheNames) { | ||
return Promise.all( | ||
cacheNames.map(function (cacheName) { | ||
return caches.delete(cacheName); | ||
}) | ||
); | ||
}).then(function () { | ||
self.refresh(); | ||
self.deleteProgress(self.deleteProgress() + 1); | ||
}); | ||
} | ||
|
||
self.deleteDBEntries = function () { | ||
return entities.deleteTable('offlineMap').then(function () { | ||
return entities.deleteTable('taxon').then(function () { | ||
self.deleteProgress(self.deleteProgress() + 1); | ||
}); | ||
}); | ||
} | ||
|
||
document.addEventListener('offline', function () { | ||
self.isOffline(true); | ||
}); | ||
|
||
document.addEventListener('online', function () { | ||
self.isOffline(false); | ||
}); | ||
|
||
self.refresh(); | ||
} | ||
|
||
function initialise() { | ||
var storageViewModel = new StorageViewModel(); | ||
ko.applyBindings(storageViewModel, document.getElementById('storage-settings')); | ||
checkOfflineForIntervalAndTriggerEvents(5000); | ||
} | ||
|
||
$(document).ready(initialise); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/** | ||
*= require base-bs4.css | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<%@ page contentType="text/html;charset=UTF-8" %> | ||
<html> | ||
<head> | ||
<meta name="layout" content="pwa"/> | ||
<title>PWA settings</title> | ||
<asset:stylesheet src="pwa-settings-manifest.css"/> | ||
<asset:javascript src="pwa-settings-manifest.js"/> | ||
<asset:script> | ||
var fcConfig = { | ||
siteUrl: "/ws/site", | ||
addActivityUrl: "/pwa/bioActivity/edit", | ||
activityViewUrl: "/pwa/bioActivity/index", | ||
activityEditUrl: "/pwa/bioActivity/edit", | ||
imageUploadUrl: "/ws/attachment/upload", | ||
bioActivityUpdate: "/ws/bioactivity/save", | ||
updateSiteUrl: "/ws/bioactivity/site", | ||
noImageUrl: "${asset.assetPath(src: "font-awesome/5.15.4/svgs/regular/image.svg")}", | ||
pwaAppUrl: "${grailsApplication.config.getProperty('pwa.appUrl')}", | ||
isCaching: ${params.getBoolean('cache', false)}, | ||
enableOffline: true | ||
}; | ||
</asset:script> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1><g:message code="pwa.settings.heading"/></h1> | ||
<div id="storage-settings"> | ||
<bc:koLoading> | ||
<h3><g:message code="pwa.settings.storage.heading"/></h3> | ||
<!-- ko if: supported --> | ||
<table class="table"> | ||
<tbody> | ||
<tr> | ||
<td colspan="2"> | ||
<div class="progress"> | ||
<div class="progress-bar bg-success" role="progressbar" data-bind="style: {width: percentage() + '%'}, text: percentage() + '%', attr: {'aria-valuenow': percentage}" aria-valuemin="0" aria-valuemax="100"></div> | ||
</div> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><g:message code="pwa.settings.storage.total"/></td> | ||
<td data-bind="text: maximum"></td> | ||
</tr> | ||
<tr> | ||
<td><g:message code="pwa.settings.storage.free"/></td> | ||
<td data-bind="text: free"></td> | ||
</tr> | ||
<tr> | ||
<td><g:message code="pwa.settings.storage.used"/></td> | ||
<td data-bind="text: used"></td> | ||
</tr> | ||
<tr> | ||
<td><g:message code="pwa.settings.storage.totalPercentage"/></td> | ||
<td data-bind="text: percentage() + ' %'"></td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<button class="btn btn-sm btn-success" data-bind="click: refresh"> | ||
<i class="fas fa-sync"></i> | ||
<g:message code="pwa.settings.storage.btn.refresh"/> | ||
</button> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<!-- /ko --> | ||
<!-- ko ifnot: supported --> | ||
<div class="alert alert-info" role="alert"> | ||
<h4 class="alert-heading"><g:message code="pwa.settings.storage.alert.heading"/> </h4> | ||
<p><g:message code="pwa.settings.storage.alert.message"/></p> | ||
</div> | ||
<!-- /ko --> | ||
<h3><g:message code="pwa.settings.manage.title"/> </h3> | ||
<div class="alert alert-danger" role="alert"> | ||
<h4 class="alert-heading"><g:message code="pwa.settings.manage.alert.heading"/> </h4> | ||
<p><g:message code="pwa.settings.manage.alert.message"/></p> | ||
</div> | ||
<div class="row mb-2"> | ||
<div class="col-12"> | ||
<button class="btn btn-danger" data-bind="click: clearAll, disable: isOffline"> | ||
<i class="fas fa-trash"></i> | ||
<g:message code="pwa.settings.manage.btn.clearAll"/> | ||
</button> | ||
</div> | ||
</div> | ||
<h6><g:message code="pwa.settings.manage.delete.progress"/> </h6> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<div class="progress"> | ||
<div class="progress-bar bg-success" role="progressbar" data-bind="style: {width: deletePercentage() + '%'}, text: deletePercentage() + '%', attr: {'aria-valuenow': deletePercentage}" aria-valuemin="0" aria-valuemax="100"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</bc:koLoading> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters