Skip to content

Commit

Permalink
email and change log
Browse files Browse the repository at this point in the history
  • Loading branch information
GroG committed Jan 8, 2025
1 parent 2ba5e79 commit 4bf209c
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 40 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
28 changes: 10 additions & 18 deletions src/main/java/org/myrobotlab/service/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ public class Email extends Service<EmailConfig> {
public Email(String n, String id) {
super(n, id);
}

Properties props = new Properties();


public Map<String, String> setGmailProps(String user, String password) {
Map<String, String> 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");
Expand Down Expand Up @@ -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) {
Expand All @@ -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.
Expand Down Expand Up @@ -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<Object> attachments) {
try {
EmailConfig config = (EmailConfig) this.config;

Properties props = new Properties();
props.putAll(config.properties);

Session session = Session.getDefaultInstance(props);

Expand Down Expand Up @@ -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("[email protected]", "xxxxxxxxx");
email.sendImage("[email protected]", "data/OpenCV/cv-00573.png");
email.setGmailProps("[email protected]", "XXXXXXXXXX");
email.sendImage("[email protected]", "data/OpenCV/i01.opencv-00136.png");

} catch (Exception e) {
log.error("main threw", e);
Expand Down
38 changes: 16 additions & 22 deletions src/main/java/org/myrobotlab/service/config/EmailConfig.java
Original file line number Diff line number Diff line change
@@ -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<String,String> 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;

}
44 changes: 44 additions & 0 deletions src/main/resources/resource/WebGui/app/service/js/EmailGui.js
Original file line number Diff line number Diff line change
@@ -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)
},
])
58 changes: 58 additions & 0 deletions src/main/resources/resource/WebGui/app/service/views/EmailGui.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<br/><br/><br/>
&nbsp;<div class="row">
<table class="padded-table">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(key, value) in service.props">
<td>{{ key }}</td>
<td>
<span ng-if="!editMode[key]">{{ value }}</span>
<input ng-if="editMode[key]" type="text" ng-model="service.props[key]" />
</td>
<td>
<button ng-click="toggleEdit(key)">
<span ng-if="!editMode[key]">✏️</span>
<span ng-if="editMode[key]">✔️</span>
</button>
<button ng-click="removeProp(key)"></button>
</td>
</tr>
<tr>
<td><input type="text" ng-model="newProp.name" placeholder="New Name" /></td>
<td><input type="text" ng-model="newProp.value" placeholder="New Value" /></td>
<td><button ng-click="addProp()"></button></td>
</tr>
</tbody>
</table>
</div>

<!-- Email Section -->
<div class="row" style="margin-top: 20px;">
<!-- Recipient Input -->
<label>To:</label>
<input type="email" ng-model="emailRecipient" style="width: 100%;" placeholder="Recipient Email" />

<!-- Email Message Input -->
<label style="margin-top: 10px;">Email Message:</label>
<textarea ng-model="emailMessage" rows="5" style="width: 100%;" placeholder="Type your message here..."></textarea>

<!-- Buttons Row -->
<div style="margin-top: 10px;">
<input type="file" ng-model="attachment" style="margin-right: 10px;" />
<button ng-click="sendEmail()">📧 Send Email</button>
</div>
</div>

<!-- Minimal Padding for Table -->
<style>
.padded-table th, .padded-table td {
padding: 5px;
}
</style>

0 comments on commit 4bf209c

Please sign in to comment.