dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19500
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8529: mobile: added /api/currentUser/forms, gives all forms belonging to user + organisationUnits. Used...
------------------------------------------------------------
revno: 8529
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-10-15 12:20:17 +0200
message:
mobile: added /api/currentUser/forms, gives all forms belonging to user + organisationUnits. Used in mobile, only one XHR for loading all required meta-data. Will refactor into storagemanager next.
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormDataSet.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormOrganisationUnit.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Forms.java
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Field.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Form.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Group.java
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm
dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.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/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-10 17:15:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-15 10:20:17 +0000
@@ -29,11 +29,14 @@
import org.apache.commons.collections.CollectionUtils;
import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.api.utils.FormUtils;
+import org.hisp.dhis.api.webdomain.FormDataSet;
+import org.hisp.dhis.api.webdomain.FormOrganisationUnit;
+import org.hisp.dhis.api.webdomain.Forms;
import org.hisp.dhis.api.webdomain.user.Dashboard;
import org.hisp.dhis.api.webdomain.user.Inbox;
import org.hisp.dhis.api.webdomain.user.Recipients;
import org.hisp.dhis.api.webdomain.user.Settings;
-import org.hisp.dhis.common.view.BasicView;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.hisp.dhis.interpretation.Interpretation;
@@ -45,7 +48,6 @@
import org.hisp.dhis.user.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@@ -53,7 +55,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -213,55 +218,66 @@
JacksonUtils.toJson( response.getOutputStream(), recipients );
}
- @RequestMapping( value = "/organisationUnits", produces = {"application/json", "text/*"} )
- public void getOrganisationUnitsJson( HttpServletResponse response,
- @RequestParam( value = "withChildren", required = false ) boolean withChildren ) throws IOException
- {
- User currentUser = currentUserService.getCurrentUser();
-
- if ( currentUser == null )
- {
- ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
- return;
- }
-
- Collection<OrganisationUnit> organisationUnits = currentUser.getOrganisationUnits();
-
- if ( withChildren )
- {
- for ( OrganisationUnit ou : organisationUnits )
- {
- organisationUnits.addAll( ou.getChildren() );
- }
- }
-
- JacksonUtils.toJsonWithView( response.getOutputStream(), organisationUnits, BasicView.class );
- }
-
- @RequestMapping( value = "/organisationUnits/{uid}/dataSets", produces = {"application/json", "text/*"} )
- public void getDataSetsJson( HttpServletResponse response,
- @PathVariable( value = "uid" ) String uid ) throws IOException
- {
- User currentUser = currentUserService.getCurrentUser();
-
- if ( currentUser == null )
- {
- ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
- return;
- }
-
- OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( uid );
-
- if ( organisationUnit == null )
- {
- ContextUtils.notFoundResponse( response, "Organisation Unit UID is invalid." );
- return;
- }
-
- Set<DataSet> dataSets = new HashSet<DataSet>( CollectionUtils.intersection( organisationUnit.getDataSets(),
- currentUser.getUserCredentials().getAllDataSets() ) );
-
- JacksonUtils.toJsonWithView( response.getOutputStream(), dataSets, BasicView.class );
+ @RequestMapping( value = "/forms", produces = {"application/json", "text/*"} )
+ public void getForms( HttpServletResponse response ) throws IOException
+ {
+ User currentUser = currentUserService.getCurrentUser();
+
+ if ( currentUser == null )
+ {
+ ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
+ return;
+ }
+
+ Forms forms = new Forms();
+
+ Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
+ Set<DataSet> userDataSets = currentUser.getUserCredentials().getAllDataSets();
+
+ for ( OrganisationUnit ou : currentUser.getOrganisationUnits() )
+ {
+ Set<DataSet> dataSets = new HashSet<DataSet>( CollectionUtils.intersection( ou.getDataSets(), userDataSets ) );
+
+ if ( dataSets.size() > 0 )
+ {
+ organisationUnits.add( ou );
+ }
+
+ for ( OrganisationUnit child : ou.getChildren() )
+ {
+ Set<DataSet> childDataSets = new HashSet<DataSet>( CollectionUtils.intersection( child.getDataSets(), userDataSets ) );
+
+ if ( childDataSets.size() > 0 )
+ {
+ organisationUnits.add( ou );
+ }
+ }
+ }
+
+ for ( OrganisationUnit organisationUnit : organisationUnits )
+ {
+ FormOrganisationUnit ou = new FormOrganisationUnit();
+ ou.setId( organisationUnit.getUid() );
+ ou.setLabel( organisationUnit.getName() );
+
+ Set<DataSet> dataSets = new HashSet<DataSet>( CollectionUtils.intersection( organisationUnit.getDataSets(), userDataSets ) );
+
+ for ( DataSet dataSet : dataSets )
+ {
+ String uid = dataSet.getUid();
+
+ FormDataSet ds = new FormDataSet();
+ ds.setId( uid );
+ ds.setLabel( dataSet.getName() );
+
+ forms.getForms().put( uid, FormUtils.fromDataSet( dataSet ) );
+ ou.getDataSets().add( ds );
+ }
+
+ forms.getOrganisationUnits().put( ou.getId(), ou );
+ }
+
+ JacksonUtils.toJson( response.getOutputStream(), forms );
}
private Set<OrganisationUnit> getOrganisationUnitsForUser( User user, String filter )
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormDataSet.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormDataSet.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormDataSet.java 2012-10-15 10:20:17 +0000
@@ -0,0 +1,69 @@
+package org.hisp.dhis.api.webdomain;
+
+/**
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * We could have gotten this information from the form instance, but
+ * in the interest of performance, we duplicate some information here.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class FormDataSet
+{
+ private String id;
+
+ private String label;
+
+ public FormDataSet()
+ {
+ }
+
+ @JsonProperty
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId( String id )
+ {
+ this.id = id;
+ }
+
+ @JsonProperty
+ public String getLabel()
+ {
+ return label;
+ }
+
+ public void setLabel( String label )
+ {
+ this.label = label;
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormOrganisationUnit.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormOrganisationUnit.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/FormOrganisationUnit.java 2012-10-15 10:20:17 +0000
@@ -0,0 +1,85 @@
+package org.hisp.dhis.api.webdomain;
+
+/**
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Simplified organisation unit class, to be used where all you need
+ * is a label + dataSets.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class FormOrganisationUnit
+{
+ private String id;
+
+ private String label;
+
+ private Set<FormDataSet> dataSets = new HashSet<FormDataSet>();
+
+ public FormOrganisationUnit()
+ {
+ }
+
+ @JsonProperty
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId( String id )
+ {
+ this.id = id;
+ }
+
+ @JsonProperty
+ public String getLabel()
+ {
+ return label;
+ }
+
+ public void setLabel( String label )
+ {
+ this.label = label;
+ }
+
+ @JsonProperty
+ public Set<FormDataSet> getDataSets()
+ {
+ return dataSets;
+ }
+
+ public void setDataSets( Set<FormDataSet> dataSets )
+ {
+ this.dataSets = dataSets;
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Forms.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Forms.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Forms.java 2012-10-15 10:20:17 +0000
@@ -0,0 +1,74 @@
+package org.hisp.dhis.api.webdomain;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.hisp.dhis.api.webdomain.form.Form;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class Forms
+{
+ // maps ou.uid => org unit.
+ private Map<String, FormOrganisationUnit> organisationUnits = new HashMap<String, FormOrganisationUnit>( );
+
+ // maps dataSet.uid => form instance
+ private Map<String, Form> forms = new HashMap<String, Form>();
+
+ public Forms()
+ {
+ }
+
+ @JsonProperty
+ public Map<String, FormOrganisationUnit> getOrganisationUnits()
+ {
+ return organisationUnits;
+ }
+
+ public void setOrganisationUnits( Map<String, FormOrganisationUnit> organisationUnits )
+ {
+ this.organisationUnits = organisationUnits;
+ }
+
+ @JsonProperty
+ public Map<String, Form> getForms()
+ {
+ return forms;
+ }
+
+ public void setForms( Map<String, Form> forms )
+ {
+ this.forms = forms;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Field.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Field.java 2012-10-09 14:07:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Field.java 2012-10-15 10:20:17 +0000
@@ -1,41 +1,37 @@
package org.hisp.dhis.api.webdomain.form;
/*
-* Copyright (c) 2004-2012, University of Oslo
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright notice, this
-* list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright notice,
-* this list of conditions and the following disclaimer in the documentation
-* and/or other materials provided with the distribution.
-* * Neither the name of the HISP project nor the names of its contributors may
-* be used to endorse or promote products derived from this software without
-* specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.Dxf2Namespace;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "field", namespace = Dxf2Namespace.NAMESPACE )
public class Field
{
private String label;
@@ -53,7 +49,6 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getLabel()
{
return label;
@@ -65,7 +60,6 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getDataElement()
{
return dataElement;
@@ -77,7 +71,6 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getCategoryOptionCombo()
{
return categoryOptionCombo;
@@ -89,7 +82,6 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getValue()
{
return value;
@@ -101,7 +93,6 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public InputType getType()
{
return type;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Form.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Form.java 2012-10-11 14:37:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Form.java 2012-10-15 10:20:17 +0000
@@ -28,10 +28,6 @@
*/
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.Dxf2Namespace;
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +35,6 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "form", namespace = Dxf2Namespace.NAMESPACE )
public class Form
{
private String label;
@@ -53,7 +48,6 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getLabel()
{
return label;
@@ -65,7 +59,6 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getPeriodType()
{
return periodType;
@@ -77,8 +70,6 @@
}
@JsonProperty
- @JacksonXmlElementWrapper( localName = "groups", namespace = Dxf2Namespace.NAMESPACE )
- @JacksonXmlProperty( localName = "group", namespace = Dxf2Namespace.NAMESPACE )
public List<Group> getGroups()
{
return groups;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Group.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Group.java 2012-10-09 14:07:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/form/Group.java 2012-10-15 10:20:17 +0000
@@ -28,10 +28,6 @@
*/
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.Dxf2Namespace;
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +35,6 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "section", namespace = Dxf2Namespace.NAMESPACE )
public class Group
{
private String label;
@@ -51,7 +46,6 @@
}
@JsonProperty
- @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
public String getLabel()
{
return label;
@@ -63,8 +57,6 @@
}
@JsonProperty
- @JacksonXmlElementWrapper( localName = "fields", namespace = Dxf2Namespace.NAMESPACE )
- @JacksonXmlProperty( localName = "field", namespace = Dxf2Namespace.NAMESPACE )
public List<Field> getFields()
{
return fields;
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm 2012-10-12 09:57:17 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm 2012-10-15 10:20:17 +0000
@@ -28,27 +28,18 @@
function loadOrganisationUnitsPage() {
$.mobile.showPageLoadingMsg();
- jQuery.ajax({
- url : '$baseUrl/../api/currentUser/organisationUnits',
- dataType: 'json',
- data: {
- 'withChildren': true
- }
- }).success(function ( data ) {
- var tmpl = jQuery('#organisation-units-template').html();
-
- jQuery('#organisation-units-page section[data-role="content"]').html(
- _.template( tmpl, { 'organisationUnits': data } )
- );
-
- jQuery('#organisation-unit-list').listview()
- jQuery('#organisation-unit-list li a').bind('click', selectOrganisationUnit);
-
- $.mobile.hidePageLoadingMsg();
- }).error(function () {
- $.mobile.showPageLoadingMsg( $.mobile.pageLoadErrorMessageTheme, "Unable to get organisationUnits", true );
- console.log('error fetching orgUnits')
- });
+ var organisationUnits = JSON.parse( localStorage['organisationUnits'] );
+
+ var tmpl = jQuery('#organisation-units-template').html();
+
+ jQuery('#organisation-units-page section[data-role="content"]').html(
+ _.template( tmpl, { 'organisationUnits': organisationUnits } )
+ );
+
+ jQuery('#organisation-unit-list').listview()
+ jQuery('#organisation-unit-list li a').bind('click', selectOrganisationUnit);
+
+ $.mobile.hidePageLoadingMsg();
}
function loadDataSetsPage() {
@@ -60,23 +51,18 @@
$.mobile.showPageLoadingMsg();
- jQuery.ajax({
- url : '$baseUrl/../api/currentUser/organisationUnits/' + Selected.orgUnit + '/dataSets',
- dataType: 'json'
- }).success(function ( data ) {
- var tmpl = jQuery('#data-sets-template').html();
-
- jQuery('#data-sets-page section[data-role="content"]').html(
- _.template( tmpl, { 'dataSets': data } )
- );
-
- jQuery('#data-set-list').listview();
- jQuery('#data-set-list li a').bind('click', selectDataSet);
- $.mobile.hidePageLoadingMsg();
- }).error(function () {
- $.mobile.showPageLoadingMsg( $.mobile.pageLoadErrorMessageTheme, "Unable to get dataSets", true );
- console.log('error fetching dataSets')
- });
+ var organisationUnits = JSON.parse( localStorage['organisationUnits'] );
+ var organisationUnit = organisationUnits[Selected.orgUnit];
+
+ var tmpl = jQuery('#data-sets-template').html();
+
+ jQuery('#data-sets-page section[data-role="content"]').html(
+ _.template( tmpl, { 'dataSets': organisationUnit.dataSets } )
+ );
+
+ jQuery('#data-set-list').listview();
+ jQuery('#data-set-list li a').bind('click', selectDataSet);
+ $.mobile.hidePageLoadingMsg();
}
function refreshPeriods() {
@@ -118,17 +104,11 @@
$.mobile.showPageLoadingMsg();
- jQuery.ajax({
- url : '$baseUrl/../api/dataSets/' + Selected.dataSet + '/form',
- dataType: 'json'
- }).success(function ( data ) {
- periodType = data.periodType;
- refreshPeriods();
- $.mobile.hidePageLoadingMsg();
- }).error(function () {
- $.mobile.showPageLoadingMsg( $.mobile.pageLoadErrorMessageTheme, "Unable to get form", true );
- console.log('error fetching form')
- });
+ var form = JSON.parse( localStorage['form_' + Selected.dataSet] );
+ periodType = form.periodType;
+ refreshPeriods();
+
+ $.mobile.hidePageLoadingMsg();
}
function loadDataEntryPage() {
@@ -154,25 +134,17 @@
$.mobile.showPageLoadingMsg();
- jQuery.ajax({
- url : '$baseUrl/../api/dataSets/' + Selected.dataSet + '/form',
- dataType: 'json'
- }).success(function ( data ) {
- console.log(data);
-
- var tmpl = jQuery('#data-entry-template').html();
-
- jQuery('#data-entry-page section[data-role="content"]').html(
- _.template( tmpl, data )
- );
-
- jQuery('#data-entry-page').trigger('pagecreate')
- jQuery('#data-entry-list').listview('refresh');
- $.mobile.hidePageLoadingMsg();
- }).error(function () {
- $.mobile.showPageLoadingMsg( $.mobile.pageLoadErrorMessageTheme, "Unable to get form", true );
- console.log('error fetching form')
- });
+ var form = JSON.parse( localStorage['form_' + Selected.dataSet] );
+
+ var tmpl = jQuery('#data-entry-template').html();
+
+ jQuery('#data-entry-page section[data-role="content"]').html(
+ _.template( tmpl, form )
+ );
+
+ jQuery('#data-entry-page').trigger('pagecreate')
+ jQuery('#data-entry-list').listview('refresh');
+ $.mobile.hidePageLoadingMsg();
}
jQuery(document).bind('pagechange', function (event, data) {
@@ -194,7 +166,7 @@
<script id="organisation-units-template" type="text/template">
<ul id="organisation-unit-list" data-role="listview" data-inset="true">
<% _( organisationUnits ).each( function(organisationUnit, idx) { %>
- <li><a href="#data-sets-page" data-id="<%= organisationUnit.id %>"><%= organisationUnit.name %></a></li>
+ <li><a href="#data-sets-page" data-id="<%= organisationUnit.id %>"><%= organisationUnit.label %></a></li>
<% }); %>
</ul>
</script>
@@ -202,7 +174,7 @@
<script id="data-sets-template" type="text/template">
<ul id="data-set-list" data-role="listview" data-inset="true">
<% _( dataSets ).each( function(dataSet, idx) { %>
- <li><a href="#period-page" data-id="<%= dataSet.id %>"><%= dataSet.name %></a></li>
+ <li><a href="#period-page" data-id="<%= dataSet.id %>"><%= dataSet.label %></a></li>
<% }); %>
</ul>
</script>
@@ -253,6 +225,8 @@
<% }); %>
<% }); %>
+
+ <li><input type="button" id="send_button" value="Send" /></li>
</ul>
</form>
</script>
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm 2012-10-10 17:14:33 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/index.vm 2012-10-15 10:20:17 +0000
@@ -9,13 +9,25 @@
if( data.unreadMessageConversation > 0 ) {
$('#messages a').append("<span class='ui-li-count'>" + data.unreadMessageConversation + "</span>");
}
-
- if( data.unreadInterpretations > 0 ) {
- $('#interpretations a').append("<span class='ui-li-count'>" + data.unreadInterpretations + "</span>");
- }
}).error(function() {
$('#messages a').append("<span class='ui-li-count'>Offline</span>")
- $('#interpretations a').append("<span class='ui-li-count'>Offline</span>")
+ });
+
+ $.mobile.showPageLoadingMsg();
+
+ $.ajax({
+ url: '../api/currentUser/forms',
+ dataType: 'json'
+ }).success(function(data) {
+ localStorage['organisationUnits'] = JSON.stringify(data.organisationUnits);
+
+ _.each(data.forms, function(v, k) {
+ localStorage['form_' + k] = JSON.stringify(v);
+ });
+
+ $.mobile.hidePageLoadingMsg();
+ }).error(function() {
+ // offline ? reuse meta-data already present
});
});
</script>