-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Page structure to Main Content and Support
- Loading branch information
1 parent
0f79b44
commit fdbb0b3
Showing
6 changed files
with
241 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../main/java/life/qbic/datamanager/views/projects/project/info/ProjectContentComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
119 changes: 119 additions & 0 deletions
119
...c/main/java/life/qbic/datamanager/views/projects/project/info/ProjectInformationMain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.