dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21891
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10473: rewrote program meta-data to be more efficient when loading for offline
------------------------------------------------------------
revno: 10473
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-04-04 14:57:59 +0700
message:
rewrote program meta-data to be more efficient when loading for offline
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java 2013-03-14 09:06:32 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java 2013-04-04 07:57:59 +0000
@@ -97,15 +97,11 @@
for ( Program program : programs )
{
Set<OrganisationUnit> organisationUnits = program.getOrganisationUnits();
+ programAssociations.put( program.getId(), new HashSet<Integer>() );
for ( OrganisationUnit organisationUnit : organisationUnits )
{
- if ( !programAssociations.containsKey( organisationUnit.getId() ) )
- {
- programAssociations.put( organisationUnit.getId(), new HashSet<Integer>() );
- }
-
- programAssociations.get( organisationUnit.getId() ).add( program.getId() );
+ programAssociations.get( program.getId() ).add( organisationUnit.getId() );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-03-30 10:45:13 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-04-04 07:57:59 +0000
@@ -11,24 +11,17 @@
$( "#orgUnitTree" ).one( "ouwtLoaded", function () {
// initialize the stores, and then try and add the data
DAO.programs = new dhis2.storage.Store( {name: 'programs', adapter: 'dom-ss'}, function ( store ) {
- DAO.programAssociations = new dhis2.storage.Store( {name: 'programAssociations', adapter: 'dom-ss'}, function ( store ) {
- jQuery.getJSON( "getProgramMetaData.action", {},function ( data ) {
- var keys = _.keys( data.metaData.programs );
- var objs = _.values( data.metaData.programs );
-
- DAO.programs.addAll( keys, objs, function ( store ) {
- var keys = _.keys( data.metaData.programAssociations );
- var objs = _.values( data.metaData.programAssociations );
-
- DAO.programAssociations.addAll( keys, objs, function ( store ) {
- selection.setListenerFunction( organisationUnitSelected );
- hideHeaderMessage();
- } );
- } );
- } ).fail( function () {
- selection.setListenerFunction( organisationUnitSelected );
- hideHeaderMessage();
- } );
+ jQuery.getJSON( "getProgramMetaData.action", {},function ( data ) {
+ var keys = _.keys( data.metaData.programs );
+ var objs = _.values( data.metaData.programs );
+
+ DAO.programs.addAll( keys, objs, function ( store ) {
+ selection.setListenerFunction( organisationUnitSelected );
+ hideHeaderMessage();
+ } );
+ } ).fail( function () {
+ selection.setListenerFunction( organisationUnitSelected );
+ hideHeaderMessage();
} );
} );
} );
@@ -53,12 +46,19 @@
hideById( 'listDiv' );
hideById( 'dataEntryInfor' );
- DAO.programAssociations.fetch( orgUnits[0], function ( store, arr ) {
- if ( arr.length > 0 ) {
- DAO.programs.fetch( arr[0], function ( store, arr ) {
- updateProgramList( arr )
- } );
+ DAO.programs.fetchAll( function ( store, arr ) {
+ var programs = [];
+
+ $.each( arr, function ( idx, item ) {
+ if ( item.programAssociations.indexOf( orgUnits[0] ) != -1 ) {
+ programs.push( item );
+ }
+ } );
+
+ if( programs.length > 0) {
+ updateProgramList( programs );
} else {
+ // if we are online, also check server to see if there are any programs
dhis2.storage.Store.plugins['anonymous-online'].call( {}, function ( arr ) {
updateProgramList( arr );
} );
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm 2013-02-20 08:03:09 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/jsonProgramMetaData.vm 2013-04-04 07:57:59 +0000
@@ -7,17 +7,11 @@
"description":"$encoder.jsonEncode( ${program.description} )",
"enrollmentDescription":"$encoder.jsonEncode( ${program.dateOfEnrollmentDescription} )",
"incidentDescription":"$encoder.jsonEncode( ${program.dateOfIncidentDescription} )",
-"programStages":[
-#set( $pssize = $program.programStages.size() )
+"programStages":[#set( $pssize = $program.programStages.size() )
#foreach( $ps in $program.programStages )
{ "id": "${ps.id}", "name": "$encoder.jsonEncode( ${ps.displayName} )", "reportDateDescription": "$encoder.jsonEncode( ${ps.reportDateDescription} )" }#if( $velocityCount < $pssize ),#end
-#end
-]
+#end],
+"programAssociations": $programAssociations.get(${program.id})
}#if( $velocityCount < $psize ),#end
-#end },
-"programAssociations": {
-#set( $psize = $programAssociations.size() )
-#foreach( $ou in $programAssociations.keySet() )
-"${ou}":$programAssociations.get(${ou})#if( $velocityCount < $psize ),#end
-#end
-}}}
+#end }
+}}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js 2013-03-30 11:53:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom-ss.js 2013-04-04 07:57:59 +0000
@@ -136,7 +136,7 @@
for ( var k = 0; k < idx.length; k++ ) {
var obj = JSON.parse( storage.getItem( idx[k] ) );
- obj.key = idx[k].replace( that.dbname + '.' + that.name + '.', '' );
+ obj.key = idx[k].replace( this.dbname + '.' + this.name + '.', '' );
arr.push( obj );
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js 2013-03-30 10:45:13 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.storage.dom.js 2013-04-04 07:57:59 +0000
@@ -1,4 +1,4 @@
-// dom storage support (localStorage)
+// dom storage support (sessionStorage)
dhis2.storage.Store.adapter( 'dom', (function () {
var storage = window.localStorage;
@@ -136,7 +136,7 @@
for ( var k = 0; k < idx.length; k++ ) {
var obj = JSON.parse( storage.getItem( idx[k] ) );
- obj.key = idx[k].replace( that.dbname + '.' + that.name + '.', '' );
+ obj.key = idx[k].replace( this.dbname + '.' + this.name + '.', '' );
arr.push( obj );
}