Skip to content

Commit

Permalink
Merge pull request #88 from psteiwer/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
psteiwer authored Mar 9, 2020
2 parents a16b4af + 875462a commit 6c916b0
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 66 deletions.
19 changes: 15 additions & 4 deletions PivotSubscriptions/EventLog.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Class PivotSubscriptions.EventLog Extends %Persistent
{

/// Event Type covers: create, update, delete, sendSubscription, and tableError
Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,tableError");
Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,tableError,unsubscribe");

Property StartTime As %TimeStamp [ InitialExpression = {$zdt($h, 3, 1)} ];

Expand All @@ -27,13 +27,18 @@ Property Name As %String(MAXLEN = 100);

Property Status As %Status;

Property Subscription As PivotSubscriptions.Subscription;

Property GUID As %String [ InitialExpression = {$System.Util.CreateGUID()} ];

/// Takes in info about an Alert Task and logs the information to the TaskLog
ClassMethod CreateEvent(pType, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, ByRef pEvent) As %Status
ClassMethod CreateEvent(pType, pSubscriptionId, pUser, pPivot, pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, ByRef pEvent) As %Status
{
Set tSC=$$$OK

Set tEventLog=##class(PivotSubscriptions.EventLog).%New()
Set tEventLog.EventType=pType
Do tEventLog.SubscriptionSetObjectId(pSubscriptionId)
Set tEventLog.UserName=pUser
Set tEventLog.Pivot=pPivot
Set tEventLog.Name=pName
Expand Down Expand Up @@ -90,9 +95,9 @@ ClassMethod DayOfWeekDisplay(pDayOfWeek) As %String [ SqlProc ]
Quit pDayOfWeek
}

Query GetEvents() As %SQLQuery
Query GetEventsForUI() As %SQLQuery
{
SELECT StartTime,EndTime,EventType,Name,Pivot,UserName,PivotSubscriptions.EventLog_DayOfWeekDisplay(DayOfWeek) As DayOfWeek,Format,"Hour","Minute",Emails,Status
SELECT ID As Details,StartTime,EndTime,EventType,Username,Name,Emails,Status
FROM PivotSubscriptions.EventLog
ORDER BY ID DESC
}
Expand Down Expand Up @@ -142,6 +147,12 @@ Storage Default
<Value name="14">
<Value>Status</Value>
</Value>
<Value name="15">
<Value>Subscription</Value>
</Value>
<Value name="16">
<Value>GUID</Value>
</Value>
</Data>
<DataLocation>^PivotSubscriptions.EventLogD</DataLocation>
<DefaultData>EventLogDefaultData</DefaultData>
Expand Down
32 changes: 30 additions & 2 deletions PivotSubscriptions/Installer.cls
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ ClassMethod RunInstaller(pRootDir)
Set tItem.title="Pivot Subscriptions"
Set tItem.bookCover="{background: {style:'background:white;',src:'covers/PivotSubscriptions_Cover.png'},header: {text:'$type',style:'display: none;'},title: {text:'$title',style:'display: none;'},image: {style:'display: none;',src:'deepsee/ds2_globe_44.png',imageStyle:'width:64px;height:64px;'},subtitle: {style:'display: none;'},footer: {text:'$owner',style:'display: none;'}}"
Set tSC=tItem.%Save()

If $$$ISERR(tSC) Quit
If $$$ISERR(tSC) Quit tSC

Set tSC=##class(PivotSubscriptions.Task).ConfigureTask()
If $$$ISERR(tSC) Quit tSC

Set tSC=##class(PivotSubscriptions.Installer).ConfigureUnsubscribeWebApp()
If $$$ISERR(tSC) Quit tSC

Quit tSC
}
Expand Down Expand Up @@ -50,4 +53,29 @@ ClassMethod ImportImage(pDir) As %Status
Quit tSC
}

ClassMethod ConfigureUnsubscribeWebApp() As %Status
{
Set tSC=$$$OK

Set tNamespace=$Namespace
ZN "%SYS"

Try {
If '##class(Security.Applications).Exists("/api/pivotsubscriptionsunsubscribe") {
Set tWebApp=##class(Security.Applications).%New()
Set tWebApp.Name="/api/pivotsubscriptionsunsubscribe"
Set tWebApp.NameSpace=tNamespace
Set tWebApp.DispatchClass="PivotSubscriptions.UI.Unsubscribe"
Set tWebApp.AutheEnabled=64
Set tSC=tWebApp.%Save()
}
} Catch ex {
Set tSC=ex.AsStatus()
}

ZN tNamespace

Quit tSC
}

}
40 changes: 40 additions & 0 deletions PivotSubscriptions/Subscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,46 @@ Property CustomFilters As array Of %String(MAXLEN = "");

Property CustomEmailText As %String(MAXLEN = "");

