Skip to content

Commit

Permalink
Add decimalPlaces attribute to Score for AtlasOfLivingAustralia/field…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 17, 2024
1 parent fa892cc commit 6cfbddc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions grails-app/assets/javascripts/score.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var ScoreModel = function (score, config) {
self.entity = ko.observable(score.entity || 'Activity');
self.tags = ko.observableArray(score.tags);
self.tagOptions = ko.observableArray(score.tags);
self.decimalPlaces = ko.observable(score.decimalPlaces);

var editorPane = document.getElementById(config.scoreEditorId);

Expand Down Expand Up @@ -52,6 +53,7 @@ var ScoreModel = function (score, config) {
model.configuration = editor.get();
delete model.configurationText;
var data = JSON.stringify(model);
data.decimalPlaces = Number(data.decimalPlaces);

delete model.transients;
$.ajax(config.updateScoreUrl, {
Expand Down
8 changes: 6 additions & 2 deletions grails-app/domain/au/org/ala/ecodata/Score.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Score {

List<RelatedScore> relatedScores

Integer decimalPlaces


/** Embedded document describing how the score should be calculated */
Map configuration
Expand All @@ -57,6 +59,7 @@ class Score {
label unique: true
scoreId unique: true
name nullable: true, unique: true
decimalPlaces nullable: true
}

static mapping = {
Expand Down Expand Up @@ -86,14 +89,15 @@ class Score {
category:category,
outputType:outputType,
isOutputTarget:isOutputTarget,
label:label,
label:label,
description:description,
displayType:displayType,
entity:entity,
externalId:externalId,
entityTypes:entityTypes,
tags:tags,
name:name
name:name,
decimalPlaces:decimalPlaces?:2
]
if (includeConfig) {
scoreMap.configuration = configuration
Expand Down
4 changes: 2 additions & 2 deletions grails-app/services/au/org/ala/ecodata/MetadataService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -936,14 +936,14 @@ class MetadataService {

properties.scoreId = Identifiers.getNew(true, '')
Score score = new Score(scoreId:properties.scoreId)
commonService.updateProperties(score, properties)
score.properties = properties
score.save(flush:true)
return score
}

Score updateScore(String id, Map properties) {
Score score = Score.findByScoreId(id)
commonService.updateProperties(score, properties)
score.properties = properties
score.save(flush:true)
return score
}
Expand Down
4 changes: 4 additions & 0 deletions grails-app/views/admin/editScore.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<label class="form-label">External ID:</label> <input class="form-control" type="text" data-bind="value:externalId"/>
</div>

<div>
<label class="form-label">Number of decimal places:</label> <input class="form-control" type="number" data-bind="value:decimalPlaces"/>
</div>

<div>
<label class="form-label" for="tags">Tags:</label>
<select id="tags" multiple="multiple" class="form-control" data-bind="options:tagOptions, selectedOptions:tags">
Expand Down

0 comments on commit 6cfbddc

Please sign in to comment.