Skip to content

Commit

Permalink
Major updates to layout for all views. Accordion in navbar removed. L…
Browse files Browse the repository at this point in the history
…ogo moved to navbar. Content pane left justified.
  • Loading branch information
pacphi committed Dec 13, 2024
1 parent 1692a9a commit f1b9b33
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.cftoolsuite.client;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -19,11 +17,9 @@ public class SanfordStreamingClient {
private static Logger log = LoggerFactory.getLogger(SanfordStreamingClient.class);

private final WebClient webClient;
private final ObjectMapper mapper;

public SanfordStreamingClient(@Value("${document.service.url}") String baseUrl, ObjectMapper mapper) {
public SanfordStreamingClient(@Value("${document.service.url}") String baseUrl) {
this.webClient = WebClient.create(baseUrl);
this.mapper = mapper;
}

public Flux<String> streamResponseToQuestion(String message, Map<String, Object> filterMetadata) {
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/org/cftoolsuite/ui/MainLayout.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.cftoolsuite.ui;

import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.server.StreamResource;
import org.cftoolsuite.ui.view.ChatView;
import org.cftoolsuite.ui.view.CrawlView;
import org.cftoolsuite.ui.view.DeleteView;
Expand Down Expand Up @@ -32,9 +34,6 @@ public class MainLayout extends AppLayout {
public MainLayout() {
Tab homeTab = createTab(VaadinIcon.HOME.create(), "Home", HomeView.class);

Accordion accordion = new Accordion();
accordion.setSizeFull();

Tabs actionTabs = createTabs();

Tab uploadTab = createTab(VaadinIcon.UPLOAD.create(), "Upload documents", UploadView.class);
Expand All @@ -47,10 +46,8 @@ public MainLayout() {
Tab downloadTab = createTab(VaadinIcon.DOWNLOAD.create(), "Download a document", DownloadView.class);
Tab deleteTab = createTab(VaadinIcon.TRASH.create(), "Delete a document", DeleteView.class);
actionTabs.add(uploadTab, crawlTab, fetchTab, chatTab, listTab, searchTab, summaryTab, downloadTab, deleteTab);
accordion.add("Actions", actionTabs).addThemeVariants(DetailsVariant.REVERSE);

addToNavbar(true, homeTab, new DrawerToggle());
addToDrawer(accordion);
addToDrawer(getLogoImage(), actionTabs);
}

private Tabs createTabs() {
Expand All @@ -77,4 +74,12 @@ private Tab createTab(Icon icon, String label, Class<? extends Component> layout
return tab;
}

private Image getLogoImage() {
StreamResource imageResource = new StreamResource("sanford.png",
() -> getClass().getResourceAsStream("/static/sanford.png"));
Image logo = new Image(imageResource, "Logo");
logo.setWidth("240px");
return logo;
}

}
50 changes: 50 additions & 0 deletions src/main/java/org/cftoolsuite/ui/view/BaseStreamingView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.cftoolsuite.ui.view;

import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.Notification.Position;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import org.cftoolsuite.client.SanfordStreamingClient;

public abstract class BaseStreamingView extends VerticalLayout {

protected SanfordStreamingClient sanfordStreamingClient;

public BaseStreamingView(SanfordStreamingClient sanfordStreamingClient) {
this.sanfordStreamingClient = sanfordStreamingClient;
setupUI();
}

protected abstract void setupUI();

protected abstract void clearAllFields();

protected void showNotification(String message, NotificationVariant variant) {
Notification notification = new Notification(message, 5000, Position.TOP_STRETCH);
notification.setPosition(Position.TOP_CENTER);
notification.addThemeVariants(variant);

Div content = new Div();
content.setText(message);
content.getStyle().set("cursor", "pointer");
content.addClickListener(event -> notification.close());

notification.add(content);

UI.getCurrent().addShortcutListener(
notification::close,
Key.ESCAPE
);

notification.open();

notification.addDetachListener(event ->
UI.getCurrent().getPage().executeJs(
"window.Vaadin.Flow.notificationEscListener.remove()"
)
);
}
}
26 changes: 8 additions & 18 deletions src/main/java/org/cftoolsuite/ui/view/BaseView.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package org.cftoolsuite.ui.view;

import org.cftoolsuite.client.SanfordClient;
import org.cftoolsuite.client.SanfordStreamingClient;

import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.notification.Notification.Position;
import com.vaadin.flow.component.notification.NotificationVariant;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.server.StreamResource;
import org.cftoolsuite.domain.AppProperties;

import java.util.Map;

public abstract class BaseView extends VerticalLayout {

protected SanfordClient sanfordClient;
protected SanfordStreamingClient sanfordStreamingClient;
Map<String, String> supportedContentTypes;

public BaseView(SanfordClient sanfordClient) {
public BaseView(SanfordClient sanfordClient, AppProperties appProperties) {
this.sanfordClient = sanfordClient;
}

public BaseView(SanfordStreamingClient sanfordStreamingClient) {
this.sanfordStreamingClient = sanfordStreamingClient;
this.supportedContentTypes = appProperties.supportedContentTypes();
setupUI();
}

protected abstract void setupUI();
Expand All @@ -43,7 +41,7 @@ protected void showNotification(String message, NotificationVariant variant) {
notification.add(content);

UI.getCurrent().addShortcutListener(
() -> notification.close(),
notification::close,
Key.ESCAPE
);

Expand All @@ -55,12 +53,4 @@ protected void showNotification(String message, NotificationVariant variant) {
)
);
}

protected Image getLogoImage() {
StreamResource imageResource = new StreamResource("sanford.png",
() -> getClass().getResourceAsStream("/static/sanford.png"));
Image logo = new Image(imageResource, "Logo");
logo.setWidth("240px");
return logo;
}
}
12 changes: 1 addition & 11 deletions src/main/java/org/cftoolsuite/ui/view/ChatView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

import jakarta.annotation.PostConstruct;

@PageTitle("sanford-ui » Chat")
@Route(value = "chat", layout = MainLayout.class)
public class ChatView extends BaseView {
public class ChatView extends BaseStreamingView {

private TextField messageInput;
private MetadataFilter metadataFilter;
Expand All @@ -33,14 +31,6 @@ public ChatView(SanfordStreamingClient sanfordStreamingClient) {
super(sanfordStreamingClient);
}

@PostConstruct
public void init() {
setAlignItems(Alignment.CENTER);
setJustifyContentMode(JustifyContentMode.CENTER);
add(getLogoImage());
setupUI();
}

@Override
protected void setupUI() {
var ui = UI.getCurrent();
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/org/cftoolsuite/ui/view/CrawlView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.stream.Collectors;

import org.cftoolsuite.client.SanfordClient;
import org.cftoolsuite.domain.AppProperties;
import org.cftoolsuite.domain.crawl.CrawlRequest;
import org.cftoolsuite.domain.crawl.CrawlResponse;
import org.cftoolsuite.ui.MainLayout;
Expand All @@ -20,8 +21,6 @@
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

import jakarta.annotation.PostConstruct;

@PageTitle("sanford-ui » Crawl")
@Route(value = "crawl", layout = MainLayout.class)
public class CrawlView extends BaseView {
Expand All @@ -34,16 +33,8 @@ public class CrawlView extends BaseView {
private Button clearButton;
private HorizontalLayout buttons;

public CrawlView(SanfordClient sanfordClient) {
super(sanfordClient);
}

@PostConstruct
public void init() {
setAlignItems(Alignment.CENTER);
setJustifyContentMode(JustifyContentMode.CENTER);
add(getLogoImage());
setupUI();
public CrawlView(SanfordClient sanfordClient, AppProperties appProperties) {
super(sanfordClient, appProperties);
}

@Override
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/org/cftoolsuite/ui/view/DeleteView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cftoolsuite.ui.view;

import org.cftoolsuite.client.SanfordClient;
import org.cftoolsuite.domain.AppProperties;
import org.cftoolsuite.ui.MainLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -14,8 +15,6 @@
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

import jakarta.annotation.PostConstruct;

@PageTitle("sanford-ui » Delete")
@Route(value = "delete", layout = MainLayout.class)
public class DeleteView extends BaseView {
Expand All @@ -27,16 +26,8 @@ public class DeleteView extends BaseView {
private Button clearButton;
private HorizontalLayout buttons;

public DeleteView(SanfordClient sanfordClient) {
super(sanfordClient);
}

@PostConstruct
public void init() {
setAlignItems(Alignment.CENTER);
setJustifyContentMode(JustifyContentMode.CENTER);
add(getLogoImage());
setupUI();
public DeleteView(SanfordClient sanfordClient, AppProperties appProperties) {
super(sanfordClient, appProperties);
}

@Override
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/org/cftoolsuite/ui/view/DownloadView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.InputStream;

import org.cftoolsuite.client.SanfordClient;
import org.cftoolsuite.domain.AppProperties;
import org.cftoolsuite.ui.MainLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -20,8 +21,6 @@
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.StreamResource;

import jakarta.annotation.PostConstruct;

@PageTitle("sanford-ui » Download")
@Route(value = "download", layout = MainLayout.class)
public class DownloadView extends BaseView {
Expand All @@ -33,16 +32,8 @@ public class DownloadView extends BaseView {
private Button clearButton;
private HorizontalLayout buttons;

public DownloadView(SanfordClient sanfordClient) {
super(sanfordClient);
}

@PostConstruct
public void init() {
setAlignItems(Alignment.CENTER);
setJustifyContentMode(JustifyContentMode.CENTER);
add(getLogoImage());
setupUI();
public DownloadView(SanfordClient sanfordClient, AppProperties appProperties) {
super(sanfordClient, appProperties);
}

@Override
Expand Down
17 changes: 4 additions & 13 deletions src/main/java/org/cftoolsuite/ui/view/FetchView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.stream.Collectors;

import org.cftoolsuite.client.SanfordClient;
import org.cftoolsuite.domain.AppProperties;
import org.cftoolsuite.domain.fetch.FetchRequest;
import org.cftoolsuite.domain.fetch.FetchResponse;
import org.cftoolsuite.ui.MainLayout;
Expand All @@ -19,29 +20,19 @@
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

import jakarta.annotation.PostConstruct;

@PageTitle("sanford-ui » Fetch")
@Route(value = "fetch", layout = MainLayout.class)
public class FetchView extends BaseView {

private static final Logger log = LoggerFactory.getLogger(CrawlView.class);
private static final Logger log = LoggerFactory.getLogger(FetchView.class);

private TextArea urls;
private Button fetchButton;
private Button clearButton;
private HorizontalLayout buttons;

public FetchView(SanfordClient sanfordClient) {
super(sanfordClient);
}

@PostConstruct
public void init() {
setAlignItems(Alignment.CENTER);
setJustifyContentMode(JustifyContentMode.CENTER);
add(getLogoImage());
setupUI();
public FetchView(SanfordClient sanfordClient, AppProperties appProperties) {
super(sanfordClient, appProperties);
}

@Override
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/org/cftoolsuite/ui/view/ListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import org.cftoolsuite.client.SanfordClient;
import org.cftoolsuite.domain.AppProperties;
import org.cftoolsuite.domain.FileMetadata;
import org.cftoolsuite.ui.MainLayout;
import org.cftoolsuite.ui.component.Markdown;
Expand Down Expand Up @@ -33,8 +34,6 @@
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.StreamResource;

import jakarta.annotation.PostConstruct;

@PageTitle("sanford-ui » List")
@Route(value = "list", layout = MainLayout.class)
public class ListView extends BaseView {
Expand All @@ -47,16 +46,8 @@ public class ListView extends BaseView {
private HorizontalLayout buttons;
private Grid<FileMetadata> grid;

public ListView(SanfordClient sanfordClient) {
super(sanfordClient);
}

@PostConstruct
public void init() {
setAlignItems(Alignment.CENTER);
setJustifyContentMode(JustifyContentMode.CENTER);
add(getLogoImage());
setupUI();
public ListView(SanfordClient sanfordClient, AppProperties appProperties) {
super(sanfordClient, appProperties);
}

@Override
Expand Down
Loading

0 comments on commit f1b9b33

Please sign in to comment.