Search in sources :

Example 1 with SpeakerListEntity

use of org.komunumo.data.entity.SpeakerListEntity in project komunumo-server by komunumo.

the class SpeakersView method configureGrid.

private void configureGrid() {
    grid.setSelectionMode(Grid.SelectionMode.NONE);
    grid.addThemeVariants(GridVariant.LUMO_NO_BORDER, GridVariant.LUMO_ROW_STRIPES);
    grid.addColumn(LitRenderer.<SpeakerListEntity>of("<span style=\"font-weight: bold;\">${item.fullName}</span><br/>" + "<a href=\"${item.website}\" target=\"_blank\" title=\"${item.title}\">${item.company}</a>").withProperty("fullName", SpeakerListEntity::fullName).withProperty("company", speakerListEntity -> FormatterUtil.formatString(speakerListEntity.company(), 50)).withProperty("title", SpeakerListEntity::company).withProperty("website", SpeakerListEntity::website)).setHeader("Name & Company").setAutoWidth(true).setFlexGrow(1);
    grid.addColumn(LitRenderer.<SpeakerListEntity>of("<a href=\"mailto:${item.email}\" target=\"_blank\">${item.email}</a>").withProperty("email", SpeakerListEntity::email)).setHeader("Email").setAutoWidth(true).setFlexGrow(0).setKey("email");
    grid.addColumn(LitRenderer.<SpeakerListEntity>of("<a href=\"https://twitter.com/${item.twitter}\" target=\"_blank\" title=\"${item.twitter}\">${item.twitter}</a>").withProperty("twitter", SpeakerListEntity::twitter)).setHeader("Twitter").setAutoWidth(true).setFlexGrow(0).setKey("twitter");
    final var eventCountRenderer = LitRenderer.<SpeakerListEntity>of("<a href=\"/admin/events?filter=${item.filterValue}\">${item.eventCount}</a>").withProperty("eventCount", SpeakerListEntity::eventCount).withProperty("filterValue", speakerListEntity -> URLEncoder.encode(speakerListEntity.fullName(), UTF_8));
    grid.addColumn(eventCountRenderer).setHeader("Events").setAutoWidth(true).setTextAlign(ColumnTextAlign.CENTER).setFlexGrow(0);
    grid.addColumn(new ComponentRenderer<>(speakerListEntity -> {
        final var editButton = new EnhancedButton(new Icon(VaadinIcon.EDIT), clickEvent -> showSpeakerDialog(speakerListEntity));
        editButton.setTitle("Edit this speaker");
        final var deleteButton = new EnhancedButton(new Icon(VaadinIcon.TRASH), clickEvent -> deleteSpeaker(speakerListEntity));
        deleteButton.setTitle("Delete this speaker");
        deleteButton.setEnabled(speakerListEntity.eventCount() == 0);
        return new HorizontalLayout(editButton, deleteButton);
    })).setHeader("Actions").setAutoWidth(true).setFlexGrow(0);
    grid.setHeightFull();
}
Also used : EnhancedButton(org.komunumo.ui.component.EnhancedButton) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) SpeakerListEntity(org.komunumo.data.entity.SpeakerListEntity) Icon(com.vaadin.flow.component.icon.Icon) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Example 2 with SpeakerListEntity

use of org.komunumo.data.entity.SpeakerListEntity in project komunumo-server by komunumo.

the class SpeakersView method downloadSpeakers.

