@ -7,6 +7,7 @@ import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant ;
import com.vaadin.flow.component.combobox.ComboBox ;
import com.vaadin.flow.component.html.H2 ;
import com.vaadin.flow.component.html.Span ;
import com.vaadin.flow.component.notification.Notification ;
import com.vaadin.flow.component.notification.NotificationVariant ;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout ;
@ -43,12 +44,14 @@ public class CrearnuevoTicketView extends VerticalLayout {
private MultiFileMemoryBuffer buffer ;
private Upload uploadFile ;
private String selectedTrackerId ;
private Span ticketTypeDesc ;
public CrearnuevoTicketView ( RedmineClient api , UserService service ) {
this . api = api ;
this . userService = service ;
this . buffer = new MultiFileMemoryBuffer ( ) ;
this . uploadFile = createUploadComponent ( ) ;
this . ticketTypeDesc = new Span ( ) ;
RedmineUser user = userService . getRedmineUser ( ) ;
@ -66,7 +69,7 @@ public class CrearnuevoTicketView extends VerticalLayout {
Button createButton = new Button ( "Enviar ticket" , event - > handleCreateButton ( user , tipoTickets , asunto , descripcion ) ) ;
createButton . addThemeVariants ( ButtonVariant . LUMO_PRIMARY , ButtonVariant . LUMO_LARGE ) ;
VerticalLayout fieldsLayout = new VerticalLayout ( descripcion , uploadFile ) ;
VerticalLayout fieldsLayout = new VerticalLayout ( descripcion , uploadFile , ticketTypeDesc ) ;
fieldsLayout . setAlignItems ( Alignment . CENTER ) ;
HorizontalLayout firstFields = new HorizontalLayout ( tipoTickets , asunto ) ;
VerticalLayout buttonLayout = new VerticalLayout ( createButton ) ;
@ -110,7 +113,7 @@ public class CrearnuevoTicketView extends VerticalLayout {
ComboBox < String > tipoTickets = new ComboBox < > ( "Tipo de ticket" ) ;
tipoTickets . setPlaceholder ( "Seleccione un tipo de ticket" ) ;
Map < String , String > ticketTypesMap = api . getTicketTypes ( ) ;
Map < String , RedmineClient . TicketType > ticketTypesMap = api . getTicketTypes ( ) ;
Set < String > ticketTypesSet = Set . of ( "Acceso/Permiso/Bajas" , "Soporte de Software" , "Capacitacion de Software" ,
"Configuracion de Software" , "Digitalizacion GIS" , "Documento" , "Funcionalidad" , "Reporte" ,
"Soporte o Mantenimiento" ) ;
@ -118,7 +121,13 @@ public class CrearnuevoTicketView extends VerticalLayout {
. filter ( ticketTypesSet : : contains )
. collect ( Collectors . toList ( ) ) ;
tipoTickets . setItems ( filteredTicketTypes ) ;
tipoTickets . addValueChangeListener ( event - > selectedTrackerId = ticketTypesMap . get ( event . getValue ( ) ) ) ;
tipoTickets . addValueChangeListener ( event - > {
String selectedType = event . getValue ( ) ;
RedmineClient . TicketType ticketType = ticketTypesMap . get ( selectedType ) ;
ticketTypeDesc . setText ( ticketType ! = null ? ticketType . getDescription ( ) : "Descripcion no disponible para este tipo de ticket" ) ;
selectedTrackerId = ticketType ! = null ? ticketType . getId ( ) : null ;
} ) ;
return tipoTickets ;
}
@ -135,6 +144,7 @@ public class CrearnuevoTicketView extends VerticalLayout {
return textArea ;
}
private void handleFileUpload ( String fileName ) {
try ( InputStream inputStream = buffer . getInputStream ( fileName ) ;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ) {
@ -218,6 +228,7 @@ public class CrearnuevoTicketView extends VerticalLayout {
asunto . clear ( ) ;
descripcion . clear ( ) ;
tipoTickets . clear ( ) ;
ticketTypeDesc . setText ( "" ) ;
asunto . setInvalid ( false ) ;
descripcion . setInvalid ( false ) ;