Skip to content

Commit 15b49f5

Browse files
committed
added a new display option for image - showRemoveButtonWithImage added functional tests to test new option. refactor function names in viewModels.js
1 parent e563a4e commit 15b49f5

File tree

8 files changed

+79
-11
lines changed

8 files changed

+79
-11
lines changed

grails-app/assets/javascripts/viewModels.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function enmapify(args) {
3636
listSitesUrl = activityLevelData.listSitesUrl || args.listSitesUrl,
3737
getSiteUrl = activityLevelData.getSiteUrl || args.getSiteUrl,
3838
context = args.context,
39-
uniqueNameUrl = (activityLevelData.uniqueNameUrlz || args.uniqueNameUrl) + "/" + ( activityLevelData.pActivity.projectActivityId || activityLevelData.pActivity.projectId),
39+
uniqueNameUrl = (activityLevelData.uniqueNameUrl || args.uniqueNameUrl) + "/" + ( activityLevelData.pActivity.projectActivityId || activityLevelData.pActivity.projectId),
4040
// hideSiteSelection is now dependent on survey's mapConfiguration
4141
// check viewModel.transients.hideSiteSelection
4242
hideMyLocation = args.hideMyLocation || false,
@@ -430,9 +430,9 @@ function enmapify(args) {
430430
lonObservable(data.decimalLongitude);
431431

432432
if (addCreatedSiteToListOfSelectedSites)
433-
completeDraw();
433+
createPublicSite();
434434
else
435-
completeDrawWithoutAdditionalSite();
435+
createPrivateSite();
436436
}
437437
}
438438
}
@@ -443,9 +443,9 @@ function enmapify(args) {
443443
map.registerListener("searchEventFired", function (e) {
444444
console.log('Received search event');
445445
if (addCreatedSiteToListOfSelectedSites)
446-
completeDraw();
446+
createPublicSite();
447447
else
448-
completeDrawWithoutAdditionalSite();
448+
createPrivateSite();
449449
});
450450

451451
// make sure the lat/lng fields are cleared when the marker is removed by cancelling a new marker
@@ -457,9 +457,9 @@ function enmapify(args) {
457457

458458
//Create site for all type including point
459459
if (addCreatedSiteToListOfSelectedSites)
460-
completeDraw();
460+
createPublicSite();
461461
else
462-
completeDrawWithoutAdditionalSite();
462+
createPrivateSite();
463463
});
464464
var saved = false;
465465
map.registerListener("draw:edited", function (e) {
@@ -474,9 +474,9 @@ function enmapify(args) {
474474
map.clearLayers();
475475
} else if (saved) {
476476
if (addCreatedSiteToListOfSelectedSites)
477-
completeDraw();
477+
createPublicSite();
478478
else
479-
completeDrawWithoutAdditionalSite()
479+
createPrivateSite()
480480
} else {
481481
console.log("cancelled edit with selected site, not clearing geometry")
482482
}
@@ -490,7 +490,14 @@ function enmapify(args) {
490490
map.markMyLocation();
491491
}
492492

493-
function completeDraw() {
493+
/**
494+
* Public sites have a name and are indexed by ElasticSearch.
495+
* Hence they are visible on site listing pages.
496+
* Creating public site also adds the site to ProjectActivity's
497+
* pre-determined list. Therefore, users will be able to pick it from
498+
* site selection drop down after creation.
499+
*/
500+
function createPublicSite() {
494501
siteSubscriber.dispose();
495502
siteIdObservable(null);
496503
Biocollect.Modals.showModal({
@@ -529,7 +536,10 @@ function enmapify(args) {
529536
siteSubscriber = siteIdObservable.subscribe(updateMapForSite);
530537
}
531538

532-
function completeDrawWithoutAdditionalSite() {
539+
/**
540+
* Private sites are not index by ElasticSearch. Hence not visible on site listing pages.
541+
*/
542+
function createPrivateSite() {
533543
siteSubscriber.dispose();
534544

535545
var extent = convertGeoJSONToExtent(map.getGeoJSON());

grails-app/assets/stylesheets/forms.css

+8
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,12 @@ table .select2 {
152152

153153
#error-info .formError.inline .formErrorContent {
154154
box-sizing: border-box;
155+
}
156+
157+
.margin-top-10 {
158+
margin-top: 10px;
159+
}
160+
161+
.margin-bottom-10 {
162+
margin-bottom: 10px;
155163
}

grails-app/conf/example_data/images.json

+3
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
},
55
"images2": {
66
"documentId": "d2"
7+
},
8+
"images3": {
9+
"documentId": "d3"
710
}
811
}

grails-app/conf/example_models/images.json

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"dataType": "image",
99
"description": "",
1010
"name": "images2"
11+
},{
12+
"dataType": "image",
13+
"description": "",
14+
"name": "images3"
1115
}
1216
],
1317
"modelName": "Images Example",
@@ -30,6 +34,15 @@
3034
"preLabel": "Default metadata behaviour:",
3135
"source": "images2",
3236
"type": "image"
37+
},
38+
{
39+
"preLabel": "Hide metadata and show remove button with image behaviour:",
40+
"source": "images3",
41+
"type": "image",
42+
"showMetadata": false,
43+
"displayOptions": {
44+
"showRemoveButtonWithImage": true
45+
}
3346
}
3447
]
3548
}

grails-app/controllers/ecodata/client/plugin/UrlMappings.groovy

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class UrlMappings {
1616
controller = 'preview'
1717
action = 'imagePreview'
1818
}
19+
"/" {
20+
controller = 'preview'
21+
action = [GET: 'index', POST: 'model']
22+
}
1923
"500"(view:'/error')
2024
}
2125
}

