← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8465: mobile: lots of minor changes

 

------------------------------------------------------------
revno: 8465
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-10-10 19:14:33 +0200
message:
  mobile: lots of minor changes
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-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
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/message.vm
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/messages.vm
  dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/settings.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 09:29:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java	2012-10-10 17:14:33 +0000
@@ -27,14 +27,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hisp.dhis.api.controller.WebOptions;
+import org.apache.commons.collections.CollectionUtils;
 import org.hisp.dhis.api.utils.ContextUtils;
-import org.hisp.dhis.api.utils.WebUtils;
 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;
 import org.hisp.dhis.interpretation.InterpretationService;
@@ -45,8 +45,7 @@
 import org.hisp.dhis.user.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.util.StringUtils;
+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;
@@ -84,96 +83,64 @@
     private OrganisationUnitService organisationUnitService;
 
     @RequestMapping( produces = {"application/json", "text/*"} )
-    public String getCurrentUser( @RequestParam Map<String, String> parameters,
-        Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    public void getCurrentUser( HttpServletResponse response ) throws Exception
     {
-        WebOptions options = new WebOptions( parameters );
         User currentUser = currentUserService.getCurrentUser();
 
         if ( currentUser == null )
         {
             ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
-            return null;
-        }
-
-        if ( options.hasLinks() )
-        {
-            WebUtils.generateLinks( currentUser );
-        }
-
-        model.addAttribute( "model", currentUser );
-        model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
-
-        return StringUtils.uncapitalize( "user" );
+            return;
+        }
+
+        JacksonUtils.toJson( response.getOutputStream(), currentUser );
     }
 
     @RequestMapping( value = "/inbox", produces = {"application/json", "text/*"} )
