Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webadmin: add Account Settings sub-tab #130

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -58,6 +58,8 @@
*/
public class Frontend implements HasHandlers {

private NotificationHandler notificationHandler;

/**
* Provides static access to {@code Frontend} singleton instance.
*/
Expand Down Expand Up @@ -1109,4 +1111,20 @@ public WebAdminSettings getWebAdminSettings() {
}
return webAdminSettings;
}

public void setNotificationHandler(NotificationHandler handler) {
this.notificationHandler = handler;
}

/**
* Display a toast notification using registered {@linkplain NotificationHandler} (if available).
*/
public void showToast(String text, NotificationStatus status) {
// use local reference for async action
NotificationHandler handler = notificationHandler;
if (handler != null) {
Scheduler.get().scheduleDeferred(() -> handler.showToast(text, status));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.ovirt.engine.ui.frontend;

/**
* Generic notification handler that can be used across all modules.
*/
public interface NotificationHandler {
void showToast(String text, NotificationStatus status);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.ovirt.engine.ui.frontend;

/**
* Version without any dependencies to be used across all modules.
*/
public enum NotificationStatus {
INFO,
SUCCESS,
WARNING,
DANGER;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1960,4 +1960,6 @@ public interface CommonApplicationConstants extends Constants {
String configChangesPending();

String permissionFilter();

String propertyId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public enum NotificationStatus {
this.iconStyleName = iconStyleName;
}

public static NotificationStatus from(org.ovirt.engine.ui.frontend.NotificationStatus status) {
switch (status){
case DANGER:
return DANGER;
case SUCCESS:
return SUCCESS;
case WARNING:
return WARNING;
case INFO:
default:
return INFO;
}
}

public String getStyleName() {
return styleName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.ovirt.engine.ui.common.widget.uicommon.users;

import org.ovirt.engine.core.common.businessentities.UserProfileProperty;
import org.ovirt.engine.core.common.businessentities.aaa.DbUser;
import org.ovirt.engine.ui.common.CommonApplicationConstants;
import org.ovirt.engine.ui.common.gin.AssetProvider;
import org.ovirt.engine.ui.common.presenter.DetailActionPanelPresenterWidget;
import org.ovirt.engine.ui.common.system.ClientStorage;
import org.ovirt.engine.ui.common.uicommon.model.SearchableTableModelProvider;
import org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn;
import org.ovirt.engine.ui.common.widget.uicommon.AbstractModelBoundTableWidget;
import org.ovirt.engine.ui.uicommonweb.models.users.UserListModel;
import org.ovirt.engine.ui.uicommonweb.models.users.UserSettingsModel;

import com.google.gwt.event.shared.EventBus;

public class UserSettingsModelTable extends AbstractModelBoundTableWidget<DbUser, UserProfileProperty, UserSettingsModel> {

private static final CommonApplicationConstants constants = AssetProvider.getConstants();

public UserSettingsModelTable(SearchableTableModelProvider<UserProfileProperty, UserSettingsModel> modelProvider,
EventBus eventBus,
DetailActionPanelPresenterWidget<DbUser, UserProfileProperty, UserListModel, UserSettingsModel> actionPanel,
ClientStorage clientStorage) {
super(modelProvider, eventBus, actionPanel, clientStorage, false);
}

@Override
public void initTable() {
getTable().enableColumnResizing();

AbstractTextColumn<UserProfileProperty> nameColumn = new AbstractTextColumn<UserProfileProperty>() {
@Override
public String getValue(UserProfileProperty property) {
return property.getName();
}
};
nameColumn.makeSortable();
getTable().addColumn(nameColumn, constants.name(), "200px"); //$NON-NLS-1$

AbstractTextColumn<UserProfileProperty> idColumn = new AbstractTextColumn<UserProfileProperty>() {
@Override
public String getValue(UserProfileProperty property) {
return property.getPropertyId().toString();
}
};
getTable().addColumn(idColumn, constants.propertyId(), "250px"); //$NON-NLS-1$

AbstractTextColumn<UserProfileProperty> typeColumn = new AbstractTextColumn<UserProfileProperty>() {
@Override
public String getValue(UserProfileProperty property) {
return property.getType().name();
}
};
typeColumn.makeSortable();
getTable().addColumn(typeColumn, constants.typePermission(), "110px"); //$NON-NLS-1$

AbstractTextColumn<UserProfileProperty> contentColumn = new AbstractTextColumn<UserProfileProperty>() {
@Override
public String getValue(UserProfileProperty property) {
return property.getContent();
}
};
getTable().addColumn(contentColumn, constants.contentDisk(), "50%"); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ profileDescriptionLabel=Description
profileNameInterface=Profile Name
profileNameLabel=Name
profileNetworkInterfacePopup=Profile
propertyId=Property ID
providerLabel=Provider
provisionedSizeDisk=Virtual Size
provisionedSizeVmDiskTable=Virtual Size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private void setAssignTagsCommand(UICommand value) {
privateAssignTagsCommand = value;
}


private final UserSettingsModel userSettingsModel;
private final UserGroupListModel groupListModel;
private final UserEventNotifierListModel eventNotifierListModel;
private final UserGeneralModel generalModel;
Expand All @@ -89,14 +91,16 @@ public UserListModel(final UserGroupListModel userGroupListModel,
final UserGeneralModel userGeneralModel,
final UserQuotaListModel userQuotaListModel,
final UserPermissionListModel userPermissionListModel,
final UserEventListModel userEventListModel) {
final UserEventListModel userEventListModel,
final UserSettingsModel userSettingsModel) {
setIsTimerDisabled(true);
this.groupListModel = userGroupListModel;
this.eventNotifierListModel = userEventNotifierListModel;
this.generalModel = userGeneralModel;
this.permissionListModel = userPermissionListModel;
this.quotaListModel = userQuotaListModel;
this.eventListModel = userEventListModel;
this.userSettingsModel = userSettingsModel;
setDetailList();
setTitle(ConstantsManager.getInstance().getConstants().usersTitle());
setApplicationPlace(WebAdminApplicationPlaces.userMainPlace);
Expand All @@ -118,6 +122,7 @@ public UserListModel(final UserGroupListModel userGroupListModel,
private void setDetailList() {
List<HasEntity<DbUser>> list = new ArrayList<>();
list.add(generalModel);
list.add(userSettingsModel);
list.add(quotaListModel);
list.add(permissionListModel);
list.add(eventListModel);
Expand Down Expand Up @@ -567,4 +572,7 @@ public UserEventListModel getEventListModel() {
return eventListModel;
}

public UserSettingsModel getUserSettingsModel() {
return userSettingsModel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package org.ovirt.engine.ui.uicommonweb.models.users;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.ovirt.engine.core.common.businessentities.UserProfileProperty;
import org.ovirt.engine.core.common.businessentities.aaa.DbUser;
import org.ovirt.engine.core.common.queries.QueryType;
import org.ovirt.engine.core.common.queries.UserProfilePropertyIdQueryParameters;
import org.ovirt.engine.ui.frontend.Frontend;
import org.ovirt.engine.ui.frontend.NotificationStatus;
import org.ovirt.engine.ui.frontend.UserProfileManager;
import org.ovirt.engine.ui.uicommonweb.BaseCommandTarget;
import org.ovirt.engine.ui.uicommonweb.UICommand;
import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
import org.ovirt.engine.ui.uicommonweb.models.SearchableListModel;
import org.ovirt.engine.ui.uicompat.ConstantsManager;
import org.ovirt.engine.ui.uicompat.UIConstants;

public class UserSettingsModel extends SearchableListModel<DbUser, UserProfileProperty> {

private static final UIConstants constants = ConstantsManager.getInstance().getConstants();

private final UICommand removeCommand;

public UserSettingsModel() {
setTitle(ConstantsManager.getInstance().getConstants().accountSettings());
setHashName("user_settings"); //$NON-NLS-1$

removeCommand = new UICommand(
"RemoveUserProfilePropertyWithConfirmation", //$NON-NLS-1$
new BaseCommandTarget() {
@Override
public void executeCommand(UICommand uiCommand) {
confirmRemoval();
}
});

updateActionAvailability();
}

private void confirmRemoval() {
if (getWindow() != null) {
return;
}

ConfirmationModel model = new ConfirmationModel();
setWindow(model);
model.setTitle(ConstantsManager.getInstance().getConstants().removeUserProfilePropertiesTitle());
model.setMessage(ConstantsManager.getInstance().getConstants().removeUserProfilePropertiesMessage());
model.setHashName("remove_user_profile_properties"); //$NON-NLS-1$

model.setItems(getSelectedItems().stream().map(UserProfileProperty::getName).collect(Collectors.toList()));

model.getCommands()
.add(
UICommand.createDefaultOkUiCommand(
"RemoveUserProfileProperty", //$NON-NLS-1$
new BaseCommandTarget() {
@Override
public void executeCommand(UICommand uiCommand) {
removeUserProfileProperty();
setWindow(null);
}
}));
model.getCommands()
.add(UICommand.createCancelUiCommand(
"CancelRemovingUserProfileProperty", //$NON-NLS-1$
new BaseCommandTarget() {
@Override
public void executeCommand(UICommand uiCommand) {
setWindow(null);
}
}));
}

private void removeUserProfileProperty() {
List<UserProfileProperty> selected = getSelectedItems();
if (selected == null || selected.isEmpty()) {
return;
}

List<Boolean> results = new ArrayList<>();
Consumer<Boolean> markAsDone = result -> {
results.add(result);
if (results.size() >= selected.size()) {
syncSearch();
}
};

for (UserProfileProperty prop : selected) {
Frontend.getInstance()
.getUserProfileManager()
.deleteProperty(
prop,
property -> markAsDone.accept(true),
error -> {
String validationMessage =
String.join("\n", error.getReturnValue().getValidationMessages()); //$NON-NLS-1$
String faultMessage = error.getReturnValue().getFault().getMessage();
String toastMessage = error.getReturnValue().isValid() ? faultMessage
: validationMessage.isEmpty() ? constants.noValidateMessage()
: validationMessage;
Frontend.getInstance()
.showToast(
toastMessage,
NotificationStatus.DANGER);
markAsDone.accept(false);
},
(remote, local) -> UserProfileManager.BaseConflictResolutionStrategy.REPORT_ERROR,
this,
false);
}
}

private void updateActionAvailability() {
getRemoveCommand().setIsExecutionAllowed(getSelectedItems() != null && getSelectedItems().size() > 0);
}

public UICommand getRemoveCommand() {
return removeCommand;
}

@Override
protected String getListName() {
return "UserSettingsModel"; //$NON-NLS-1$
}

@Override
protected void onEntityChanged() {
super.onEntityChanged();

getSearchCommand().execute();
updateActionAvailability();
}

@Override
protected void syncSearch() {
DbUser user = getEntity();
if (user != null) {
super.syncSearch(QueryType.GetUserProfilePropertiesByUserId,
new UserProfilePropertyIdQueryParameters(user.getId(), null));
}
}

@Override
protected void onSelectedItemChanged() {
super.onSelectedItemChanged();
updateActionAvailability();
}

@Override
protected void selectedItemsChanged() {
super.selectedItemsChanged();
updateActionAvailability();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public final class WebAdminApplicationPlaces {
// User

public static final String userGeneralSubTabPlace = userMainPlace + SUB_TAB_PREFIX + "general"; //$NON-NLS-1$
public static final String userSettingsSubTabPlace= userMainPlace + SUB_TAB_PREFIX + "settings"; //$NON-NLS-1$
public static final String userQuotaSubTabPlace = userMainPlace + SUB_TAB_PREFIX + "quota"; //$NON-NLS-1$
public static final String userGroupSubTabPlace = userMainPlace + SUB_TAB_PREFIX + "directory_groups"; //$NON-NLS-1$
public static final String userEventNotifierSubTabPlace = userMainPlace + SUB_TAB_PREFIX + "event_notifier"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ public interface UIConstants extends Constants {

String removeUsersTitle();

String removeUserProfilePropertiesTitle();

String removeUserProfilePropertiesMessage();

String directoryGroupsTitle();

String quotaTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,8 @@ removeTemplateDisksTitle=Remove Template Disk(s)
removeTemplatesTitle=Remove Template(s)
removeUnregisteredTemplatesTitle=Remove Unregistered Template(s)
removeUsersTitle=Remove User(s)
removeUserProfilePropertiesTitle=Remove User Profile properties
removeUserProfilePropertiesMessage=Are you sure you want to remove the following User Profile properties?
removeVirtualMachineTitle=Remove Virtual Machine
removeUnregisteredVirtualMachineTitle=Remove Unregistered Virtual Machine
removeVirtualMachinesTitle=Remove Virtual Machine(s)
Expand Down
Loading