Search in sources :

Example 1 with FaqRecord

use of org.komunumo.data.db.tables.records.FaqRecord in project komunumo-server by komunumo.

the class FaqDialog method createForm.

@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<FaqRecord> binder) {
    final var question = new TextField("Question");
    question.setRequiredIndicatorVisible(true);
    question.setValueChangeMode(EAGER);
    final var answer = new RichTextEditor();
    answer.setRequiredIndicatorVisible(true);
    formLayout.add(question, new CustomLabel("Answer"), answer);
    binder.forField(question).withValidator(new StringLengthValidator("Please enter the question (max. 255 chars)", 1, 255)).bind(FaqRecord::getQuestion, FaqRecord::setQuestion);
    binder.forField(answer.asHtml()).withValidator(new StringLengthValidator("Please enter the question (max. 255 chars)", 1, 10_000)).bind(FaqRecord::getAnswer, FaqRecord::setAnswer);
}
Also used : CustomLabel(org.komunumo.ui.component.CustomLabel) FaqRecord(org.komunumo.data.db.tables.records.FaqRecord) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) TextField(com.vaadin.flow.component.textfield.TextField) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor)

Example 2 with FaqRecord

use of org.komunumo.data.db.tables.records.FaqRecord in project komunumo-server by komunumo.

the class FaqView method downloadEntries.

private void downloadEntries() {
    final var resource = new StreamResource("faq.csv", () -> {
        final var stringWriter = new StringWriter();
        final var csvWriter = new CSVWriter(stringWriter);
        csvWriter.writeNext(new String[] { "ID", "Question", "Answer" });
        grid.getGenericDataView().getItems().map(faqRecord -> new String[] { faqRecord.getId().toString(), faqRecord.getQuestion(), faqRecord.getAnswer() }).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) 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) 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) VaadinSession(com.vaadin.flow.server.VaadinSession) Grid(com.vaadin.flow.component.grid.Grid) GridVariant(com.vaadin.flow.component.grid.GridVariant) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StringWriter(java.io.StringWriter) VaadinIcon(com.vaadin.flow.component.icon.VaadinIcon) CSVWriter(com.opencsv.CSVWriter) Nullable(org.jetbrains.annotations.Nullable) DatabaseService(org.komunumo.data.service.DatabaseService) FaqRecord(org.komunumo.data.db.tables.records.FaqRecord) 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

TextField (com.vaadin.flow.component.textfield.TextField)2 FaqRecord (org.komunumo.data.db.tables.records.FaqRecord)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 Grid (com.vaadin.flow.component.grid.Grid)1 GridVariant (com.vaadin.flow.component.grid.GridVariant)1 Icon (com.vaadin.flow.component.icon.Icon)1 VaadinIcon (com.vaadin.flow.component.icon.VaadinIcon)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 RichTextEditor (com.vaadin.flow.component.richtexteditor.RichTextEditor)1 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)1 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)1 PageTitle (com.vaadin.flow.router.PageTitle)1 Route (com.vaadin.flow.router.Route)1 StreamRegistration (com.vaadin.flow.server.StreamRegistration)1 StreamResource (com.vaadin.flow.server.StreamResource)1 VaadinSession (com.vaadin.flow.server.VaadinSession)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1