Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Sep 21, 2023
2 parents 9f76650 + e3e44da commit 4b36757
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion grails-app/assets/javascripts/viewModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,15 @@ function enmapify(args) {
viewModel.getSiteId = function () {
return siteIdObservable();
};
viewModel.loadActivitySite = function () {
viewModel.loadActivitySite = function (data) {
var siteId = activityLevelData.activity && activityLevelData.activity.siteId;
siteId && siteIdObservable(siteId);
// if siteId is not set, then we need to create a site from lat and lon coordinates
if (edit && !siteIdObservable() && data) {
if (data.decimalLatitude && data.decimalLongitude) {
viewModel.addMarker(data);
}
}
};

function isEmpty(value){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class ModelJSTagLib {
if (data.${mod.name} && typeof data.${mod.name} !== 'undefined') {
self.data.${mod.name}(data.${mod.name});
} else {
self.loadActivitySite();
self.loadActivitySite({decimalLatitude: data.${mod.name}Latitude, decimalLongitude: data.${mod.name}Longitude});
}
if (data.${mod.name}Accuracy){
Expand Down
18 changes: 18 additions & 0 deletions src/test/js/spec/EnmapifySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,24 @@ describe("Enmapify Spec", function () {

});

it("should create site if siteId is not provided", function () {
options.activityLevelData.activity.siteId = "";
options.activityLevelData.siteId = "";
options.container.Test = "";

var result = enmapify(options);
spyOn(result.viewModel, "addMarker").and.returnValue(true);
result.viewModel.loadActivitySite({decimalLatitude: 1, decimalLongitude: 1});
expect(result.viewModel.addMarker).toHaveBeenCalledWith({decimalLatitude: 1, decimalLongitude: 1});

// should not call when in read mode
options.edit = false;
result = enmapify(options);
spyOn(result.viewModel, "addMarker").and.returnValue(true);
result.viewModel.loadActivitySite({decimalLatitude: 0, decimalLongitude: 0});
expect(result.viewModel.addMarker).not.toHaveBeenCalled();
});

it("centroid for line should be the first coordinate", function () {
var result = enmapify(options);
var line = {
Expand Down

0 comments on commit 4b36757

Please sign in to comment.