Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
psteiwer committed Mar 9, 2020
2 parents 32ed7db + 5799000 commit be782dd
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 21 deletions.
13 changes: 10 additions & 3 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,unsubscribe");
Property EventType As %String(VALUELIST = ",create,update,delete,sendSubscription,sendNow,tableError,unsubscribe");

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

Expand Down Expand Up @@ -31,8 +31,10 @@ Property Subscription As PivotSubscriptions.Subscription;

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

Property RunOnce As %Boolean;

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

Expand All @@ -42,6 +44,7 @@ ClassMethod CreateEvent(pType, pSubscriptionId, pUser, pPivot, pDayOfWeek, pHour
Set tEventLog.UserName=pUser
Set tEventLog.Pivot=pPivot
Set tEventLog.Name=pName
Set tEventLog.RunOnce=pRunOnce

Set tEventLog.DayOfWeek=pDayOfWeek
Set tEventLog.Hour=pHour
Expand All @@ -67,7 +70,7 @@ Method UpdateStatus(pStatus) As %Status
Quit tSC
}

Method UpdateEvent(pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName) As %Status
Method UpdateEvent(pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName, pRunOnce) As %Status
{
Set tSC=$$$OK

Expand All @@ -77,6 +80,7 @@ Method UpdateEvent(pDayOfWeek, pHour, pMinute, pFormat, pEmails, pName) As %Stat
Set ..Format=pFormat
Set ..Emails=pEmails
Set ..Name=pName
Set ..RunOnce=pRunOnce

Set tSC=..%Save()

Expand Down Expand Up @@ -153,6 +157,9 @@ Storage Default
<Value name="16">
<Value>GUID</Value>
</Value>
<Value name="17">
<Value>RunOnce</Value>
</Value>
</Data>
<DataLocation>^PivotSubscriptions.EventLogD</DataLocation>
<DefaultData>EventLogDefaultData</DefaultData>
Expand Down
4 changes: 2 additions & 2 deletions PivotSubscriptions/Installer.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class PivotSubscriptions.Installer
{

ClassMethod RunInstaller(pRootDir)
ClassMethod RunInstaller(pRootDir = "")
{
Set tSC=$$$OK

Expand All @@ -16,7 +16,7 @@ ClassMethod RunInstaller(pRootDir)
Set tPage="PivotSubscriptions.UI.SubscriptionManager.zen"
Set tItem.href=$system.CSP.GetPortalApp($namespace,tPage)_tPage
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 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: {text:'"_##class(PivotSubscriptions.Utils).GetVersion()_"',style:'font-size:9px;top:179px;'},footer: {text:'$owner',style:'display: none;'}}"
Set tSC=tItem.%Save()
If $$$ISERR(tSC) Quit tSC

Expand Down
9 changes: 7 additions & 2 deletions PivotSubscriptions/Subscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ Property CustomFilters As array Of %String(MAXLEN = "");

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

Property RunOnce As %Boolean [ InitialExpression = 0 ];

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 tSC=##class(PivotSubscriptions.EventLog).CreateEvent("unsubscribe",..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,pEmail,..Name,..RunOnce,.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.EventLog).CreateEvent("delete",..%Id(),$username,..Pivot,..DayOfWeek,..Hour,..Minute,..Format,..Emails,..Name,..RunOnce,.tDeleteEvent)
Set tSC=##class(PivotSubscriptions.Subscription).%DeleteId(..%Id())
Do tDeleteEvent.UpdateStatus(tSC)
Do tEvent.UpdateStatus(tSC)
Expand Down Expand Up @@ -106,6 +108,9 @@ Storage Default
<Value name="11">
<Value>CustomEmailText</Value>
</Value>
<Value name="12">
<Value>RunOnce</Value>
</Value>
</Data>
<DataLocation>^PivotSubscriptions.SubD</DataLocation>
<DefaultData>SubscriptionDefaultData</DefaultData>
Expand Down
23 changes: 16 additions & 7 deletions PivotSubscriptions/Task.cls
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Method OnTask() As %Status
// Ignore minute for testing purposes
// This will allow the task to be run on demand and send emails immediately
// Leaving DayOfWeek and Hour so the scheduled task does not spam emails
Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT ID,Emails,Name,Pivot,Format,DayOfWeek,""Hour"",""Minute"" FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=?",tDayOfWeek,tHour)
Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT ID,Emails,Name,Pivot,Format,DayOfWeek,""Hour"",""Minute"",RunOnce FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=?",tDayOfWeek,tHour)
} Else {
Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT ID,Emails,Name,Pivot,Format,DayOfWeek,""Hour"",""Minute"" FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=? AND ""Minute""=?",tDayOfWeek,tHour,tMinute)
Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT ID,Emails,Name,Pivot,Format,DayOfWeek,""Hour"",""Minute"",RunOnce FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=? AND ""Minute""=?",tDayOfWeek,tHour,tMinute)
}

// Loop through Subscription results and send emails.
Expand All @@ -31,14 +31,21 @@ Method OnTask() As %Status
Set tHour=tRS.%Get("Hour")
Set tMinute=tRS.%Get("Minute")
Set tName=tRS.%Get("Name")
Set tRunOnce=tRS.%Get("RunOnce")

Set tSC = ##class(PivotSubscriptions.Task).SendSubscription(tID,tPivot,tEmails,tFormat,tDayOfWeek,tHour,tMinute,tName)
Set tSC = ##class(PivotSubscriptions.Task).SendSubscription(tID,0,tPivot,tEmails,tFormat,tDayOfWeek,tHour,tMinute,tName)

If tRunOnce {
Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",tID,$username,tPivot,tDayOfWeek,tHour,tMinute,tFormat,tEmails,tName,tRunOnce,.tDeleteEvent)
Set tSC=##class(PivotSubscriptions.Subscription).%DeleteId(tID)
Do tDeleteEvent.UpdateStatus(tSC)
}
}

