Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
SugaryLump committed Dec 3, 2024
1 parent 4283ac2 commit 622089b
Show file tree
Hide file tree
Showing 19 changed files with 511 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import com.databasepreservation.common.api.exceptions.RESTException;
import com.databasepreservation.common.exceptions.AuthorizationException;
import org.apache.solr.client.solrj.SolrServerException;
import org.roda.core.data.exceptions.GenericException;
import org.roda.core.data.exceptions.NotFoundException;
Expand All @@ -27,6 +24,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.databasepreservation.common.api.exceptions.RESTException;
import com.databasepreservation.common.api.v1.utils.StringResponse;
import com.databasepreservation.common.client.ViewerConstants;
import com.databasepreservation.common.client.index.FindRequest;
Expand All @@ -45,11 +43,13 @@
import com.databasepreservation.common.client.index.filter.SimpleFilterParameter;
import com.databasepreservation.common.client.index.sort.Sorter;
import com.databasepreservation.common.client.models.activity.logs.LogEntryState;
import com.databasepreservation.common.client.models.authorization.AuthorizationDetails;
import com.databasepreservation.common.client.models.status.database.DatabaseStatus;
import com.databasepreservation.common.client.models.structure.ViewerDatabase;
import com.databasepreservation.common.client.models.structure.ViewerDatabaseStatus;
import com.databasepreservation.common.client.models.user.User;
import com.databasepreservation.common.client.services.DatabaseService;
import com.databasepreservation.common.exceptions.AuthorizationException;
import com.databasepreservation.common.exceptions.ViewerException;
import com.databasepreservation.common.server.ViewerConfiguration;
import com.databasepreservation.common.server.ViewerFactory;
Expand Down Expand Up @@ -389,7 +389,7 @@ public Boolean delete(String databaseUUID) {
}

