Skip to content

Commit

Permalink
Add a date to the log data
Browse files Browse the repository at this point in the history
  • Loading branch information
Rockerby committed Mar 6, 2025
1 parent cfbe050 commit cfce7cf
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const DocumentGranularPermissionModelSchema = {
} as const;

export const EmailLogSchema = {
required: ['emailLogUmbracoKey', 'id', 'isSuccessful', 'message', 'recipients', 'subject'],
required: ['dateSent', 'emailLogUmbracoKey', 'id', 'isSuccessful', 'message', 'recipients', 'subject'],
type: 'object',
properties: {
id: {
Expand All @@ -42,6 +42,10 @@ export const EmailLogSchema = {
},
isSuccessful: {
type: 'boolean'
},
dateSent: {
type: 'string',
format: 'date-time'
}
},
additionalProperties: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type EmailLog = {
subject: string;
message: string;
isSuccessful: boolean;
dateSent: string;
};

export type ReadOnlyUserGroupModel = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,37 @@
import { LitElement, css, html, customElement, state, repeat } from "@umbraco-cms/backoffice/external/lit";
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";
import { EmailLog, UmbracoCommunityEmailLoggerService, UserModel } from "../api";
import { EmailLog, UmbracoCommunityEmailLoggerService } from "../api";
import { UUIButtonElement } from "@umbraco-cms/backoffice/external/uui";
import { UMB_NOTIFICATION_CONTEXT, UmbNotificationContext } from "@umbraco-cms/backoffice/notification";
import { UMB_CURRENT_USER_CONTEXT, UmbCurrentUserModel } from "@umbraco-cms/backoffice/current-user";
// import { UMB_NOTIFICATION_CONTEXT } from "@umbraco-cms/backoffice/notification";
// import { UMB_CURRENT_USER_CONTEXT } from "@umbraco-cms/backoffice/current-user";

@customElement('example-dashboard')
export class ExampleDashboardElement extends UmbElementMixin(LitElement) {

@state()
private _yourName: string | undefined = "Press the button!";

@state()
private _timeFromMrWolf: Date | undefined;

@state()
private _serverUserData: UserModel | undefined = undefined;

@state()
private _userData: Array<EmailLog> = [];

@state()
private _contextCurrentUser: UmbCurrentUserModel | undefined = undefined;

@state()
private _showCode: boolean = true;

constructor() {
super();

this.consumeContext(UMB_NOTIFICATION_CONTEXT, (notificationContext) => {
this.#notificationContext = notificationContext;
});
// this.consumeContext(UMB_NOTIFICATION_CONTEXT, (notificationContext) => {
// this.#notificationContext = notificationContext;
// });

this.consumeContext(UMB_CURRENT_USER_CONTEXT, (currentUserContext) => {
// this.consumeContext(UMB_CURRENT_USER_CONTEXT, (currentUserContext) => {

// When we have the current user context
// We can observe properties from it, such as the current user or perhaps just individual properties
// When the currentUser object changes we will get notified and can reset the @state properrty
this.observe(currentUserContext.currentUser, (currentUser) => {
this._contextCurrentUser = currentUser;
});
});
// // When we have the current user context
// // We can observe properties from it, such as the current user or perhaps just individual properties
// // When the currentUser object changes we will get notified and can reset the @state properrty
// this.observe(currentUserContext.currentUser, (currentUser) => {
// this._contextCurrentUser = currentUser;
// });
// });
}

#notificationContext: UmbNotificationContext | undefined = undefined;

#onClickWhoAmI = async (ev: Event) => {
const buttonElement = ev.target as UUIButtonElement;
Expand Down Expand Up @@ -74,44 +61,10 @@ export class ExampleDashboardElement extends UmbElementMixin(LitElement) {
})
}*/
}
#togglePretty = async (ev: Event) => {
#togglePretty = async () => {
this._showCode = !this._showCode;
}

#onClickWhatsTheTimeMrWolf = async (ev: Event) => {
const buttonElement = ev.target as UUIButtonElement;
buttonElement.state = "waiting";

// Getting a string - should I expect a datetime?!
const { data, error } = await UmbracoCommunityEmailLoggerService.whatsTheTimeMrWolf();

if (error) {
buttonElement.state = "failed";
console.error(error);
return;
}

if (data !== undefined) {
this._timeFromMrWolf = new Date(data);
buttonElement.state = "success";
}
}

#onClickWhatsMyName = async (ev: Event) => {
const buttonElement = ev.target as UUIButtonElement;
buttonElement.state = "waiting";

const { data, error } = await UmbracoCommunityEmailLoggerService.whatsMyName();

if (error) {
buttonElement.state = "failed";
console.error(error);
return;
}

this._yourName = data;
buttonElement.state = "success";
}

render() {
return html`
Expand All @@ -128,6 +81,7 @@ export class ExampleDashboardElement extends UmbElementMixin(LitElement) {
<uui-box headline="Email Logs" class="wide">
<uui-table id="users-wrapper">
<uui-table-row>
<uui-table-head-cell>Date Sent</uui-table-head-cell>
<uui-table-head-cell>Recipient</uui-table-head-cell>
<uui-table-head-cell>Subject</uui-table-head-cell>
<uui-table-head-cell>Sent</uui-table-head-cell>
Expand All @@ -143,6 +97,7 @@ export class ExampleDashboardElement extends UmbElementMixin(LitElement) {
private _renderEmailLog(user: EmailLog) {
if (!user) return;
return html`<uui-table-row class="user">
<uui-table-cell>${user.dateSent}</uui-table-cell>
<uui-table-cell>${user.recipients}</uui-table-cell>
<uui-table-cell>${user.subject}</uui-table-cell>
<uui-table-cell>${user.isSuccessful ? 'YES' : 'No'}</uui-table-cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) =>
entity.Property(e => e.Message).HasColumnName("message");
entity.Property(e => e.Subject).HasColumnName("subject");
entity.Property(e => e.Recipients).HasColumnName("recipients");
entity.Property(e => e.DateSent).HasColumnName("dateSent");
});
}
}
1 change: 1 addition & 0 deletions src/Umbraco.Community.EmailLogger/Models/EmailLogDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public class EmailLog
public required string Subject { get; set; }
public string Message { get; set; } = string.Empty;
public bool IsSuccessful { get; set; }
public DateTime DateSent { get; set; }
}
}
6 changes: 4 additions & 2 deletions src/Umbraco.Community.EmailLogger/Services/EmailLogSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ await scope.ExecuteWithContextAsync<Task>(async db =>
Recipients = String.Join(", ", message.To),
Subject = message.Subject ?? "",
IsSuccessful = true,
Message = message.Body ?? ""
Message = message.Body ?? "",
DateSent = DateTime.Now
});
await db.SaveChangesAsync();
});
Expand All @@ -191,7 +192,8 @@ await scope.ExecuteWithContextAsync<Task>(async db =>
Recipients = String.Join(", ", message.To),
Subject = message.Subject ?? "",
IsSuccessful = false,
Message = message.Body ?? ""
Message = message.Body ?? "",
DateSent = DateTime.Now
});
await db.SaveChangesAsync();
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cfce7cf

Please sign in to comment.