Fotobot
Get data from your photovoltaic plant
Signals | Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
InvertorsController Class Reference
Inheritance diagram for InvertorsController:
WebPage MRequestHandler

Signals

int saveInvertor (DBT_INVERTORS)
 
void deleteInvertor (int)
 

Public Member Functions

 InvertorsController ()
 
void servicePrivate (HttpRequest &request)
 
- Public Member Functions inherited from WebPage
 WebPage ()
 
virtual void service (HttpRequest &request, HttpResponse &response)
 
void redirect (const QString &location)
 
- Public Member Functions inherited from MRequestHandler
 MRequestHandler ()
 

Static Public Member Functions

static QString getEditFormContents (HttpRequest &request, DBT_INVERTORS line=DBT_INVERTORS(), bool generator=false)
 
static void readForm (DBT_INVERTORS &invertor, HttpRequest &request)
 
- Static Public Member Functions inherited from WebPage
static QString percentEncode (const QString &s)
 

Private Member Functions

 Q_DISABLE_COPY (InvertorsController)
 
void actionAdd (HttpRequest &request)
 
void actionEdit (HttpRequest &request)
 
void actionDelete (HttpRequest &request)
 

Additional Inherited Members

- Protected Member Functions inherited from WebPage
void setStatus (int code, QByteArray description)
 
void setHeader (QByteArray name, QByteArray value)
 
void setHeader (QByteArray name, int value)
 
void write (QByteArray data)
 
void write (QString data)
 
void write (const char *data)
 
void about ()
 
HttpSession getSession ()
 
virtual void writeHeader (HttpRequest &request, HttpResponse &response)
 
virtual void writeFooter (HttpRequest &request, HttpResponse &response)
 
- Protected Member Functions inherited from MRequestHandler
bool needsLogin (HttpRequest &request, HttpResponse &response)
 
- Protected Attributes inherited from WebPage
QString m_javascript
 
- Protected Attributes inherited from MRequestHandler
bool m_needs_access_data
 
bool m_needs_change_settings
 
bool m_cacheable
 

Detailed Description

Definition at line 16 of file invertorscontroller.h.

Constructor & Destructor Documentation

InvertorsController::InvertorsController ( )

Constructor

Definition at line 12 of file invertorscontroller.cpp.

12  {
13  qRegisterMetaType<DBT_INVERTORS>();
14  connect(this, SIGNAL(saveInvertor(DBT_INVERTORS)), Static::db, SLOT(saveInvertor(DBT_INVERTORS)), Qt::QueuedConnection);
15  connect(this, SIGNAL(deleteInvertor(int)), Static::db, SLOT(deleteInvertor(int)), Qt::QueuedConnection);
16 }
Class describing database table INVERTORS.

Member Function Documentation

void InvertorsController::actionAdd ( HttpRequest &  request)
private

Add an invertor action

a form

second page doing the action and redirecting

validation

Definition at line 195 of file invertorscontroller.cpp.

195  {
196  QByteArray action = request.getParameter("action");
198  write(QString("<h2>%1</h2>\n").arg(tr("Add an invertor")));
199  write("<form method=\"post\">\n"
200  "<input type=\"hidden\" name=\"action\" value=\"add2\" />\n");
201  DBT_INVERTORS invertor;
202  readForm(invertor, request);
203  write("<table class=\"formTable\">");
204  write(getEditFormContents(request));
205  write("</table>");
206  write(QString("<input type=\"submit\" value=\"%1\">\n"
207  "</form>\n").arg(tr("Add")));
208  if(action == "add2") {
210  invertor.invertor = 0;
212  if(true) {
213  emit saveInvertor(invertor);
214  QString location = QString("/invertors?message=%1").arg(percentEncode(tr("Invertor added.")));
215  redirect(location);
216  } else {
217  write(QString("<p>%1</p>").arg(tr("Invertor definition invalid (not added).")));
218  }
219  }
220 }
static QString getEditFormContents(HttpRequest &request, DBT_INVERTORS line=DBT_INVERTORS(), bool generator=false)
static void readForm(DBT_INVERTORS &invertor, HttpRequest &request)
Class describing database table INVERTORS.
void InvertorsController::actionDelete ( HttpRequest &  request)
private

