Search in sources :

Example 6 with Attachment

use of org.phoebus.logbook.Attachment in project phoebus by ControlSystemStudio.

the class OlogAttributeProvider method setAttributes.

/**
 * Processes image nodes to prepend the service root URL, where needed. For table nodes the olog-table
 * class is added in order to give it some styling.
 *
 * @param node The {@link org.commonmark.node.Node} being processed.
 * @param s    The HTML tag, e.g. p, img, strong etc.
 * @param map  Map of attributes for the node.
 */
@Override
public void setAttributes(org.commonmark.node.Node node, String s, Map<String, String> map) {
    if (node instanceof TableBlock) {
        map.put("class", "olog-table");
    }
    // Relative paths must be prepended with service root URL, while absolute URLs must not be changed.
    if (node instanceof org.commonmark.node.Image) {
        String src = map.get("src");
        if (!src.toLowerCase().startsWith("http") && !this.preview) {
            if (serviceUrl.endsWith("/")) {
                serviceUrl = serviceUrl.substring(0, serviceUrl.length() - 1);
            }
            src = serviceUrl + "/" + src;
        }
        // has to be converted to 'file://attachment_path'
        if (src.startsWith("attachment") && this.preview) {
            String attachmentId = src.substring(11, src.length());
            for (Attachment attachment : attachments) {
                if (attachment.getId().equals(attachmentId)) {
                    src = "file://" + FilenameUtils.separatorsToUnix(attachment.getFile().getAbsolutePath());
                }
            }
        }
        map.put("src", src);
    }
}
Also used : TableBlock(org.commonmark.ext.gfm.tables.TableBlock) Attachment(org.phoebus.logbook.Attachment)

Example 7 with Attachment

use of org.phoebus.logbook.Attachment in project phoebus by ControlSystemStudio.

the class SendLogbookAction method submitLogEntry.

private void submitLogEntry(final Node parent, final String title, final String body, final File image_file) {
    OlogLog ologLog = new OlogLog();
    ologLog.setTitle(title != null ? title : "");
    ologLog.setDescription(body != null ? body : "");
    if (image_file != null) {
        try {
            final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
            List<Attachment> attachments = new ArrayList<>();
            attachments.add(attachment);
            ologLog.setAttachments(attachments);
        } catch (FileNotFoundException ex) {
            logger.log(Level.WARNING, "Cannot attach " + image_file, ex);
        }
    }
    new LogEntryEditorStage(parent, ologLog).show();
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Attachment(org.phoebus.logbook.Attachment) LogEntryEditorStage(org.phoebus.logbook.olog.ui.write.LogEntryEditorStage) OlogLog(org.phoebus.olog.es.api.model.OlogLog)

Aggregations

Attachment (org.phoebus.logbook.Attachment)7 ArrayList (java.util.ArrayList)3 LogClient (org.phoebus.logbook.LogClient)3 LogEntry (org.phoebus.logbook.LogEntry)3 Property (org.phoebus.logbook.Property)3 OlogLog (org.phoebus.olog.es.api.model.OlogLog)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 List (java.util.List)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2 FXCollections (javafx.collections.FXCollections)2 ObservableList (javafx.collections.ObservableList)2 FXML (javafx.fxml.FXML)2 Image (javafx.scene.image.Image)2 ImageView (javafx.scene.image.ImageView)2 JobManager (org.phoebus.framework.jobs.JobManager)2 Logbook (org.phoebus.logbook.Logbook)2 LogbookException (org.phoebus.logbook.LogbookException)2