Method Unsubscribe(pEmail) As %Status
{
Set tSC=$$$OK

Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("unsubscribe",..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,pEmail,..Name,.tEvent)

Set tEmailList=$LFS(..Emails,",")

If $LL(tEmailList)=1 {
If ..Emails=pEmail {
// This is the only Email for the subscription, delete subscription
Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",,..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,..Emails,..Name,.tDeleteEvent)
Set tSC=##class(PivotSubscriptions.Subscription).%DeleteId(..%Id())
Do tDeleteEvent.UpdateStatus(tSC)
Do tEvent.UpdateStatus(tSC)
Return tSC
}
}

Set tPosition=$Listfind(tEmailList,pEmail)
If tPosition=0 {
Set tSC=$$$ERROR($$$GeneralError,"Not subscribed")
} ElseIf tPosition=1 {
Set tEmailList=$List(tEmailList,2,*)
} ElseIf tPosition=$LL(tEmailList) {
Set tEmailList=$List(tEmailList,1,*-1)
} Else {
Set tEmailList=$List(tEmailList,1,tPosition-1)_$List(tEmailList,tPosition+1,*)
}

If tPosition'=0 {
Set ..Emails=$LTS(tEmailList,",")
Set tSC=..%Save()
}

Do tEvent.UpdateStatus(tSC)

Quit tSC
}

Storage Default
{
<Data name="CustomFilters">
Expand Down
61 changes: 32 additions & 29 deletions PivotSubscriptions/Task.cls
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,31 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St
For tCount=1:1:$l(pEmails,",") {
Set tEmail=$p(pEmails,",",tCount)

Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("sendSubscription",$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,.pEvent)
Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("sendSubscription",pID,$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,.pEvent)
If $$$ISERR(tSC) Quit tSC

Set tHasResults=0
Try {
Set tHasResults=0

Set tCustomFilter=tSubscription.CustomFilters.GetAt(tEmail)
Set tSC=##class(PivotSubscriptions.Utils).ExecuteForSubscription(mdx,tCustomFilter,.tHasResults)

If tHasResults {
// Only generate file if requested pivot has results
Set tSC=##class(PivotSubscriptions.Utils).GenerateFileForSubscription("Excel",mdx,tCustomFilter,pName,pPivot,.tFilename)
}
Set tCustomFilter=tSubscription.CustomFilters.GetAt(tEmail)
Set tSC=##class(PivotSubscriptions.Utils).ExecuteForSubscription(mdx,tCustomFilter,.tHasResults)
If $$$ISERR(tSC) Quit

If tHasResults {
// Only generate file if requested pivot has results
Set tSC=##class(PivotSubscriptions.Utils).GenerateFileForSubscription("Excel",mdx,tCustomFilter,pName,pPivot,.tFilename)
If $$$ISERR(tSC) Quit
}

// Generate email
If tSC {
// Generate email
// check whether the table generated is too wide/truncated AND whether the table has data
Set tableStatus=##class(PivotSubscriptions.Utils).CheckTable(pName)

Set server=##class(%Net.SMTP).%New()
Set server.smtpserver=##class(%SYS.Task.Config).GetData("MailServer")
Set msg=##class(%Net.MailMessage).%New()
Set msg.From="PivotSubscriptions"
Do msg.To.SetAt(tEmail,1)

Set validAdminEmail=##class(PivotSubscriptions.Utils).CheckConfigurationGlobal("AdminEmail")

Expand All @@ -100,45 +103,45 @@ ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %St
Set msg.Subject=pName
Set msg.IsBinary=0
Set msg.IsHTML=1 // Set IsHTML to 1 if email uses HTML

Set tUnsubscribeList=$LB(tSubscription.%Id(),tEmail,pEvent.GUID)

If tHasResults {
// Add attachment
Do ##class(PivotSubscriptions.Utils).WriteEmail(tSubscription, msg, tableStatus)
Do ##class(PivotSubscriptions.Utils).WriteEmail(tSubscription,msg,tableStatus,tUnsubscribeList)

// if table is too large, then just attach Excel instead
If ((pFormat = "PDF") && (tableStatus)) {
Set tSC=##class(PivotSubscriptions.Utils).GenerateFileForSubscription("PDF",mdx,tCustomFilter,pName,pPivot,.tFilename)
If $$$ISERR(tSC) Quit
} ElseIf 'tableStatus {
// Check if both configuration settings for admin email is valid before sending error message
If validAdminEmail {
Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"TooLarge")
Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"TooLarge",mdx)
}
}

Set status=msg.AttachFile("",tFilename)

If $$$ISERR(status) {
Do $System.Status.DisplayError(status)
Quit $$$ERROR()
}
Set tSC=msg.AttachFile("",tFilename)
If $$$ISERR(tSC) Quit
} Else {
Do ##class(PivotSubscriptions.Utils).WriteEmailHeader(msg)
Do msg.TextData.WriteLine(##class(PivotSubscriptions.Utils).GetSettings("NoDataMessage","No data for requested pivot."))
Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(msg)
Do ##class(PivotSubscriptions.Utils).WriteUnsubscribe(msg,tUnsubscribeList)
Do ##class(PivotSubscriptions.Utils).WriteEmailFooter(msg)

Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"NoResults")
Do ##class(PivotSubscriptions.Utils).TableErrorMessage(tSubscription,tEmail,pName,"NoResults",mdx)
}

// Send email
If tHasResults||##class(PivotSubscriptions.Utils).GetSettings("SendNoData",1) {
Set tSC=server.Send(msg)
If $$$ISERR(tSC) Quit
}
} Catch ex {
Set tSC=ex.AsStatus()
}