private void downloadSpeakers() {
    final var resource = new StreamResource("speakers.csv", () -> {
        final var stringWriter = new StringWriter();
        final var csvWriter = new CSVWriter(stringWriter);
        csvWriter.writeNext(new String[] { "ID", "First name", "Last name", "Company", "Email", "Twitter", "Website", "Event count" });
        grid.getGenericDataView().getItems().map(speakerListEntity -> new String[] { speakerListEntity.id().toString(), speakerListEntity.firstName(), speakerListEntity.lastName(), speakerListEntity.company(), speakerListEntity.email(), speakerListEntity.twitter(), speakerListEntity.website(), speakerListEntity.eventCount().toString() }).forEach(csvWriter::writeNext);
        return new ByteArrayInputStream(stringWriter.toString().getBytes(UTF_8));
    });
    final StreamRegistration registration = VaadinSession.getCurrent().getResourceRegistry().registerResource(resource);
    UI.getCurrent().getPage().setLocation(registration.getResourceUri());
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) HasUrlParameter(com.vaadin.flow.router.HasUrlParameter) AdminLayout(org.komunumo.ui.view.admin.AdminLayout) RolesAllowed(javax.annotation.security.RolesAllowed) CssImport(com.vaadin.flow.component.dependency.CssImport) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) EnhancedButton(org.komunumo.ui.component.EnhancedButton) PageTitle(com.vaadin.flow.router.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Route(com.vaadin.flow.router.Route) ByteArrayInputStream(java.io.ByteArrayInputStream) UI(com.vaadin.flow.component.UI) ResizableView(org.komunumo.ui.component.ResizableView) Icon(com.vaadin.flow.component.icon.Icon) TextField(com.vaadin.flow.component.textfield.TextField) StreamRegistration(com.vaadin.flow.server.StreamRegistration) Role(org.komunumo.data.entity.Role) FormatterUtil(org.komunumo.util.FormatterUtil) VaadinSession(com.vaadin.flow.server.VaadinSession) Serial(java.io.Serial) Grid(com.vaadin.flow.component.grid.Grid) GridVariant(com.vaadin.flow.component.grid.GridVariant) LitRenderer(com.vaadin.flow.data.renderer.LitRenderer) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StringWriter(java.io.StringWriter) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) CSVWriter(com.opencsv.CSVWriter) SpeakerListEntity(org.komunumo.data.entity.SpeakerListEntity) OptionalParameter(com.vaadin.flow.router.OptionalParameter) Nullable(org.jetbrains.annotations.Nullable) DatabaseService(org.komunumo.data.service.DatabaseService) URLEncoder(java.net.URLEncoder) List(java.util.List) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) StreamResource(com.vaadin.flow.server.StreamResource) ConfirmDialog(com.vaadin.flow.component.confirmdialog.ConfirmDialog) NotNull(org.jetbrains.annotations.NotNull) FilterField(org.komunumo.ui.component.FilterField) StreamResource(com.vaadin.flow.server.StreamResource) StringWriter(java.io.StringWriter) StreamRegistration(com.vaadin.flow.server.StreamRegistration) ByteArrayInputStream(java.io.ByteArrayInputStream) CSVWriter(com.opencsv.CSVWriter)

Aggregations

Icon (com.vaadin.flow.component.icon.Icon)2 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)2 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)2 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)2 SpeakerListEntity (org.komunumo.data.entity.SpeakerListEntity)2 EnhancedButton (org.komunumo.ui.component.EnhancedButton)2 CSVWriter (com.opencsv.CSVWriter)1 UI (com.vaadin.flow.component.UI)1 ConfirmDialog (com.vaadin.flow.component.confirmdialog.ConfirmDialog)1 CssImport (com.vaadin.flow.component.dependency.CssImport)1 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)1 Grid (com.vaadin.flow.component.grid.Grid)1 GridVariant (com.vaadin.flow.component.grid.GridVariant)1 TextField (com.vaadin.flow.component.textfield.TextField)1 LitRenderer (com.vaadin.flow.data.renderer.LitRenderer)1 BeforeEvent (com.vaadin.flow.router.BeforeEvent)1 HasUrlParameter (com.vaadin.flow.router.HasUrlParameter)1 OptionalParameter (com.vaadin.flow.router.OptionalParameter)1 PageTitle (com.vaadin.flow.router.PageTitle)1 Route (com.vaadin.flow.router.Route)1