Quit tSC
}

ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat As %String, pDayOfWeek, pHour, pMinute, pName) As %Status
ClassMethod SendSubscription(pID, pSendNow As %Boolean = 0, pPivot As %String, pEmails As %String, pFormat As %String, pDayOfWeek, pHour, pMinute, pName) As %Status
{
Set tSC=$$$OK

Expand All @@ -47,18 +54,20 @@ ClassMethod SendSubscription(pID, pPivot As %String, pEmails As %String, pFormat
}

Try {
Set tSC=##class(PivotSubscriptions.Task).SendEmail(pID,pPivot,pEmails,pFormat,pName)
Set tSC=##class(PivotSubscriptions.Task).SendEmail(pID,pSendNow,pPivot,pEmails,pFormat,pName)
} Catch ex {
Set tSC=ex.AsStatus()
}

Quit tSC
}

ClassMethod SendEmail(pID, pPivot As %String, pEmails As %String, pFormat As %String, pName As %String) As %Status
ClassMethod SendEmail(pID, pSendNow As %Boolean = 0, pPivot As %String, pEmails As %String, pFormat As %String, pName As %String) As %Status
{
Set tSC=$$$OK
Set tFilename=""

Set tEventType=$Select(pSendNow:"sendNow",1:"sendSubscription")

Set mdx=##class(%DeepSee.Utils).%GetMDXFromPivot(pPivot,.tSC,0)
Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pID)
Expand All @@ -67,7 +76,7 @@ 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",pID,$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,.pEvent)
Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent(tEventType,pID,$username,pPivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tEmail,pName,tSubscription.RunOnce,.pEvent)
If $$$ISERR(tSC) Quit tSC

