Revision 58
hci/trunk/eneraptor-web-app/grails-app/views/actions/viewAction.gsp | ||
---|---|---|
1 |
<html> |
|
2 |
|
|
3 |
<head> |
|
4 |
<title>Scenarios » View scenario</title> |
|
5 |
<meta name="layout" content="main" /> |
|
6 |
</head> |
|
7 |
|
|
8 |
<body> |
|
9 |
|
|
10 |
<erptr:box title="Scenario: ${scenario.name}"> |
|
11 |
|
|
12 |
<p>Scenario Id: <b>${scenario.id}</b></p> |
|
13 |
<p>Scenario name (short description): <b>${scenario.name}</b></p> |
|
14 |
<br /> |
|
15 |
<p>Measuring device: <b>${scenario.inDevice}</b></p> |
|
16 |
<p>Controlling device: <b>${scenario.outDevice}</b></p> |
|
17 |
<br /> |
|
18 |
<p>Measuring device values:</p> |
|
19 |
<table> |
|
20 |
<thead> |
|
21 |
<tr> |
|
22 |
<th><p>Minimal value</p></th> |
|
23 |
<th><p>Optimal value</p></th> |
|
24 |
<th><p>Maximal value</p></th> |
|
25 |
<th><p>Tolerance</p></th> |
|
26 |
</tr> |
|
27 |
</thead> |
|
28 |
<tbody> |
|
29 |
<tr> |
|
30 |
<td><p>${scenario.minVal}</p></td> |
|
31 |
<td><p>${scenario.optVal}</p></td> |
|
32 |
<td><p>${scenario.maxVal}</p></td> |
|
33 |
<td><p>± ${scenario.tolerance}</p></td> |
|
34 |
</tr> |
|
35 |
</tbody> |
|
36 |
</table> |
|
37 |
<br /> |
|
38 |
|
|
39 |
<p>Checking frequency: <b>${scenario.check_active} seconds</b> when active, <b>${scenario.check_idle} seconds</b> when idle.</p> |
|
40 |
<br /> |
|
41 |
|
|
42 |
<p>Reaction:</p> |
|
43 |
<table> |
|
44 |
<thead> |
|
45 |
<tr> |
|
46 |
<th><p>Calculation type</p></th> |
|
47 |
<th><p>Alpha value</p></th> |
|
48 |
<th><p>Action to execute</p></th> |
|
49 |
<th><p>Parameters</p></th> |
|
50 |
</tr> |
|
51 |
</thead> |
|
52 |
<tbody> |
|
53 |
<tr> |
|
54 |
<td><p>${scenario.reaction}</p></td> |
|
55 |
<td><p>${scenario.alpha}</p></td> |
|
56 |
<td><p style="font-family:monospace;">${scenario.action}</p></td> |
|
57 |
<td><p style="font-family:monospace;">${scenario.params} ${scenario.param}</p></td> |
|
58 |
</tr> |
|
59 |
</tbody> |
|
60 |
</table> |
|
61 |
<br /> |
|
62 |
|
|
63 |
</erptr:box> |
|
64 |
|
|
65 |
</body> |
|
66 |
|
|
67 |
</html> |
hci/trunk/eneraptor-web-app/grails-app/views/actions/view.gsp | ||
---|---|---|
8 | 8 |
<body> |
9 | 9 |
|
10 | 10 |
<erptr:box title="View scenarios"> |
11 |
<p>TODO</p> |
|
11 |
<p>Scenarios are saved internally in the logic module.</p> |
|
12 |
<p>You can view and edit them here.</p> |
|
12 | 13 |
</erptr:box> |
14 |
|
|
15 |
<erptr:box title="Scenarios"> |
|
16 |
<div name="scenariosHolder" id="scenariosHolder" > |
|
17 |
<p><img src="${resource(dir:'img/',file:'spinner.gif')}" style="float:left;position:relative;top:-2px;" /> Retrieving scenarios. Please wait...</p> |
|
18 |
</div> |
|
19 |
</erptr:box> |
|
13 | 20 |
|
21 |
<g:javascript> |
|
22 |
function includeToOnLoadDo() { |
|
23 |
new Ajax.Updater('scenariosHolder','<g:createLink action="getActions" />',{asynchronous:true,evalScripts:true}); |
|
24 |
} |
|
25 |
</g:javascript> |
|
26 |
|
|
14 | 27 |
</body> |
15 | 28 |
|
16 | 29 |
</html> |
hci/trunk/eneraptor-web-app/grails-app/views/actions/getActions.gsp | ||
---|---|---|
1 |
<g:if test="${replyError}"> |
|
2 |
<center> |
|
3 |
<p>Could not retrieve scenarios from the logic.</p> |
|
4 |
<p>Please try again by <g:link action="view">refreshing</g:link> this page.</p> |
|
5 |
<br /> |
|
6 |
<p><i>Error: ${replyError}</i></p> |
|
7 |
</center> |
|
8 |
</g:if> |
|
9 |
<g:else> |
|
10 |
<table> |
|
11 |
<thead> |
|
12 |
<tr> |
|
13 |
<th><p>Name (short description)</p></th> |
|
14 |
<th><p>Id</p></th> |
|
15 |
<th><p>Main input device</p></th> |
|
16 |
<th><p>Output device</p></th> |
|
17 |
<th style="width:60px;"><p>Options</p></th> |
|
18 |
</tr> |
|
19 |
</thead> |
|
20 |
<tbody> |
|
21 |
<g:each in="${scenarios}" var="scenario"> |
|
22 |
<tr> |
|
23 |
<td><p><g:link action="viewAction" params="[actionId: scenario[0]]" >${scenario[1].encodeAsHTML()}</g:link></p></td> |
|
24 |
<td><p>${scenario[0]}</p></td> |
|
25 |
<td><p>${scenario[2]}</p></td> |
|
26 |
<td><p>${scenario[3]}</p></td> |
|
27 |
<td> |
|
28 |
<g:link title="View" action="viewAction" params="[actionId: scenario[0]]" ><erptr:icon w="script" /></g:link> |
|
29 |
<g:link title="Edit" action="editAction" params="[actionId: scenario[0]]" ><erptr:icon w="pencil" /></g:link> |
|
30 |
<g:link title="Delete" action="deleteAction" params="[actionId: scenario[0]]" ><erptr:icon w="delete" /></g:link> |
|
31 |
</td> |
|
32 |
</tr> |
|
33 |
</g:each> |
|
34 |
</tbody> |
|
35 |
</table> |
|
36 |
</g:else> |
hci/trunk/eneraptor-web-app/grails-app/views/layouts/main.gsp | ||
---|---|---|
105 | 105 |
<g:javascript> |
106 | 106 |
function onLoadDo() { |
107 | 107 |
<g:if test="${flash.confirms}"> |
108 |
new Effect.Pulsate('confirmBox',{pulses:2, duration: 0.2, from: 0.5}) |
|
108 |
new Effect.Pulsate('confirmBox',{pulses:2, duration: 0.2, from: 0.5});
|
|
109 | 109 |
new Effect.Fade('confirmBox', {duration: 3, delay: 3}); |
110 | 110 |
</g:if> |
111 | 111 |
<g:if test="${flash.errors}"> |
112 |
new Effect.Shake('errorBox', {duration: 0.2, distance: 5}) |
|
112 |
new Effect.Shake('errorBox', {duration: 0.2, distance: 5});
|
|
113 | 113 |
</g:if> |
114 | 114 |
<g:if test="${flash.warnings}"> |
115 |
new Effect.Pulsate('warningBox',{pulses:2, duration: 0.2, from: 0.5}) |
|
115 |
new Effect.Pulsate('warningBox',{pulses:2, duration: 0.2, from: 0.5});
|
|
116 | 116 |
</g:if> |
117 |
<g:if test="${includeToOnLoadDo}"> |
|
118 |
includeToOnLoadDo(); |
|
119 |
</g:if> |
|
117 | 120 |
} |
118 | 121 |
</g:javascript> |
119 | 122 |
|
hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/StatisticsController.groovy | ||
---|---|---|
440 | 440 |
render(text: cont,contentType:"text/csv",encoding:"UTF-8") |
441 | 441 |
|
442 | 442 |
} |
443 |
|
|
444 |
def deleteGraph = { |
|
445 |
|
|
446 |
if(params['id']) { |
|
447 |
|
|
448 |
def graphToDelete = EneGraph.get(params['id']) |
|
449 |
if(graphToDelete) { |
|
450 |
|
|
451 |
graphToDelete.delete() |
|
452 |
flash['confirms'] = "<p>Graph deleted successfully.</p>" |
|
453 |
redirect(action:'graphs') |
|
454 |
return true |
|
455 |
|
|
456 |
} else { |
|
457 |
flash['errors'] = "<p>No graph was deleted. Graph ID invalid!</p>" |
|
458 |
redirect(action:'graphs') |
|
459 |
return false |
|
460 |
} |
|
461 |
|
|
462 |
} else { |
|
463 |
|
|
464 |
flash['errors'] = "<p>No graph was deleted. Graph ID not specified!</p>" |
|
465 |
redirect(action:'graphs') |
|
466 |
return false |
|
467 |
|
|
468 |
} |
|
469 |
|
|
470 |
} |
|
443 | 471 |
|
444 | 472 |
} |
hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/ActionsController.groovy | ||
---|---|---|
1 | 1 |
package com.eneraptor.hci |
2 | 2 |
|
3 |
import grails.converters.* |
|
4 |
|
|
3 | 5 |
class ActionsController { |
4 |
|
|
6 |
|
|
7 |
def hciLogicCommService |
|
8 |
|
|
5 | 9 |
def main = { } |
6 | 10 |
|
7 |
def view = { } |
|
11 |
def view = { |
|
12 |
|
|
13 |
[includeToOnLoadDo: true] |
|
14 |
|
|
15 |
} |
|
8 | 16 |
|
17 |
def getActions = { |
|
18 |
|
|
19 |
String reqStr = "<?xml version=\"1.0\"?><hci-request type=\"getScenarios\"></hci-request>" |
|
20 |
Map reply = hciLogicCommService.getReplyToRequest(reqStr) |
|
21 |
|
|
22 |
if(reply['status'] == 'error' || reply['content'] == null) { |
|
23 |
return [replyError: reply['content']] |
|
24 |
} else { |
|
25 |
def filteredResponse = reply['content'].minus("<?xml version=\"1.0\"?>") |
|
26 |
//System.out.println("[eneraptor-hci] Recieved reply (filtered): " + filteredResponse) |
|
27 |
def rootNode = XML.parse(filteredResponse) |
|
28 |
if(rootNode.@type == "getScenarios") { |
|
29 |
List scenarios = new ArrayList() |
|
30 |
rootNode.scenariotree.scenario.each { |
|
31 |
scenarios << [it.@id.text(),it.@name.text(),it.inDevice.@id.text(),it.outDevice.@id.text()] |
|
32 |
} |
|
33 |
[scenarios:scenarios] |
|
34 |
} else { |
|
35 |
return [replyError: "The response is invalid. Check logic's IP and port numbers."] |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
} |
|
40 |
|
|
9 | 41 |
def add = { } |
42 |
|
|
43 |
def viewAction = { |
|
44 |
|
|
45 |
String reqStr = "<?xml version=\"1.0\"?><hci-request type=\"getScenarios\"></hci-request>" |
|
46 |
Map reply = hciLogicCommService.getReplyToRequest(reqStr) |
|
47 |
|
|
48 |
if(reply['status'] == 'error' || reply['content'] == null) { |
|
49 |
flash['errors'] = "<p>Error connecting with logic: " + reply['content'] + "</p>" |
|
50 |
redirect(action:'view') |
|
51 |
return false |
|
52 |
} else { |
|
53 |
def filteredResponse = reply['content'].minus("<?xml version=\"1.0\"?>") |
|
54 |
def rootNode = XML.parse(filteredResponse) |
|
55 |
if(rootNode.@type == "getScenarios") { |
|
56 |
def scenarioNode = rootNode.scenariotree[0].scenario.find { |
|
57 |
it.@id.text() == params['actionId'] |
|
58 |
} |
|
59 |
if(scenarioNode == null) { |
|
60 |
flash['errors'] = "<p>Could not find a scanario with the id " + params['actionId'] + ".</p>" |
|
61 |
redirect(action:'view') |
|
62 |
return false |
|
63 |
} else { |
|
64 |
Map scenario = new HashMap() |
|
65 |
scenario['id'] = scenarioNode.@id.text() |
|
66 |
scenario['name'] = scenarioNode.@name.text() |
|
67 |
scenario['inDevice'] = scenarioNode.inDevice.@id.text() |
|
68 |
scenario['outDevice'] = scenarioNode.outDevice.@id.text() |
|
69 |
scenario['reaction'] = scenarioNode.reaction.@func.text() |
|
70 |
scenario['check_idle'] = scenarioNode.check_idle.@val.text() |
|
71 |
scenario['check_active'] = scenarioNode.check_active.@val.text() |
|
72 |
scenario['alpha'] = scenarioNode.alpha.@val.text() |
|
73 |
scenario['params'] = scenarioNode.params.@val.text() |
|
74 |
scenario['minVal'] = scenarioNode.inDevAalues.@minval.text() |
|
75 |
scenario['maxVal'] = scenarioNode.inDevAalues.@maxval.text() |
|
76 |
scenario['optVal'] = scenarioNode.inDevAalues.@optval.text() |
|
77 |
scenario['tolerance'] = scenarioNode.inDevAalues.@tolerance.text() |
|
78 |
scenario['action'] = scenarioNode.action.@act.text() |
|
79 |
scenario['param'] = scenarioNode.param.@par.text() |
|
80 |
|
|
81 |
return [scenario:scenario] |
|
82 |
} |
|
83 |
} else { |
|
84 |
flash['errors'] = "<p>Error connecting with logic: The response is invalid. Check logic's IP and port numbers.</p>" |
|
85 |
redirect(action:'view') |
|
86 |
return false |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
def deleteAction = { |
|
93 |
|
|
94 |
// First part: get XML from logic and modify |
|
95 |
|
|
96 |
String reqStr = "<?xml version=\"1.0\"?><hci-request type=\"getScenarios\"></hci-request>" |
|
97 |
Map reply = hciLogicCommService.getReplyToRequest(reqStr) |
|
98 |
|
|
99 |
if(reply['status'] == 'error' || reply['content'] == null) { |
|
100 |
flash['errors'] = "<p>Error connecting with logic: " + reply['content'] + "</p>" |
|
101 |
redirect(action:'view') |
|
102 |
return false |
|
103 |
} else { |
|
104 |
def filteredResponse = reply['content'].minus("<?xml version=\"1.0\"?>") |
|
105 |
def rootNode = new groovy.util.XmlParser().parseText(filteredResponse) |
|
106 |
if(rootNode.@type == "getScenarios") { |
|
107 |
def scenarioTree = rootNode.scenariotree[0] |
|
108 |
def nodeToRemove = scenarioTree.scenario.find { |
|
109 |
it.@id == params['actionId'] |
|
110 |
} |
|
111 |
scenarioTree.remove(nodeToRemove) |
|
112 |
|
|
113 |
def writer = new StringWriter() |
|
114 |
new XmlNodePrinter(new PrintWriter(writer)).print(scenarioTree) |
|
115 |
def result = writer.toString() |
|
116 |
|
|
117 |
result = "<?xml version=\"1.0\"?><hci-request type=\"setScenarios\">" + result + "</hci-request>" |
|
118 |
|
|
119 |
// Second part: give modified XML to logic |
|
120 |
|
|
121 |
Map reply2 = hciLogicCommService.getReplyToRequest(result) |
|
122 |
|
|
123 |
if(reply2['status'] == 'error' || reply2['content'] == null) { |
|
124 |
flash['errors'] = "<p>Error connecting with logic: " + reply2['content'] + "</p>" |
|
125 |
redirect(action:'view') |
|
126 |
return false |
|
127 |
} else { |
|
128 |
def rootNode2 = XML.parse(reply2['content']) |
|
129 |
if(rootNode2.@type.text() == "setScenarios") { |
|
130 |
flash['confirms'] = "<p>Scenario deleted successfully.</p>" |
|
131 |
redirect(action:'view') |
|
132 |
return true |
|
133 |
} else { |
|
134 |
flash['errors'] = "<p>Error connecting with logic: The response is invalid. Check logic's IP and port numbers.</p>" |
|
135 |
redirect(action:'view') |
|
136 |
return false |
|
137 |
} |
|
138 |
} |
|
139 |
|
|
140 |
} else { |
|
141 |
flash['errors'] = "<p>Error connecting with logic: The response is invalid. Check logic's IP and port numbers.</p>" |
|
142 |
redirect(action:'view') |
|
143 |
return false |
|
144 |
} |
|
145 |
} |
|
146 |
} |
|
10 | 147 |
|
11 | 148 |
} |
hci/trunk/eneraptor-web-app/grails-app/controllers/com/eneraptor/hci/LogicRequestController.groovy | ||
---|---|---|
1 | 1 |
package com.eneraptor.hci |
2 | 2 |
|
3 |
import grails.converters.* |
|
4 |
|
|
3 | 5 |
class LogicRequestController { |
4 | 6 |
|
5 | 7 |
def reportService |
... | ... | |
21 | 23 |
output += reportService.println("<span style='color:red;'>Error: " + testReply['content'] + "</span>") |
22 | 24 |
} else { |
23 | 25 |
output += reportService.println("Connection established succesfully") |
24 |
if(testReply['content'] == "<logic-response type=\"checkConnection\"><data>12345</data></logic-response>") { |
|
25 |
output += "<span style='color:green;'>Logic unit replied! The eneraptor system is set up properly.</span>" |
|
26 |
def rootNode = XML.parse(testReply['content']) |
|
27 |
if(rootNode.data == "12345") { |
|
28 |
output += reportService.println("<span style='color:green;'>Logic unit replied! The eneraptor system is set up properly.</span>") |
|
26 | 29 |
} else { |
27 | 30 |
output += reportService.println("<span style='color:red;'>The connection was established, but there was no reply from the logic unit.</span>") |
28 |
output += reportService.println("<span style='color:red;'>You should check the logic's port number and IP address.</span>"); |
|
29 |
output += reportService.println("<span style='color:red;'>Returned: " + testReply['content'].encodeAsHTML() + "</span>"); |
|
31 |
output += reportService.println("<span style='color:red;'>You should check the logic's port number and IP address.</span>") |
|
32 |
output += reportService.println("<span style='color:red;'> Returned: " + testReply['content'].encodeAsHTML() + "</span>") |
|
33 |
output += reportService.println("<span style='color:red;'>Should be: " + "<logic-response type=\"checkConnection\"><data>12345</data></logic-response>".encodeAsHTML() + "</span>") |
|
30 | 34 |
} |
31 | 35 |
} |
32 | 36 |
|
Also available in: Unified diff