Skip to content

Commit

Permalink
better feedback when uploading activity
Browse files Browse the repository at this point in the history
  • Loading branch information
temi committed Dec 11, 2024
1 parent 84e792e commit 799ed24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
15 changes: 12 additions & 3 deletions grails-app/assets/javascripts/offline-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ function ActivitiesViewModel (config) {
self.disableUpload = ko.computed(function () {
return self.activities().length === 0 || !self.online();
});
// check if any activity is uploading
self.isUploading = ko.computed(function () {
var activities = self.activities();
for (var i = 0; i < activities.length; i++) {
if (activities[i].uploading()) {
return true;
}
}
});


self.init = function() {
Expand Down Expand Up @@ -271,11 +280,11 @@ function ActivityViewModel (activity, parent) {
data: toSave,
contentType: 'application/json',
success: function success(data) {
if (data.errors || data.error) {
deferred.reject({data: {oldActivityId: oldActivityId, error: data.errors || data.error}});
if (data && data.resp && data.resp.activityId) {
deferred.resolve({data: {oldActivityId: oldActivityId, activityId: data.resp.activityId }});
}
else {
deferred.resolve({data: {oldActivityId: oldActivityId, activityId: data.resp.activityId }});
deferred.reject({data: {oldActivityId: oldActivityId, error: data.errors || data.error}});
}
},
error: function (jqXHR, status, error) {
Expand Down
20 changes: 18 additions & 2 deletions grails-app/views/bioActivity/pwaOfflineList.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@
</div>
<script id="page-actions-buttons" type="text/html">
<div class="my-2 float-right">
<button type="button" class="btn btn-success upload-records" disabled data-bind="click: uploadAllHandler, disable: disableUpload()"><i class="fas fa-upload"></i> <g:message code="pwa.upload.all"/></button>
<button type="button" class="btn btn-success upload-records" disabled data-bind="click: uploadAllHandler, disable: disableUpload">
<!-- ko if: isUploading -->
<i class="fa fa-spin fa-spinner"></i>
<!-- /ko -->
<!-- ko ifnot: isUploading -->
<i class="fas fa-upload"></i>
<!-- /ko -->
<g:message code="pwa.upload.all"/>
</button>
<!-- ko if: transients.isProjectActivity -->
<a class="btn btn-primary" id="create-activity" data-bind="attr: {href: transients.addActivityUrl()}"> <i class="fas fa-plus"></i> <g:message code="pwa.add.records"/></a>
<!-- /ko -->
Expand Down Expand Up @@ -75,7 +83,15 @@
</ol>
</td>
<td class="btn-space">
<button class="btn btn-success btn-sm upload-record" disabled data-bind="click: upload, enable: $parent.online, disable: disableUpload"><i class="fas fa-upload"></i> <g:message code="label.upload"/></button>
<button class="btn btn-success btn-sm upload-record" disabled data-bind="click: upload, enable: $parent.online, disable: disableUpload">
<!-- ko if: uploading -->
<i class="fa fa-spin fa-spinner"></i>
<!-- /ko -->
<!-- ko ifnot: uploading -->
<i class="fas fa-upload"></i>
<!-- /ko -->
<g:message code="label.upload"/>
</button>
<a class="btn btn-primary btn-sm view-record" data-bind="attr: {href: transients.viewActivityUrl()}, disable: uploading"><i class="far fa-eye"></i> <g:message code="label.view"/></a>
<a class="btn btn-dark btn-sm edit-record" data-bind="attr: {href: transients.editActivityUrl()}, disable: uploading"><i class="fas fa-pencil-alt"></i> <g:message code="label.edit"/></a>
<button class="btn btn-danger btn-sm delete-record" data-bind="click: deleteActivity, enable: $parent.online, disable: uploading"><i class="far fa-trash-alt"></i> <g:message code="label.delete"/></button>
Expand Down

0 comments on commit 799ed24

Please sign in to comment.