Skip to content

Commit

Permalink
Update Page structure to Main Content and Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffengreiner committed Jul 11, 2023
1 parent 0f79b44 commit fdbb0b3
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import life.qbic.datamanager.views.AppRoutes.Projects;
import life.qbic.datamanager.views.MainLayout;
import life.qbic.datamanager.views.projects.project.experiments.ExperimentInformationMain;
import life.qbic.datamanager.views.projects.project.info.ProjectInformationPage;
import life.qbic.datamanager.views.projects.project.info.ProjectInformationMain;
import life.qbic.datamanager.views.projects.project.samples.SampleInformationPage;
import life.qbic.logging.api.Logger;
import life.qbic.logging.service.LoggerFactory;
Expand All @@ -38,20 +38,20 @@ public class ProjectViewPage extends Div implements BeforeEnterObserver, RouterL
private static final Logger log = LoggerFactory.logger(ProjectViewPage.class);
private final transient Handler handler;

public ProjectViewPage(@Autowired ProjectInformationPage projectInformationPage,
public ProjectViewPage(@Autowired ProjectInformationMain projectInformationMain,
@Autowired ExperimentInformationMain experimentInformationMain,
@Autowired SampleInformationPage sampleInformationPage,
@Autowired ProjectInformationService projectInformationService) {
Objects.requireNonNull(projectInformationPage);
Objects.requireNonNull(projectInformationMain);
Objects.requireNonNull(experimentInformationMain);
Objects.requireNonNull(sampleInformationPage);
stylePage();
handler = new Handler(projectInformationPage,
handler = new Handler(projectInformationMain,
experimentInformationMain, sampleInformationPage, projectInformationService);
log.debug(String.format(
"New instance for project view (#%s) created with a project information page (#%s), an experiment information page (#%s), and a sample information page (#%s)",
System.identityHashCode(this),
System.identityHashCode(projectInformationPage),
System.identityHashCode(projectInformationMain),
System.identityHashCode(experimentInformationMain),
System.identityHashCode(sampleInformationPage)));
}
Expand Down Expand Up @@ -82,23 +82,23 @@ private void navigateToNotFound(RuntimeException e, BeforeEnterEvent enterEvent)
*/
static class Handler {

private final ProjectInformationPage projectInformationPage;
private final ProjectInformationMain projectInformationMain;
private final ExperimentInformationMain experimentInformationMain;
private final SampleInformationPage sampleInformationPage;

private final ProjectInformationService projectInformationService;


public Handler(ProjectInformationPage projectInformationPage,
public Handler(ProjectInformationMain projectInformationMain,
ExperimentInformationMain experimentInformationMain,
SampleInformationPage sampleInformationPage,
ProjectInformationService projectInformationService) {
Objects.requireNonNull(projectInformationPage);
Objects.requireNonNull(projectInformationMain);
Objects.requireNonNull(experimentInformationMain);
Objects.requireNonNull(sampleInformationPage);
Objects.requireNonNull(projectInformationService);

this.projectInformationPage = projectInformationPage;
this.projectInformationMain = projectInformationMain;
this.experimentInformationMain = experimentInformationMain;
this.sampleInformationPage = sampleInformationPage;
this.projectInformationService = projectInformationService;
Expand All @@ -111,7 +111,7 @@ public Handler(ProjectInformationPage projectInformationPage,
* @since 1.0.0
*/
public void setProjectId(ProjectId projectId) {
this.projectInformationPage.projectId(projectId);
this.projectInformationMain.projectId(projectId);
this.experimentInformationMain.projectId(projectId);
this.sampleInformationPage.projectId(projectId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ExperimentInformationMain extends MainComponent implements BeforeEn
private static final Logger log = LoggerFactory.logger(ProjectViewPage.class);
public static final String EXPERIMENT_ID_ROUTE_PARAMETER = "experimentId";
public static final String PROJECT_ID_ROUTE_PARAMETER = "projectId";
private final transient ExperimentInformationPageHandler experimentInformationPageHandler;
private final transient ExperimentInformationMainHandler experimentInformationMainHandler;
private final ProjectNavigationBarComponent projectNavigationBarComponent;

public ExperimentInformationMain(
Expand All @@ -68,7 +68,7 @@ public ExperimentInformationMain(
Objects.requireNonNull(experimentInformationService);
this.projectNavigationBarComponent = projectNavigationBarComponent;
layoutComponent();
experimentInformationPageHandler = new ExperimentInformationPageHandler(
experimentInformationMainHandler = new ExperimentInformationMainHandler(
projectNavigationBarComponent, experimentContentComponent, experimentSupportComponent,
projectInformationService, experimentInformationService);
log.debug(String.format(
Expand All @@ -95,9 +95,9 @@ private void layoutComponent() {
public void beforeEnter(BeforeEnterEvent beforeEnterEvent) {
beforeEnterEvent.getRouteParameters().get(EXPERIMENT_ID_ROUTE_PARAMETER)
.ifPresentOrElse(
experimentIdParam -> experimentInformationPageHandler.propagateExperimentId(
experimentIdParam -> experimentInformationMainHandler.propagateExperimentId(
experimentIdParam, beforeEnterEvent),
() -> experimentInformationPageHandler.rerouteToActiveExperiment(beforeEnterEvent));
() -> experimentInformationMainHandler.rerouteToActiveExperiment(beforeEnterEvent));
}

/**
Expand All @@ -107,10 +107,10 @@ public void beforeEnter(BeforeEnterEvent beforeEnterEvent) {
* @param projectId The projectId to be propagated
*/
public void projectId(ProjectId projectId) {
experimentInformationPageHandler.setProjectId(projectId);
experimentInformationMainHandler.setProjectId(projectId);
}

private final class ExperimentInformationPageHandler {
private final class ExperimentInformationMainHandler {

private ProjectId projectId;
private final ProjectNavigationBarComponent projectNavigationBarComponent;
Expand All @@ -119,7 +119,7 @@ private final class ExperimentInformationPageHandler {
private final ProjectInformationService projectInformationService;
private final ExperimentInformationService experimentInformationService;

public ExperimentInformationPageHandler(
public ExperimentInformationMainHandler(
ProjectNavigationBarComponent projectNavigationBarComponent,
ExperimentContentComponent experimentContentComponent,
ExperimentSupportComponent experimentSupportComponent,
Expand Down Expand Up @@ -210,7 +210,7 @@ private boolean isExperimentEqualToContent(ExperimentCreationContent experimentC
private void propagateExperimentId(String experimentParam, BeforeEnterEvent beforeEnterEvent) {
try {
ExperimentId experimentId = ExperimentId.parse(experimentParam);
experimentInformationPageHandler.setExperimentId(experimentId);
experimentInformationMainHandler.setExperimentId(experimentId);
} catch (IllegalArgumentException e) {
log.debug(
String.format("Provided ExperimentId %s is invalid due to %s", experimentParam,
Expand All @@ -227,7 +227,7 @@ private void propagateExperimentId(String experimentParam, BeforeEnterEvent befo
* experiment of a project
*/
private void rerouteToActiveExperiment(BeforeEnterEvent beforeEnterEvent) {
ExperimentId activeExperimentId = experimentInformationPageHandler.getActiveExperimentIdForProject(
ExperimentId activeExperimentId = experimentInformationMainHandler.getActiveExperimentIdForProject(
projectId);
log.debug(String.format("Rerouting to active experiment %s of project %s",
activeExperimentId.value(), projectId.value()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package life.qbic.datamanager.views.projects.project.info;

import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
import java.io.Serial;
import java.util.Objects;
import life.qbic.logging.api.Logger;
import life.qbic.logging.service.LoggerFactory;
import life.qbic.projectmanagement.domain.project.ProjectId;
import org.springframework.beans.factory.annotation.Autowired;

/**
* Project Content component
* <p>
* The content component is a {@link Div} container, which is responsible for hosting the components
* handling the content within the {@link ProjectInformationMain}. It is intended to propagate
* project information provided in the {@link ProjectDetailsComponent} to the
* {@link ProjectInformationMain} and vice versa and can be easily extended with additional
* components if necessary
*/

@SpringComponent
@UIScope
public class ProjectContentComponent extends Div {

private static final Logger log = LoggerFactory.logger(ProjectContentComponent.class);
@Serial
private static final long serialVersionUID = -1061134126086910532L;
private final ProjectDetailsComponent projectDetailsComponent;

public ProjectContentComponent(
@Autowired ProjectDetailsComponent projectDetailsComponent) {
Objects.requireNonNull(projectDetailsComponent);
this.projectDetailsComponent = projectDetailsComponent;
layoutComponent();
}

private void layoutComponent() {
this.add(projectDetailsComponent);
}

/**
* Triggers the propagation of the provided {@link ProjectId} to internal components
*
* @param projectId The projectId to be propagated
*/
public void projectId(ProjectId projectId) {
projectDetailsComponent.projectId(projectId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package life.qbic.datamanager.views.projects.project.info;

import static life.qbic.datamanager.views.projects.project.experiments.ExperimentInformationMain.PROJECT_ID_ROUTE_PARAMETER;

import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteParam;
import com.vaadin.flow.router.RouterLayout;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
import jakarta.annotation.security.PermitAll;
import java.io.Serial;
import java.util.Objects;
import life.qbic.datamanager.views.general.MainComponent;
import life.qbic.datamanager.views.projects.project.ProjectNavigationBarComponent;
import life.qbic.datamanager.views.projects.project.ProjectViewPage;
import life.qbic.logging.api.Logger;
import life.qbic.logging.service.LoggerFactory;
import life.qbic.projectmanagement.domain.project.ProjectId;
import org.springframework.beans.factory.annotation.Autowired;


/**
* Project Information Main Component
* <p>
* This component hosts the components necessary to show and update the
* {@link life.qbic.projectmanagement.domain.project.Project} information via the provided
* {@link life.qbic.projectmanagement.domain.project.ProjectId} in the URL
*/

@SpringComponent
@UIScope
@Route(value = "projects/:projectId?/info", layout = ProjectViewPage.class)
@PermitAll
public class ProjectInformationMain extends MainComponent implements BeforeEnterObserver,
RouterLayout {

@Serial
private static final long serialVersionUID = 5797835576569148873L;
private static final Logger log = LoggerFactory.logger(ProjectViewPage.class);
private final ProjectNavigationBarComponent projectNavigationBarComponent;
private final transient ProjectInformationMainHandler projectInformationMainHandler;

public ProjectInformationMain(
@Autowired ProjectNavigationBarComponent projectNavigationBarComponent,
@Autowired ProjectContentComponent projectContentComponent,
@Autowired ProjectSupportComponent projectSupportComponent) {
super(projectContentComponent, projectSupportComponent);
Objects.requireNonNull(projectNavigationBarComponent);
Objects.requireNonNull(projectContentComponent);
Objects.requireNonNull(projectSupportComponent);
this.projectNavigationBarComponent = projectNavigationBarComponent;
layoutComponent();
projectInformationMainHandler = new ProjectInformationMainHandler(projectNavigationBarComponent,
projectContentComponent,
projectSupportComponent);
log.debug(String.format(
"New instance for project Information Page (#%s) created with Project Navigation Bar Component (#%s) and Project Content Component (#%s) and Project Support Component (#%s)",
System.identityHashCode(this), System.identityHashCode(projectNavigationBarComponent),
System.identityHashCode(projectContentComponent),
System.identityHashCode(projectSupportComponent)));
}

private void layoutComponent() {
addClassName("project");
addComponentAsFirst(projectNavigationBarComponent);
}

public void projectId(ProjectId projectId) {
projectInformationMainHandler.setProjectId(projectId);
}

@Override
public void beforeEnter(BeforeEnterEvent event) {
event.getRouteParameters().get(PROJECT_ID_ROUTE_PARAMETER)
.ifPresent(
projectInformationMainHandler::propagateProjectId);
}

private final class ProjectInformationMainHandler {

private final ProjectNavigationBarComponent projectNavigationComponent;
private final ProjectContentComponent projectContentComponent;
private final ProjectSupportComponent projectSupportComponent;

public ProjectInformationMainHandler(ProjectNavigationBarComponent projectNavigationComponent,
ProjectContentComponent projectContentComponent,
ProjectSupportComponent projectSupportComponent) {
this.projectNavigationComponent = projectNavigationComponent;
this.projectContentComponent = projectContentComponent;
this.projectSupportComponent = projectSupportComponent;
}

public void setProjectId(ProjectId projectId) {
projectNavigationComponent.projectId(projectId);
projectContentComponent.projectId(projectId);
projectSupportComponent.projectId(projectId);
}

/**
* Reroutes to the ProjectId provided in the URL
* <p>
* This method generates the URL and routes the user via {@link RouteParam} to the provided
* ProjectId
*/
private void propagateProjectId(String projectParam) {
try {
ProjectId projectId = ProjectId.parse(projectParam);
projectInformationMainHandler.setProjectId(projectId);
} catch (IllegalArgumentException e) {
log.debug(
String.format("Provided ProjectId %s is invalid due to %s", projectParam,
e.getMessage()));
}
}
}

}
Loading

0 comments on commit fdbb0b3

Please sign in to comment.