CommitteeOverviewPageModContentFactoryImpl.java

  1. /*
  2.  * Copyright 2010-2025 James Pether Sörling
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  *  $Id$
  17.  *  $HeadURL$
  18. */
  19. package com.hack23.cia.web.impl.ui.application.views.user.committee.pagemode;

  20. import java.util.Locale;

  21. import org.springframework.security.access.annotation.Secured;
  22. import org.springframework.stereotype.Component;

  23. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommittee;
  24. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  25. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  26. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandCommitteeConstants;
  27. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  28. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
  29. import com.vaadin.icons.VaadinIcons;
  30. import com.vaadin.server.Responsive;
  31. import com.vaadin.ui.HorizontalLayout;
  32. import com.vaadin.ui.Layout;
  33. import com.vaadin.ui.Link;
  34. import com.vaadin.ui.MenuBar;
  35. import com.vaadin.ui.Panel;
  36. import com.vaadin.ui.VerticalLayout;

  37. /**
  38.  * The Class CommitteeOverviewPageModContentFactoryImpl.
  39.  */
  40. @Component
  41. public final class CommitteeOverviewPageModContentFactoryImpl extends AbstractCommitteePageModContentFactoryImpl {

  42.     /**
  43.      * Instantiates a new committee overview page mod content factory impl.
  44.      */
  45.     public CommitteeOverviewPageModContentFactoryImpl() {
  46.         super();
  47.     }

  48.     /**
  49.      * Creates the content.
  50.      *
  51.      * @param parameters the parameters
  52.      * @param menuBar the menu bar
  53.      * @param panel the panel
  54.      * @return the layout
  55.      */
  56.     @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
  57.     @Override
  58.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  59.         final VerticalLayout panelContent = createPanelContent();
  60.         panel.setContent(panelContent);

  61.         final String pageId = getPageId(parameters);

  62.         final ViewRiksdagenCommittee viewRiksdagenCommittee = getItem(parameters);
  63.         getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);

  64.         CardInfoRowUtil.createPageHeader(panel, panelContent,
  65.                 CommitteeViewConstants.OV_TITLE_HEADER + viewRiksdagenCommittee.getEmbeddedId().getDetail(),
  66.                 CommitteeViewConstants.OV_TITLE,
  67.                 CommitteeViewConstants.OV_DESCRIPTION);

  68.         final Link addCommitteePageLink = getPageLinkFactory().addCommitteePageLink(viewRiksdagenCommittee);
  69.         panelContent.addComponent(addCommitteePageLink);
  70.         panelContent.setExpandRatio(addCommitteePageLink, ContentRatio.SMALL);

  71.         // Create a card panel for the committee overview
  72.         final Panel cardPanel = new Panel();
  73.         cardPanel.addStyleName("politician-overview-card");
  74.         cardPanel.setWidth("100%");
  75.         cardPanel.setHeightUndefined();
  76.         Responsive.makeResponsive(cardPanel);

  77.         final VerticalLayout cardContent = new VerticalLayout();
  78.         cardContent.setMargin(true);
  79.         cardContent.setSpacing(true);
  80.         cardContent.setWidth("100%");
  81.         cardPanel.setContent(cardContent);

  82.         panelContent.addComponent(cardPanel);
  83.         panelContent.setExpandRatio(cardPanel, ContentRatio.SMALL_GRID);

  84.         CardInfoRowUtil.createCardHeader(cardContent,"Committee: " + viewRiksdagenCommittee.getEmbeddedId().getDetail());

  85.         // Two-column layout for committee attributes
  86.         final HorizontalLayout attributesLayout = new HorizontalLayout();
  87.         attributesLayout.setSpacing(true);
  88.         attributesLayout.setWidth("100%");
  89.         cardContent.addComponent(attributesLayout);

  90.         // First column: Committee Profile (keep existing, but add activity level)
  91.         final VerticalLayout profileDetailsLayout = CardInfoRowUtil.createSectionLayout(CommitteeViewConstants.OV_SECTION_PROFILE);

  92.         profileDetailsLayout.addComponent(CardInfoRowUtil.createInfoRow("Detail:", viewRiksdagenCommittee.getEmbeddedId().getDetail(),
  93.                 VaadinIcons.INFO_CIRCLE, "Internal identifier detail for the committee"));
  94.         profileDetailsLayout.addComponent(CardInfoRowUtil.createInfoRow("Status:", viewRiksdagenCommittee.isActive() ? "Active" : "Inactive",
  95.                 VaadinIcons.FLAG, "Current committee status"));
  96.         profileDetailsLayout.addComponent(CardInfoRowUtil.createInfoRow("Activity Level:", viewRiksdagenCommittee.getActivityLevel(),
  97.                 VaadinIcons.CHART, "Committee's current activity level"));
  98.         profileDetailsLayout.addComponent(CardInfoRowUtil.createInfoRow("First Assignment:", String.valueOf(viewRiksdagenCommittee.getFirstAssignmentDate()),
  99.                 VaadinIcons.CALENDAR, "Date the committee's first assignment started"));
  100.         profileDetailsLayout.addComponent(CardInfoRowUtil.createInfoRow("Last Assignment:", String.valueOf(viewRiksdagenCommittee.getLastAssignmentDate()),
  101.                 VaadinIcons.CALENDAR_CLOCK, "Date of the committee's most recent assignment"));

  102.         // Second column: Membership Statistics
  103.         final VerticalLayout membershipStatsLayout = CardInfoRowUtil.createSectionLayout(CommitteeViewConstants.OV_SECTION_MEMBERSHIP);

  104.         membershipStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Current Members:", String.valueOf(viewRiksdagenCommittee.getCurrentMemberSize()),
  105.                 VaadinIcons.GROUP, "Total current committee members"));
  106.         membershipStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Regular Members:", String.valueOf(viewRiksdagenCommittee.getCurrentRegularMembers()),
  107.                 VaadinIcons.USER, "Number of current regular members"));
  108.         membershipStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Leadership Positions:", String.valueOf(viewRiksdagenCommittee.getCurrentLeadershipPositions()),
  109.                 VaadinIcons.STAR, "Current number of leadership positions"));
  110.         membershipStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Substitute Positions:", String.valueOf(viewRiksdagenCommittee.getCurrentSubstitutePositions()),
  111.                 VaadinIcons.USER_CLOCK, "Current number of substitute positions"));
  112.         membershipStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Total Leadership Roles:", String.valueOf(viewRiksdagenCommittee.getTotalLeadershipPositions()),
  113.                 VaadinIcons.USERS, "Historical total of leadership positions"));
  114.         membershipStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Total Substitute Roles:", String.valueOf(viewRiksdagenCommittee.getTotalSubstitutePositions()),
  115.                 VaadinIcons.USERS, "Historical total of substitute positions"));

  116.         // Third column: Document Statistics
  117.         final VerticalLayout documentStatsLayout = CardInfoRowUtil.createSectionLayout(CommitteeViewConstants.OV_SECTION_DOCUMENT);

  118.         documentStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Total Documents:", String.valueOf(viewRiksdagenCommittee.getTotalDocuments()),
  119.                 VaadinIcons.FILE_TEXT, "Total number of documents produced"));
  120.         documentStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Documents Last Year:", String.valueOf(viewRiksdagenCommittee.getDocumentsLastYear()),
  121.                 VaadinIcons.FILE_O, "Documents produced in the last year"));
  122.         documentStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Avg Documents/Member:", String.format(Locale.ENGLISH,"%.1f", viewRiksdagenCommittee.getAvgDocumentsPerMember()),
  123.                 VaadinIcons.CHART_LINE, "Average documents per committee member"));
  124.         documentStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Committee Motions:", String.valueOf(viewRiksdagenCommittee.getTotalCommitteeMotions()),
  125.                 VaadinIcons.FILE_PRESENTATION, "Total number of committee motions"));
  126.         documentStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Total Assignments:", String.valueOf(viewRiksdagenCommittee.getTotalAssignments()),
  127.                 VaadinIcons.TASKS, "Total number of assignments"));
  128.         documentStatsLayout.addComponent(CardInfoRowUtil.createInfoRow("Days Served:", String.valueOf(viewRiksdagenCommittee.getTotalDaysServed()),
  129.                 VaadinIcons.CLOCK, "Total days of committee service"));

  130.         // Clear existing components and add all three columns
  131.         attributesLayout.removeAllComponents();
  132.         attributesLayout.addComponents(profileDetailsLayout, membershipStatsLayout, documentStatsLayout);

  133.         // Optional: Add some styling to make the columns more responsive
  134.         attributesLayout.setWidth("100%");
  135.         attributesLayout.setSpacing(true);


  136.         // After the card, add the overview layout
  137.         final VerticalLayout overviewLayout = new VerticalLayout();
  138.         overviewLayout.setSizeFull();
  139.         panelContent.addComponent(overviewLayout);
  140.         panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);

  141.         getCommitteeMenuItemFactory().createOverviewPage(overviewLayout, pageId);

  142.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER, NAME,
  143.                 parameters, pageId);

  144.         return panelContent;
  145.     }

  146.     /**
  147.      * Matches.
  148.      *
  149.      * @param page the page
  150.      * @param parameters the parameters
  151.      * @return true, if successful
  152.      */
  153.     @Override
  154.     public boolean matches(final String page, final String parameters) {
  155.         return PageCommandCommitteeConstants.COMMAND_COMMITTEE_OVERVIEW.matches(page, parameters);
  156.     }

  157. }