Do msg.To.SetAt(tEmail,1)

// Send email
If tHasResults||##class(PivotSubscriptions.Utils).GetSettings("SendNoData",1) {
Set tSC=server.Send(msg)
Set tSC=pEvent.UpdateStatus(tSC)
If $$$ISERR(tSC) Quit tSC
}
Set tSC=pEvent.UpdateStatus(tSC)

If tHasResults {
// Delete file
Expand Down
2 changes: 1 addition & 1 deletion PivotSubscriptions/UI/Dialog/EditSubscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Method EditSubscription(pSubscriptionId, pPivot, pDayOfWeek, pHour, pMinute, pEm
Set tEventType="create"
}

Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent(tEventType,$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,.tEvent)
Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent(tEventType,pSubscriptionId,$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,.tEvent)

Set tSubscription.DayOfWeek=pDayOfWeek
Set tSubscription.Hour=pHour
Expand Down
112 changes: 112 additions & 0 deletions PivotSubscriptions/UI/Dialog/EventDetails.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Class PivotSubscriptions.UI.Dialog.EventDetails Extends %DeepSee.UI.Dialog.standardDialog
{

/// Class name of application this page belongs to.
Parameter APPLICATION;

/// Displayed name of this page.
Parameter PAGENAME;

Parameter DOMAIN = "PivotSubscriptions";

Property EventId As %ZEN.Datatype.integer(ZENURL = "EVENTID");

Parameter APPLYBUTTON = 0;

/// This Style block contains page-specific CSS style definitions.
XData Style
{
<style type="text/css">
</style>
}

/// This XML block defines the contents of this page.
XData dialogBody [ XMLNamespace = "http://www.intersystems.com/zen" ]
{
<pane xmlns="http://www.intersystems.com/zen" title="">
<html label="Event Details:" OnDrawContent="DrawDetails" seed="#(%page.EventId)#"/>
</pane>
}

/// Get the (localized) title string for the dialog.
Method %OnGetTitle() As %String
{
Quit "Event Details"
}

Method %OnGetSubtitle() As %String
{
Quit ""
}

ClassMethod DrawDetails(pEventId) As %Status
{
Set tSC=$$$OK

Set tEvent=##class(PivotSubscriptions.EventLog).%OpenId(pEventId)
&html<
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>ID</td>
<td>#(pEventId)#</td>
</tr>
<tr>
<td>GUID</td>
<td>#(tEvent.GUID)#</td>
</tr>
<tr>
<td>Type</td>
<td>#(tEvent.EventType)#</td>
</tr>
<tr>
<td>Start Time</td>
<td>#(tEvent.StartTime)#</td>
</tr>
<tr>
<td>End Time</td>
<td>#(tEvent.EndTime)#</td>
</tr>
<tr>
<td>Name</td>
<td>#(tEvent.Name)#</td>
</tr>
<tr>
<td>Pivot</td>
<td>#(tEvent.Pivot)#</td>
</tr>
<tr>
<td>UserName</td>
<td>#(tEvent.UserName)#</td>
</tr>
<tr>
<td>Format</td>
<td>#(tEvent.Format)#</td>
</tr>
<tr>
<td>DayOfWeek</td>
<td>#(##class(PivotSubscriptions.EventLog).DayOfWeekDisplay(tEvent.DayOfWeek))#</td>
</tr>
<tr>
<td>Time</td>
<td>#(tEvent.Hour)#:#($replace($j(tEvent.Minute,2)," ",0))#</td>
</tr>
<tr>
<td>Email</td>
<td>#(tEvent.Emails)#</td>
</tr>
<tr>
<td>Status</td>
<td>#($Select(tEvent.Status:"OK",1:$system.Status.GetErrorText(tEvent.Status)))#</td>
</tr>
</table>
>

Quit tSC
}

ClientMethod getDialogValue() [ Language = javascript ]
{
return '';
}

}
Loading

0 comments on commit 6c916b0

Please sign in to comment.