Skip to content

Commit

Permalink
different fixes around task pages -> localizations, visibility operat…
Browse files Browse the repository at this point in the history
…ional buttons,...
  • Loading branch information
katkav committed Mar 15, 2021
1 parent 656aca5 commit 6e39ae9
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 74 deletions.
Expand Up @@ -380,6 +380,11 @@ private void initOperationalButtonsPanel() {
protected void addButtons(RepeatingView repeatingView) {
initOperationalButtons(repeatingView);
}

@Override
protected void addStateButtons(RepeatingView stateButtonsView) {
initStateButtons(stateButtonsView);
}
};

opButtonPanel.setOutputMarkupId(true);
Expand Down Expand Up @@ -452,6 +457,10 @@ public void onClick(AjaxRequestTarget target) {
repeatingView.add(changeArchetype);
}

protected void initStateButtons(RepeatingView stateButtonsView) {

}

protected OperationalButtonsPanel getOperationalButtonsPanel() {
return (OperationalButtonsPanel) get(ID_BUTTONS);
}
Expand Down
Expand Up @@ -23,6 +23,9 @@
<span class="button-group">
<span class="btn btn-margin-left " wicket:id="buttons"/>
</span>
<span class="pull-right button-group">
<span class="btn btn-margin-left " wicket:id="stateButtons"/>
</span>
</div>
</div>
</div>
Expand Down
@@ -1,3 +1,9 @@
/*
* Copyright (C) 2020-2020 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.web.page.admin.server;

import java.util.Iterator;
Expand All @@ -10,6 +16,7 @@
public class OperationalButtonsPanel extends BasePanel<Void> {

private static final String ID_BUTTONS = "buttons";
private static final String ID_STATE_BUTTONS = "stateButtons";

public OperationalButtonsPanel(String id) {
super(id);
Expand All @@ -27,12 +34,21 @@ private void initLayout() {
add(repeatingView);

addButtons(repeatingView);

RepeatingView stateButtonsView = new RepeatingView(ID_STATE_BUTTONS);
add(stateButtonsView);

addStateButtons(stateButtonsView);
}

protected void addButtons(RepeatingView repeatingView) {

}

protected void addStateButtons(RepeatingView stateButtonsView) {

}

public boolean buttonsExist(){
RepeatingView repeatingView = (RepeatingView) get(ID_BUTTONS);
boolean buttonsExist = repeatingView != null && repeatingView.iterator().hasNext();
Expand Down
Expand Up @@ -13,6 +13,8 @@
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.gui.api.prism.ItemStatus;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -158,9 +160,6 @@ protected void initOperationalButtons(RepeatingView repeatingView) {
createCleanupPerformanceButton(repeatingView);
createCleanupResultsButton(repeatingView);

createRefreshNowIconButton(repeatingView);
createResumePauseButton(repeatingView);

// AjaxIconButton cleanupErrors = new AjaxIconButton(repeatingView.newChildId(), new Model<>(GuiStyleConstants.CLASS_ICON_TRASH),
// createStringResource("operationalButtonsPanel.cleanupErrors")) {
//
Expand All @@ -175,10 +174,16 @@ protected void initOperationalButtons(RepeatingView repeatingView) {

setOutputMarkupId(true);

final Label status = new Label(repeatingView.newChildId(), this::createRefreshingLabel);
status.setOutputMarkupId(true);
repeatingView.add(status);
}

//TODO later migrate higher.. this might be later used for all focuses
@Override
protected void initStateButtons(RepeatingView stateButtonsView) {
createRefreshNowIconButton(stateButtonsView);
createResumePauseButton(stateButtonsView);
final Label status = new Label(stateButtonsView.newChildId(), this::createRefreshingLabel);
status.setOutputMarkupId(true);
stateButtonsView.add(status);
}

private void createSuspendButton(RepeatingView repeatingView) {
Expand All @@ -194,7 +199,7 @@ public void onClick(AjaxRequestTarget target) {
}
};
suspend.add(new VisibleBehaviour(() -> WebComponentUtil.canSuspendTask(getTask(), PageTask.this)));
suspend.add(AttributeAppender.append("class", "btn-danger"));
suspend.add(AttributeAppender.append("class", "btn-danger btn-sm"));
repeatingView.add(suspend);
}

Expand All @@ -210,7 +215,7 @@ public void onClick(AjaxRequestTarget target) {
afterOperation(target, result);
}
};
resume.add(AttributeAppender.append("class", "btn-primary"));
resume.add(AttributeAppender.append("class", "btn-primary btn-sm"));
resume.add(new VisibleBehaviour(() -> WebComponentUtil.canResumeTask(getTask(), PageTask.this)));
repeatingView.add(resume);
}
Expand All @@ -225,7 +230,7 @@ public void onClick(AjaxRequestTarget target) {
afterOperation(target, result);
}
};
runNow.add(AttributeAppender.append("class", "btn-success"));
runNow.add(AttributeAppender.append("class", "btn-success btn-sm"));
runNow.add(new VisibleBehaviour(() -> WebComponentUtil.canRunNowTask(getTask(), PageTask.this)));
repeatingView.add(runNow);
}
Expand Down Expand Up @@ -257,7 +262,7 @@ public boolean isEnabled() {
return isNotRunning();
}
});
manageLivesyncToken.add(AttributeAppender.append("class", "btn-default"));
manageLivesyncToken.add(AttributeAppender.append("class", "btn-default btn-sm"));
manageLivesyncToken.setOutputMarkupId(true);
repeatingView.add(manageLivesyncToken);
}
Expand Down Expand Up @@ -294,7 +299,7 @@ public void onClick(AjaxRequestTarget target) {
}
};
download.add(new VisibleBehaviour(this::isDownloadReportVisible));
download.add(AttributeAppender.append("class", "btn-primary"));
download.add(AttributeAppender.append("class", "btn-primary btn-sm"));
repeatingView.add(download);
}

Expand Down Expand Up @@ -519,12 +524,7 @@ private void savePerformed(AjaxRequestTarget target, boolean run) {
PrismObjectWrapper<TaskType> taskWrapper = getObjectWrapper();
try {
// TODO MID-6783
PrismPropertyWrapper<TaskExecutionStateType> executionStatus = taskWrapper.findProperty(ItemPath.create(TaskType.F_EXECUTION_STATUS));
if (run) {
executionStatus.getValue().setRealValue(TaskExecutionStateType.RUNNABLE);
} else {
executionStatus.getValue().setRealValue(TaskExecutionStateType.SUSPENDED);
}
setTaskInitialState(taskWrapper, run);

setupOwner(taskWrapper);
setupRecurrence(taskWrapper);
Expand All @@ -548,6 +548,32 @@ private void savePerformed(AjaxRequestTarget target, boolean run) {
super.savePerformed(target);
}

private void setTaskInitialState(PrismObjectWrapper<TaskType> taskWrapper, boolean run) throws SchemaException {
if (!isAdd()) {
return;
}
PrismPropertyWrapper<TaskExecutionStateType> executionStatus = taskWrapper.findProperty(ItemPath.create(TaskType.F_EXECUTION_STATUS));
PrismPropertyWrapper<TaskSchedulingStateType> schedulingState = taskWrapper.findProperty(ItemPath.create(TaskType.F_SCHEDULING_STATE));
if (executionStatus == null || schedulingState == null) {
throw new SchemaException("Task cannot be set as running, no execution status or scheduling status present");
}
if (run) {
setTaskInitiallyRunning(executionStatus, schedulingState);
} else {
setTaskInitiallySuspended(executionStatus, schedulingState);
}
}

private void setTaskInitiallyRunning(PrismPropertyWrapper<TaskExecutionStateType> executionStatus, PrismPropertyWrapper<TaskSchedulingStateType> schedulingState) throws SchemaException {
executionStatus.getValue().setRealValue(TaskExecutionStateType.RUNNABLE);
schedulingState.getValue().setRealValue(TaskSchedulingStateType.READY);
}

private void setTaskInitiallySuspended(PrismPropertyWrapper<TaskExecutionStateType> executionStatus, PrismPropertyWrapper<TaskSchedulingStateType> schedulingState) throws SchemaException {
executionStatus.getValue().setRealValue(TaskExecutionStateType.SUSPENDED);
schedulingState.getValue().setRealValue(TaskSchedulingStateType.SUSPENDED);
}

private void setupOwner(PrismObjectWrapper<TaskType> taskWrapper) throws SchemaException {
PrismReferenceWrapper<Referencable> taskOwner = taskWrapper.findReference(ItemPath.create(TaskType.F_OWNER_REF));
if (taskOwner == null) {
Expand Down
Expand Up @@ -165,37 +165,34 @@ protected IModel<String> getDisplayNameModel() {

@Override
protected IModel<String> getTitleModel() {
return new IModel<String>() {
@Override
public String getObject() {
TaskType taskType = getModelObject();

String rv;
if (taskType.getExpectedTotal() != null) {
rv = createStringResource("TaskSummaryPanel.progressWithTotalKnown", taskType.getProgress(), taskType.getExpectedTotal())
.getString();
} else {
rv = createStringResource("TaskSummaryPanel.progressWithTotalUnknown", taskType.getProgress()).getString();
}
if (taskType.getExecutionStatus() != null) {
switch (taskType.getExecutionStatus()) {
case SUSPENDED:
rv += " " + getString("TaskSummaryPanel.progressIfSuspended");
break;
case CLOSED:
rv += " " + getString("TaskSummaryPanel.progressIfClosed");
break;
case WAITING:
rv += " " + getString("TaskSummaryPanel.progressIfWaiting");
break;
}
}
Long stalledSince = WebComponentUtil.xgc2long(taskType.getStalledSince());
if (stalledSince != null) {
rv += " " + getString("TaskSummaryPanel.progressIfStalled", WebComponentUtil.formatDate(new Date(stalledSince)));
return (IModel<String>) () -> {
TaskType taskType = getModelObject();

String rv;
if (taskType.getExpectedTotal() != null) {
rv = createStringResource("TaskSummaryPanel.progressWithTotalKnown", taskType.getProgress(), taskType.getExpectedTotal())
.getString();
} else {
rv = createStringResource("TaskSummaryPanel.progressWithTotalUnknown", taskType.getProgress()).getString();
}
if (taskType.getExecutionStatus() != null) {
switch (taskType.getExecutionStatus()) {
case SUSPENDED:
rv += " " + getString("TaskSummaryPanel.progressIfSuspended");
break;
case CLOSED:
rv += " " + getString("TaskSummaryPanel.progressIfClosed");
break;
case WAITING:
rv += " " + getString("TaskSummaryPanel.progressIfWaiting");
break;
}
return rv;
}
}
Long stalledSince = WebComponentUtil.xgc2long(taskType.getStalledSince());
if (stalledSince != null) {
rv += " " + getString("TaskSummaryPanel.progressIfStalled", WebComponentUtil.formatDate(new Date(stalledSince)));
}
return rv;
};
}

Expand All @@ -217,33 +214,30 @@ public String getObject() {

@Override
protected IModel<String> getTitle3Model() {
return new IModel<String>() {
@Override
public String getObject() {
return (IModel<String>) () -> {

TaskType taskType = getModelObject();
if (taskType == null) {
return null;
}
long started = XmlTypeConverter.toMillis(taskType.getLastRunStartTimestamp());
long finished = XmlTypeConverter.toMillis(taskType.getLastRunFinishTimestamp());
if (started == 0) {
return null;
}
TaskDtoExecutionState status = TaskDtoExecutionState.fromTaskExecutionStatus(
taskType.getExecutionStatus(), taskType.getNodeAsObserved() != null);
if (status.equals(TaskDtoExecutionState.RUNNING)
|| finished == 0 || finished < started) {

return getString("TaskStatePanel.message.executionTime.notFinished",
WebComponentUtil.getShortDateTimeFormattedValue(new Date(started), getPageBase()),
DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - started));
} else {
return getString("TaskStatePanel.message.executionTime.finished",
WebComponentUtil.getShortDateTimeFormattedValue(new Date(started), getPageBase()),
WebComponentUtil.getShortDateTimeFormattedValue(new Date(finished), getPageBase()),
DurationFormatUtils.formatDurationHMS(finished - started));
}
TaskType taskType = getModelObject();
if (taskType == null) {
return null;
}
long started = XmlTypeConverter.toMillis(taskType.getLastRunStartTimestamp());
long finished = XmlTypeConverter.toMillis(taskType.getLastRunFinishTimestamp());
if (started == 0) {
return null;
}
TaskDtoExecutionState status = TaskDtoExecutionState.fromTaskExecutionStatus(
taskType.getExecutionStatus(), taskType.getNodeAsObserved() != null);
if (status.equals(TaskDtoExecutionState.RUNNING)
|| finished == 0 || finished < started) {

return getString("TaskStatePanel.message.executionTime.notFinished",
WebComponentUtil.getShortDateTimeFormattedValue(new Date(started), getPageBase()),
DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - started));
} else {
return getString("TaskStatePanel.message.executionTime.finished",
WebComponentUtil.getShortDateTimeFormattedValue(new Date(started), getPageBase()),
WebComponentUtil.getShortDateTimeFormattedValue(new Date(finished), getPageBase()),
DurationFormatUtils.formatDurationHMS(finished - started));
}
};
}
Expand Down
Expand Up @@ -87,7 +87,7 @@ private TaskInfoBoxType createInfoBoxType(String title, ProcessedItemSetType pro
}

private String createInfoBoxMessage(String result, ProcessedItemSetType processedItemSetType) {
return getString("TaskIterativeProgress.box.title" + result, getFormattedDate(processedItemSetType));
return getString("TaskIterativeProgress.box.title." + result, getFormattedDate(processedItemSetType));
}

//TODO use also this in chart?
Expand Down
Expand Up @@ -453,6 +453,9 @@
<item>
<c:path>executionStatus</c:path>
</item>
<item>
<c:path>schedulingState</c:path>
</item>
<item>
<c:path>node</c:path>
</item>
Expand Down

0 comments on commit 6e39ae9

Please sign in to comment.