-    public String getInbox( @RequestParam Map<String, String> parameters,
-        Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    public void getInbox( HttpServletResponse response ) throws Exception
     {
-        WebOptions options = new WebOptions( parameters );
         User currentUser = currentUserService.getCurrentUser();
 
         if ( currentUser == null )
         {
             ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
-            return null;
+            return;
         }
 
         Inbox inbox = new Inbox();
         inbox.setMessageConversations( new ArrayList<MessageConversation>( messageService.getMessageConversations( 0, Integer.MAX_VALUE ) ) );
         inbox.setInterpretations( new ArrayList<Interpretation>( interpretationService.getInterpretations( 0, Integer.MAX_VALUE ) ) );
 
-        if ( options.hasLinks() )
-        {
-            WebUtils.generateLinks( inbox );
-        }
-
-        model.addAttribute( "model", inbox );
-        model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
-
-        return StringUtils.uncapitalize( "inbox" );
+        JacksonUtils.toJson( response.getOutputStream(), inbox );
     }
 
     @RequestMapping( value = "/dashboard", produces = {"application/json", "text/*"} )
-    public String getDashboard( @RequestParam Map<String, String> parameters,
-        Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    public void getDashboard( HttpServletResponse response ) throws Exception
     {
-        WebOptions options = new WebOptions( parameters );
         User currentUser = currentUserService.getCurrentUser();
 
         if ( currentUser == null )
         {
             ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
-            return null;
+            return;
         }
 
         Dashboard dashboard = new Dashboard();
         dashboard.setUnreadMessageConversation( messageService.getUnreadMessageConversationCount() );
         dashboard.setUnreadInterpretations( interpretationService.getNewInterpretationCount() );
 
-        if ( options.hasLinks() )
-        {
-            WebUtils.generateLinks( dashboard );
-        }
-
-        model.addAttribute( "model", dashboard );
-        model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
-
-        return StringUtils.uncapitalize( "dashboard" );
+        JacksonUtils.toJson( response.getOutputStream(), dashboard );
     }
 
     @RequestMapping( value = "/settings", produces = {"application/json", "text/*"} )
-    public String getSettings( @RequestParam Map<String, String> parameters,
-        Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    public void getSettings( HttpServletResponse response ) throws Exception
     {
-        WebOptions options = new WebOptions( parameters );
         User currentUser = currentUserService.getCurrentUser();
 
         if ( currentUser == null )
         {
             ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
-            return null;
+            return;
         }
 
         Settings settings = new Settings();
@@ -182,15 +149,7 @@
         settings.setEmail( currentUser.getEmail() );
         settings.setPhoneNumber( currentUser.getPhoneNumber() );
 
-        if ( options.hasLinks() )
-        {
-            WebUtils.generateLinks( settings );
-        }
-
-        model.addAttribute( "model", settings );
-        model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
-
-        return StringUtils.uncapitalize( "settings" );
+        JacksonUtils.toJson( response.getOutputStream(), settings );
     }
 
     @RequestMapping( value = "/settings", method = RequestMethod.POST, consumes = "application/xml" )
@@ -237,7 +196,7 @@
 
     @RequestMapping( value = "/recipients", produces = {"application/json", "text/*"} )
     public void recipientsJson( HttpServletResponse response,
-        @RequestParam( value = "filter", required = false ) String filter ) throws IOException
+        @RequestParam( value = "filter" ) String filter ) throws IOException
     {
         User currentUser = currentUserService.getCurrentUser();
 
@@ -250,16 +209,8 @@
         Recipients recipients = new Recipients();
         recipients.setOrganisationUnits( getOrganisationUnitsForUser( currentUser, filter ) );
 
-        if ( filter == null || filter.isEmpty() )
-        {
-            recipients.setUsers( new HashSet<User>( userService.getAllUsers() ) );
-            recipients.setUserGroups( new HashSet<UserGroup>( userGroupService.getAllUserGroups() ) );
-        }
-        else
-        {
-            recipients.setUsers( new HashSet<User>( userService.getAllUsersBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
-            recipients.setUserGroups( new HashSet<UserGroup>( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
-        }
+        recipients.setUsers( new HashSet<User>( userService.getAllUsersBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
+        recipients.setUserGroups( new HashSet<UserGroup>( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
 
         JacksonUtils.toJson( response.getOutputStream(), recipients );
     }
@@ -289,6 +240,32 @@
         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 );
+    }
+
     private Set<OrganisationUnit> getOrganisationUnitsForUser( User user, String filter )
     {
         Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();

=== 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-10 09:29:10 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/data-entry.vm	2012-10-10 17:14:33 +0000
@@ -1,9 +1,111 @@
 
+<script>
+    function selectOrganisationUnit(e, data) {
+        var $this = $(this);
+        console.log($this.data('id'));
+    }
+
+    function loadOrganisationUnitsPage() {
+        jQuery.ajax({
+            url   : '$baseUrl/../api/currentUser/organisationUnits',
+            data: {
+              'withChildren': true
+            },
+            dataType: 'json'
+        }).success(function ( data ) {
+            var tmpl = jQuery('#organisation-units-template').html();
+
+            jQuery('#organisation-units-page section[data-role="content"]').html(
+                _.template( tmpl, { 'organisationUnits': data } )
+            );
+
+            console.log(data);
+            jQuery('#organisation-unit-list').listview()
+        }).error(function () {
+            console.log('error fetching orgUnits')
+        });
+
+    }
+
+    function loadDataEntryPage() {
+
+    }
+
+    function loadDataSetsPage() {
+
+    }
+
+    jQuery(document).bind('pagechange', function (event, data) {
+        var pageId = data.toPage.attr('id');
+        console.log(pageId);
+
+        if( pageId == 'organisation-units-page' ) {
+            loadOrganisationUnitsPage();
+        } else if( pageId == 'data-sets-page' ) {
+            loadDataSetsPage();
+        } else if( pageId == 'data-entry-page' ) {
+            loadDataEntryPage();
+        }
+    });
+
+    jQuery(document).bind('pageinit', function() {
+        $('#organisation-unit-list li a').bind('click', selectOrganisationUnit);
+    });
+</script>
+
+<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>
+        <% }); %>
+    </ul>
+</script>
+
+<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="#data-entry-page" data-id="<%= dataSet.id %>"><%= dataSet.name %></a></li>
+        <% }); %>
+    </ul>
+</script>
+
+<section data-role="page" id="organisation-units-page" data-theme="c">
+
+	<header data-role="header" data-theme="b">
+        <h1 align="center"><img src="$baseUrl/../dhis-web-commons/css/light_blue/logo_banner.png" /></h1>
+        <a href="index" data-icon="back">Back</a>
+	</header>
+
+	<section data-role="content">
+	</section>
+
+    <footer data-role="footer" data-theme="b">
+        <h1></h1>
+   	</footer>
+
+</section>
+
+<section data-role="page" id="data-sets-page" data-theme="c">
+
+	<header data-role="header" data-theme="b">
+        <h1 align="center"><img src="$baseUrl/../dhis-web-commons/css/light_blue/logo_banner.png" /></h1>
+        <a href="#organisation-units-page" data-icon="back">Back</a>
+	</header>
+
+	<section data-role="content">
+	</section>
+
+    <footer data-role="footer" data-theme="b">
+        <h1></h1>
+   	</footer>
+
+</section>
+
 <section data-role="page" id="data-entry-page" data-theme="c">
 
 	<header data-role="header" data-theme="b">
         <h1 align="center"><img src="$baseUrl/../dhis-web-commons/css/light_blue/logo_banner.png" /></h1>
-        <a href="index" data-icon="back">Back</a>
+        <a href="#data-sets-page" data-icon="back">Back</a>
 	</header>
 
 	<section data-role="content">

=== 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 09:29:10 +0000
+++ 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
@@ -2,7 +2,8 @@
 <script>
     $(document).bind('pagebeforecreate',function(){
         $.ajax({
-            url: '../api/currentUser/dashboard.json',
+            url: '../api/currentUser/dashboard',
+            dataType: 'json',
             async: false
         }).success(function(data) {
             if( data.unreadMessageConversation > 0 ) {

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/message.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/message.vm	2012-10-10 09:29:10 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/message.vm	2012-10-10 17:14:33 +0000
@@ -3,6 +3,7 @@
     jQuery(document).bind('pagebeforecreate', function () {
         jQuery.ajax({
             url   : '$baseUrl/../api/messageConversations/${messageId}.json',
+            dataType: 'json',
             async : false
         }).success(function ( data ) {
             var tmpl = jQuery('#message-template').html();

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/messages.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/messages.vm	2012-10-10 09:29:10 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/messages.vm	2012-10-10 17:14:33 +0000
@@ -2,7 +2,8 @@
 <script>
     jQuery(document).bind('pagebeforecreate',function(){
         jQuery.ajax({
-            url: '../api/currentUser/inbox.json',
+            url: '../api/currentUser/inbox',
+            dataType: 'json',
             async: false
         }).success(function(data) {
             jQuery.each(data.messageConversations, function(i, item) {

=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/settings.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/settings.vm	2012-10-10 09:29:10 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/settings.vm	2012-10-10 17:14:33 +0000
@@ -2,7 +2,8 @@
 <script>
     $(document).bind('pageinit',function(){
         $.ajax({
-            url: '../api/currentUser.json',
+            url: '../api/currentUser',
+            dataType: 'json',
             async: false
         }).success(function(data) {
             $('#firstNameInput').val(data.firstName);