← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9276: FRED-API: proper updating of dataSets. Also updated ui to allow edit of code, parent, dataSets.

 

------------------------------------------------------------
revno: 9276
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-12-12 10:57:09 +0300
message:
  FRED-API: proper updating of dataSets. Also updated ui to allow edit of code, parent, dataSets.
modified:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facility.vm


--
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-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-11 13:34:09 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-12 07:57:09 +0000
@@ -184,6 +184,11 @@
 
         model.addAttribute( "esc", StringEscapeUtils.class );
         model.addAttribute( "entity", facility );
+
+        List<DataSet> dataSets = new ArrayList<DataSet>( dataSetService.getAllDataSets() );
+        Collections.sort( dataSets, IdentifiableObjectNameComparator.INSTANCE );
+        model.addAttribute( "dataSets", dataSets );
+
         model.addAttribute( "baseUrl", linkTo( FredController.class ).toString() );
         model.addAttribute( "pageName", "facility" );
         model.addAttribute( "page", FredController.PREFIX + "/facility.vm" );
@@ -302,16 +307,20 @@
             ou.setName( organisationUnit.getName() );
             ou.setShortName( organisationUnit.getShortName() );
             ou.setCode( organisationUnit.getCode() );
-
             ou.setFeatureType( organisationUnit.getFeatureType() );
             ou.setCoordinates( organisationUnit.getCoordinates() );
-            ou.setDataSets( organisationUnit.getDataSets() );
             ou.setParent( organisationUnit.getParent() );
-
             ou.setActive( organisationUnit.isActive() );
 
+            ou.removeAllDataSets();
             organisationUnitService.updateOrganisationUnit( ou );
 
+            for ( DataSet dataSet : organisationUnit.getDataSets() )
+            {
+                dataSet.addOrganisationUnit( ou );
+                dataSetService.updateDataSet( dataSet );
+            }
+
             return new ResponseEntity<String>( json, headers, HttpStatus.OK );
         }
         else

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facility.vm'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facility.vm	2012-12-10 13:53:34 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facility.vm	2012-12-12 07:57:09 +0000
@@ -65,6 +65,31 @@
 
                 data.coordinates = [ lng, lat ];
 
+                data.properties = {};
+                data.properties.parent = $( '#facilityDhis2Parent' ).val();
+
+                var dhis2Code = $( '#facilityDhis2Code' ).val();
+
+                if ( dhis2Code.length > 0 ) {
+                    data.identifiers = [
+                        {
+                            'agency': 'DHIS2',
+                            'context': 'DHIS2_CODE',
+                            'id': dhis2Code
+                        }
+                    ]
+                }
+
+                var facilityDhis2DataSets = $( '#facilityDhis2DataSets :selected' );
+
+                if ( facilityDhis2DataSets.length > 0 ) {
+                    data.properties.dataSets = [];
+
+                    $.each( facilityDhis2DataSets, function ( idx, item ) {
+                        data.properties.dataSets.push( $( item ).val() );
+                    } );
+                }
+
                 $.ajax({
                     url: '$baseUrl/facilities/${entity.id}',
                     contentType: 'application/json; charset=UTF-8',
@@ -102,7 +127,6 @@
                 <input #if(!$canUpdate)disabled#end id="facilityName" type="text" class="$inputSize" value="$esc.escapeHtml4($entity.name)"/>
 
                 <label for="facilityActive">Active</label>
-
                 <select id="facilityActive" #if(!$canUpdate)disabled#end class="$inputSize">
                     <option value="true" #if($entity.active)selected#end>Yes</option>
                     <option value="false" #if(!$entity.active)selected#end>No</option>
@@ -113,6 +137,34 @@
 
                 <label for="facilityLongitude">Longitude</label>
                 <input #if(!$canUpdate)disabled#end id="facilityLongitude" type="text" class="$inputSize" value=""/>
+
+                <fieldset>
+                    <legend>DHIS 2</legend>
+
+                    #foreach( $identifier in $entity.identifiers )
+                        #if( $identifier.context == "DHIS2_CODE" )
+                            #set( $dhis2Code = $identifier.id )
+                        #end
+                    #end
+
+                    <label for="facilityDhis2Code">Code</label>
+                    <input #if(!$canUpdate)disabled#end id="facilityDhis2Code" type="text" class="$inputSize" value="$!esc.escapeHtml4($dhis2Code)"/>
+
+                    #set( $dhis2Parent = $entity.properties.get('parent') )
+
+                    <label for="facilityDhis2Parent">Parent</label>
+                    <input #if(!$canUpdate)disabled#end id="facilityDhis2Parent" type="text" class="$inputSize" value="$!esc.escapeHtml4($dhis2Parent)"/>
+
+                    #set( $dhis2DataSets = $entity.properties.get('dataSets') )
+
+                    <label for="facilityDhis2DataSets">Data Sets</label>
+                    <select #if(!$canUpdate)disabled#end id="facilityDhis2DataSets" class="$inputSize" multiple="multiple">
+                    #foreach( $dataSet in $dataSets )
+                        <option value="$dataSet.uid" #if( $dhis2DataSets.contains( $dataSet.uid ))selected="selected"#end>$!esc.escapeHtml4($dataSet.name)</option>
+                    #end
+                    </select>
+
+                </fieldset>
             </fieldset>
 
             <button #if(!$canUpdate)disabled#end type="submit" id="facilitySubmit" class="btn btn-info">Save</button>