MinistryOverviewPageModContentFactoryImpl.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.goverment.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.ministry.impl.ViewRiksdagenMinistry;
  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.PageCommandMinistryConstants;
  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 MinistryOverviewPageModContentFactoryImpl.
  39.  */
  40. @Component
  41. public final class MinistryOverviewPageModContentFactoryImpl extends AbstractMinistryPageModContentFactoryImpl {

  42.     /**
  43.      * Instantiates a new ministry overview page mod content factory impl.
  44.      */
  45.     // Existing constructor remains the same
  46.     public MinistryOverviewPageModContentFactoryImpl() {
  47.         super();
  48.     }

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

  62.         final String pageId = getPageId(parameters);
  63.         final ViewRiksdagenMinistry viewRiksdagenMinistry = getItem(parameters);

  64.         getMinistryMenuItemFactory().createMinistryMenuBar(menuBar, pageId);

  65.         CardInfoRowUtil.createPageHeader(panel,
  66.                 panelContent,
  67.                 MinistryViewConstants.OVERVIEW_TITLE + " " + viewRiksdagenMinistry.getNameId(),
  68.                 MinistryViewConstants.OVERVIEW_SUBTITLE,
  69.                 MinistryViewConstants.OVERVIEW_DESC);

  70.         final Link addMinistryPageLink = getPageLinkFactory().addMinistryPageLink(viewRiksdagenMinistry);
  71.         panelContent.addComponent(addMinistryPageLink);
  72.         panelContent.setExpandRatio(addMinistryPageLink, ContentRatio.SMALL);

  73.         // Create a card panel
  74.         final Panel cardPanel = new Panel();
  75.         cardPanel.addStyleName(MinistryLayoutConstants.MINISTRY_CARD_STYLE);
  76.         cardPanel.setWidth(MinistryLayoutConstants.WIDTH_100_PERCENT);
  77.         cardPanel.setHeightUndefined();
  78.         Responsive.makeResponsive(cardPanel);

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

  84.         panelContent.addComponent(cardPanel);
  85.         panelContent.setExpandRatio(cardPanel, ContentRatio.SMALL_GRID);

  86.         // Header layout
  87.         CardInfoRowUtil.createCardHeader(cardContent,viewRiksdagenMinistry.getNameId());

  88.         // Multi-column layout for attributes
  89.         final HorizontalLayout attributesLayout = new HorizontalLayout();
  90.         attributesLayout.setSpacing(true);
  91.         attributesLayout.setWidth("100%");
  92.         cardContent.addComponent(attributesLayout);

  93.         // Column 1: Basic Ministry Details
  94.         final VerticalLayout profileDetailsLayout = CardInfoRowUtil.createSectionLayout(MinistrySectionConstants.MINISTRY_PROFILE);

  95.         createProfileDetails(profileDetailsLayout, viewRiksdagenMinistry);

  96.         // Column 2: Service Statistics
  97.         final VerticalLayout serviceStatsLayout = CardInfoRowUtil.createSectionLayout(MinistryViewConstants.MINISTRY_SERVICE_STATS_TITLE);

  98.         createServiceStatisticsSection(serviceStatsLayout, viewRiksdagenMinistry);

  99.         // Column 3: Document Statistics
  100.         final VerticalLayout documentStatsLayout = CardInfoRowUtil.createSectionLayout(MinistryViewConstants.MINISTRY_DOCUMENT_STATS_TITLE);

  101.         createDocumentStatisticsSection(documentStatsLayout, viewRiksdagenMinistry);

  102.         // Add all columns to the attributes layout
  103.         attributesLayout.addComponents(profileDetailsLayout, serviceStatsLayout, documentStatsLayout);

  104.         // Add the overview layout
  105.         final VerticalLayout overviewLayout = new VerticalLayout();
  106.         overviewLayout.setSizeFull();
  107.         panelContent.addComponent(overviewLayout);
  108.         panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);

  109.         getMinistryMenuItemFactory().createOverviewPage(overviewLayout, pageId);

  110.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MINISTRY_VIEW, ApplicationEventGroup.USER, NAME,
  111.                 parameters, pageId);

  112.         return panelContent;
  113.     }

  114.     /**
  115.      * Creates the profile details.
  116.      *
  117.      * @param layout the layout
  118.      * @param ministry the ministry
  119.      */
  120.     private void createProfileDetails(final VerticalLayout layout, final ViewRiksdagenMinistry ministry) {
  121.         layout.addComponent(CardInfoRowUtil.createInfoRow(
  122.             MinistryFieldConstants.MINISTRY_ID_LABEL,
  123.             ministry.getNameId(),
  124.             MinistryIconConstants.INFO_ICON,
  125.             MinistryFieldConstants.MINISTRY_ID_DESC));

  126.         layout.addComponent(CardInfoRowUtil.createInfoRow(
  127.             MinistryFieldConstants.STATUS_LABEL,
  128.             ministry.isActive() ? "Active" : "Inactive",
  129.             MinistryIconConstants.FLAG_ICON,
  130.             MinistryFieldConstants.STATUS_DESC));

  131.         layout.addComponent(CardInfoRowUtil.createInfoRow(MinistryViewConstants.MINISTRY_CURRENT_MEMBERS_LABEL,
  132.             String.valueOf(ministry.getCurrentMemberSize()), VaadinIcons.GROUP,
  133.             MinistryDescriptionConstants.CURRENT_MINISTRY_MEMBERS_DESC));
  134.         layout.addComponent(CardInfoRowUtil.createInfoRow(MinistryViewConstants.MINISTRY_ACTIVITY_LEVEL_LABEL,
  135.             ministry.getActivityLevel(), VaadinIcons.CHART,
  136.             MinistryDescriptionConstants.ACTIVITY_LEVEL_DESC));
  137.     }


  138.     /**
  139.      * Creates the service statistics section.
  140.      *
  141.      * @param layout the layout
  142.      * @param ministry the ministry
  143.      */
  144.     private void createServiceStatisticsSection(final VerticalLayout layout, final ViewRiksdagenMinistry ministry) {
  145.         layout.addComponent(CardInfoRowUtil.createInfoRow(
  146.             MinistryStatisticsConstants.TOTAL_ASSIGNMENTS,
  147.             String.valueOf(ministry.getTotalAssignments()),
  148.             MinistryIconConstants.TASK_ICON,
  149.             MinistryStatisticsConstants.ASSIGNMENTS_DESC));

  150.         layout.addComponent(CardInfoRowUtil.createInfoRow(
  151.             MinistryStatisticsConstants.FIRST_ASSIGNMENT,
  152.             String.valueOf(ministry.getFirstAssignmentDate()),
  153.             MinistryIconConstants.CALENDAR_ICON,
  154.             MinistryStatisticsConstants.FIRST_DATE_DESC));

  155.         layout.addComponent(CardInfoRowUtil.createInfoRow(MinistryViewConstants.MINISTRY_LAST_ASSIGNMENT_LABEL,
  156.             String.valueOf(ministry.getLastAssignmentDate()), VaadinIcons.CALENDAR_CLOCK,
  157.             MinistryDescriptionConstants.LAST_ASSIGNMENT_DESC));
  158.         layout.addComponent(CardInfoRowUtil.createInfoRow(MinistryViewConstants.MINISTRY_TOTAL_DAYS_SERVED_LABEL,
  159.             String.valueOf(ministry.getTotalDaysServed()), VaadinIcons.CLOCK,
  160.             MinistryDescriptionConstants.TOTAL_DAYS_SERVED_DESC));
  161.     }

  162.     /**
  163.      * Creates the document statistics section.
  164.      *
  165.      * @param layout the layout
  166.      * @param ministry the ministry
  167.      */
  168.     private void createDocumentStatisticsSection(final VerticalLayout layout, final ViewRiksdagenMinistry ministry) {
  169.         layout.addComponent(CardInfoRowUtil.createInfoRow(
  170.             MinistryStatisticsConstants.TOTAL_DOCUMENTS,
  171.             String.valueOf(ministry.getTotalDocuments()),
  172.             MinistryIconConstants.FILE_ICON,
  173.             MinistryStatisticsConstants.TOTAL_DOCS_DESC));

  174.         layout.addComponent(CardInfoRowUtil.createInfoRow(
  175.             MinistryStatisticsConstants.AVG_DOCUMENTS,
  176.             String.valueOf(ministry.getAvgDocumentsPerMember()),
  177.             MinistryIconConstants.CHART_ICON,
  178.             MinistryStatisticsConstants.AVG_DOCS_DESC));

  179.         layout.addComponent(CardInfoRowUtil.createInfoRow(MinistryViewConstants.MINISTRY_DOCUMENTS_LAST_YEAR_LABEL,
  180.             String.valueOf(ministry.getDocumentsLastYear()), VaadinIcons.FILE_O,
  181.             MinistryDescriptionConstants.DOCUMENTS_LAST_YEAR_DESC));
  182.         layout.addComponent(CardInfoRowUtil.createInfoRow(MinistryViewConstants.MINISTRY_AVG_DOCUMENTS_MEMBER_LABEL,
  183.             String.format(Locale.ENGLISH,"%.1f", ministry.getAvgDocumentsPerMember()),
  184.             VaadinIcons.CHART_LINE, MinistryDescriptionConstants.AVG_DOCUMENTS_MEMBER_DESC));
  185.         layout.addComponent(CardInfoRowUtil.createInfoRow(MinistryViewConstants.MINISTRY_TOTAL_PROPOSITIONS_LABEL,
  186.             String.valueOf(ministry.getTotalPropositions()), VaadinIcons.FILE_PRESENTATION,
  187.             MinistryDescriptionConstants.TOTAL_PROPOSITIONS_DESC));
  188.         layout.addComponent(CardInfoRowUtil.createInfoRow(MinistryViewConstants.MINISTRY_GOVERNMENT_BILLS_LABEL,
  189.             String.valueOf(ministry.getTotalGovernmentBills()), VaadinIcons.FILE_TEXT_O,
  190.             MinistryDescriptionConstants.GOVERNMENT_BILLS_DESC));
  191.     }

  192.     /**
  193.      * Matches.
  194.      *
  195.      * @param page the page
  196.      * @param parameters the parameters
  197.      * @return true, if successful
  198.      */
  199.     @Override
  200.     public boolean matches(final String page, final String parameters) {
  201.         return PageCommandMinistryConstants.COMMAND_MINISTRY_OVERVIEW.matches(page, parameters);
  202.     }
  203. }