|
|
@ -60,18 +60,21 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
|
|
|
|
//Componentes principales de la UI |
|
|
|
ComboBox<String> tipoTickets = createTicketTypeComboBox(); |
|
|
|
TextField asunto = createTextField("Asunto", "1000px"); |
|
|
|
RichTextEditor descripcion = createTextArea("Descripcion", "1000px", "250px"); |
|
|
|
TextField asunto = createTextField("Asunto"); |
|
|
|
TextField area = createTextField("Area"); |
|
|
|
RichTextEditor descripcion = createTextArea("Descripcion"); |
|
|
|
|
|
|
|
// Marcar campos como obligatorios |
|
|
|
tipoTickets.setRequiredIndicatorVisible(true); |
|
|
|
asunto.setRequiredIndicatorVisible(true); |
|
|
|
area.setRequiredIndicatorVisible(true); |
|
|
|
area.setPlaceholder("Dinos a que área perteneces para poder ubicarte más pronto!!"); |
|
|
|
descripcion.setRequiredIndicatorVisible(true); |
|
|
|
|
|
|
|
uploadFile.addSucceededListener(event -> handleFileUpload(event.getFileName())); |
|
|
|
|
|
|
|
//Configuracion del Boton |
|
|
|
Button createButton = new Button("Enviar ticket", event -> handleCreateButton(user, tipoTickets, asunto, descripcion)); |
|
|
|
Button createButton = new Button("Enviar ticket", event -> handleCreateButton(user, tipoTickets, asunto, area, descripcion)); |
|
|
|
createButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY, ButtonVariant.LUMO_LARGE); |
|
|
|
|
|
|
|
uploadFile.addSucceededListener(event -> { |
|
|
@ -95,9 +98,12 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
//Alineacion de los componentes ComboBox Tipos de tickets y Descripcion del tipo de ticket |
|
|
|
HorizontalLayout firstFields = new HorizontalLayout(tipoTickets, ticketTypeDesc); |
|
|
|
|
|
|
|
// Alineacion de los campos para el asunto y el autor |
|
|
|
HorizontalLayout secondFields = new HorizontalLayout(asunto, area); |
|
|
|
secondFields.setSizeFull(); |
|
|
|
|
|
|
|
//Alineacion de los componentes de asunto y descripcion |
|
|
|
VerticalLayout fieldsLayout = new VerticalLayout(asunto, descripcion); |
|
|
|
//Alineacion de los componentes de descripcion |
|
|
|
VerticalLayout fieldsLayout = new VerticalLayout(descripcion); |
|
|
|
fieldsLayout.setAlignItems(Alignment.START); |
|
|
|
|
|
|
|
|
|
|
@ -115,7 +121,8 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add(new H2("Crear nuevo ticket"), firstFields, fieldsLayout, buttonLayout); |
|
|
|
// Agregar layouts a la interfaz de usuario |
|
|
|
add(new H2("Crear nuevo ticket"), firstFields, secondFields, fieldsLayout, buttonLayout); |
|
|
|
} |
|
|
|
|
|
|
|
private Upload createUploadComponent() { |
|
|
@ -169,13 +176,13 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
return tipoTickets; |
|
|
|
} |
|
|
|
|
|
|
|
private TextField createTextField(String label, String width) { |
|
|
|
private TextField createTextField(String label) { |
|
|
|
TextField textField = new TextField(label); |
|
|
|
textField.setSizeFull(); |
|
|
|
return textField; |
|
|
|
} |
|
|
|
|
|
|
|
private RichTextEditor createTextArea(String label, String width, String height) { |
|
|
|
private RichTextEditor createTextArea(String label) { |
|
|
|
RichTextEditor textArea = new RichTextEditor(); |
|
|
|
textArea.setSizeFull(); |
|
|
|
textArea.setMaxHeight("200px"); |
|
|
@ -198,7 +205,7 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void handleCreateButton(RedmineUser user, ComboBox<String> tipoTickets, TextField asunto, RichTextEditor descripcion) { |
|
|
|
private void handleCreateButton(RedmineUser user, ComboBox<String> tipoTickets, TextField asunto, TextField area, RichTextEditor descripcion) { |
|
|
|
if (user.getKey() == null || user.getKey().isEmpty()) { |
|
|
|
Notification.show("No se encontró la API key en la sesión.", 5000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
@ -223,10 +230,18 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (area.isEmpty()) { |
|
|
|
Notification.show("Especifica tu área, por favor!!", 3000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_WARNING); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, String> issueDetails = new HashMap<>(); |
|
|
|
issueDetails.put("project_id", "soporte-tecnico-t-i"); |
|
|
|
issueDetails.put("subject", asunto.getValue()); |
|
|
|
issueDetails.put("description", descripcion.getValue()); |
|
|
|
String areaValue = area.getValue().trim(); |
|
|
|
String descriptionCompleta = descripcion.getValue() + ("Area: " + areaValue + "\n\n"); // Concatenamos el valor del campo Area a la descripcion del ticket |
|
|
|
issueDetails.put("description", descriptionCompleta); |
|
|
|
issueDetails.put("tracker_id", selectedTrackerId); |
|
|
|
|
|
|
|
JsonArray uploadsJsonArray = new JsonArray(); |
|
|
@ -248,24 +263,25 @@ public class CrearnuevoTicketView extends VerticalLayout { |
|
|
|
} |
|
|
|
|
|
|
|
String response = api.createIssue(issueDetails, uploadsJsonArray, user.getKey()); |
|
|
|
handleResponse(response, asunto, descripcion, tipoTickets); |
|
|
|
handleResponse(response, asunto, area, descripcion, tipoTickets); |
|
|
|
} |
|
|
|
|
|
|
|
private void handleResponse(String response, TextField asunto, RichTextEditor descripcion, ComboBox<String> tipoTickets) { |
|
|
|
private void handleResponse(String response, TextField asunto, TextField area, RichTextEditor descripcion, ComboBox<String> tipoTickets) { |
|
|
|
if (response.startsWith("{\"issue\":")) { |
|
|
|
JsonObject jsonResponse = JsonParser.parseString(response).getAsJsonObject(); |
|
|
|
int issueNumber = jsonResponse.getAsJsonObject("issue").get("id").getAsInt(); |
|
|
|
Notification.show("Su ticket se ha enviado correctamente! Numero de ticket: #" + issueNumber, 5000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_SUCCESS); |
|
|
|
resetForm(asunto, descripcion, tipoTickets); |
|
|
|
resetForm(asunto, area, descripcion, tipoTickets); |
|
|
|
} else { |
|
|
|
Notification.show("Error al crear el ticket: " + response, 5000, Notification.Position.MIDDLE) |
|
|
|
.addThemeVariants(NotificationVariant.LUMO_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void resetForm(TextField asunto, RichTextEditor descripcion, ComboBox<String> tipoTickets) { |
|
|
|
private void resetForm(TextField asunto, TextField area, RichTextEditor descripcion, ComboBox<String> tipoTickets) { |
|
|
|
asunto.clear(); |
|
|
|
area.clear(); |
|
|
|
descripcion.clear(); |
|
|
|
tipoTickets.clear(); |
|
|
|
ticketTypeDesc.setText(""); |
|
|
|