Delete invertor action

Definition at line 271 of file invertorscontroller.cpp.

271  {
272  write(QString("<h2>%1</h2>\n").arg(tr("Delete an invertor")));
273  QString location;
274  QByteArray id = request.getParameter("id");
275  int idi = id.toInt();
276  if(!id.isEmpty() && idi > 0) {
277  emit deleteInvertor(idi);
278  location = QString("/invertors?message=%1").arg(percentEncode(tr("Invertor deleted.")));
279  } else {
280  location = QString("/invertors?message=%1").arg(percentEncode(tr("Error: Invalid invertor ID. Invertor not deleted.")));
281  }
282  redirect(location);
283 }
void InvertorsController::actionEdit ( HttpRequest &  request)
private

Edit invertor action

a form

second page doing the action and redirecting validation

Definition at line 225 of file invertorscontroller.cpp.

225  {
226  QByteArray action = request.getParameter("action");
227  DBT_INVERTORS invertor;
229  write(QString("<h2>%1</h2>\n").arg(tr("Edit an invertor")));
230  write("<form method=\"post\">\n"
231  "<input type=\"hidden\" name=\"action\" value=\"edit2\" />\n");
232  if(action == "edit") {
233  QByteArray id = request.getParameter("id");
234  int idi = id.toInt();
235  if(id.isEmpty() || idi < 1) {
236  redirect(QString("/invertors?message=%1").arg(percentEncode(tr("Error: Invalid invertor ID."))));
237  return;
238  }
239  QList<DBT_INVERTORS> invertors = Static::db->invertors(QList<int>() << idi);
240  if(invertors.empty()) {
241  redirect(QString("/invertors?message=%1").arg(percentEncode(tr("Error: no such invertor found."))));
242  return;
243  }
244  write("<table class=\"formTable\">");
245  write(getEditFormContents(request, invertors.at(0)));
246  write("</table>");
247  } else {
248  readForm(invertor, request);
249  write("<table class=\"formTable\">");
250  write(getEditFormContents(request, invertor));
251  write("</table>");
252  }
253  write(QString("<input type=\"submit\" value=\"%1\">\n"
254  "</form>\n").arg(tr("Edit")));
255  if(action == "edit2") {
258  if(invertor.invertor > 0 && true) {
259  emit saveInvertor(invertor);
260  QString location = QString("/invertors?message=%1").arg(percentEncode(tr("Invertor edited.")));
261  redirect(location);
262  } else {
263  write(QString("<p>%1</p>").arg(tr("Error: Invertor definition invalid (not edited).")));
264  }
265  }
266 }
QList< DBT_INVERTORS > invertors(int line=0)
Returns list of invertors filtered by line number.
Definition: database.cpp:411
static QString getEditFormContents(HttpRequest &request, DBT_INVERTORS line=DBT_INVERTORS(), bool generator=false)
static void readForm(DBT_INVERTORS &invertor, HttpRequest &request)
Class describing database table INVERTORS.
QString InvertorsController::getEditFormContents ( HttpRequest &  request,
DBT_INVERTORS  line = DBT_INVERTORS(),
bool  generator = false 
)
static

Generates an edit form contents (html input fields)

Definition at line 109 of file invertorscontroller.cpp.

