dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #27121
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13450: Impl UI for data approval in data set report
------------------------------------------------------------
revno: 13450
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-12-27 17:53:58 +0100
message:
Impl UI for data approval in data set report
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css
dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java 2013-12-27 14:02:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java 2013-12-27 16:53:58 +0000
@@ -35,10 +35,12 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
+import org.springframework.transaction.annotation.Transactional;
/**
* @author Jim Grace
*/
+@Transactional
public class DefaultDataApprovalService
implements DataApprovalService
{
@@ -107,10 +109,11 @@
{
switch ( getDataApprovalState( dataSet, period, child, attributeOptionCombo ) )
{
- //
+ // -------------------------------------------------------------
// If ready or waiting at a lower level, return
// WAITING_FOR_LOWER_LEVEL_APPROVAL at this level.
- //
+ // -------------------------------------------------------------
+
case READY_FOR_APPROVAL:
case WAITING_FOR_LOWER_LEVEL_APPROVAL:
return DataApprovalState.WAITING_FOR_LOWER_LEVEL_APPROVAL;
@@ -127,21 +130,23 @@
}
}
- //
+ // ---------------------------------------------------------------------
// If approved at lower levels (and not ready or waiting at any),
// and/or if data is configured for entry at this level (whether or
// not it has been entered), return READY_FOR_APPROVAL.
- //
+ // ---------------------------------------------------------------------
+
if ( approvedAtLowerLevels || organisationUnit.getAllDataSets().contains ( dataSet ) )
{
return DataApprovalState.READY_FOR_APPROVAL;
}
- //
+ // ---------------------------------------------------------------------
// Finally, if we haven't seen any approval action at lower levels,
// and this level is not configured for data entry from this data set,
// then return APPROVAL_NOT_NEEDED.
- //
+ // ---------------------------------------------------------------------
+
return DataApprovalState.APPROVAL_NOT_NEEDED;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java 2013-12-27 14:30:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java 2013-12-27 16:53:58 +0000
@@ -179,12 +179,15 @@
DataApprovalState state = dataApprovalService.getDataApprovalState( dataSet, period, organisationUnit, attributeOptionCombo );
- if ( DataApprovalState.READY_FOR_APPROVAL.equals( state ) )
+ if ( !DataApprovalState.READY_FOR_APPROVAL.equals( state ) )
{
- DataApproval approval = new DataApproval( dataSet, period, organisationUnit, attributeOptionCombo, new Date(), user );
-
- dataApprovalService.addDataApproval( approval );
+ ContextUtils.conflictResponse( response, "Data is not ready for approval: " + state );
+ return;
}
+
+ DataApproval approval = new DataApproval( dataSet, period, organisationUnit, attributeOptionCombo, new Date(), user );
+
+ dataApprovalService.addDataApproval( approval );
}
@PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css 2013-12-20 12:15:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/widgets.css 2013-12-27 16:53:58 +0000
@@ -338,14 +338,25 @@
/* Message field */
/*----------------------------------------------------------------------------*/
+.messageBox
+{
+ display: none;
+ padding: 1em;
+ margin: 1em 0;
+ background-color: #f8eab0;
+ border: 1px solid #dbae56;
+ width: 480px;
+ border-radius: 3px;
+}
+
span#message
{
display: none;
padding: 1em;
- margin: 1em;
+ margin: 1em 0;
background-color: #f8eab0;
border: 1px solid #dbae56;
- width: 500px;
+ width: 480px;
border-radius: 3px;
}
@@ -353,10 +364,10 @@
{
display: block;
padding: 1em;
- margin: 1em;
+ margin: 1em 0;
background-color: #baffbc;
border: 1px solid #12cd17;
- width: 500px;
+ width: 480px;
border-radius: 3px;
}
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2013-12-25 15:01:48 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/org/hisp/dhis/reporting/i18n_module.properties 2013-12-27 16:53:58 +0000
@@ -246,4 +246,9 @@
analytics_tables_update=Analytics tables update
aggregation_period_types=Aggregation period types
data_mart_tables_update=Data mart tables update
-analytics_and_data_mart=Analytics and Data Mart
\ No newline at end of file
+analytics_and_data_mart=Analytics and Data Mart
+approve=Approve
+unapprove=Unapprove
+waiting_for_lower_level_approval=Waiting for lower level organisation units to approve
+confirm_approval=Are you sure you want to approve this data set?
+confirm_unapproval=Are you sure you want to unapprove this data set?
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm 2013-12-25 12:07:24 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/dataSetReportForm.vm 2013-12-27 16:53:58 +0000
@@ -39,6 +39,9 @@
var i18n_share_your_interpretation = '$encoder.jsEscape( $i18n.getString( "share_your_interpretation" ), "'")';
var i18n_interpretation_was_shared = '$encoder.jsEscape( $i18n.getString( "interpretation_was_shared" ), "'")';
var i18n_select_option_view_all = '$encoder.jsEscape( $i18n.getString( "select_option_view_all" ) , "'")';
+var i18n_waiting_for_lower_level_approval = '$encoder.jsEscape( $i18n.getString( "waiting_for_lower_level_approval" ) , "'")';
+var i18n_confirm_approval = '$encoder.jsEscape( $i18n.getString( "confirm_approval" ) , "'")';
+var i18n_confirm_unapproval = '$encoder.jsEscape( $i18n.getString( "confirm_unapproval" ) , "'")';
</script>
<style type="text/css" media="print">
@@ -92,7 +95,9 @@
<select id="dataSetId" name="dataSetId" style="width:330px" onchange="dhis2.dsr.dataSetSelected()">
<option value="">[ $i18n.getString( "select" ) ]</option>
#foreach( $dataSet in $dataSets )
- <option value="$dataSet.uid" data-categorycombo="${dataSet.categoryCombo.uid}">$encoder.htmlEncode( $dataSet.displayName )</option>
+ <option value="$dataSet.uid" data-categorycombo="${dataSet.categoryCombo.uid}" data-approval="${dataSet.approveData}">
+ $encoder.htmlEncode( $dataSet.displayName )
+ </option>
#end
</select>
</div>
@@ -152,3 +157,10 @@
#parse( "dhis-web-commons/loader/loader.vm" )
<div id="content"></div>
+
+<div id="approvalDiv" class="page inputCriteria" style="width: 263px; display:none;">
+<input type="button" id="approveButton" value="$i18n.getString( 'approve' )" onclick="dhis2.dsr.approveData()" style="width:120px">
+<input type="button" id="unapproveButton" value="$i18n.getString( 'unapprove' )" onclick="dhis2.dsr.unapproveData()" style="width:120px">
+</div>
+
+<div id="message" class="messageBox"></div>
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js 2013-12-25 12:07:24 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js 2013-12-27 16:53:58 +0000
@@ -3,6 +3,7 @@
dhis2.dsr.currentPeriodOffset = 0;
dhis2.dsr.periodTypeFactory = new PeriodType();
+dhis2.dsr.currentDataSetReport = null;
//------------------------------------------------------------------------------
// Get and set methods
@@ -115,7 +116,7 @@
$( "#attributeComboDiv" ).show().html( html );
} );
-};
+}
//------------------------------------------------------------------------------
// Period
@@ -156,8 +157,6 @@
// Run report
//------------------------------------------------------------------------------
-//TODO rewrite to use uid only
-
function drillDownDataSetReport( orgUnitId, orgUnitUid )
{
selectionTree.clearSelectedOrganisationUnits();
@@ -192,6 +191,8 @@
return false;
}
+ dhis2.dsr.currentDataSetReport = dataSetReport;
+
hideHeaderMessage();
hideCriteria();
hideContent();
@@ -200,31 +201,41 @@
delete dataSetReport.periodType;
delete dataSetReport.offset;
- var url = "generateDataSetReport.action?ds=" + dataSetReport.ds +
- "&pe=" + dataSetReport.pe + "&ou=" + dataSetReport.ou +
- "&selectedUnitOnly=" + dataSetReport.selectedUnitOnly;
-
- $.each( dataSetReport.dimension, function( inx, val ) {
- url += "&dimension=" + val;
- } );
+ var url = "generateDataSetReport.action" + dhis2.dsr.getDatSetReportQueryParams( dataSetReport );
$.get( url, function( data ) {
$( '#content' ).html( data );
hideLoader();
showContent();
+ dhis2.dsr.showApproval();
setTableStyles();
} );
}
+/**
+ * Generates the query params part of the URL for the given data set report.
+ */
+dhis2.dsr.getDatSetReportQueryParams = function( dataSetReport )
+{
+ var url =
+ "?ds=" + dataSetReport.ds +
+ "&pe=" + dataSetReport.pe +
+ "&ou=" + dataSetReport.ou +
+ "&selectedUnitOnly=" + dataSetReport.selectedUnitOnly;
+
+ $.each( dataSetReport.dimension, function( inx, val ) {
+ url += "&dimension=" + val;
+ } );
+
+ return url;
+}
+
function exportDataSetReport( type )
{
- var dataSetReport = getDataSetReport();
+ var dataSetReport = dhis2.dsr.currentDataSetReport;
var url = "generateDataSetReport.action" +
- "?ds=" + dataSetReport.ds +
- "&pe=" + dataSetReport.pe +
- "&selectedUnitOnly=" + dataSetReport.selectedUnitOnly +
- "&ou=" + dataSetReport.ou +
+ dhis2.dsr.getDatSetReportQueryParams( dataSetReport ) +
"&type=" + type;
window.location.href = url;
@@ -271,20 +282,95 @@
$( "#advancedOptions" ).show();
}
+dhis2.dsr.showApproval = function()
+{
+ var approval = $( "#dataSetId :selected" ).data( "approval" );
+
+ if ( !approval ) {
+ $( "#approvalDiv" ).hide();
+ return false;
+ }
+
+ var dataSetReport = dhis2.dsr.currentDataSetReport;
+
+ var url = "../api/dataApprovals" + dhis2.dsr.getDatSetReportQueryParams( dataSetReport );
+
+ $.get( url, function( status ) {
+ if ( status && '"READY_FOR_APPROVAL"' == status ) {
+ $( "#approvalDiv" ).show();
+ $( "#approveButton" ).prop( "disabled", false );
+ $( "#unapproveButton" ).prop( "disabled", true );
+ $( "#message" ).hide();
+ }
+ else if ( status && '"APPROVED"' == status ) {
+ $( "#approvalDiv" ).show();
+ $( "#approveButton" ).prop( "disabled", true );
+ $( "#unapproveButton" ).prop( "disabled", false );
+ $( "#message" ).hide();
+ }
+ else if ( status && '"WAITING_FOR_LOWER_LEVEL_APPROVAL"' == status ) {
+ $( "#approvalDiv" ).hide();
+ $( "#message" ).show().html( i18n_waiting_for_lower_level_approval );
+ }
+ } );
+}
+
+//------------------------------------------------------------------------------
+// Approval
+//------------------------------------------------------------------------------
+
+dhis2.dsr.approveData = function()
+{
+ var check = confirm( i18n_confirm_approval );
+
+ if ( !check ) {
+ return false;
+ }
+
+ var dataSetReport = dhis2.dsr.currentDataSetReport;
+ var url = "../api/dataApprovals" + dhis2.dsr.getDatSetReportQueryParams( dataSetReport );
+
+ $.ajax( {
+ url: url,
+ type: "post",
+ success: function() {
+ $( "#approveButton" ).prop( "disabled", true );
+ $( "#unapproveButton" ).prop( "disabled", false );
+ },
+ error: function( xhr, status, error ) {
+ alert( xhr.responseText );
+ }
+ } );
+}
+
+dhis2.dsr.unapproveData = function()
+{
+ var check = confirm( i18n_confirm_unapproval );
+
+ if ( !check ) {
+ return false;
+ }
+
+ var dataSetReport = dhis2.dsr.currentDataSetReport;
+ var url = "../api/dataApprovals" + dhis2.dsr.getDatSetReportQueryParams( dataSetReport );
+
+ $.ajax( {
+ url: url,
+ type: "delete",
+ success: function() {
+ $( "#approveButton" ).prop( "disabled", false );
+ $( "#unapproveButton" ).prop( "disabled", true );
+ },
+ error: function( xhr, status, error ) {
+ alert( xhr.responseText );
+ }
+ } );
+}
+
//------------------------------------------------------------------------------
// Share
//------------------------------------------------------------------------------
-function viewShareForm() // Not in use
-{
- $( "#shareForm" ).dialog( {
- modal : true,
- width : 550,
- resizable: false,
- title : i18n_share_your_interpretation
- } );
-}
-
function shareInterpretation()
{
var dataSetReport = getDataSetReport();