Statistics
| Revision:

root / hci / trunk / eneraptor-web-app / grails-app / controllers / com / eneraptor / hci / SysStateController.groovy @ 6

History | View | Annotate | Download (3.4 KB)

1
package com.eneraptor.hci
2

    
3
class SysStateController {
4

    
5
        def reportService
6
        def hciLogicCommService
7
        
8
    def main = {
9
                
10
                List inDevices = DeviceInfo.findAllByInputDevice(true, [sort:'friendlyName', order:'asc'])
11
                List inDevicesData = new ArrayList()
12
                inDevices.each {
13
                        Map inDeviceDataEntry = new HashMap()
14
                        inDeviceDataEntry['friendlyName'] = it.friendlyName
15
                        inDeviceDataEntry['icon'] = it.iconPath
16
                        inDeviceDataEntry['loggedData'] = LoggedData.findByDeviceId(it.deviceId, [sort:'dateRecieved', order:'desc'])        
17
                        inDevicesData << inDeviceDataEntry
18
                }
19
                
20
                List outDevices = DeviceInfo.findAllByOutputDevice(true, [sort:'friendlyName', order:'asc'])
21
                List outDevicesData = new ArrayList()
22
                outDevices.each {
23
                        Map outDeviceDataEntry = new HashMap()
24
                        outDeviceDataEntry['friendlyName'] = it.friendlyName
25
                        outDeviceDataEntry['icon'] = it.iconPath
26
                        outDeviceDataEntry['loggedData'] = LoggedData.findByDeviceId(it.deviceId, [sort:'dateRecieved', order:'desc'])
27
                        outDevicesData << outDeviceDataEntry
28
                }
29
                
30
                [inDevicesData: inDevicesData, outDevicesData: outDevicesData]
31
                
32
        }
33
        
34
        def measure = {
35
                
36
                List inDevices = DeviceInfo.findAllByInputDevice(true, [sort:'friendlyName', order:'asc'])
37
                List inDevicesData = new ArrayList()
38
                inDevices.each {
39
                        Map inDeviceDataEntry = new HashMap()
40
                        inDeviceDataEntry['deviceId'] = it.deviceId
41
                        inDeviceDataEntry['friendlyName'] = it.friendlyName
42
                        inDeviceDataEntry['icon'] = it.iconPath
43
                        inDeviceDataEntry['loggedData'] = LoggedData.findByDeviceId(it.deviceId, [sort:'dateRecieved', order:'desc'])
44
                        inDevicesData << inDeviceDataEntry
45
                }
46
                
47
                [inDevicesData: inDevicesData]
48
                
49
    }
50
        
51
        def measureUpdate = {
52
                
53
                List devices = new ArrayList()
54
                
55
                DeviceInfo.findAllByInputDevice(true).each {
56
                        if(params[it.deviceId] == "on")
57
                                devices << it.deviceId
58
                }
59
                
60
                def output = "";
61
                
62
                if(devices.size == 0) {
63
                        flash['errors'] = "<p>No device was selected. At least one device must be selected.</p>"
64
                        redirect(action: 'measure')
65
                        return false
66
                }
67
                
68
                output += reportService.println("Trying to update measurements manually for devices")
69
                devices.each {
70
                        output += reportService.println(" - " + it)
71
                }
72
                output += reportService.println("Generating request xml")
73
                
74
                // generate request xml
75
                def reqXML = "<todo />"
76
                
77
                output += reportService.println("Request xml generated")
78
                output += reportService.println("Sending request")
79
                
80
                // send request
81
                Map rspXML = hciLogicCommService.getReplyToRequest(reqXML)
82
                
83
                if(rspXML['status'] == "error") {
84
                        output += reportService.println("<span style='color:red;'>Error: " + rspXML['content'] + "</span>")
85
                } else {
86
                        output += reportService.println("<span style='color:red;'>Error: implementation missing - TODO.</span>")
87
                }
88
                
89
                [errorExplanation: output]
90
                
91
        }
92
        
93
        def actions = {
94
                
95
                List outDevices = DeviceInfo.findAllByOutputDevice(true, [sort:'friendlyName', order:'asc'])
96
                List outDevicesData = new ArrayList()
97
                outDevices.each {
98
                        Map outDeviceDataEntry = new HashMap()
99
                        outDeviceDataEntry['deviceId'] = it.deviceId
100
                        outDeviceDataEntry['friendlyName'] = it.friendlyName
101
                        outDeviceDataEntry['icon'] = it.iconPath
102
                        outDeviceDataEntry['loggedData'] = LoggedData.findByDeviceId(it.deviceId, [sort:'dateRecieved', order:'desc'])
103
                        outDevicesData << outDeviceDataEntry
104
                }
105
                
106
                [outDevicesData: outDevicesData]
107
                
108
    }
109
        
110
}