109  {
110  QString s;
111  if(generator) {
112  // number of invertors textbox
113  QString iii ("<tr><td><label for=\"%2\">%1</label>: </td><td><input type=\"%3\" name=\"%2\" %4 /></td></tr>\n");
114  QByteArray gener = request.getParameter("generate");
115  int gen = (gener.isEmpty()) ? 0 : gener.toInt();
116  s.append(iii.arg(tr("Number of invertors"), "generate", "text", QString("value=\"%1\"").arg(gen)));
117  }
118  s.append(QString("<input type=\"hidden\" name=\"id\" value=\"%1\" />\n").arg(invertor.invertor));
119  QString i ("<tr><td><label for=\"%2\">%1</label>: </td><td><input type=\"text\" name=\"%2\" value=\"%3\" /></td></tr>\n");
120  if(!generator) {
121  s.append(i.arg(tr("Description"), "idescription").arg(invertor.description));
122  // line selectbox
123  QList<DBT_LINES> lines = Static::db->lines();
124  s.append(QString("<tr><td><label for=\"%2\">%1</label>: </td><td><select id=\"%2\" name=\"%2\">\n").arg(tr("Line"), "line"));
125  QList<DBT_LINES>::const_iterator ii;
126  for(ii = lines.constBegin(); ii != lines.constEnd(); ++ii) {
127  const DBT_LINES& l = *ii;
128  s.append(QString("<option value=\"%1\" %4>%1 %2 %3</option>\n")
129  .arg(l.line).arg(l.device, l.description,
130  (l.line == invertor.line) ? "selected=\"selected\"" : ""));
131  }
132  s.append("</select></td></tr>\n");
133 
134  s.append(i.arg(tr("Address (sensors +1000)"), "address").arg(invertor.address));
135  } else {
136  s.append(i.arg(tr("First invertor address"), "address").arg(invertor.address));
137  }
138  i = QString("<tr><td><label for=\"%2\">%1</label>: </td><td><input type=\"checkbox\" name=\"%2\" id=\"%2\" %3 /></td></tr>\n");
139  s.append(i.arg(tr("Now Power"), "now_power").arg((invertor.now_power) ? "checked=\"checked\"" : ""));
140  s.append(i.arg(tr("Now AC Current"), "now_ac_current").arg((invertor.now_ac_current) ? "checked=\"checked\"" : ""));
141  s.append(i.arg(tr("Now AC Voltage"), "now_ac_voltage").arg((invertor.now_ac_voltage) ? "checked=\"checked\"" : ""));
142  s.append(i.arg(tr("Now AC Frequency"), "now_ac_frequency").arg((invertor.now_ac_frequency) ? "checked=\"checked\"" : ""));
143  s.append(i.arg(tr("Now DC Current"), "now_dc_current").arg((invertor.now_dc_current) ? "checked=\"checked\"" : ""));
144  s.append(i.arg(tr("Now DC Voltage"), "now_dc_voltage").arg((invertor.now_dc_voltage) ? "checked=\"checked\"" : ""));
145  s.append(i.arg(tr("Day Energy"), "day_energy").arg((invertor.day_energy) ? "checked=\"checked\"" : ""));
146  s.append(i.arg(tr("Day Power Maximum"), "day_power_maximum").arg((invertor.day_power_maximum) ? "checked=\"checked\"" : ""));
147  s.append(i.arg(tr("Day AC Voltage Maximum"), "day_ac_voltage_maximum").arg((invertor.day_ac_voltage_maximum) ? "checked=\"checked\"" : ""));
148  s.append(i.arg(tr("Day AC Voltage Minimum"), "day_ac_voltage_minimum").arg((invertor.day_ac_voltage_minimum) ? "checked=\"checked\"" : ""));
149  s.append(i.arg(tr("Day DC Voltage Maximum"), "day_dc_voltage_maximum").arg((invertor.day_dc_voltage_maximum) ? "checked=\"checked\"" : ""));
150  s.append(i.arg(tr("Day Operating Hours"), "day_operating_hours").arg((invertor.day_operating_hours) ? "checked=\"checked\"" : ""));
151  s.append(i.arg(tr("Total Energy"), "total_energy").arg((invertor.total_energy) ? "checked=\"checked\"" : ""));
152  s.append(i.arg(tr("Total Power Maximum"), "total_power_maximum").arg((invertor.total_power_maximum) ? "checked=\"checked\"" : ""));
153  s.append(i.arg(tr("Total AC Voltage Maximum"), "total_ac_voltage_maximum").arg((invertor.total_ac_voltage_maximum) ? "checked=\"checked\"" : ""));
154  s.append(i.arg(tr("Total AC Voltage Minimum"), "total_ac_voltage_minimum").arg((invertor.total_ac_voltage_minimum) ? "checked=\"checked\"" : ""));
155  s.append(i.arg(tr("Total DC Voltage Maximum"), "total_dc_voltage_maximum").arg((invertor.total_dc_voltage_maximum) ? "checked=\"checked\"" : ""));
156  s.append(i.arg(tr("Total Operating Hours"), "total_operating_hours").arg((invertor.total_operating_hours) ? "checked=\"checked\"" : ""));
157  s.append(i.arg(tr("Temperature ch. 1"), "temperature_1").arg((invertor.temperature_1) ? "checked=\"checked\"" : ""));
158  s.append(i.arg(tr("Temperature ch. 2"), "temperature_2").arg((invertor.temperature_2) ? "checked=\"checked\"" : ""));
159  s.append(i.arg(tr("Irradiance"), "irradiance").arg((invertor.irradiance) ? "checked=\"checked\"" : ""));
160 
161  return s;
162 }
QList< DBT_LINES > lines(int line=0)
Returns list of communications lines.
Definition: database.cpp:380
Class describing database table LINES.
void InvertorsController::readForm ( DBT_INVERTORS invertor,
HttpRequest &  request 
)
static

