dashboard layout configuration now stored as xml; added support for configurable...
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 2 Jun 2011 17:28:49 +0000 (17:28 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 2 Jun 2011 17:28:49 +0000 (17:28 +0000)
12 files changed:
doc/internal/dashboard_element_config.txt [new file with mode: 0644]
include/netxmsdb.h
include/nms_cscp.h
sql/schema.in
sql/setup.in
src/java/netxms-base/src/main/java/org/netxms/base/NXCPCodes.java
src/java/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/netxms-eclipse/OSM/src/org/netxms/ui/eclipse/osm/tools/MapLoader.java
src/server/core/dashboard.cpp
src/server/core/session.cpp
src/server/include/nms_objects.h
src/server/tools/nxdbmgr/upgrade.cpp

diff --git a/doc/internal/dashboard_element_config.txt b/doc/internal/dashboard_element_config.txt
new file mode 100644 (file)
index 0000000..9814bdb
--- /dev/null
@@ -0,0 +1,24 @@
+Dashboard Element Configuration Format
+
+1. Element Data
+
+Common for all element configuration is top-level <element> tag. All inner tags are
+element type dependent.
+
+1.1. Label
+
+<element>
+       <title>label text</title>
+</element>
+
+
+2. Layout data
+
+Common for all elements.
+
+<layout>
+       <horizontalSpan>value</horizontalSpan>
+       <verticalSpan>value</verticalSpan>
+       <horizontalAlignment>value</horizontalAlignment>
+       <verticalAlignment>value</verticalAlignment>
+</layout>
index 0ca2de2..79d7276 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   229
+#define DB_FORMAT_VERSION   230
 
 #endif
index c55ea04..1c74052 100644 (file)
@@ -862,6 +862,7 @@ typedef struct
 #define VID_DRIVER_VERSION          ((DWORD)381)
 #define VID_NUM_VLANS               ((DWORD)382)
 #define VID_CREATE_JOB_ON_HOLD      ((DWORD)383)
+#define VID_TILE_SERVER_URL         ((DWORD)384)
 
 // Map elements list base
 #define VID_ELEMENT_LIST_BASE       ((DWORD)0x10000000)
index 2ef6534..accff38 100644 (file)
@@ -1282,9 +1282,6 @@ CREATE TABLE dashboard_elements
        element_id integer not null,
        element_type integer not null,
        element_data SQL_TEXT null,
-       horizontal_span integer not null,
-       vertical_span integer not null,
-       horizontal_alignment integer not null,
-       vertical_alignment integer not null,
+       layout_data SQL_TEXT null,
        PRIMARY KEY(dashboard_id,element_id)
 ) TABLE_TYPE;
index 8f6d2a3..6ad14f8 100644 (file)
@@ -224,6 +224,8 @@ INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
        VALUES ('BlockInactiveUserAccounts','0',1,0);
 INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
        VALUES ('AllowTrapVarbindsConversion','1',1,1);
+INSERT INTO config (var_name,var_value,is_visible,need_server_restart)
+       VALUES ('TileServerURL','http://tile.openstreetmap.org/',1,0);
 
 
 /*
index 95621af..3f5ca96 100644 (file)
@@ -666,6 +666,7 @@ public final class NXCPCodes
        public static final long VID_DRIVER_VERSION          = 381;\r
        public static final long VID_NUM_VLANS               = 382;\r
        public static final long VID_CREATE_JOB_ON_HOLD      = 383;\r
+       public static final long VID_TILE_SERVER_URL         = 384;\r
 \r
        public static final long VID_ACL_USER_BASE            = 0x00001000L;\r
        public static final long VID_ACL_USER_LAST            = 0x00001FFFL;\r
index 912dc99..684af82 100644 (file)
@@ -191,6 +191,7 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
        private String serverTimeZone;\r
        private byte[] serverChallenge = new byte[CLIENT_CHALLENGE_SIZE];\r
        private boolean zoningEnabled = false;\r
+       private String tileServerURL;\r
 \r
        // Objects\r
        private Map<Long, GenericObject> objectList = new HashMap<Long, GenericObject>();\r
@@ -1153,6 +1154,17 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
                        serverId = response.getVariableAsBinary(NXCPCodes.VID_SERVER_ID);\r
                        serverTimeZone = response.getVariableAsString(NXCPCodes.VID_TIMEZONE);\r
                        serverChallenge = response.getVariableAsBinary(NXCPCodes.VID_CHALLENGE);\r
+                       \r
+                       tileServerURL = response.getVariableAsString(NXCPCodes.VID_TILE_SERVER_URL);\r
+                       if (tileServerURL != null)\r
+                       {\r
+                               if (!tileServerURL.endsWith("/"))\r
+                                       tileServerURL = tileServerURL.concat("/");\r
+                       }\r
+                       else\r
+                       {\r
+                               tileServerURL = "http://tile.openstreetmap.org/";\r
+                       }\r
 \r
                        // Setup encryption if required\r
                        if (connUseEncryption)\r
@@ -1334,6 +1346,14 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
        }\r
 \r
        /**\r
+        * @return the tileServerURL\r
+        */\r
+       public String getTileServerURL()\r
+       {\r
+               return tileServerURL;\r
+       }\r
+\r
+       /**\r
         * @return the zoningEnabled\r
         */\r
        public boolean isZoningEnabled()\r
