Skip to content

Commit

Permalink
Merge branch 'master' into feature/smart-correlation-prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Aug 2, 2022
2 parents fa79120 + 0b24dfb commit 8f96fb6
Show file tree
Hide file tree
Showing 25 changed files with 477 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;


/**
* @author lskublik
*/
Expand Down Expand Up @@ -142,17 +141,20 @@ protected IModel<String> getSubTextModel() {
}

public boolean onNextPerformed(AjaxRequestTarget target) {
getWizard().next();
target.add(getWizard().getPanel());
WizardModel model = getWizard();
if (model.hasNext()) {
model.next();
target.add(model.getPanel());
}

return false;
}

public boolean onBackPerformed(AjaxRequestTarget target) {
int index = getWizard().getActiveStepIndex();
if (index > 0) {
getWizard().previous();
target.add(getWizard().getPanel());
WizardModel model = getWizard();
if (model.hasPrevious()) {
model.previous();
target.add(model.getPanel());
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public void init(Page page) {
String stepId = getStepIdFromParams(page);
if (stepId != null) {
setActiveStepById(stepId);
} else {
for (int i = 0; i < steps.size(); i++) {
WizardStep step = steps.get(i);

if (BooleanUtils.isTrue(step.isStepVisible().getObject())) {
activeStepIndex = i;
break;
}
}
}

fireActiveStepChanged(getActiveStep());
Expand Down Expand Up @@ -113,17 +122,13 @@ public void setActiveStepById(String id) {
WizardStep step = steps.get(i);

if (Objects.equals(id, step.getStepId()) && BooleanUtils.isTrue(step.isStepVisible().getObject())) {
setActiveStepIndex(i);
activeStepIndex = i;
break;
}
}
}

public int getActiveStepIndex() {
return activeStepIndex;
}

public int getActiveStepVisibleIndex() {
int index = 0;
for (int i = 0; i < activeStepIndex; i++) {
if (BooleanUtils.isTrue(steps.get(i).isStepVisible().getObject())) {
Expand All @@ -133,27 +138,70 @@ public int getActiveStepVisibleIndex() {
return index;
}

private void setActiveStepIndex(int activeStepIndex) {
if (activeStepIndex < 0) {
return;
public boolean hasNext() {
return findNextStep() != null;
}

private WizardStep findNextStep() {
for (int i = activeStepIndex + 1; i < steps.size(); i++) {
if (i >= steps.size()) {
return null;
}

if (BooleanUtils.isTrue(steps.get(i).isStepVisible().getObject())) {
return steps.get(i);
}
}
if (activeStepIndex >= steps.size()) {

return null;
}

public void next() {
int index = activeStepIndex;

WizardStep next = findNextStep();
if (next == null) {
return;
}

this.activeStepIndex = activeStepIndex;
activeStepIndex = steps.indexOf(next);

if (index != activeStepIndex) {
fireActiveStepChanged(getActiveStep());
}
}

public boolean hasPrevious() {
return findPreviousStep() != null;
}

public void next() {
setActiveStepIndex(activeStepIndex + 1);
private WizardStep findPreviousStep() {
for (int i = activeStepIndex - 1; i >= 0; i--) {
if (i < 0) {
return null;
}

fireActiveStepChanged(getActiveStep());
if (BooleanUtils.isTrue(steps.get(i).isStepVisible().getObject())) {
return steps.get(i);
}
}

return null;
}

public void previous() {
setActiveStepIndex(activeStepIndex - 1);
int index = activeStepIndex;

fireActiveStepChanged(getActiveStep());
WizardStep previous = findPreviousStep();
if (previous == null) {
return;
}

activeStepIndex = steps.indexOf(previous);

if (index != activeStepIndex) {
fireActiveStepChanged(getActiveStep());
}
}

public WizardStep getNextPanel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void initLayout() {
protected void populateItem(ListItem<IModel<String>> listItem) {
WizardHeaderStepPanel step = new WizardHeaderStepPanel(ID_STEP, listItem.getIndex(), listItem.getModelObject());
// todo fix, if steps are invisible index might shift?
step.add(AttributeAppender.append("class", () -> wizardModel.getActiveStepVisibleIndex() == listItem.getIndex() ? "active" : null));
step.add(AttributeAppender.append("class", () -> wizardModel.getActiveStepIndex() == listItem.getIndex() ? "active" : null));
listItem.add(step);

WebMarkupContainer line = new WebMarkupContainer(ID_LINE);
Expand All @@ -144,7 +144,7 @@ protected void onBackPerformed(AjaxRequestTarget target) {
return;
}

if (wizardModel.getActiveStepIndex() == 0) {
if (!wizardModel.hasPrevious()) {
getPageBase().redirectBack();
} else {
wizardModel.previous();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4588,8 +4588,8 @@ public static <T> List<T> sortDropDownChoices(IModel<? extends List<? extends T>
return sortedList;
}

public static IChoiceRenderer<QName> getRelationChoicesRenderer(PageBase pageBase) {
return new IChoiceRenderer<QName>() {
public static IChoiceRenderer<QName> getRelationChoicesRenderer() {
return new IChoiceRenderer<>() {

private static final long serialVersionUID = 1L;

Expand All @@ -4608,8 +4608,9 @@ public Object getDisplayValue(QName object) {
DisplayType display = def.getDisplay();
if (display != null) {
PolyStringType label = display.getLabel();

if (PolyStringUtils.isNotEmpty(label)) {
return pageBase.createStringResource(label).getString();
return getTranslatedPolyString(label);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,6 @@ private void initLayout() {
WizardPanel wizard = new WizardPanel(ID_WIZARD, new WizardModel(createSteps()));
wizard.setOutputMarkupId(true);
mainForm.add(wizard);

// List<ListGroupMenuItem> list = new ArrayList<>();
// ListGroupMenuItem allRoles = new ListGroupMenuItem("fa fa-fw fa-border-all", "All roles");
// allRoles.setActive(true);
// list.add(allRoles);
//
// ListGroupMenuItem rolesOfTeamMate = new ListGroupMenuItem("fa fa-fw fa-users", "Roles of team mate");
// rolesOfTeamMate.setBadge("12");
// list.add(rolesOfTeamMate);
//
// ListGroupMenuItem menu2 = new ListGroupMenuItem("fa fa-fw fa-users", "Roles of team mate");
// list.add(menu2);
//
// ListGroupMenuItem o1 = new ListGroupMenuItem(null, "Option 1");
// menu2.getItems().add(o1);
// ListGroupMenuItem o2 = new ListGroupMenuItem(null, "Option 2");
// menu2.getItems().add(o2);
// ListGroupMenuItem o3 = new ListGroupMenuItem(null, "Option 3");
// menu2.getItems().add(o3);
// ListGroupMenuItem o31 = new ListGroupMenuItem(null, "Option 31");
// o3.getItems().add(o31);
//
// ListGroupMenuPanel sample = new ListGroupMenuPanel("sample", Model.ofList(list));
// add(sample);
}

private List<WizardStep> createSteps() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@ <h3 class="card-title">
<select class="form-control" wicket:id="validity"/>
</div>
</wicket:enclosure>
<div class="form-group" wicket:id="customValidity">
<div class="form-group">
<label class="col-form-label-sm"><wicket:message key="ActivationType.validFrom"/></label>
<div wicket:id="customValidityFrom"/>
</div>
<div class="form-group">
<label class="col-form-label-sm"><wicket:message key="ActivationType.validTo"/></label>
<div wicket:id="customValidityTo"/>
</div>
</div>
<div class="form-group" wicket:id="customValidity"/>
<wicket:enclosure child="comment">
<div class="form-group">
<label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ public class CartSummaryPanel extends BasePanel<RequestAccess> implements Access
private static final String ID_VALIDITY_INFO = "validityInfo";
private static final String ID_COMMENT_INFO = "commentInfo";
private static final String ID_CUSTOM_VALIDITY = "customValidity";
private static final String ID_CUSTOM_VALIDITY_INFO = "customValidityInfo";
private static final String ID_CUSTOM_VALIDITY_FROM = "customValidityFrom";
private static final String ID_CUSTOM_VALIDITY_TO = "customValidityTo";
private static final String ID_FORM = "form";
private static final String ID_MESSAGES = "messages";

Expand Down Expand Up @@ -158,35 +155,21 @@ public void setObject(Object object) {
}
};

IModel<Date> customFrom = Model.of((Date) null);
IModel<Date> customTo = Model.of((Date) null);

MidpointForm form = new MidpointForm(ID_FORM);
add(form);

WebMarkupContainer customValidity = new WebMarkupContainer(ID_CUSTOM_VALIDITY);
IModel<CustomValidity> customValidityModel = Model.of(new CustomValidity());

CustomValidityPanel customValidity = new CustomValidityPanel(ID_CUSTOM_VALIDITY, customValidityModel);
customValidity.add(new VisibleBehaviour(() -> RequestAccess.VALIDITY_CUSTOM_LENGTH.equals(validityModel.getObject())));
customValidity.setOutputMarkupId(true);
customValidity.setOutputMarkupPlaceholderTag(true);
form.add(customValidity);

Label customValidityInfo = new Label(ID_CUSTOM_VALIDITY_INFO);
customValidityInfo.add(new TooltipBehavior());
customValidity.add(customValidityInfo);

DateInput customValidFrom = new DateInput(ID_CUSTOM_VALIDITY_FROM, customFrom);
customValidFrom.setOutputMarkupId(true);
customValidity.add(customValidFrom);

DateInput customValidTo = new DateInput(ID_CUSTOM_VALIDITY_TO, customTo);
customValidTo.setOutputMarkupId(true);
customValidity.add(customValidTo);

form.add(new DateValidator(customValidFrom, customValidTo));
form.add(new AbstractFormValidator() {
@Override
public FormComponent<?>[] getDependentFormComponents() {
return new FormComponent[] { customValidFrom, customValidTo };
return new FormComponent[] { customValidity.getFrom(), customValidity.getTo() };
}

@Override
Expand All @@ -195,8 +178,8 @@ public void validate(Form<?> form) {
return;
}

Date from = customValidFrom.getConvertedInput();
Date to = customValidTo.getConvertedInput();
Date from = customValidity.getFrom().getConvertedInput();
Date to = customValidity.getTo().getConvertedInput();
if (from == null && to == null) {
form.error(getString("CartSummaryPanel.validityEmpty"));
}
Expand Down Expand Up @@ -262,7 +245,7 @@ public void onClick(AjaxRequestTarget target) {

@Override
protected void onSubmit(AjaxRequestTarget target) {
submitPerformed(target, customFrom, customTo);
submitPerformed(target, customValidityModel);
}

@Override
Expand All @@ -278,16 +261,17 @@ protected void onError(AjaxRequestTarget target) {
protected void openConflictPerformed(AjaxRequestTarget target) {
}

private void submitPerformed(AjaxRequestTarget target, IModel<Date> customFrom, IModel<Date> customTo) {
private void submitPerformed(AjaxRequestTarget target, IModel<CustomValidity> customValidity) {
RequestAccess access = getModelObject();

if (!RequestAccess.VALIDITY_CUSTOM_LENGTH.equals(access.getSelectedValidity())) {
submitPerformed(target);
return;
}

XMLGregorianCalendar from = XmlTypeConverter.createXMLGregorianCalendar(customFrom.getObject());
XMLGregorianCalendar to = XmlTypeConverter.createXMLGregorianCalendar(customTo.getObject());
CustomValidity cv = customValidity.getObject();
XMLGregorianCalendar from = XmlTypeConverter.createXMLGregorianCalendar(cv.getFrom());
XMLGregorianCalendar to = XmlTypeConverter.createXMLGregorianCalendar(cv.getTo());

access.setValidity(from, to);

Expand Down Expand Up @@ -466,7 +450,7 @@ public void onClick(AjaxRequestTarget target) {
private void editItemPerformed(AjaxRequestTarget target, IModel<ShoppingCartItem> model) {
PageBase page = getPageBase();

ShoppingCartEditPanel panel = new ShoppingCartEditPanel(model) {
ShoppingCartEditPanel panel = new ShoppingCartEditPanel(model, getModel()) {

@Override
protected void savePerformed(AjaxRequestTarget target, IModel<ShoppingCartItem> model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ protected PrismObjectWrapper load() {
}
};

SingleContainerPanel container = new SingleContainerPanel(ID_PANEL, wrapper, item.getModelObject());
item.add(container);
// SingleContainerPanel container = new SingleContainerPanel(ID_PANEL, wrapper, item.getModelObject());
// item.add(container);

// SingleContainerPanel panel = new SingleContainerPanel(ID_PANEL,
// PrismContainerWrapperModel.fromContainerWrapper(wrapper, ItemPath.create(RoleType.F_ACTIVATION)),
// ActivationType.COMPLEX_TYPE);
// item.add(panel);
SingleContainerPanel panel = new SingleContainerPanel(ID_PANEL,
PrismContainerWrapperModel.fromContainerWrapper(wrapper, ItemPath.EMPTY_PATH),
ActivationType.COMPLEX_TYPE);
item.add(panel);
}
};
add(panels);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.gui.impl.page.self.requestAccess;

import java.io.Serializable;
import java.util.Date;

/**
* Created by Viliam Repan (lazyman).
*/
public class CustomValidity implements Serializable {

private Date from;

private Date to;

public Date getFrom() {
return from;
}

public void setFrom(Date from) {
this.from = from;
}

public Date getTo() {
return to;
}

public void setTo(Date to) {
this.to = to;
}
}

0 comments on commit 8f96fb6

Please sign in to comment.