Skip to content

Commit

Permalink
updated functional test code
Browse files Browse the repository at this point in the history
  • Loading branch information
temi committed Nov 15, 2024
1 parent 5663d5e commit cfda857
Show file tree
Hide file tree
Showing 24 changed files with 15,334 additions and 9,498 deletions.
45 changes: 29 additions & 16 deletions grails-app/assets/javascripts/offline-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,33 @@ function ActivityViewModel (activity, parent) {
deferred.reject();
}, function () {
loadPromise.then(function (){
self.uploading(true);
promises.push(self.uploadImages());
promises.push(self.uploadSite().then(self.updateActivityWithSiteId).then(self.saveAsNewSite));
$.when.apply($, promises).then(function (imagesToDelete, oldSitesToDelete) {
self.saveActivityToDB().then(self.uploadActivity).then(self.deleteActivityFromDB).then(self.removeMeFromList).then(async function () {
self.uploading(false);
await self.deleteImages(imagesToDelete);
await self.deleteOldSite(oldSitesToDelete);
deferred.resolve({data: { activityId: activity.activityId} });
});
}, function (error) {
self.saveActivityToDB().then(function () {
self.uploading(false);
deferred.reject({data: { activityId: activity.activityId}, message: "There was an error uploading activity", error: error});
try {
self.uploading(true);
promises.push(self.uploadImages());
promises.push(self.uploadSite().then(self.updateActivityWithSiteId).then(self.saveAsNewSite));
$.when.apply($, promises).then(function (imagesToDelete, oldSitesToDelete) {
self.saveActivityToDB().then(self.uploadActivity).then(self.deleteActivityFromDB).then(self.removeMeFromList).then(async function () {
self.uploading(false);
await self.deleteImages(imagesToDelete);
await self.deleteOldSite(oldSitesToDelete);
deferred.resolve({data: {activityId: activity.activityId}});
});
}, function (error) {
self.saveActivityToDB().then(function () {
self.uploading(false);
deferred.reject({
data: {activityId: activity.activityId},
message: "There was an error uploading activity",
error: error
});
});
});
});
}
catch (error) {
console.error(error);
deferred.reject();
alert("There was an error uploading activity");
}
}, function () {
deferred.reject();
alert("There was an error fetching metadata for activity");
Expand Down Expand Up @@ -399,7 +410,9 @@ function ActivityViewModel (activity, parent) {

self.uploadImage = function(image) {
var formData = new FormData();
formData.append("files", image.getBlob());
var blob = image.getBlob();
var file = new File([blob], image.filename, {type: image.contentType()});
formData.append("files", file);
return $.ajax({
url: fcConfig.imageUploadUrl,
type: "POST",
Expand Down
4 changes: 0 additions & 4 deletions grails-app/assets/javascripts/pwa-messages.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
window.addEventListener('message', function(event) {
var origins = [fcConfig.originUrl, fcConfig.pwaAppUrl]
if (origins.indexOf(event.origin) == -1)
return

var type = event.data.event;
switch (type) {
case 'viewmodelloadded':
Expand Down
34 changes: 34 additions & 0 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ environments {
grails.mail.port = 3025 // com.icegreen.greenmail.util.ServerSetupTest.SMTP.port
temp.dir="/tmp/stylesheet"
google.maps.apiKey="testGoogleApi"
speciesCatalog.dir="./src/integration-test/resources/data"
}

production {
Expand Down Expand Up @@ -145,6 +146,39 @@ webservice['jwt-scopes'] = "ala/internal users/read ala/attrs ecodata/read_test
webservice['client-id']='changeMe'
webservice['client-secret'] = 'changeMe'

speciesCatalog = [
url: "To be set",
fileName: "combined.zip",
vernacularFileName: "vernacularname.txt",
taxonFileName: "taxon.txt",
totalFileName: "total.json",
batchSize: 1000,
dir: "/data/biocollect/speciesCatalog",
filters: [
language: "en",
exclude: [
unrankedValue: "unranked"
]
],
taxon: [
headerNames: [
guid: "taxonID",
scientificName: "scientificName",
rankString: "taxonRank",
name: "scientificName"
]
],
vernacular: [
headerNames: [
taxonID: "taxonID",
vernacularName: "vernacularName",
language: "language",
preferred: "isPreferredName"
]
]
]


dataAccessMethods = [
"oasrdfs",
"oaordfs",
Expand Down
25 changes: 0 additions & 25 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,30 +335,5 @@ pwa:
overlays: [ ]

---
speciesCatalog:
url: "To be set"
fileName: "combined.zip"
vernacularFileName: "vernacularname.txt"
taxonFileName: "taxon.txt"
totalFileName: "total.json"
batchSize: 1000
dir: "/data/biocollect/speciesCatalog"
filters:
language: "en"
exclude:
unrankedValue: "unranked"
taxon:
headerNames:
guid: "taxonID"
scientificName: "scientificName"
rankString: "taxonRank"
name: "scientificName"
vernacular:
headerNames:
taxonID: "taxonID"
vernacularName: "vernacularName"
language: "language"
preferred: "isPreferredName"

fathom:
enabled: true
2 changes: 1 addition & 1 deletion grails-app/views/bioActivity/_activities.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
<div class="tab-pane active" id="recordVis">
<!-- ko if: activities().length == 0 -->
<div class="row">
<div class="col-12"
<div class="col-12">
<h3 class="text-left mb-1">
<span data-bind="if: $root.searchTerm() == '' && $root.filterViewModel.selectedFacets().length == 0 && !$root.transients.loading()">
No data has been recorded for this project yet
Expand Down
120 changes: 61 additions & 59 deletions grails-app/views/bioActivity/pwaOfflineList.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -25,74 +25,76 @@
<body>
<div class="container">
<h1><g:message code="pwa.unpublished.heading"/></h1>
<bc:koLoading>
<bc:koLoading></bc:koLoading>
<!-- ko template: {name: 'page-actions-buttons', data: $data } --><!-- /ko -->
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th><g:message code="pwa.offlinelist.image.heading"/></th>
<th><g:message code="pwa.offlinelist.surveydate.heading"/></th>
<th><g:message code="pwa.offlinelist.species.heading"/></th>
<th><g:message code="pwa.offlinelist.actions.heading"/></th>
</tr>
</thead>
<tbody>
<!-- ko foreach: activities -->
<tr data-bind="style: { opacity: uploading() ? 0.5 : 1 }">
<td>
<!-- ko if: featureImage() -->
<div class="project-logo" data-bind="">
<img class="image-logo image-window" onload="findLogoScalingClass(this, 200, 150)"
data-bind="attr: {src: featureImage().thumbnailUrl}" alt="<g:message code="pwa.offlinelist.record.image.alt"/>"/>
</div>
<!-- /ko -->
<!-- ko ifnot: featureImage() -->
<div class="project-logo">
<img class="image-logo image-window" onload="findLogoScalingClass(this, 200, 150);"
data-bind="attr: {src: fcConfig.noImageUrl}" alt="<g:message code="pwa.offlinelist.record.noimage.alt"/>"/>
</div>
<!-- /ko -->
</td>
<td>
<span data-bind="text: convertToSimpleDate(surveyDate())"></span>
</td>
<td>
<ol data-bind="foreach: species">
<li data-bind="text: name"></li>
</ol>
</td>
<td class="btn-space">
<button class="btn btn-success btn-sm" data-bind="click: upload, enable: $parent.online, disable: disableUpload"><i class="fas fa-upload"></i> <g:message code="label.upload"/></button>
<a class="btn btn-primary btn-sm" 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" 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" data-bind="click: deleteActivity, enable: $parent.online, disable: uploading"><i class="far fa-trash-alt"></i> <g:message code="label.delete"/></button>
</td>
</tr>
<!-- /ko -->
<!-- ko if: activities().length == 0 -->
<tr>
<td colspan="4">
<div class="alert alert-info" role="alert">
<g:message code="pwa.activities.empty.msg"/>
</div>
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
</div>
<g:render template="/shared/pagination" model="[bs:4]"/>
<!-- ko template: {name: 'template-unpublished-records', data: $data } --><!-- /ko -->
<!-- ko template: {name: 'page-actions-buttons', data: $data } --><!-- /ko -->
</bc:koLoading>
</div>
<script id="page-actions-buttons" type="text/html">
<div class="my-2 float-right">
<button type="button" class="btn btn-success" 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()"><i class="fas fa-upload"></i> <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 -->
</div>
</script>
<script id="template-unpublished-records" type="text/html">
<div class="table-responsive">
<table id="offlineList" class="table">
<thead>
<tr>
<th><g:message code="pwa.offlinelist.image.heading"/></th>
<th><g:message code="pwa.offlinelist.surveydate.heading"/></th>
<th><g:message code="pwa.offlinelist.species.heading"/></th>
<th><g:message code="pwa.offlinelist.actions.heading"/></th>
</tr>
</thead>
<tbody>
<!-- ko foreach: activities -->
<tr data-bind="style: { opacity: uploading() ? 0.5 : 1 }">
<td>
<!-- ko if: featureImage() -->
<div class="project-logo" data-bind="">
<img class="image-logo image-window" onload="findLogoScalingClass(this, 200, 150)"
data-bind="attr: {src: featureImage().thumbnailUrl}" alt="<g:message code="pwa.offlinelist.record.image.alt"/>"/>
</div>
<!-- /ko -->
<!-- ko ifnot: featureImage() -->
<div class="project-logo">
<img class="image-logo image-window" onload="findLogoScalingClass(this, 200, 150);"
data-bind="attr: {src: fcConfig.noImageUrl}" alt="<g:message code="pwa.offlinelist.record.noimage.alt"/>"/>
</div>
<!-- /ko -->
</td>
<td>
<span data-bind="text: convertToSimpleDate(surveyDate())"></span>
</td>
<td>
<ol data-bind="foreach: species">
<li data-bind="text: name"></li>
</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>
<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>
</td>
</tr>
<!-- /ko -->
<!-- ko if: activities().length == 0 -->
<tr>
<td colspan="4">
<div class="alert alert-info" role="alert">
<g:message code="pwa.activities.empty.msg"/>
</div>
</td>
</tr>
<!-- /ko -->
</tbody>
</table>
</div>
<g:render template="/shared/pagination" model="[bs:4]"/>
</script>
</body>
</html>
Loading

0 comments on commit cfda857

Please sign in to comment.