index faa3f3e..05a35a8 100644 (file)
@@ -34,8 +34,10 @@ import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.Rectangle;\r
 import org.eclipse.swt.widgets.Display;\r
 import org.netxms.client.GeoLocation;\r
+import org.netxms.client.NXCSession;\r
 import org.netxms.ui.eclipse.osm.Activator;\r
 import org.netxms.ui.eclipse.osm.GeoLocationCache;\r
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;\r
 \r
 /**\r
  * Map Loader - loads geographic map from tile server. Uses cached tiles when possible.\r
@@ -114,11 +116,12 @@ public class MapLoader
                int maxTileNum = (1 << zoom) - 1;\r
                if ((x < 0) || (y < 0) || (x > maxTileNum) || (y > maxTileNum))\r
                        return getBorderTileImage();\r
-               \r
+\r
+               final String tileServerURL = ((NXCSession)ConsoleSharedData.getSession()).getTileServerURL();\r
                URL url = null;\r
                try\r
                {\r
-                       url = new URL("http://tile.openstreetmap.org/" + zoom + "/" + x + "/" + y + ".png");\r
+                       url = new URL(tileServerURL + zoom + "/" + x + "/" + y + ".png");\r
                }\r
                catch(MalformedURLException e)\r
                {\r
index cb04087..03cf0e8 100644 (file)
@@ -80,9 +80,7 @@ BOOL Dashboard::CreateFromDB(DWORD dwId)
                m_numColumns = (int)DBGetFieldLong(hResult, 0, 0);
        DBFreeResult(hResult);
 
-       _sntprintf(query, 256, _T("SELECT element_type,element_data,")
-                                   _T("horizontal_span,vertical_span,horizontal_alignment,")
-                                                                 _T("vertical_alignment FROM dashboard_elements ")
+       _sntprintf(query, 256, _T("SELECT element_type,element_data,layout_data FROM dashboard_elements ")
                                                                  _T("WHERE dashboard_id=%d ORDER BY element_id"), (int)dwId);
        hResult = DBSelect(g_hCoreDB, query);
        if (hResult == NULL)
@@ -94,10 +92,7 @@ BOOL Dashboard::CreateFromDB(DWORD dwId)
                DashboardElement *e = new DashboardElement;
                e->m_type = (int)DBGetFieldLong(hResult, i, 0);
                e->m_data = DBGetField(hResult, i, 1, NULL, 0);
-               e->m_horizontalSpan = (int)DBGetFieldLong(hResult, i, 2);
-               e->m_verticalSpan = (int)DBGetFieldLong(hResult, i, 3);
-               e->m_horizontalAlignment = (int)DBGetFieldLong(hResult, i, 4);
-               e->m_verticalAlignment = (int)DBGetFieldLong(hResult, i, 5);
+               e->m_layout = DBGetField(hResult, i, 2, NULL, 0);
                m_elements->add(e);
        }
 
@@ -144,11 +139,11 @@ BOOL Dashboard::SaveToDB(DB_HANDLE hdb)
    {
                DashboardElement *element = m_elements->get(i);
                String data = DBPrepareString(hdb, element->m_data);
-               int len = data.getSize() + 256;
+               String layout = DBPrepareString(hdb, element->m_layout);
+               int len = data.getSize() + layout.getSize() + 256;
                TCHAR *eq = (TCHAR *)malloc(len * sizeof(TCHAR));
-      _sntprintf(eq, len, _T("INSERT INTO dashboard_elements (dashboard_id,element_id,element_type,element_data,horizontal_span,vertical_span,horizontal_alignment,vertical_alignment) VALUES (%d,%d,%d,%s,%d,%d,%d,%d)"),
-                          (int)m_dwId, i, element->m_type, (const TCHAR *)data, element->m_horizontalSpan,
-                                         element->m_verticalSpan, element->m_horizontalAlignment, element->m_verticalAlignment);
+      _sntprintf(eq, len, _T("INSERT INTO dashboard_elements (dashboard_id,element_id,element_type,element_data,layout_data) VALUES (%d,%d,%d,%s,%s)"),
+                          (int)m_dwId, i, element->m_type, (const TCHAR *)data, (const TCHAR *)layout);
       if (!DBQuery(hdb, eq))
                {
                        free(eq);
@@ -199,11 +194,8 @@ void Dashboard::CreateMessage(CSCPMessage *msg)
                DashboardElement *element = m_elements->get(i);
                msg->SetVariable(varId++, (WORD)element->m_type);
                msg->SetVariable(varId++, CHECK_NULL_EX(element->m_data));
-               msg->SetVariable(varId++, (WORD)element->m_horizontalSpan);
-               msg->SetVariable(varId++, (WORD)element->m_verticalSpan);
-               msg->SetVariable(varId++, (WORD)element->m_horizontalAlignment);
-               msg->SetVariable(varId++, (WORD)element->m_verticalAlignment);
-               varId += 4;
+               msg->SetVariable(varId++, CHECK_NULL_EX(element->m_layout));
+               varId += 7;
        }
 }
 
@@ -229,11 +221,8 @@ DWORD Dashboard::ModifyFromMessage(CSCPMessage *request, BOOL alreadyLocked)
                        DashboardElement *e = new DashboardElement;
                        e->m_type = (int)request->GetVariableShort(varId++);
                        e->m_data = request->GetVariableStr(varId++);
-                       e->m_horizontalSpan = (int)request->GetVariableShort(varId++);
-                       e->m_verticalSpan = (int)request->GetVariableShort(varId++);
-                       e->m_horizontalAlignment = (int)request->GetVariableShort(varId++);
-                       e->m_verticalAlignment = (int)request->GetVariableShort(varId++);
-                       varId += 4;
+                       e->m_layout = request->GetVariableStr(varId++);
+                       varId += 7;
                        m_elements->add(e);
                }
        }
index ee97648..9f208f1 100644 (file)
@@ -1480,6 +1480,9 @@ void ClientSession::SendServerInfo(DWORD dwRqId)
        strURL.translate(_T("%version%"), NETXMS_VERSION_STRING);
        msg.SetVariable(VID_CONSOLE_UPGRADE_URL, (const TCHAR *)strURL);
 
+       ConfigReadStr(_T("TileServerURL"), szBuffer, 1024, _T("http://tile.openstreetmap.org/"));
+       msg.SetVariable(VID_TILE_SERVER_URL, szBuffer);
+
    // Send response
    sendMessage(&msg);
 }
index 5c98eaa..326423f 100644 (file)
@@ -1455,13 +1455,10 @@ class DashboardElement
 public:
        int m_type;
        TCHAR *m_data;
-       int m_horizontalSpan;
-       int m_verticalSpan;
-       int m_horizontalAlignment;
-       int m_verticalAlignment;
+       TCHAR *m_layout;
 
-       DashboardElement() { m_data = NULL; }
-       ~DashboardElement() { safe_free(m_data); }
+       DashboardElement() { m_data = NULL; m_layout = NULL; }
+       ~DashboardElement() { safe_free(m_data); safe_free(m_layout); }
 };
 
 class NXCORE_EXPORTABLE Dashboard : public Container
index 6ad2119..8471ff7 100644 (file)
@@ -256,6 +256,57 @@ static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column, const TCH
 
 
 //
+// Upgrade from V229 to V230
+//
+
+static BOOL H_UpgradeFromV229(int currVersion, int newVersion)
+{
+       static TCHAR batch1[] = 
+               _T("ALTER TABLE dashboard_elements ADD layout_data $SQL:TEXT\n")
+               _T("<END>");
+
+       CHK_EXEC(SQLBatch(batch1));
+
+       DB_RESULT hResult = SQLSelect(_T("SELECT dashboard_id,element_id,horizontal_span,vertical_span,horizontal_alignment,vertical_alignment FROM dashboard_elements"));
+       if (hResult != NULL)
+       {
+               TCHAR query[1024], xml[1024];
+
+               int count = DBGetNumRows(hResult);
+               for(int i = 0; i < count; i++)
+               {
+                       _sntprintf(xml, 1024, _T("<layout><horizontalSpan>%d</horizontalSpan><verticalSpan>%d</verticalSpan><horizontalAlignment>%d</horizontalAlignment><verticalAlignment>%d</verticalAlignment></layout>"),
+                                  (int)DBGetFieldLong(hResult, i, 2), (int)DBGetFieldLong(hResult, i, 3),
+                                                 (int)DBGetFieldLong(hResult, i, 4), (int)DBGetFieldLong(hResult, i, 5));
+                       _sntprintf(query, 1024, _T("UPDATE dashboard_elements SET layout_data=%s WHERE dashboard_id=%d AND element_id=%d"),
+                                  (const TCHAR *)DBPrepareString(g_hCoreDB, xml), (int)DBGetFieldLong(hResult, i, 0), (int)DBGetFieldLong(hResult, i, 1));
+                       CHK_EXEC(SQLQuery(query));
+               }
+               DBFreeResult(hResult);
+       }
+       else
+       {
+               if (!g_bIgnoreErrors)
+                       return FALSE;
+       }
+
+       static TCHAR batch2[] = 
+               _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_span\n")
+               _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_span\n")
+               _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_alignment\n")
+               _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_alignment\n")
+               _T("<END>");
+
+       CHK_EXEC(SQLBatch(batch2));
+
+       CreateConfigParam(_T("TileServerURL"), _T("http://tile.openstreetmap.org/"), 1, 0);
+
+       CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='230' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
+
+//
 // Upgrade from V228 to V229
 //
 
@@ -5249,6 +5300,7 @@ static struct
        { 226, 227, H_UpgradeFromV226 },
        { 227, 228, H_UpgradeFromV227 },
        { 228, 229, H_UpgradeFromV228 },
+       { 229, 230, H_UpgradeFromV229 },
    { 0, NULL }
 };