Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,20 @@
package org.roda.wui.client.browse.tabs;

import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.ui.Widget;
import org.roda.core.data.v2.notifications.Notification;

/**
*
* @author Eduardo Teixeira <eteixeira@keep.pt>
*/
public class BrowseNotificationsTabs extends Tabs {
public void init(Notification notification) {
createAndAddTab(SafeHtmlUtils.fromSafeConstant(messages.detailsTab()), new TabContentBuilder() {
@Override
public Widget buildTabWidget() {
return new DetailsTab(notification);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

import org.roda.core.data.v2.ip.IndexedFile;
import org.roda.core.data.v2.ip.TransferredResource;
import org.roda.core.data.v2.notifications.Notification;
import org.roda.core.data.v2.log.LogEntry;
import org.roda.wui.client.common.model.BrowseAIPResponse;
import org.roda.wui.client.common.model.BrowseRepresentationResponse;
import org.roda.wui.client.management.DetailsPanelNotification;
import org.roda.wui.client.management.DetailsPanelLogEntry;
import org.roda.wui.client.ingest.transfer.DetailsPanelTransferredResource;
import org.roda.wui.client.planning.DetailsPanelAIP;
Expand Down Expand Up @@ -67,6 +69,12 @@ public DetailsTab(TransferredResource resource) {
content.add(detailsPanel);
}

public DetailsTab(Notification notification) {
initWidget(uiBinder.createAndBindUi(this));
DetailsPanelNotification detailsPanel = new DetailsPanelNotification(notification);
content.add(detailsPanel);
}

public DetailsTab(LogEntry logEntry) {
initWidget(uiBinder.createAndBindUi(this));
DetailsPanelLogEntry detailsPanel = new DetailsPanelLogEntry(logEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,18 @@ pre code {
border-radius: 4px;
}

.notification-body-content pre > code {
overflow: visible;
}

.notification-body-content pre code {
max-height: none;
}

.notification-body-content {
overflow: visible;
}

.error {
color: #D20707;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ public static native void runHighlighter() /*-{
}-*/;

public static native void runHighlighter(JavaScriptObject parent) /*-{
$wnd.jQuery(parent).find('pre code').each(function(i, block) {
$wnd.jQuery(parent).find('pre code').each(function(i, block) {
if ($wnd.hljs && $wnd.hljs.highlightElement) {
$wnd.hljs.highlightElement(block);
} else if ($wnd.hljs && $wnd.hljs.highlightBlock) {
$wnd.hljs.highlightBlock(block);
});
}-*/;
}
});
}-*/;

public static native void runHighlighterOn(JavaScriptObject parent) /*-{
$wnd.jQuery(parent).each(function(i, block) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,21 @@ public static List<BreadcrumbItem> getLogEntryBreadcrumbs(LogEntry logEntry) {
return ret;
}

public static List<BreadcrumbItem> getNotificationBreadcrumbs(Notification notification) {
List<BreadcrumbItem> ret = new ArrayList<>();
ret.add(new BreadcrumbItem(SafeHtmlUtils.fromSafeConstant(messages.notificationsTitle()),
messages.notificationsTitle(), NotificationRegister.RESOLVER.getHistoryPath()));

if (notification != null) {
List<String> path = new ArrayList<>(ShowNotification.RESOLVER.getHistoryPath());
path.add(notification.getUUID());
String label = StringUtils.isNotBlank(notification.getId()) ? notification.getId() : notification.getUUID();
ret.add(new BreadcrumbItem(SafeHtmlUtils.fromString(label), label, path));
}

return ret;
}

public static List<BreadcrumbItem> getDipBreadcrumbs(IndexedDIP dip, DIPFile dipFile,
List<DIPFile> dipFileAncestors) {
List<BreadcrumbItem> ret = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package org.roda.wui.client.management;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.gwt.json.client.JSONParser;
import com.google.gwt.user.client.ui.HTML;
import org.roda.core.data.v2.notifications.Notification;
import org.roda.wui.client.common.utils.HtmlSnippetUtils;
import org.roda.wui.client.common.utils.JavascriptUtils;
import org.roda.wui.common.client.tools.Humanize;
import org.roda.wui.common.client.tools.StringUtils;

import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

import config.i18n.client.ClientMessages;

/**
*
* @author Eduardo Teixeira <eteixeira@keep.pt>
*/
public class DetailsPanelNotification extends Composite {
private static final ClientMessages messages = GWT.create(ClientMessages.class);
private static final MyUiBinder uiBinder = GWT.create(DetailsPanelNotification.MyUiBinder.class);

@UiField
FlowPanel details;

public DetailsPanelNotification(Notification resource) {
initWidget(uiBinder.createAndBindUi(this));
init(resource);
}

public void init(Notification n) {
addIfNotBlank(messages.notificationIdentifier(), n.getId());
addIfNotBlank(messages.notificationSubject(), n.getSubject());

if (StringUtils.isNotBlank(n.getBody())) {
details.add(buildBodyField(messages.notificationBody(), n.getBody()));
}

if (n.getSentOn() != null) {
details.add(buildField(messages.notificationSentOn(),
new InlineHTML(SafeHtmlUtils.htmlEscape(Humanize.formatDateTime(n.getSentOn())))));
}

addIfNotBlank(messages.notificationFromUser(), n.getFromUser());
addIfNotBlank(messages.notificationIsAcknowledged(),
messages.isAcknowledged(Boolean.toString(n.isAcknowledged()).toLowerCase()));

if (n.getState() != null) {
details.add(buildField(messages.notificationState(),
new InlineHTML(HtmlSnippetUtils.getNotificationStateHTML(n.getState()))));
}

if (n.getAcknowledgedUsers() != null && !n.getAcknowledgedUsers().isEmpty()) {
FlowPanel ack = new FlowPanel();
for (Map.Entry<String, String> e : n.getAcknowledgedUsers().entrySet()) {
ack.add(new InlineHTML(SafeHtmlUtils.htmlEscape(e.getKey() + " " + e.getValue())));
}
details.add(buildField(messages.notificationAcknowledgedUsers(), ack));
}

List<String> remaining = new ArrayList<>();
if (n.getRecipientUsers() != null) {
remaining.addAll(n.getRecipientUsers());
}

if (n.getAcknowledgedUsers() != null) {
remaining.removeAll(n.getAcknowledgedUsers().keySet());
}
if (!remaining.isEmpty()) {
FlowPanel notAck = new FlowPanel();
for (String user : remaining) {
notAck.add(new InlineHTML(SafeHtmlUtils.htmlEscape(user)));
}
details.add(buildField(messages.notificationNotAcknowledgedUsers(), notAck));
}
}

private void addIfNotBlank(String label, String value) {
if (StringUtils.isNotBlank(value)) {
details.add(buildField(label, new InlineHTML(SafeHtmlUtils.htmlEscape(value))));
}
}

private FlowPanel buildField(String label, Widget valueWidget) {
FlowPanel fieldPanel = new FlowPanel();
fieldPanel.setStyleName("field");

Label fieldLabel = new Label(label);
fieldLabel.setStyleName("label");

FlowPanel fieldValuePanel = new FlowPanel();
fieldValuePanel.setStyleName("value");
fieldValuePanel.add(valueWidget);

fieldPanel.add(fieldLabel);
fieldPanel.add(fieldValuePanel);

return fieldPanel;
}

private FlowPanel buildBodyField(String label, String rawBody) {
FlowPanel bodyPanel = new FlowPanel();
bodyPanel.setStyleName("field");

Label fieldLabel = new Label(label);
fieldLabel.setStyleName("label");

FlowPanel fieldValuePanel = new FlowPanel();
fieldValuePanel.setStyleName("value");
fieldValuePanel.addStyleName("code-pre");
fieldValuePanel.addStyleName("notification-body-content");

fieldValuePanel.add(buildNotificationBody(rawBody));

bodyPanel.add(fieldLabel);
bodyPanel.add(fieldValuePanel);

return bodyPanel;
}

private Widget buildNotificationBody(String rawBody) {
String body = rawBody == null ? "" : rawBody.trim();

if (body.isEmpty()) {
return new InlineHTML("");
}

if (isJson(body)) {
return buildHighlightedCodeBlock(body, "json");
}

if (isHtml(body)) {
return buildHighlightedCodeBlock(body, "html");
}

return new HTML("<pre>" + SafeHtmlUtils.htmlEscape(body) + "</pre>");
}

private boolean isJson(String body) {
try {
JSONParser.parseStrict(body);
return true;
} catch (Exception e) {
return false;
}
}

private boolean isHtml(String body) {
String s = body == null ? "" : body.trim().toLowerCase();
return s.contains("<html") || s.contains("<body") || s.contains("<div") || s.contains("<p") || s.contains("<h1")
|| s.contains("<h2") || s.contains("<ul") || s.contains("<table") || s.contains("<a ") || s.contains("<style");
}

private HTML buildHighlightedCodeBlock(String body, String language) {
String escaped = SafeHtmlUtils.htmlEscape(body);
HTML codeHtml = new HTML("<pre><code class=\"language-" + language + "\">" + escaped + "</code></pre>");
codeHtml.addAttachHandler(event -> {
if (event.isAttached()) {
JavascriptUtils.runHighlighter(codeHtml.getElement());
}
});
return codeHtml;
}

interface MyUiBinder extends UiBinder<Widget, DetailsPanelNotification> {
Widget createAndBindUi(DetailsPanelNotification detailsPanelNotification);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui"
>

<ui:with field='messages' type='config.i18n.client.ClientMessages'/>

<g:FlowPanel addStyleNames="descriptiveMetadataHTML">
<g:FlowPanel ui:field="details" addStyleNames="descriptiveMetadata"/>

</g:FlowPanel>
</ui:UiBinder>
Loading
Loading