Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

[HAL-908] - Unnecessary add and remove button for main-administrator … #439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
Expand All @@ -23,6 +24,7 @@
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.shared.proxy.PlaceRequest;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.core.BootstrapContext;
import org.jboss.as.console.client.core.NameTokens;
import org.jboss.as.console.client.core.SuspendableViewImpl;
import org.jboss.as.console.client.domain.model.ServerGroupRecord;
Expand Down Expand Up @@ -85,7 +87,7 @@ interface StatusTemplate extends SafeHtmlTemplates {

@Inject
public ColumnHostView(final HostStore hostStore, final ServerStore serverStore,
final PreviewContentFactory contentFactory) {
final PreviewContentFactory contentFactory, final BootstrapContext bootstrapContext) {
super();
this.contentFactory = contentFactory;

Expand Down Expand Up @@ -172,15 +174,16 @@ public Object getKey(ServerGroupRecord item) {
return item.getName().contains(token);
});

groups.setTopMenuItems(new MenuDelegate<ServerGroupRecord>("Add",
new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(ServerGroupRecord group) {
// TODO "/server-group=*", "add" permission
presenter.launchNewGroupDialog();
}
}, MenuDelegate.Role.Operation)
);
if (bootstrapContext.isAdmin() || bootstrapContext.isSuperUser()) {
groups.setTopMenuItems(new MenuDelegate<ServerGroupRecord>("Add",
new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(ServerGroupRecord group) {
// TODO "/server-group=*", "add" permission
presenter.launchNewGroupDialog();
}
}, MenuDelegate.Role.Operation));
}

groups.setPreviewFactory((data, callback) -> contentFactory
.createContent(PreviewContent.INSTANCE.runtime_server_group(), callback));
Expand Down Expand Up @@ -418,54 +421,67 @@ public void execute() {
}
});

groups.setMenuItems(
List<MenuDelegate<ServerGroupRecord>> menuList = new LinkedList<>();

menuList.add(
new MenuDelegate<ServerGroupRecord>( // TODO permissions
Console.CONSTANTS.common_label_view(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {
Console.CONSTANTS.common_label_view(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

//groups.selectByKey(group.getName());
Console.getCircuit().dispatch(new GroupSelection(group.getName()));

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
Console.getPlaceManager().revealRelativePlace(
new PlaceRequest(NameTokens.ServerGroupPresenter).with("action", "edit")
);
}
});

//groups.selectByKey(group.getName());
Console.getCircuit().dispatch(new GroupSelection(group.getName()));
}
})
);

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
Console.getPlaceManager().revealRelativePlace(
new PlaceRequest(NameTokens.ServerGroupPresenter).with("action", "edit")
);
}
});
if(bootstrapContext.isAdmin() || bootstrapContext.isSuperUser()) {
menuList.add(
new MenuDelegate<ServerGroupRecord>( // TODO permissions "/server-group=*", "remove"
Console.CONSTANTS.common_label_delete(),
new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

Console.getCircuit().dispatch(new GroupSelection(group.getName()));

Feedback.confirm(
Console.MESSAGES.deleteServerGroup(),
Console.MESSAGES.deleteServerGroupConfirm(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onDeleteGroup(group);
}
});
}
}, MenuDelegate.Role.Operation)
);
}

}
}),
new MenuDelegate<ServerGroupRecord>( // TODO permissions "/server-group=*", "remove"
Console.CONSTANTS.common_label_delete(),
new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

Console.getCircuit().dispatch(new GroupSelection(group.getName()));

Feedback.confirm(
Console.MESSAGES.deleteServerGroup(),
Console.MESSAGES.deleteServerGroupConfirm(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onDeleteGroup(group);
}
});
}
}, MenuDelegate.Role.Operation),
menuList.add(
new MenuDelegate<ServerGroupRecord>( // TODO permissions "/server-group=*", "add"
Console.CONSTANTS.common_label_copy(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {
Console.getCircuit().dispatch(new GroupSelection(group.getName()));
presenter.launchCopyWizard(group);
}
}, MenuDelegate.Role.Operation),
}, MenuDelegate.Role.Operation)
);

menuList.add(
new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.common_label_start(), new ContextualCommand<ServerGroupRecord>() {
@Override
Expand All @@ -485,104 +501,116 @@ public void onConfirmation(boolean isConfirmed) {
);
}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*", "start-servers"),
.setOperationAddress("/server-group=*", "start-servers")
);

menuList.add(
new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.common_label_stop(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

Feedback.confirm(
Console.CONSTANTS.stopServerGroup(),
Console.MESSAGES.wantToStopServerGroup(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onGroupLifecycle(group.getName(), LifecycleOperation.STOP);
}
Console.CONSTANTS.common_label_stop(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

Feedback.confirm(
Console.CONSTANTS.stopServerGroup(),
Console.MESSAGES.wantToStopServerGroup(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onGroupLifecycle(group.getName(), LifecycleOperation.STOP);
}
);
}
);

}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*", "stop-servers"),
}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*", "stop-servers")
);

new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.suspend(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {
menuList.add(
new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.suspend(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

presenter.onLaunchSuspendDialogue(group);
presenter.onLaunchSuspendDialogue(group);

}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*", "suspend-servers"),
}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*", "suspend-servers")
);

new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.resume(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

Feedback.confirm(
Console.CONSTANTS.resumeServerGroup(),
Console.MESSAGES.wantToResumeServerGroup(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onGroupLifecycle(group.getName(), LifecycleOperation.RESUME);
}
menuList.add(
new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.resume(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

Feedback.confirm(
Console.CONSTANTS.resumeServerGroup(),
Console.MESSAGES.wantToResumeServerGroup(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onGroupLifecycle(group.getName(), LifecycleOperation.RESUME);
}
);
}
);

}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*","resume-servers"),
}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*","resume-servers")
);

new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.common_label_restart(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {
menuList.add(
new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.common_label_restart(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

Feedback.confirm(
Console.CONSTANTS.restartServerGroup(),
Console.MESSAGES.wantToRestartServerGroup(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onGroupLifecycle(group.getName(), LifecycleOperation.RESTART);
}
Feedback.confirm(
Console.CONSTANTS.restartServerGroup(),
Console.MESSAGES.wantToRestartServerGroup(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onGroupLifecycle(group.getName(), LifecycleOperation.RESTART);
}
);
}
);

}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*","restart-servers"),
}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*","restart-servers")
);

new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.common_label_reload(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {
menuList.add(
new MenuDelegate<ServerGroupRecord>(
Console.CONSTANTS.common_label_reload(), new ContextualCommand<ServerGroupRecord>() {
@Override
public void executeOn(final ServerGroupRecord group) {

Feedback.confirm(
Console.CONSTANTS.reloadServerGroup(),
Console.MESSAGES.wantToReloadServerGroup(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onGroupLifecycle(group.getName(), LifecycleOperation.RELOAD);
}
Feedback.confirm(
Console.CONSTANTS.reloadServerGroup(),
Console.MESSAGES.wantToReloadServerGroup(group.getName()),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed)
presenter.onGroupLifecycle(group.getName(), LifecycleOperation.RELOAD);
}
);
}
);

}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*","reload-servers")
}
}, MenuDelegate.Role.Operation)
.setOperationAddress("/server-group=*","reload-servers")
);

groups.setMenuItems(menuList.toArray(new MenuDelegate[menuList.size()]));
}

public void updateBrowseItems() {
Expand Down