Try {
Expand Down
50 changes: 46 additions & 4 deletions PivotSubscriptions/UI/Dialog/EditSubscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ XData dialogBody [ XMLNamespace = "http://www.intersystems.com/zen" ]
<text id="SubscriptionId" value="0" hidden="true"/>
<label id="Name" label="Subscription name: "/>
<text id="SubscriptionName" size="40"/>
<radioSet id="RunOnce" label="Run Once?" displayList="No,Yes" valueList="0,1" value="0"/>
<select id="Preset" label="Preset Schedules" displayList="Weekdays,Weekends,Twice Weekly,Three Times Weekly" valueList="0,1,2,3" onchange="zenPage.updateSchedule();"/>
<multiSelectSet id="DayOfWeek" label="Day(s) Of Week" layout="horizontal" displayList="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday" valueList="0,1,2,3,4,5,6"/>
<hgroup>
<select id="Hour" label="Hour" displayList="00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23" valueList="0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23"/>
Expand Down Expand Up @@ -78,6 +80,7 @@ Method %OnAfterCreatePage() As %Status
Set ..%GetComponentById("Emails").value=tSubscription.Emails
Set ..%GetComponentById("SubscriptionName").value=tSubscription.Name
Set ..%GetComponentById("CustomEmailText").value=tSubscription.CustomEmailText
Set ..%GetComponentById("RunOnce").value=tSubscription.RunOnce

// Populate CustomFilters
Set tKey=""
Expand Down Expand Up @@ -109,6 +112,19 @@ Method %OnAfterCreatePage() As %Status
Do ..%AddComponent(tOption)
}

// Populate Preset Selection Dropdown
Set tPreset=..%GetComponentById("Preset")
Set tDayOfWeek=..%GetComponentById("DayOfWeek")
If tDayOfWeek.value="1,2,3,4,5" {
Set tPreset.value=0
} ElseIf tDayOfWeek.value="0,6" {
Set tPreset.value=1
} ElseIf tDayOfWeek.value="2,4" {
Set tPreset.value=2
} ElseIf tDayOfWeek.value="1,3,5" {
Set tPreset.value=3
}

Quit $$$OK
}

Expand All @@ -126,8 +142,9 @@ ClientMethod ondialogFinish(action) As %Boolean [ Language = javascript ]
var name=zen('SubscriptionName').getValue();
var pivot=this.pivotName;
var emailtext=zen('CustomEmailText').getValue();
var runonce=zen('RunOnce').getValue();

var status=zenPage.EditSubscription(subscriptionid,pivot,dayofweek,hour,minute,emails,format,name,emailtext);
var status=zenPage.EditSubscription(subscriptionid,pivot,dayofweek,hour,minute,emails,format,name,emailtext,runonce);

if (status!=1) {
alert("Error during save, see Event Log for more details.");
Expand All @@ -145,7 +162,7 @@ ClientMethod getDialogValue() [ Language = javascript ]
return '';
}