Read form HTTP post reply and load into the invertor

Definition at line 164 of file invertorscontroller.cpp.

164  {
165  invertor.invertor = request.getParameter("id").toInt();
166  invertor.description = request.getParameter("idescription");
167  invertor.line = request.getParameter("line").toInt();
168  invertor.address = request.getParameter("address").toInt();
169  invertor.now_power = !request.getParameter("now_power").isEmpty();
170  invertor.now_ac_current = !request.getParameter("now_ac_current").isEmpty();
171  invertor.now_ac_voltage = !request.getParameter("now_ac_voltage").isEmpty();
172  invertor.now_ac_frequency = !request.getParameter("now_ac_frequency").isEmpty();
173  invertor.now_dc_current = !request.getParameter("now_dc_current").isEmpty();
174  invertor.now_dc_voltage = !request.getParameter("now_dc_voltage").isEmpty();
175  invertor.day_energy = !request.getParameter("day_energy").isEmpty();
176  invertor.day_power_maximum = !request.getParameter("day_power_maximum").isEmpty();
177  invertor.day_ac_voltage_maximum = !request.getParameter("day_ac_voltage_maximum").isEmpty();
178  invertor.day_ac_voltage_minimum = !request.getParameter("day_ac_voltage_minimum").isEmpty();
179  invertor.day_dc_voltage_maximum = !request.getParameter("day_dc_voltage_maximum").isEmpty();
180  invertor.day_operating_hours = !request.getParameter("day_operating_hours").isEmpty();
181  invertor.total_energy = !request.getParameter("total_energy").isEmpty();
182  invertor.total_power_maximum = !request.getParameter("total_power_maximum").isEmpty();
183  invertor.total_ac_voltage_maximum = !request.getParameter("total_ac_voltage_maximum").isEmpty();
184  invertor.total_ac_voltage_minimum = !request.getParameter("total_ac_voltage_minimum").isEmpty();
185  invertor.total_dc_voltage_maximum = !request.getParameter("total_dc_voltage_maximum").isEmpty();
186  invertor.total_operating_hours = !request.getParameter("total_operating_hours").isEmpty();
187  invertor.temperature_1 = !request.getParameter("temperature_1").isEmpty();
188  invertor.temperature_2 = !request.getParameter("temperature_2").isEmpty();
189  invertor.irradiance = !request.getParameter("irradiance").isEmpty();
190 }
void InvertorsController::servicePrivate ( HttpRequest &  request)
virtual

Generates the response

Default action/page

Implements WebPage.

Definition at line 18 of file invertorscontroller.cpp.

