Skip to content

Commit

Permalink
Validation and label format changes #338
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Dec 10, 2024
1 parent 8bd1a2f commit 9a9caa5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions grails-app/assets/javascripts/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ OrganisationPageViewModel = function (props, options) {
}

self.attachValidation = function() {
$("#organisation-targets > table").validationEngine('attach');
$(options.organisationDetailsSelector).validationEngine('attach');
};

self.saveOrganisationConfiguration = function() {
Expand All @@ -762,7 +762,7 @@ OrganisationPageViewModel = function (props, options) {
};

self.saveCustomFields = function() {
if ($("#organisation-targets > table").validationEngine('validate')) {
if ($(options.organisationDetailsSelector).validationEngine('validate')) {
blockUIWithMessage("Saving organisation data...");
var json = JSON.parse(self.reportingTargetsAndFunding().modelAsJSON());
saveOrganisation(json).done(function() {
Expand Down
6 changes: 6 additions & 0 deletions grails-app/assets/stylesheets/organisation.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,9 @@ ul.ui-autocomplete {
width:7em;
}

#organisation-details th {
white-space: normal;
word-wrap: normal;
min-width: 7em;
}

Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class OrganisationService {
regenerateOrganisationReports(organisation, organisationReportCategories)
}

List<String> generateTargetPeriods(String id) {
List<Map> generateTargetPeriods(String id) {
Map organisation = get(id)
generateTargetPeriods(organisation)
}
Expand Down
12 changes: 9 additions & 3 deletions grails-app/services/au/org/ala/merit/ReportService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,16 @@ class ReportService {
List<Map> generateTargetPeriods(ReportConfig reportConfig, ReportOwner reportOwner, String formatString = null) {
List<Map> reports = new ReportGenerator().generateReports(
reportConfig, reportOwner, 0, null)
Closure dateFormatter = {
formatString ? DateUtils.format(DateUtils.parse(it), formatString) : it
Closure fromDateFormatter = {
formatString ? DateUtils.format(DateUtils.parse(it), formatString, DateTimeZone.default) : it
}
reports.collect{[label:dateFormatter(it.toDate), value:it.toDate]}
Closure toDateFormatter = {
// Compensate for the endDate of a report being 00:00:00 on the following day to have no overlap with the next start time.
DateTime toDate = DateUtils.parse(it).minusHours(1)
formatString ? DateUtils.format(toDate, formatString, DateTimeZone.default) : it
}

reports.collect{[label:fromDateFormatter(it.fromDate) +' - '+toDateFormatter(it.toDate), value:it.toDate]}
}

boolean needsRegeneration(Map report1, Map report2) {
Expand Down
4 changes: 2 additions & 2 deletions grails-app/views/organisation/_admin.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<a class="nav-link" data-toggle="pill" href="#config" id="config-tab" role="tab">Configuration</a>
</g:if>
<g:if test="${showTargets}">
<a class="nav-link" data-toggle="pill" href="#organisation-targets" id="organisation-targets-tab" role="tab">Targets</a>
<a class="nav-link" data-toggle="pill" href="#organisation-details" id="organisation-details-tab" role="tab">Targets</a>
</g:if>
</div>

Expand Down Expand Up @@ -155,7 +155,7 @@
<!-- /ko -->
</g:else>
<g:if test="${showTargets}">
<div id="organisation-targets" class="tab-pane">
<div id="organisation-details" class="tab-pane validationEngineContainer">
<h3>Total funding</h3>
<g:render template="/organisation/funding"/>
<h3>Service Targets</h3>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/organisation/_funding.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<tr>
<!-- ko foreach: costs -->
<td class="budget-amount">
<input type="number" class="form-control form-control-sm" data-bind="value: dollar, numeric: $root.number, disable: $root.isProjectDetailsLocked()" data-validation-engine="validate[custom[number]]"/>
<input type="number" class="form-control form-control-sm" data-bind="value: dollar, numeric: $root.number, disable: $root.isProjectDetailsLocked()" data-validation-engine="validate[custom[number],min[0]"/>
</td>
<!-- /ko -->
</tr>
Expand Down
12 changes: 6 additions & 6 deletions grails-app/views/organisation/_serviceTargets.gsp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<!-- ko with:reportingTargetsAndFunding() -->
<h4>${title ?: "Organisation services and minimum targets"}</h4>
<!-- ko with: services -->
<table class="table service-targets validationEngineContainer">
<table class="table service-targets">
<thead>
<tr>
<th class="index" rowspan="2"></th>
<th class="service required" rowspan="2">${serviceName ?: "Service"}</th>
<th class="score required" rowspan="2" style="width: 20px">Target measure</th>
<th class="budget-cell required" rowspan="2">Overall target <g:if test="${totalHelpText}"> <fc:iconHelp> ${totalHelpText} </fc:iconHelp></g:if></th>
<th class="budget-cell required" rowspan="2">Overall target (%) <g:if test="${totalHelpText}"> <fc:iconHelp> ${totalHelpText} </fc:iconHelp></g:if></th>
<g:if test="${showTargetDate}">
<th class="target-date required" rowspan="2">
Delivery date <g:if test="${deliveryHelpText}"> <fc:iconHelp> ${deliveryHelpText} </fc:iconHelp> </g:if>
</th>
</g:if>
<!-- ko if: periods && periods.length -->
<th data-bind="attr:{colspan:periods.length+1}">${periodTargetsLabel ?: "Targets by date"}</th>
<th data-bind="attr:{colspan:periods.length+1}">${periodTargetsLabel ?: " % Targets by date"}</th>
<!-- /ko -->
</tr>
<!-- ko if: periods && periods.length -->
Expand All @@ -30,16 +30,16 @@
<tr>
<td class="index"><span data-bind="text:$index()+1"></span></td>
<td class="service">
<select class="form-control form-control-sm" data-bind="options: selectableServices, optionsText:'name', optionsValue:'id', optionsCaption: 'Please select', value:serviceId, disable: $root.isProjectDetailsLocked()"
<select class="form-control form-control-sm" data-bind="options: selectableServices, optionsText:'name', optionsValue:'id', value:serviceId, disable: $root.isProjectDetailsLocked()"
data-validation-engine="validate[required]"></select>
</td>
<td class="score">
<select class="form-control form-control-sm" data-bind="options: selectableScores, optionsText:'label', optionsValue:'scoreId', optionsCaption: 'Please select', value:scoreId, disable: $root.isProjectDetailsLocked()"
<select class="form-control form-control-sm" data-bind="options: selectableScores, optionsText:'label', optionsValue:'scoreId', value:scoreId, disable: $root.isProjectDetailsLocked()"
data-validation-engine="validate[required]"></select>
</td>
<td class="budget-cell">
<input class="form-control form-control-sm" type="number" disabled data-bind="value: target"
data-validation-engine="validate[min[0.01]]" data-warningmessage="The sum of the minimum targets must be less than or equal to the overall target">
data-validation-engine="validate[min[0]]" data-warningmessage="The sum of the minimum targets must be less than or equal to the overall target">
</td>

<g:if test="${showTargetDate}">
Expand Down
3 changes: 2 additions & 1 deletion grails-app/views/organisation/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
reportingConfigSelector:'#reporting-config form',
availableReportCategories:availableReportCategories,
targetPeriods: targetPeriods,
services: services
services: services,
organisationDetailsSelector: '#organisation-details',

}, fcConfig);

Expand Down
5 changes: 3 additions & 2 deletions src/main/groovy/au/org/ala/merit/DateUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ class DateUtils {
dateTime.format(ISO_DATE_FORMATTER)
}

static String format(DateTime date, String formatString) {
DateTimeFormatter formatter = DateTimeFormat.forPattern(formatString).withZone(date.getZone())
static String format(DateTime date, String formatString, DateTimeZone zone = null) {
zone = zone ?: date.getZone()
DateTimeFormatter formatter = DateTimeFormat.forPattern(formatString).withZone(zone)
return formatter.print(date)
}

Expand Down

0 comments on commit 9a9caa5

Please sign in to comment.