Method EditSubscription(pSubscriptionId, pPivot, pDayOfWeek, pHour, pMinute, pEmails, pFormat, pName, pEmailText) As %Status [ ZenMethod ]
Method EditSubscription(pSubscriptionId, pPivot, pDayOfWeek, pHour, pMinute, pEmails, pFormat, pName, pEmailText, pRunOnce) As %Status [ ZenMethod ]
{
Set tSC=$$$OK

Expand All @@ -160,7 +177,7 @@ Method EditSubscription(pSubscriptionId, pPivot, pDayOfWeek, pHour, pMinute, pEm
Set tEventType="create"
}

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 tSC=##class(PivotSubscriptions.EventLog).CreateEvent(tEventType,pSubscriptionId,$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,tSubscription.RunOnce,.tEvent)

Set tSubscription.DayOfWeek=pDayOfWeek
Set tSubscription.Hour=pHour
Expand All @@ -169,6 +186,7 @@ Method EditSubscription(pSubscriptionId, pPivot, pDayOfWeek, pHour, pMinute, pEm
Set tSubscription.Emails=pEmails
Set tSubscription.Name=pName
Set tSubscription.CustomEmailText=pEmailText
Set tSubscription.RunOnce=pRunOnce

// Get Custom Filter info
Set tKey=""
Expand All @@ -182,7 +200,7 @@ Method EditSubscription(pSubscriptionId, pPivot, pDayOfWeek, pHour, pMinute, pEm
Set tSC=tSubscription.%Save()
Do tEvent.UpdateStatus(tSC)
If tSC {
Do tEvent.UpdateEvent(pDayOfWeek,pHour,pMinute,pFormat,pEmails,pName)
Do tEvent.UpdateEvent(pDayOfWeek,pHour,pMinute,pFormat,pEmails,pName,pRunOnce)
}

Quit tSC
Expand Down Expand Up @@ -289,6 +307,30 @@ Method GetCustomFilter(pEmail) As %String [ ZenMethod ]
Quit tFilter
}

ClientMethod updateSchedule() [ Language = javascript ]
{
var schedule=zen('Preset');
var dayofweek=zen('DayOfWeek');

switch(parseInt(schedule.value)) {
case 0:
dayofweek.setProperty("value","1,2,3,4,5")
break;
case 1:
dayofweek.setProperty("value","0,6")
break;
case 2:
dayofweek.setProperty("value","2,4")
break;
case 3:
dayofweek.setProperty("value","1,3,5")
break;
default:
break;
}
dayofweek.updateValue();
}

ClientMethod customFilter() [ Language = javascript ]
{
var emailList=zen('EmailList');
Expand Down
4 changes: 4 additions & 0 deletions PivotSubscriptions/UI/Dialog/EventDetails.cls
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ ClassMethod DrawDetails(pEventId) As %Status
<td>Email</td>
<td>#(tEvent.Emails)#</td>
</tr>
<tr>
<td>Run Once</td>
<td>#(tEvent.RunOnce)#</td>
</tr>
<tr>
<td>Status</td>
<td>#($Select(tEvent.Status:"OK",1:$system.Status.GetErrorText(tEvent.Status)))#</td>
Expand Down
4 changes: 2 additions & 2 deletions PivotSubscriptions/UI/SubscriptionManager.cls
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Method Delete(pId As %Integer) As %String [ ZenMethod ]
Set tMsg="Subscription Deleted."

Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pId)
Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",pId,$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,.tEvent)
Set tSC=##class(PivotSubscriptions.EventLog).CreateEvent("delete",pId,$username,tSubscription.Pivot,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Format,tSubscription.Emails,tSubscription.Name,tSubscription.RunOnce,.tEvent)

If $$$ISERR(tSC) Quit tSC

Expand All @@ -153,7 +153,7 @@ Method SendNow(pId, pPivot, pEmail As %String) As %String [ ZenMethod ]

If pId'=0 {
Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pId)
Set tSC=##class(PivotSubscriptions.Task).SendSubscription(pId,pPivot,pEmail,tSubscription.Format,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Name)
Set tSC=##class(PivotSubscriptions.Task).SendSubscription(pId,1,pPivot,pEmail,tSubscription.Format,tSubscription.DayOfWeek,tSubscription.Hour,tSubscription.Minute,tSubscription.Name)

If $$$ISERR(tSC) {
Set tMsg=$System.Status.GetErrorText(tSC)
Expand Down
2 changes: 1 addition & 1 deletion PivotSubscriptions/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ ClassMethod WriteEmail(pSubscription As PivotSubscriptions.Subscription, pMsg As
ClassMethod TableErrorMessage(pSubscription As PivotSubscriptions.Subscription, pEmail As %String, pName As %String, pReason As %String, pMDX As %String) As %Status
{
Set tAdminEmail=##class(PivotSubscriptions.Utils).GetSettings("AdminEmail")
Set tLog=##class(PivotSubscriptions.EventLog).CreateEvent("tableError",pSubscription.%Id(),$username,pSubscription.Pivot,pSubscription.DayOfWeek,pSubscription.Hour,pSubscription.Minute,pSubscription.Format,tAdminEmail,pName,.pEvent)
Set tLog=##class(PivotSubscriptions.EventLog).CreateEvent("tableError",pSubscription.%Id(),$username,pSubscription.Pivot,pSubscription.DayOfWeek,pSubscription.Hour,pSubscription.Minute,pSubscription.Format,tAdminEmail,pName,pSubscription.RunOnce,.pEvent)

If $$$ISERR(tLog) Quit tLog

Expand Down

0 comments on commit be782dd

Please sign in to comment.