dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19267
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8321: mobile: minor fixes to new-message recipient page. Also added /api/currentUser/recipients?filter=...
------------------------------------------------------------
revno: 8321
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-10-01 20:21:22 +0700
message:
mobile: minor fixes to new-message recipient page. Also added /api/currentUser/recipients?filter=... for getting a set of possible message recipients (only user, usergroup now, ou coming soon)
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Recipients.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-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.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-09-27 09:58:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/CurrentUserController.java 2012-10-01 13:21:22 +0000
@@ -32,17 +32,15 @@
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.dxf2.utils.JacksonUtils;
-import org.hisp.dhis.i18n.locale.LocaleManager;
-import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager;
import org.hisp.dhis.interpretation.Interpretation;
import org.hisp.dhis.interpretation.InterpretationService;
import org.hisp.dhis.message.MessageConversation;
import org.hisp.dhis.message.MessageService;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.user.User;
-import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.user.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -53,7 +51,11 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -71,6 +73,9 @@
private UserService userService;
@Autowired
+ private UserGroupService userGroupService;
+
+ @Autowired
private MessageService messageService;
@Autowired
@@ -78,7 +83,7 @@
@RequestMapping
public String getCurrentUser( @RequestParam Map<String, String> parameters,
- Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
User currentUser = currentUserService.getCurrentUser();
@@ -102,7 +107,7 @@
@RequestMapping( value = "/inbox" )
public String getInbox( @RequestParam Map<String, String> parameters,
- Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
User currentUser = currentUserService.getCurrentUser();
@@ -130,7 +135,7 @@
@RequestMapping( value = "/dashboard" )
public String getDashboard( @RequestParam Map<String, String> parameters,
- Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
User currentUser = currentUserService.getCurrentUser();
@@ -158,7 +163,7 @@
@RequestMapping( value = "/settings" )
public String getSettings( @RequestParam Map<String, String> parameters,
- Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+ Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
User currentUser = currentUserService.getCurrentUser();
@@ -187,7 +192,7 @@
}
@RequestMapping( value = "/settings", method = RequestMethod.POST, consumes = "application/xml" )
- public void postSettingsXml(HttpServletResponse response, HttpServletRequest request) throws Exception
+ public void postSettingsXml( HttpServletResponse response, HttpServletRequest request ) throws Exception
{
Settings settings = JacksonUtils.fromXml( request.getInputStream(), Settings.class );
User currentUser = currentUserService.getCurrentUser();
@@ -208,7 +213,7 @@
}
@RequestMapping( value = "/settings", method = RequestMethod.POST, consumes = "application/json" )
- public void postSettingsJson(HttpServletResponse response, HttpServletRequest request) throws Exception
+ public void postSettingsJson( HttpServletResponse response, HttpServletRequest request ) throws Exception
{
Settings settings = JacksonUtils.fromJson( request.getInputStream(), Settings.class );
User currentUser = currentUserService.getCurrentUser();
@@ -227,4 +232,31 @@
userService.updateUser( currentUser );
}
+
+ @RequestMapping( value = "/recipients", produces = "application/json" )
+ public void recipientsJson( HttpServletResponse response, @RequestParam( value = "filter", required = false ) String filter ) throws IOException
+ {
+ User currentUser = currentUserService.getCurrentUser();
+
+ if ( currentUser == null )
+ {
+ ContextUtils.notFoundResponse( response, "User object is null, user is not authenticated." );
+ return;
+ }
+
+ Recipients recipients = new Recipients();
+
+ 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.getUsersByName( filter ) ) );
+ recipients.setUserGroups( new HashSet<UserGroup>( userGroupService.getUserGroupsBetweenByName( filter, 0, Integer.MAX_VALUE ) ) );
+ }
+
+ JacksonUtils.toJson( response.getOutputStream(), recipients );
+ }
}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Recipients.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Recipients.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/user/Recipients.java 2012-10-01 13:21:22 +0000
@@ -0,0 +1,103 @@
+package org.hisp.dhis.api.webdomain.user;
+
+/*
+ * Copyright (c) 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.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+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.BaseIdentifiableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserGroup;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "recipients", namespace = Dxf2Namespace.NAMESPACE )
+public class Recipients
+{
+ private Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
+
+ private Set<User> users = new HashSet<User>();
+
+ private Set<UserGroup> userGroups = new HashSet<UserGroup>();
+
+ public Recipients()
+ {
+ }
+
+ @JsonProperty
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+ @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = Dxf2Namespace.NAMESPACE )
+ @JacksonXmlProperty( localName = "organisationUnit", namespace = Dxf2Namespace.NAMESPACE )
+ public Set<OrganisationUnit> getOrganisationUnits()
+ {
+ return organisationUnits;
+ }
+
+ public void setOrganisationUnits( Set<OrganisationUnit> organisationUnits )
+ {
+ this.organisationUnits = organisationUnits;
+ }
+
+ @JsonProperty
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+ @JacksonXmlElementWrapper( localName = "users", namespace = Dxf2Namespace.NAMESPACE )
+ @JacksonXmlProperty( localName = "user", namespace = Dxf2Namespace.NAMESPACE )
+ public Set<User> getUsers()
+ {
+ return users;
+ }
+
+ public void setUsers( Set<User> users )
+ {
+ this.users = users;
+ }
+
+ @JsonProperty
+ @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+ @JacksonXmlElementWrapper( localName = "userGroups", namespace = Dxf2Namespace.NAMESPACE )
+ @JacksonXmlProperty( localName = "userGroup", namespace = Dxf2Namespace.NAMESPACE )
+ public Set<UserGroup> getUserGroups()
+ {
+ return userGroups;
+ }
+
+ public void setUserGroups( Set<UserGroup> userGroups )
+ {
+ this.userGroups = userGroups;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm'
--- dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm 2012-10-01 04:01:22 +0000
+++ dhis-2/dhis-web/dhis-web-mobile/src/main/webapp/WEB-INF/dhis-web-mobile-velocity/new-message.vm 2012-10-01 13:21:22 +0000
@@ -1,17 +1,110 @@
<script>
var selected = {};
- jQuery(document).bind('pageinit', function() {
- $('#new-message-form input:submit').bind('click', function() {
- var subject = jQuery('#new-message-subject').val();
- var text = jQuery('#new-message-text').val();
-
- console.log(subject);
- console.log(text);
-
- return false;
- });
+ function displaySelected()
+ {
+ $('#selection-list').append('<li id="organisation-unit-list" data-role="list-divider">Organisation Units</li>')
+ $('#selection-list').append('<li>None selected.</li>');
+
+ $('#selection-list').append('<li id="user-list" data-role="list-divider">Users</li>')
+ $('#selection-list').append('<li>None selected.</li>');
+
+ $('#selection-list').append('<li id="user-group-list" data-role="list-divider">Users Groups</li>')
+ $('#selection-list').append('<li>None selected.</li>');
+
+ $('#selection-list').listview('refresh');
+ }
+
+ function updateRecipientCounter()
+ {
+ $('#message-recipient-counter').html(selected.length);
+ }
+
+ function manageRecipientsPage()
+ {
+ var fn1 = $('form[role="search"] input:text').data('events')['keyup'][1];
+ $('form[role="search"] input:text').unbind('keyup');
+
+ $('form[role="search"] input:text').bind('keyup', function () {
+ var search = $('form[role="search"] input:text').val();
+
+ $('#selection-list').children().remove();
+
+ if( search.length == 0)
+ {
+ displaySelected();
+ return;
+ }
+ else if ( search.length < 3 )
+ {
+ return;
+ }
+
+ $.ajax({
+ url : '$baseUrl/../api/currentUser/recipients',
+ type : 'get',
+ async: false,
+ dataType: 'json',
+ data : {
+ 'filter' : search
+ }
+ }).success(function ( data ) {
+ if( data.users && data.users.length > 0 )
+ {
+ $('#selection-list').append('<li id="user-list" data-role="list-divider">Users</li>')
+
+ _(data.users).each(function(user) {
+ $('#selection-list').append('<li data-id="' + user.id + '">' + user.name + '</li>');
+ });
+ }
+
+ if( data.userGroups && data.userGroups.length > 0 )
+ {
+ $('#selection-list').append('<li id="user-group-list" data-role="list-divider">Users Groups</li>')
+
+ _(data.userGroups).each(function(userGroup) {
+ $('#selection-list').append('<li data-id="' + userGroup.id + '">' + userGroup.name + '</li>');
+ });
+ }
+
+ $('#selection-list').listview('refresh');
+
+ });
+
+ $('form[role="search"] input:text').bind('keyup', fn1);
+ });
+
+ displaySelected();
+ }
+
+ function newMessagePage()
+ {
+ $('#new-message-form input:submit').bind('click', function () {
+ var subject = jQuery('#new-message-subject').val();
+ var text = jQuery('#new-message-text').val();
+
+ console.log(subject);
+ console.log(text);
+
+ return false;
+ });
+
+ updateRecipientCounter();
+ }
+
+ jQuery(document).bind('pagechange', function (event, data) {
+ var pageId = data.toPage.attr('id');
+
+ if( pageId == 'manage-recipients-page')
+ {
+ manageRecipientsPage();
+ }
+ else if( pageId == 'new-message-page')
+ {
+ newMessagePage();
+ }
});
+
</script>
<section data-role="page" id="new-message-page" data-theme="c">
@@ -27,13 +120,13 @@
<form id="new-message-form">
<label for='new-message-subject'>Subject</label>
<input type="text" id='new-message-subject' />
- <label for='new-message-body'>Text</label>
- <textarea id='new-message-body'></textarea>
+ <label for='new-message-text'>Text</label>
+ <textarea id='new-message-text'></textarea>
<input type="submit" value="Send message" />
</form>
</li>
- <li data-icon="gear"><a href="#manage-recipients-page" data-icon="plus">Manage recipients</a> <span class='ui-li-count'>1</a></li>
+ <li data-icon="gear"><a href="#manage-recipients-page" data-icon="plus">Manage recipients</a> <span id="message-recipient-counter" class='ui-li-count'>0</span></li>
</ul>
</section>
@@ -52,15 +145,7 @@
</header>
<section data-role="content">
- <ul data-role="listview" data-inset="true" data-filter="true" data-filter-placeholder="Search for recipients..">
- <li data-role="list-divider">Organisation Units</li>
- <li>Not implemented.</li>
-
- <li data-role="list-divider">Users</li>
- <li>Not implemented.</li>
-
- <li data-role="list-divider">User groups</li>
- <li>Not implemented.</li>
+ <ul id="selection-list" data-role="listview" data-inset="true" data-filter="true" data-filter-placeholder="Enter 3 or more characters to search">
</ul>
</section>