grails-app/views/output/_imageDataTypeEditModelTemplate.gsp

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
</a>
1414
</div>
1515
</div>
16+
<g:if test="${options?.showRemoveButtonWithImage}">
17+
<div class="row-fluid">
18+
<div class="span12">
19+
<a class="btn btn-danger btn-small margin-top-10 margin-bottom-10 remove-btn-with-image" data-bind="click: remove.bind($data,$parent.${name})"><i
20+
class="icon-remove icon-white"></i> Remove</a>
21+
</div>
22+
</div>
23+
</g:if>
1624
</div>
1725
<div class="span8" style="display:${showImgMetadata};">
1826
<div class="row-fluid">

grails-app/views/preview/index.gsp

+10
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@
120120
filename:"Landscape_2.jpg",
121121
filesize:1000
122122
123+
},
124+
{
125+
documentId:'d3',
126+
url:fcConfig.imagePreviewUrl+'/Landscape_1.jpg',
127+
thumbnailUrl:fcConfig.imagePreviewUrl+'/Landscape_1.jpg',
128+
"name": "Test image 3",
129+
"attribution": "Test attribution 3",
130+
"notes": "Test notes 3",
131+
filename:"Landscape_1.jpg",
132+
filesize:1000
123133
}
124134
],
125135
pActivity: {

src/integration-test/groovy/au/org/ala/ecodata/forms/ImageTypeSpec.groovy

+12
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@ class ImageTypeSpec extends GebReportingSpec {
4141
$("ul[data-bind*=images1] span[data-bind*=notes]").text() == "Test notes 1"
4242

4343
}
44+
45+
def "If the showRemoveButtonWithImage displayOption is set, a remove button is added below image. This can be combined with showMetadata false."() {
46+
when:
47+
to ([name:'images'], PreviewPage)
48+
49+
then:
50+
title == "Preview Images Example"
51+
52+
and: "The remove button is displayed below image"
53+
$("a.remove-btn-with-image").size() == 1
54+
$(".fileupload-buttonbar:nth-child(3) .image-title-input").displayed == false
55+
}
4456
}

0 commit comments

Comments
 (0)