← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20751: Added StyleObject for rending of flags and styles.

 

------------------------------------------------------------
revno: 20751
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-16 22:17:09 +0200
message:
  Added StyleObject for rending of flags and styles.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/StyleObject.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/StyleManager.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemController.java
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/settings/userGeneralSettings.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java


--
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-api/src/main/java/org/hisp/dhis/setting/StyleManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/StyleManager.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/StyleManager.java	2015-10-16 20:17:09 +0000
@@ -28,7 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.SortedMap;
+import java.util.List;
 
 /**
  * @author Lars Helge Overland
@@ -47,5 +47,5 @@
     
     String getCurrentStyleDirectory();
         
-    SortedMap<String, String> getStyles();
+    List<StyleObject> getStyles();
 }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/StyleObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/StyleObject.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/StyleObject.java	2015-10-16 20:17:09 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.setting;
+
+/*
+ * Copyright (c) 2004-2015, 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;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class StyleObject
+{
+    private String name;
+    
+    private String key;
+    
+    private String path;
+
+    public StyleObject()
+    {
+    }
+
+    public StyleObject( String name, String key, String path )
+    {
+        this.name = name;
+        this.key = key;
+        this.path = path;
+    }
+    
+    @JsonProperty
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    @JsonProperty
+    public String getKey()
+    {
+        return key;
+    }
+
+    public void setKey( String key )
+    {
+        this.key = key;
+    }
+
+    @JsonProperty
+    public String getPath()
+    {
+        return path;
+    }
+
+    public void setPath( String path )
+    {
+        this.path = path;
+    }
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java	2015-10-15 17:01:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java	2015-10-16 20:17:09 +0000
@@ -68,6 +68,8 @@
     // -------------------------------------------------------------------------
 
     List<String> getFlags();
+    
+    List<StyleObject> getFlagObjects();
 
     String getFlagImage();
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java	2015-10-14 11:29:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultStyleManager.java	2015-10-16 20:17:09 +0000
@@ -29,9 +29,16 @@
  */
 
 import java.io.File;
+import java.util.List;
+import java.util.Map.Entry;
 import java.util.SortedMap;
 
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nManager;
 import org.hisp.dhis.user.UserSettingService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.google.common.collect.Lists;
 
 /**
  * @author Lars Helge Overland
@@ -70,6 +77,9 @@
     {
         this.styles = styles;
     }
+    
+    @Autowired
+    private I18nManager i18nManager;
 
     // -------------------------------------------------------------------------
     // StyleManager implementation
@@ -125,8 +135,19 @@
     }
 
     @Override
-    public SortedMap<String, String> getStyles()
+    public List<StyleObject> getStyles()
     {
-        return styles;
+        I18n i18n = i18nManager.getI18n();
+        
+        List<StyleObject> list = Lists.newArrayList();
+        
+        for ( Entry<String, String> entry : styles.entrySet() )
+        {
+            String name = i18n.getString( entry.getKey() );
+            
+            list.add( new StyleObject( name, entry.getKey(), entry.getValue() ) );
+        }
+        
+        return list;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java	2015-10-15 17:01:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java	2015-10-16 20:17:09 +0000
@@ -40,11 +40,15 @@
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.lang3.StringUtils;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nManager;
 import org.hisp.dhis.system.util.ValidationUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.Lists;
 
 /**
  * @author Stian Strandli
@@ -81,6 +85,9 @@
         this.flags = flags;
     }
 
+    @Autowired
+    private I18nManager i18nManager;
+
     // -------------------------------------------------------------------------
     // SystemSettingManager implementation
     // -------------------------------------------------------------------------
@@ -265,6 +272,26 @@
         Collections.sort( flags );
         return flags;
     }
+    
+    @Override
+    public List<StyleObject> getFlagObjects()
+    {
+        Collections.sort( flags );
+        
+        I18n i18n = i18nManager.getI18n();
+        
+        List<StyleObject> list = Lists.newArrayList();
+        
+        for ( String flag : flags )
+        {
+            String name = i18n.getString( flag );
+            String file = flag + ".png";
+            
+            list.add( new StyleObject( name, flag, file ) );
+        }
+        
+        return list;
+    }
 
     @Override
     public String getFlagImage()

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemController.java	2015-10-15 15:48:11 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/SystemController.java	2015-10-16 20:17:09 +0000
@@ -28,6 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.dataintegrity.DataIntegrityReport;
 import org.hisp.dhis.dataintegrity.FlattenedDataIntegrityReport;
@@ -40,6 +48,7 @@
 import org.hisp.dhis.scheduling.TaskCategory;
 import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.setting.StyleManager;
+import org.hisp.dhis.setting.StyleObject;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.SystemInfo;
 import org.hisp.dhis.system.SystemService;
@@ -57,14 +66,6 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.SortedMap;
-import java.util.UUID;
-
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -199,13 +200,13 @@
     }
     
     @RequestMapping( value = "/flags", method = RequestMethod.GET, produces = { "application/json" } )
-    public @ResponseBody List<String> getFlags()
+    public @ResponseBody List<StyleObject> getFlags()
     {
-        return systemSettingManager.getFlags();
+        return systemSettingManager.getFlagObjects();
     }
     
     @RequestMapping( value = "/styles", method = RequestMethod.GET, produces = { "application/json" } )
-    public @ResponseBody SortedMap<String, String> getStyles()
+    public @ResponseBody List<StyleObject> getStyles()
     {
         return styleManager.getStyles();
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/settings/userGeneralSettings.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/settings/userGeneralSettings.vm	2014-08-26 18:26:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/settings/userGeneralSettings.vm	2015-10-16 20:17:09 +0000
@@ -51,8 +51,8 @@
 
 <div class="setting">
 <select id="currentStyle" name="currentStyle">
-#foreach( $style in $styles.entrySet() )
-	<option value="$style.value" #if( $style.value == $currentStyle )selected="selected"#end>$i18n.getString( $style.key )</option>
+#foreach( $style in $styles )
+	<option value="$style.path" #if( $style.path == $currentStyle )selected="selected"#end>$encoder.htmlEncode( $style.name )</option>
 #end
 </select>
 </div>

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/settings/user/action/GetGeneralSettingsAction.java	2015-10-16 20:17:09 +0000
@@ -35,13 +35,13 @@
 
 import java.util.List;
 import java.util.Locale;
-import java.util.SortedMap;
 
 import java.io.Serializable;
 
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.i18n.locale.LocaleManager;
 import org.hisp.dhis.setting.StyleManager;
+import org.hisp.dhis.setting.StyleObject;
 import org.hisp.dhis.user.UserSettingService;
 
 import com.opensymphony.xwork2.Action;
@@ -123,9 +123,9 @@
         return currentStyle;
     }
 
-    private SortedMap<String, String> styles;
+    private List<StyleObject> styles;
 
-    public SortedMap<String, String> getStyles()
+    public List<StyleObject> getStyles()
     {
         return styles;
     }