Skip to content

Commit

Permalink
redirect from self dashboard widget with View all button
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed Aug 10, 2022
1 parent 9953c53 commit 456cf08
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ protected Search createSearch(Class<O> type) {
return SearchFactory.createSearch(type, collectionName, getPageBase());
}

protected List<ItemPath> getFixedSearchItems() {
List<ItemPath> fixedSearchItems = new ArrayList<>();
fixedSearchItems.add(ObjectType.F_NAME);
return fixedSearchItems;
}

protected final SelectableBeanObjectDataProvider<O> createSelectableBeanObjectDataProvider(SerializableSupplier<ObjectQuery> querySuplier,
SerializableFunction<SortParam<String>, List<ObjectOrdering>> orderingSuplier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.impl.component.ContainerableListPanel;
import com.evolveum.midpoint.gui.impl.component.menu.PageTypes;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityCollectionType;

Expand Down Expand Up @@ -1269,7 +1270,8 @@ public static String getTranslatedPolyString(PolyString value, LocalizationServi
localizationService = MidPointApplication.get().getLocalizationService();
}
String translatedValue = localizationService.translate(value, getCurrentLocale(), true);
if (StringUtils.isNotEmpty(translatedValue)) {
String translationKey = value.getTranslation() != null ? value.getTranslation().getKey() : null;
if (StringUtils.isNotEmpty(translatedValue) && !translatedValue.equals(translationKey)) {
return translatedValue;
}
return value.getOrig();
Expand Down Expand Up @@ -2649,6 +2651,22 @@ public static void dispatchToObjectDetailsPage(Class<? extends ObjectType> objec
}
}

public static void dispatchToListPage(Class<? extends Containerable> objectClass, String collectionViewId, Component component, boolean failIfUnsupported) {
QName type = WebComponentUtil.containerClassToQName(PrismContext.get(), objectClass);
PageTypes pageTypes = PageTypes.getPageTypesByType(type);
if (pageTypes != null) {
Class<? extends PageBase> listPage = pageTypes.getListClass();
PageParameters pageParameters = new PageParameters();
pageParameters.add(PageBase.PARAMETER_OBJECT_COLLECTION_NAME, collectionViewId);
if (listPage != null) {
((PageBase) component.getPage()).navigateToNext(listPage, pageParameters);
}
}
if (failIfUnsupported) {
throw new SystemException("Cannot determine details page for " + objectClass);
}
}

public static boolean hasDetailsPage(PrismObject<?> object) {
Class<?> clazz = object.getCompileTimeClass();
return hasDetailsPage(clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
*/
package com.evolveum.midpoint.gui.impl.component;

import java.lang.reflect.Constructor;
import java.util.*;
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.impl.component.menu.PageTypes;
import com.evolveum.midpoint.gui.impl.component.table.WidgetTableHeader;
import com.evolveum.midpoint.web.application.PanelType;
import com.evolveum.midpoint.web.component.AjaxIconButton;
import com.evolveum.midpoint.web.page.admin.configuration.PageImportObject;

import com.evolveum.midpoint.web.session.ObjectDetailsStorage;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -423,25 +428,27 @@ protected boolean enableSavePageSize() {
private List<IColumn<PO, String>> createColumns() {
List<IColumn<PO, String>> columns = collectColumns();

List<InlineMenuItem> menuItems = createInlineMenu();
if (menuItems == null) {
menuItems = new ArrayList<>();
}
addCustomActions(menuItems, this::getSelectedRealObjects);
if (!isDashboard()) {
List<InlineMenuItem> menuItems = createInlineMenu();
if (menuItems == null) {
menuItems = new ArrayList<>();
}
addCustomActions(menuItems, this::getSelectedRealObjects);

if (!menuItems.isEmpty()) {
InlineMenuButtonColumn<PO> actionsColumn = new InlineMenuButtonColumn<>(menuItems, getPageBase()) {
@Override
public String getCssClass() {
return "inline-menu-column";
}
if (!menuItems.isEmpty()) {
InlineMenuButtonColumn<PO> actionsColumn = new InlineMenuButtonColumn<>(menuItems, getPageBase()) {
@Override
public String getCssClass() {
return "inline-menu-column";
}

@Override
protected boolean isButtonMenuItemEnabled(IModel<PO> rowModel) {
return isMenuItemVisible(rowModel);
}
};
columns.add(actionsColumn);
@Override
protected boolean isButtonMenuItemEnabled(IModel<PO> rowModel) {
return isMenuItemVisible(rowModel);
}
};
columns.add(actionsColumn);
}
}
return columns;
}
Expand Down Expand Up @@ -953,8 +960,7 @@ private AjaxIconButton createViewAllButton(String buttonId) {

@Override
public void onClick(AjaxRequestTarget target) {
PageBase page = ContainerableListPanel.this.getPageBase();

viewAllActionPerformed(target);
}
};
viewAll.add(new VisibleBehaviour(() -> isDashboard()));
Expand All @@ -963,6 +969,31 @@ public void onClick(AjaxRequestTarget target) {
return viewAll;
}

protected void viewAllActionPerformed(AjaxRequestTarget target) {
FocusType principal = getPageBase().getPrincipalFocus();
String widgetPanelType = config != null ? config.getPanelType() : null;
QName principalFocusType = WebComponentUtil.classToQName(PrismContext.get(), principal.getClass());
if (widgetPanelType != null) {
ContainerPanelConfigurationType panelConfig = getPageBase().getCompiledGuiProfile().findPrincipalFocusDetailsPanel(
principalFocusType, widgetPanelType);
if (panelConfig != null) {
ObjectDetailsStorage pageStorage = getPageBase().getSessionStorage().getObjectDetailsStorage(getStorageKey());
if (pageStorage == null) {
getPageBase().getSessionStorage().setObjectDetailsStorage(getStorageKey(), panelConfig);
} else {
pageStorage.setDefaultConfiguration(panelConfig);
}
WebComponentUtil.dispatchToObjectDetailsPage(principal.asPrismObject(), ContainerableListPanel.this);
return;
}
}

CompiledObjectCollectionView view = getObjectCollectionView();
if (view != null) {
WebComponentUtil.dispatchToListPage(getType(), view.getViewIdentifier(), ContainerableListPanel.this, false);
}
}

protected String getStorageKey() {
if (isCollectionViewPanelForCompiledView()) {
StringValue collectionName = WebComponentUtil.getCollectionNameParameterValue(getPageBase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.evolveum.midpoint.gui.impl.page.admin.service.PageService;
import com.evolveum.midpoint.gui.impl.page.admin.task.PageTask;
import com.evolveum.midpoint.gui.impl.page.admin.user.PageUser;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.web.page.admin.PageAdmin;
import com.evolveum.midpoint.web.page.admin.archetype.PageArchetypes;
import com.evolveum.midpoint.web.page.admin.cases.PageCases;
Expand All @@ -36,7 +37,7 @@
import com.evolveum.midpoint.web.page.admin.users.PageUsers;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

//TODO remove in 4.5
//TODO remove in future
public enum PageTypes {

USER("users", GuiStyleConstants.CLASS_OBJECT_USER_ICON, PageUsers.class, PageUser.class, UserType.COMPLEX_TYPE),
Expand Down Expand Up @@ -85,4 +86,13 @@ public Class<? extends PageBase> getDetailsPage() {
public QName getTypeName() {
return typeName;
}

public static PageTypes getPageTypesByType(QName type) {
for (PageTypes pageType : values()) {
if (QNameUtil.match(pageType.typeName, type)) {
return pageType;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ protected IModel<String> getConfirmationMessageModel(ColumnMenuAction action, St
protected List<IColumn<SelectableBean<OrgType>, String>> createDefaultColumns() {
return ColumnUtils.getDefaultOrgColumns(getPageBase());
}

@Override
protected List<ItemPath> getFixedSearchItems() {
List<ItemPath> fixedSearchItems = new ArrayList<>();
fixedSearchItems.add(ObjectType.F_NAME);
fixedSearchItems.add(AbstractRoleType.F_DISPLAY_NAME);
fixedSearchItems.add(OrgType.F_PARENT_ORG_REF);
return fixedSearchItems;
}
};
table.setOutputMarkupId(true);
mainForm.add(table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ protected IModel<String> getConfirmationMessageModel(ColumnMenuAction action, St
// return ColumnUtils.getDefaultRoleColumns();
// }

@Override
protected List<ItemPath> getFixedSearchItems() {
List<ItemPath> fixedSearchItems = new ArrayList<>();
fixedSearchItems.add(ObjectType.F_NAME);
fixedSearchItems.add(AbstractRoleType.F_DISPLAY_NAME);
fixedSearchItems.add(AbstractRoleType.F_IDENTIFIER);
return fixedSearchItems;
}
};
table.setOutputMarkupId(true);
mainForm.add(table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ protected IModel<String> getConfirmationMessageModel(ColumnMenuAction action, St
return listInlineMenuHelper.createRowActions(getType());
}

@Override
protected List<ItemPath> getFixedSearchItems() {
List<ItemPath> fixedSearchItems = new ArrayList<>();
fixedSearchItems.add(ObjectType.F_NAME);
fixedSearchItems.add(AbstractRoleType.F_DISPLAY_NAME);
fixedSearchItems.add(AbstractRoleType.F_IDENTIFIER);
return fixedSearchItems;
}
};
table.setOutputMarkupId(true);
mainForm.add(table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,6 @@ protected List<InlineMenuItem> createInlineMenu() {
return createRowActions();
}

@Override
protected List<ItemPath> getFixedSearchItems() {
List<ItemPath> fixedSearchItems = new ArrayList<>();
fixedSearchItems.add(UserType.F_NAME);
fixedSearchItems.add(UserType.F_GIVEN_NAME);
fixedSearchItems.add(UserType.F_FAMILY_NAME);
return fixedSearchItems;
}

@Override
protected String getNothingSelectedMessage() {
return getString("pageUsers.message.nothingSelected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
<cssClass>fe fe-assignment</cssClass>
</icon>
</display>
<panelType>myAccesses</panelType>
<panelType>allAssignments</panelType>
<preview>true</preview>
</widget>
<widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import com.evolveum.midpoint.schema.ResourceShadowCoordinates;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.schema.constants.ObjectTypes;
Expand Down Expand Up @@ -553,4 +555,26 @@ public HomePageType getHomePage() {
public void setHomePage(HomePageType homePage) {
this.homePage = homePage;
}

public ContainerPanelConfigurationType findPrincipalFocusDetailsPanel(@NotNull QName focusType, @NotNull String panelType) {
if (getObjectDetails() == null || CollectionUtils.isEmpty(getObjectDetails().getObjectDetailsPage())) {
return null;
}
List<GuiObjectDetailsPageType> focusDetailsList = getObjectDetails().getObjectDetailsPage();
GuiObjectDetailsPageType focusDetailsPage = null;
for (GuiObjectDetailsPageType detailsPage : focusDetailsList) {
if (QNameUtil.match(detailsPage.getType(), focusType)) {
focusDetailsPage = detailsPage;
break;
}
}
if (focusDetailsPage != null && CollectionUtils.isNotEmpty(focusDetailsPage.getPanel())) {
for (ContainerPanelConfigurationType panel : focusDetailsPage.getPanel()) {
if (panelType.equals(panel.getPanelType())) {
return panel;
}
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Controller;

Expand Down

0 comments on commit 456cf08

Please sign in to comment.