moved code for device module into its own folder. Implement graphs.
This commit is contained in:
110
apps/aqhome-cgi/modules/devices/mdevices_index.c
Normal file
110
apps/aqhome-cgi/modules/devices/mdevices_index.c
Normal file
@@ -0,0 +1,110 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "./mdevices_index.h"
|
||||
|
||||
#include "aqhome-cgi/service/module.h"
|
||||
#include "aqhome-cgi/modules/mdataclient.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/timestamp.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defs and enums
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define GBAS GWEN_Buffer_AppendString
|
||||
#define GBAA GWEN_Buffer_AppendArgs
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* code
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void AQH_ModDevices_RunIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf)
|
||||
{
|
||||
AQH_DEVICE_LIST *deviceList;
|
||||
AQH_DEVICE *device;
|
||||
uint32_t perms;
|
||||
|
||||
perms=AQH_ModService_GetUserPerms(m);
|
||||
|
||||
deviceList=AQH_DataClient_GetDevices(dc, NULL);
|
||||
if (deviceList==NULL) {
|
||||
DBG_ERROR(NULL, "No device received");
|
||||
GBAS(dbuf, "<p>No devices.</p>");
|
||||
return;
|
||||
}
|
||||
|
||||
GBAS(dbuf, "<h1>Devices</h1>\n");
|
||||
GBAS(dbuf,
|
||||
"<table class=\"datatable\">\n"
|
||||
"<thead>\n"
|
||||
"<tr>"
|
||||
"<th>Name For System</th>"
|
||||
"<th>Room</th>"
|
||||
"<th>Location</th>"
|
||||
"<th>Description</th>"
|
||||
"</tr>\n"
|
||||
"</thead>\n"
|
||||
"<tbody>\n");
|
||||
|
||||
device=AQH_Device_List_First(deviceList);
|
||||
while(device) {
|
||||
const char *s;
|
||||
|
||||
GBAA(dbuf, "<tr>");
|
||||
/* name for system */
|
||||
s=AQH_Device_GetNameForSystem(device);
|
||||
if (perms & AQH_MODDEVICES_PERMS_VALUEREAD) {
|
||||
GBAS(dbuf,"<td><a href=\"values.html?device=");
|
||||
GWEN_Text_EscapeToBufferTolerant(s, dbuf);
|
||||
GBAA(dbuf,"\">%s</a></td>", s?s:"");
|
||||
}
|
||||
else
|
||||
GBAA(dbuf,"<td>%s</td>", s?s:"");
|
||||
/* room */
|
||||
s=AQH_Device_GetRoomName(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* location */
|
||||
s=AQH_Device_GetLocation(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
/* description */
|
||||
s=AQH_Device_GetDescription(device);
|
||||
GBAA(dbuf, "<td>%s</td>", s?s:"");
|
||||
|
||||
GBAA(dbuf, "</tr>");
|
||||
device=AQH_Device_List_Next(device);
|
||||
}
|
||||
|
||||
GBAS(dbuf,
|
||||
"</tbody>\n"
|
||||
"</table>\n");
|
||||
AQH_Device_List_free(deviceList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user