18  {
19  QByteArray action = request.getParameter("action");
20  if(action.startsWith("add")) {
21  actionAdd(request); return;
22  } else if(action.startsWith("edit")) {
23  actionEdit(request); return;
24  } else if(action.startsWith("delete")) {
25  actionDelete(request); return;
26  }
27 
30  QList<DBT_INVERTORS> invertors = Static::db->invertors();
31  write(QString("<h2>%1</h2>\n").arg(tr("Invertors")));
32  write(QString("<a href=\"/invertors?action=add\">%1</a>\n").arg(tr("Add an invertor")));
33  write("<table>\n");
34  QString s0 ("<tr class=\"line1st\"><th colspan=\"4\"></th><th colspan=\"6\">%1</th><th colspan=\"6\">%2</th><th colspan=\"6\">%3</th><th colspan=\"3\">%4</th></tr>");
35  s0 = s0.arg(tr("Now"), tr("Day"), tr("Total"), tr("Sensors"));
36  QString s ("<tr class=\"line2nd\"><th></th>"
37  "<th>%1</th>"
38  "<th>%2</th>"
39  "<th>%3</th>"
40  "<th class=\"group\">%4</th>"
41  "<th>AC [V]</th>"
42  "<th>AC [A]</th>"
43  "<th>AC [Hz]</th>"
44  "<th>DC [V]</th>"
45  "<th>DC [A]</th>"
46  "<th class=\"group\">%5</th>"
47  "<th>%6</th>"
48  "<th>AC max [V]</th>"
49  "<th>AC min [V]</th>"
50  "<th>DC max [V]</th>"
51  "<th>%7</th>"
52  "<th class=\"group\">%5</th>"
53  "<th>%6</th>"
54  "<th>AC max [V]</th>"
55  "<th>AC min [V]</th>"
56  "<th>DC max [V]</th>"
57  "<th>%7</th>"
58  "<th class=\"group\">T1 [&#176;C]</th>"
59  "<th>T2 [&#176;C]</th>"
60  "<th>Irr [W/m&#179;]</th>"
61  "</tr>");
62  s = s.arg(tr("Description"), tr("Line"), tr("Addr"), tr("Pwr [W]"), tr("Energy"), tr("Pwr max [W]"), tr("Hours"));
63  write(s0);
64  write(s);
65 
66  QString s2 ("<tr>"
67  "<td>"
68  "<a href=\"/invertors?action=edit&id=%1\">%26</a> "
69  "<a href=\"/invertors?action=delete&id=%1\">%27</a>"
70  "</td>");
71  for(int k = 2; k <= 25; k++)
72  s2.append(QString("<td>\%%1</td>").arg(k));
73  s2.append("</tr>\n");
74  QList<DBT_INVERTORS>::const_iterator i;
75  for(i = invertors.constBegin(); i != invertors.constEnd(); ++i) {
76  const DBT_INVERTORS& l = *i;
77  write(QString(s2)
78  .arg(l.invertor)
79  .arg(l.description)
80  .arg(l.line)
81  .arg(l.address)
82  .arg((l.now_power) ? "&#x2713;" : "")
83  .arg((l.now_ac_current) ? "&#x2713;" : "")
84  .arg((l.now_ac_voltage) ? "&#x2713;" : "")
85  .arg((l.now_ac_frequency) ? "&#x2713;" : "")
86  .arg((l.now_dc_current) ? "&#x2713;" : "")
87  .arg((l.now_dc_voltage) ? "&#x2713;" : "")
88  .arg((l.day_energy) ? "&#x2713;" : "")
89  .arg((l.day_power_maximum) ? "&#x2713;" : "")
90  .arg((l.day_ac_voltage_maximum) ? "&#x2713;" : "")
91  .arg((l.day_ac_voltage_minimum) ? "&#x2713;" : "")
92  .arg((l.day_dc_voltage_maximum) ? "&#x2713;" : "")
93  .arg((l.day_operating_hours) ? "&#x2713;" : "")
94  .arg((l.total_energy) ? "&#x2713;" : "")
95  .arg((l.total_power_maximum) ? "&#x2713;" : "")
96  .arg((l.total_ac_voltage_maximum) ? "&#x2713;" : "")
97  .arg((l.total_ac_voltage_minimum) ? "&#x2713;" : "")
98  .arg((l.total_dc_voltage_maximum) ? "&#x2713;" : "")
99  .arg((l.total_operating_hours) ? "&#x2713;" : "")
100  .arg((l.temperature_1) ? "&#x2713;" : "")
101  .arg((l.temperature_2) ? "&#x2713;" : "")
102  .arg((l.irradiance) ? "&#x2713;" : "")
103  .arg(tr("Edit"), tr("Delete")));
104  }
105 
106  write("</table>\n");
107 }
void actionDelete(HttpRequest &request)
void actionEdit(HttpRequest &request)
QList< DBT_INVERTORS > invertors(int line=0)
Returns list of invertors filtered by line number.
Definition: database.cpp:411
void actionAdd(HttpRequest &request)
Class describing database table INVERTORS.

The documentation for this class was generated from the following files: