From 4bf209c7079ed739b3e92d87601274682b9dd0d3 Mon Sep 17 00:00:00 2001 From: GroG Date: Tue, 7 Jan 2025 20:44:36 -0800 Subject: [PATCH] email and change log --- .github/workflows/build.yml | 10 ++++ .../java/org/myrobotlab/service/Email.java | 28 ++++----- .../service/config/EmailConfig.java | 38 +++++------- .../WebGui/app/service/js/EmailGui.js | 44 ++++++++++++++ .../WebGui/app/service/views/EmailGui.html | 58 +++++++++++++++++++ 5 files changed, 138 insertions(+), 40 deletions(-) create mode 100644 src/main/resources/resource/WebGui/app/service/js/EmailGui.js create mode 100644 src/main/resources/resource/WebGui/app/service/views/EmailGui.html diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9317e4cafd..546faae41d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -85,6 +85,14 @@ jobs: name: myrobotlab path: target/ + - name: Generate Change Log + run: | + echo "## Changelog" > changelog.md + echo "" >> changelog.md + git log --pretty=format:"- %s" -n 10 >> changelog.md + echo "" >> changelog.md + cat changelog.md + - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: @@ -106,6 +114,8 @@ jobs: You will need **Java 11 or newer**. If you are only running MyRobotLab, you need the JRE (Java Runtime Environment). If you are building from source, you will need the JDK (Java Development Kit). Oracle or OpenJDK will work. + $(cat changelog.md) + files: target/myrobotlab-${{ needs.build.outputs.version }}.zip draft: false prerelease: false diff --git a/src/main/java/org/myrobotlab/service/Email.java b/src/main/java/org/myrobotlab/service/Email.java index db9e5f5088..c84e7702c5 100644 --- a/src/main/java/org/myrobotlab/service/Email.java +++ b/src/main/java/org/myrobotlab/service/Email.java @@ -44,9 +44,12 @@ public class Email extends Service { public Email(String n, String id) { super(n, id); } + + Properties props = new Properties(); + - public Map setGmailProps(String user, String password) { - Map props = ((EmailConfig) this.config).properties; + public Properties setGmailProps(String user, String password) { + props.put("mail.smtp.user", user); props.put("mail.smtp.pass", password); props.put("mail.smtp.host", "smtp.gmail.com"); @@ -88,11 +91,7 @@ public void sendImage(String to, String imageFile) { */ public void sendMail(String to, String subject, String body, String imageFile) { - EmailConfig config = (EmailConfig) this.config; - - Properties props = new Properties(); - props.putAll(config.properties); - sendTextMail(config.properties.get("mail.smtp.user"), to, subject, body, config.format, null); + sendTextMail((String)props.get("mail.smtp.user"), to, subject, body, config.format, null); } public void sendHtmlMail(String from, String to, String subject, String body, String imageFileName) { @@ -108,9 +107,6 @@ public void sendHtmlMail(String from, String to, String subject, String body, St to = config.to; } - Properties props = new Properties(); - props.putAll(config.properties); - Session session = Session.getDefaultInstance(props); // Create a default MimeMessage object. @@ -191,10 +187,6 @@ public void sendHtmlMail(String from, String to, String subject, String body, St public void sendTextMail(String from, String to, String subject, String body, String format, List attachments) { try { - EmailConfig config = (EmailConfig) this.config; - - Properties props = new Properties(); - props.putAll(config.properties); Session session = Session.getDefaultInstance(props); @@ -252,11 +244,11 @@ public static void main(String[] args) { try { LoggingFactory.init(Level.INFO); - + Runtime.start("webgui","WebGui"); + Runtime.start("python","Python"); Email email = (Email) Runtime.start("email", "Email"); - - email.setGmailProps("myuser@gmail.com", "xxxxxxxxx"); - email.sendImage("some-email@email.com", "data/OpenCV/cv-00573.png"); + email.setGmailProps("supertick@gmail.com", "XXXXXXXXXX"); + email.sendImage("supertick@gmail.com", "data/OpenCV/i01.opencv-00136.png"); } catch (Exception e) { log.error("main threw", e); diff --git a/src/main/java/org/myrobotlab/service/config/EmailConfig.java b/src/main/java/org/myrobotlab/service/config/EmailConfig.java index fcedfd2b6f..44df0c8f9a 100644 --- a/src/main/java/org/myrobotlab/service/config/EmailConfig.java +++ b/src/main/java/org/myrobotlab/service/config/EmailConfig.java @@ -1,29 +1,23 @@ package org.myrobotlab.service.config; -import java.util.HashMap; -import java.util.Map; - +/** + * Email config gets turned into javax email props + */ public class EmailConfig extends ServiceConfig { - @Deprecated /* is supposed to be userfriendly not like a single properties */ - public Map properties = new HashMap<>(); - - public String to; // if set sends auto - + public String to; // if set sends auto public String format = "text/html"; // text/html or text/plain - - // elements in the map - public String user = null; - public String host = null; - public int port = 25; /* 465, 587 */ - public String from = null; - boolean auth = true; - boolean starttls = true; - boolean debug = true; - boolean starttlsRequired = true; - String protocols = "TLSv1.2"; - String socketFactory = "javax.net.ssl.SSLSocketFactory"; - - public String pass = null; + public String user = null; + public String host = null; + public int port = 25; /* 465, 587 */ + public String from = null; + boolean auth = true; + boolean starttls = true; + boolean debug = true; + boolean starttlsRequired = true; + String protocols = "TLSv1.2"; + String socketFactory = "javax.net.ssl.SSLSocketFactory"; + + public String pass = null; } diff --git a/src/main/resources/resource/WebGui/app/service/js/EmailGui.js b/src/main/resources/resource/WebGui/app/service/js/EmailGui.js new file mode 100644 index 0000000000..ae3eab0fd9 --- /dev/null +++ b/src/main/resources/resource/WebGui/app/service/js/EmailGui.js @@ -0,0 +1,44 @@ +angular.module("mrlapp.service.EmailGui", []).controller("EmailGuiCtrl", [ + "$scope", + "mrl", + function ($scope, mrl) { + console.info("EmailGuiCtrl") + var _self = this + var msg = this.msg + + // GOOD TEMPLATE TO FOLLOW + this.updateState = function (service) { + $scope.service = service + } + + // init scope variables + $scope.onTime = null + $scope.onEpoch = null + + this.onMsg = function (inMsg) { + let data = inMsg.data[0] + switch (inMsg.method) { + case "onState": + _self.updateState(data) + $scope.$apply() + break + case "onTime": + const date = new Date(data) + $scope.onTime = date.toLocaleString() + $scope.$apply() + break + case "onEpoch": + $scope.onEpoch = data + $scope.$apply() + break + default: + console.error("ERROR - unhandled method " + $scope.name + " " + inMsg.method) + break + } + } + + msg.subscribe("publishTime") + msg.subscribe("publishEpoch") + msg.subscribe(this) + }, +]) diff --git a/src/main/resources/resource/WebGui/app/service/views/EmailGui.html b/src/main/resources/resource/WebGui/app/service/views/EmailGui.html new file mode 100644 index 0000000000..cd1844ed3b --- /dev/null +++ b/src/main/resources/resource/WebGui/app/service/views/EmailGui.html @@ -0,0 +1,58 @@ +


+ + + + + + + + + + + + + + + + + + + + +
NameValueActions
{{ key }} + {{ value }} + + + + +
+
+ + +
+ + + + + + + + + +
+ + +
+
+ + + + \ No newline at end of file