From 73afdff925decf89d62af8ead1e411c1b9adc5fc Mon Sep 17 00:00:00 2001 From: "Eduardo L. Buratti" <elb09@c3sl.ufpr.br> Date: Mon, 17 Mar 2014 11:57:18 -0300 Subject: [PATCH] Add error messages to install view Signed-off-by: Eduardo L. Buratti <elb09@c3sl.ufpr.br> --- web/app/controllers/Install.java | 32 +++++++++++------- web/app/views/install/index.scala.html | 45 +++++++++++++++++++++++--- web/conf/routes | 2 +- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/web/app/controllers/Install.java b/web/app/controllers/Install.java index b54f978..05bf1b9 100644 --- a/web/app/controllers/Install.java +++ b/web/app/controllers/Install.java @@ -5,8 +5,6 @@ import java.util.ArrayList; import java.awt.*; -import javax.swing.JOptionPane; - import play.*; import play.mvc.*; import play.data.*; @@ -20,7 +18,7 @@ public class Install extends Controller { private static String MAKE_OUTPUT_DIR = "/tmp/"; public static Result index() { - return ok(views.html.install.index.render()); + return ok(views.html.install.index.render(null,null,false,null,null,null,null,true)); } public static Result makePackage() { @@ -36,9 +34,23 @@ public class Install extends Controller { String proxyUser = requestData.get("proxyUser"); String proxyPass = requestData.get("proxyPass"); + String osStr = requestData.get("os"); + boolean osLinux = false; + if (osStr.equals("true")) osLinux = true; + + if (!osLinux) { + return ok(views.html.install.index.render( + "O pacote de instalação para Windows está temporariamente indisponível.", + inep, useProxy, + proxyHost, proxyPort, proxyUser, proxyPass, + osLinux)); + } + if ((inep == null) || (inep.length() < 6) || (inep.length() > 12)) { - JOptionPane.showMessageDialog(null, "Inep Inválido", "INEP", JOptionPane.ERROR_MESSAGE); - return ok(views.html.install.index.render()); + return ok(views.html.install.index.render( + "INEP inválido!", inep, useProxy, + proxyHost, proxyPort, proxyUser, proxyPass, + osLinux)); } School school = null; @@ -52,15 +64,13 @@ public class Install extends Controller { } if (school == null) { - JOptionPane.showMessageDialog(null, "Inep Inválido", "INEP", JOptionPane.ERROR_MESSAGE); - return ok(views.html.install.index.render()); + return ok(views.html.install.index.render( + "INEP não encontrado na base de dados!", inep, useProxy, + proxyHost, proxyPort, proxyUser, proxyPass, + osLinux)); } - // build the package - String osStr = requestData.get("os"); - boolean osLinux = false; - if (osStr.equals("true")) osLinux = true; String command = ""; if (osLinux) command = "sh " + MAKE_PACKAGE_BIN_L + " " + inep; diff --git a/web/app/views/install/index.scala.html b/web/app/views/install/index.scala.html index 04bb303..97999a8 100644 --- a/web/app/views/install/index.scala.html +++ b/web/app/views/install/index.scala.html @@ -1,6 +1,40 @@ +@(error: String = "", + inep: String = "", + useProxy: Boolean = false, + proxyHost: String = "", + proxyPort: String = "", + proxyUser: String = "", + proxyPass: String = "", + useLinux: Boolean = true) + @scripts = { <script> (function ($) { + @if(useProxy) { + $('#useProxy').prop('checked', true); + $('#dontUseProxy').prop('checked', false); + $('.proxy').each(function () { + $(this).show(); + }); + } else { + $('#useProxy').prop('checked', false); + $('#dontUseProxy').prop('checked', true); + $('.proxy').each(function () { + $(this).hide(); + }); + } + + @if(useLinux) { + $('#useLinux').prop('checked', true); + $('#dontUseLinux').prop('checked', false); + } + + $('#inep').val("@inep"); + $('#proxyHost').val("@proxyHost"); + $('#proxyPort').val("@proxyPort"); + $('#proxyUser').val("@proxyUser"); + $('#proxyPass').val("@proxyPass"); + $('#useProxy').click(function (){ $('.proxy').each(function () { $(this).show(); @@ -12,10 +46,6 @@ $(this).hide(); }); }); - - $('.proxy').each(function () { - $(this).hide(); - }); })( jQuery ); </script> } @@ -37,6 +67,13 @@ para maiores detalhes. <div class="row-fluid main-row"> <form class="span8 offset2" action="@routes.Install.makePackage()" method="POST"> + @if(error && (!error.isEmpty())) { + <div class="alert alert-error"> + <b>Erro:</b> + @error + </div> + } + <div class="well form-horizontal"> <div class="control-group"> <label class="control-label" for="inep">INEP:</label> diff --git a/web/conf/routes b/web/conf/routes index 9b87e3d..17c5a05 100644 --- a/web/conf/routes +++ b/web/conf/routes @@ -8,7 +8,7 @@ GET / controllers.Application.index() GET /doc/ controllers.Doc.index() GET /install/ controllers.Install.index() -POST /install/make/ controllers.Install.makePackage() +POST /install/ controllers.Install.makePackage() GET /attendance/ controllers.Attendance.index() -- GitLab