@Override
public Set<String> getDatabasePermissions(String databaseUUID) {
public Map<String, AuthorizationDetails> getDatabasePermissions(String databaseUUID) {
ControllerAssistant controllerAssistant = new ControllerAssistant() {};

LogEntryState state = LogEntryState.SUCCESS;
Expand All @@ -410,7 +410,8 @@ public Set<String> getDatabasePermissions(String databaseUUID) {
}

@Override
public Set<String> updateDatabasePermissions(String databaseUUID, Set<String> permissions) {
public Map<String, AuthorizationDetails> updateDatabasePermissions(String databaseUUID,
Map<String, AuthorizationDetails> permissions) {
ControllerAssistant controllerAssistant = new ControllerAssistant() {};

LogEntryState state = LogEntryState.SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public class ViewerConstants {
public static final String INDEX_SEARCH = "search";
public static final String INDEX_WILDCARD = "*";

/*
* COMMON FIELDS
*/
public static final String SOLR_CONTENT_TYPE = "content_type";

/*
* DATABASE FIELDS
*/
Expand All @@ -141,6 +146,10 @@ public class ViewerConstants {
public static final String SOLR_DATABASES_VALIDATION_WARNINGS = "siard_validation_warnings";
public static final String SOLR_DATABASES_VALIDATION_SKIPPED = "siard_validation_skipped";
public static final String SOLR_DATABASES_PERMISSIONS = "database_permissions";
public static final String SOLR_DATABASES_PERMISSIONS_GROUP = "group_value";
public static final String SOLR_DATABASES_PERMISSIONS_EXPIRY = "expiry_date";
public static final String SOLR_DATABASES_CONTENT_TYPE_ROOT = "database";
public static final String SOLR_DATABASES_CONTENT_TYPE_PERMISSION = "permission";

/*
* ACTIVITY LOG FIELDS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
package com.databasepreservation.common.client.common.lists.cells;

import static com.google.gwt.dom.client.BrowserEvents.CLICK;
import static com.google.gwt.dom.client.BrowserEvents.KEYDOWN;

import java.util.Date;

import com.google.gwt.cell.client.AbstractEditableCell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.text.shared.SafeHtmlRenderer;
import com.google.gwt.text.shared.SimpleSafeHtmlRenderer;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.datepicker.client.DatePicker;

/**
* @author Alexandre Flores <aflores@keep.pt>
*/
public class DatePickerAllowsNullCell extends AbstractEditableCell<Date, Date> {

private static final int ESCAPE = 27;
private static final String open_text_span = "<span class=\"DatePickerAllowsNullCell_text\">";
private static final String close_text_span = "</span>";

private final DatePicker datePicker;
private final DateTimeFormat format;
private int offsetX = 10;
private int offsetY = 10;
private Object lastKey;
private Element lastParent;
private int lastIndex;
private int lastColumn;
private Date lastValue;
private PopupPanel panel;
private final SafeHtmlRenderer<String> renderer;
private ValueUpdater<Date> valueUpdater;

/**
* Constructs a new DatePickerCell that uses the date/time format given by
* {@link DateTimeFormat#getFullDateFormat}.
*/
@SuppressWarnings("deprecation")
public DatePickerAllowsNullCell() {
this(DateTimeFormat.getFullDateFormat(), SimpleSafeHtmlRenderer.getInstance());
}

/**
* Constructs a new DatePickerCell that uses the given date/time format and a
* {@link SimpleSafeHtmlRenderer}.
*
* @param format
* a {@link DateTimeFormat} instance
*/
public DatePickerAllowsNullCell(DateTimeFormat format) {
this(format, SimpleSafeHtmlRenderer.getInstance());
}

/**
* Constructs a new DatePickerCell that uses the date/time format given by
* {@link DateTimeFormat#getFullDateFormat} and the given
* {@link SafeHtmlRenderer}.
*
* @param renderer
* a {@link SafeHtmlRenderer SafeHtmlRenderer<String>} instance
*/
public DatePickerAllowsNullCell(SafeHtmlRenderer<String> renderer) {
this(DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_FULL), renderer);
}

/**
* Constructs a new DatePickerCell that uses the given date/time format and
* {@link SafeHtmlRenderer}.
*
* @param format
* a {@link DateTimeFormat} instance
* @param renderer
* a {@link SafeHtmlRenderer SafeHtmlRenderer<String>} instance
*/
public DatePickerAllowsNullCell(DateTimeFormat format, SafeHtmlRenderer<String> renderer) {
super(CLICK, KEYDOWN);
if (format == null) {
throw new IllegalArgumentException("format == null");
}
if (renderer == null) {
throw new IllegalArgumentException("renderer == null");
}
this.format = format;
this.renderer = renderer;

this.datePicker = new DatePicker();
this.panel = new PopupPanel(true, true) {
@Override
protected void onPreviewNativeEvent(Event.NativePreviewEvent event) {
if (Event.ONKEYUP == event.getTypeInt()) {
if (event.getNativeEvent().getKeyCode() == ESCAPE) {
// Dismiss when escape is pressed
panel.hide();
}
}
}
};
panel.addCloseHandler(new CloseHandler<PopupPanel>() {
public void onClose(CloseEvent<PopupPanel> event) {
lastKey = null;
lastValue = null;
lastIndex = -1;
lastColumn = -1;
if (lastParent != null && !event.isAutoClosed()) {
// Refocus on the containing cell after the user selects a value, but
// not if the popup is auto closed.
lastParent.focus();
}
lastParent = null;
}
});
panel.add(datePicker);

// Hide the panel and call valueUpdater.update when a date is selected
datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {
public void onValueChange(ValueChangeEvent<Date> event) {
// Remember the values before hiding the popup.
Element cellParent = lastParent;
Date oldValue = lastValue;
Object key = lastKey;
int index = lastIndex;
int column = lastColumn;
panel.hide();

// Update the cell and value updater.
Date date = event.getValue();
setViewData(key, date);
setValue(new Context(index, column, key), cellParent, oldValue);
if (valueUpdater != null) {
valueUpdater.update(date);
}
}
});
}

/**
* Returns the underlying {@link DatePicker} widget used by this cell.
*/
public DatePicker getDatePicker() {
return datePicker;
}

@Override
public boolean isEditing(Context context, Element parent, Date value) {
return lastKey != null && lastKey.equals(context.getKey());
}

@Override
public void onBrowserEvent(Context context, Element parent, Date value, NativeEvent event,
ValueUpdater<Date> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
if (CLICK.equals(event.getType())) {
onEnterKeyDown(context, parent, value, event, valueUpdater);
}
}

@Override
public void render(Context context, Date value, SafeHtmlBuilder sb) {
// Get the view data.
Object key = context.getKey();
Date viewData = getViewData(key);
if (viewData != null && viewData.equals(value)) {
clearViewData(key);
viewData = null;
}

String s = null;
if (viewData != null) {
s = format.format(viewData);
} else if (value != null) {
s = format.format(value);
}
sb.append(SafeHtmlUtils.fromSafeConstant(open_text_span));
if (s != null) {
sb.append(renderer.render(s));
} else {
sb.append(SafeHtmlUtils.fromSafeConstant("NO DATE"));
}
sb.append(SafeHtmlUtils.fromSafeConstant(close_text_span));
if (s != null) {
Button removeButton = new Button("X");
removeButton.addStyleName("datePickerAllowsNullCell_remove");
removeButton.addClickHandler(event -> {
// Remember the values before hiding the popup.
Element cellParent = lastParent;
Object removeKey = lastKey;
int index = lastIndex;
int column = lastColumn;

// Update the cell and value updater.
setViewData(removeKey, null);
setValue(new Context(index, column, removeKey), cellParent, null);
if (valueUpdater != null) {
valueUpdater.update(null);
}
});
}
}

@Override
protected void onEnterKeyDown(Context context, Element parent, Date value, NativeEvent event,
ValueUpdater<Date> valueUpdater) {
this.lastKey = context.getKey();
this.lastParent = parent;
this.lastValue = value;
this.lastIndex = context.getIndex();
this.lastColumn = context.getColumn();
this.valueUpdater = valueUpdater;

Date viewData = getViewData(lastKey);
Date date = (viewData == null) ? lastValue : viewData;
if (date == null) {
date = new Date();
}
datePicker.setCurrentMonth(date);
datePicker.setValue(date);
panel.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
public void setPosition(int offsetWidth, int offsetHeight) {
panel.setPopupPosition(lastParent.getAbsoluteLeft() + offsetX, lastParent.getAbsoluteTop() + offsetY);
}
});
}

public void addStyleNameToPopupPanel(String styleName) {
this.panel.addStyleName(styleName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package com.databasepreservation.common.client.common.visualization.manager.SIARDPanel;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -29,6 +30,7 @@
import com.databasepreservation.common.client.common.visualization.manager.SIARDPanel.navigation.SIARDNavigationPanel;
import com.databasepreservation.common.client.common.visualization.manager.SIARDPanel.navigation.ValidationNavigationPanel;
import com.databasepreservation.common.client.index.IsIndexed;
import com.databasepreservation.common.client.models.authorization.AuthorizationDetails;
import com.databasepreservation.common.client.models.authorization.AuthorizationGroup;
import com.databasepreservation.common.client.models.structure.ViewerDatabase;
import com.databasepreservation.common.client.models.structure.ViewerDatabaseStatus;
Expand Down Expand Up @@ -141,7 +143,7 @@ private void populateNavigationPanels() {
navigationPanels.add(browseNavigationPanel.build());

if (ApplicationType.getType().equals(ViewerConstants.APPLICATION_ENV_SERVER)) {
DatabaseService.Util.call((Set<String> databasePermissions) -> {
DatabaseService.Util.call((Map<String, AuthorizationDetails> databasePermissions) -> {
ContextService.Util.call((Set<AuthorizationGroup> authorizationGroups) -> {
permissionsNavigationPanel = PermissionsNavigationPanel.getInstance(database, databasePermissions, authorizationGroups);
if (permissionsNavigationPanel.hasPermissionsOrGroups()) {
Expand Down Expand Up @@ -177,8 +179,8 @@ public void refreshInstance(String databaseUUID) {

if (ApplicationType.getType().equals(ViewerConstants.APPLICATION_ENV_SERVER)) {
if (permissionsNavigationPanel.hasPermissionsOrGroups()) {
DatabaseService.Util.call((Set<String> databasePermissions) -> {
permissionsNavigationPanel.update(databasePermissions);
DatabaseService.Util.call((Map<String, AuthorizationDetails> databasePermissions) -> {
permissionsNavigationPanel.update(databasePermissions.keySet());
}).getDatabasePermissions(database.getUuid());
}
}
Expand Down
Loading

0 comments on commit 622089b

Please sign in to comment.