Skip to content

Commit

Permalink
Merge pull request #10 from psteiwer/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
psteiwer authored Mar 28, 2019
2 parents 5aec5ed + d8e1f0a commit 4eaaefc
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 31 deletions.
18 changes: 14 additions & 4 deletions PivotSubscriptions/Subscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ Class PivotSubscriptions.Subscription Extends %Persistent

Property CreatedBy As %String;

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

Property Frequency As %Integer(DISPLAYLIST = ",Daily,Weekly", VALUELIST = ",1,7");
Property DayOfWeek As %String;

Property Hour As %Integer(MINVAL=0, MAXVAL=23);

Property Minute As %Integer (VALUELIST=",0,15,30,45");

Property Format As %String(VALUELIST = ",Excel,PDF");

Expand All @@ -24,12 +28,18 @@ Storage Default
<Value>Pivot</Value>
</Value>
<Value name="4">
<Value>Frequency</Value>
<Value>DayOfWeek</Value>
</Value>
<Value name="5">
<Value>Format</Value>
<Value>Hour</Value>
</Value>
<Value name="6">
<Value>Minute</Value>
</Value>
<Value name="7">
<Value>Format</Value>
</Value>
<Value name="8">
<Value>Emails</Value>
</Value>
</Data>
Expand Down
62 changes: 49 additions & 13 deletions PivotSubscriptions/Task.cls
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,24 @@ Method OnTask() As %Status
{
Set tSC=$$$OK

// Default frequency to daily
Set tFrequency=1
// Construct current day and time for query
Set tDayOfWeek=$zd($h,10)
If tDayOfWeek=5 {
// Weekly run day is Friday
// If today is our "Weekly" run day, set tFrequency to "" to get all
Set tFrequency=""
}
Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT Emails,Frequency,Pivot FROM PivotSubscriptions.Subscription WHERE Frequency=? OR ? is null",tFrequency,tFrequency)
Set tHour=$p($zt($piece($h,",",2),2),":",1)
Set tMinute=$p($zt($piece($h,",",2),2),":",2)
Set tRS=##class(%SQL.Statement).%ExecDirect(,"SELECT Emails,Pivot FROM PivotSubscriptions.Subscription WHERE DayOfWeek[? AND ""Hour""=? AND ""Minute""=?",tDayOfWeek,tHour,tMinute)

// Loop through Subscription results for given frequency and send emails.
// Loop through Subscription results and send emails.
While tRS.%Next() {
Set tEmails=tRS.%Get("Emails")
Set tPivot=tRS.%Get("Pivot")
Set tFreq=tRS.%Get("Frequency")

Do ..SendEmail(tPivot,tEmails,tFreq)
Do ..SendEmail(tPivot,tEmails)
}

Quit tSC
}

ClassMethod SendEmail(pPivot As %String, pEmails As %String, pFrequency As %Integer) As %Status
ClassMethod SendEmail(pPivot As %String, pEmails As %String) As %Status
{
Set tSC=$$$OK
Set mdx=##class(%DeepSee.Utils).%GetMDXFromPivot(pPivot,.tSC,0)
Expand All @@ -54,7 +49,7 @@ ClassMethod SendEmail(pPivot As %String, pEmails As %String, pFrequency As %Inte
Set pParms("TITLE")=$E(pPivot,1,*-6)
Set pParms("SUBTITLE")="Report generated on "_$zd($h,6)
Set pParms("MDX")=mdx
Set filename=$replace($E(pPivot,1,*-6)_" - "_$zd($h,6),"/","-")_".xls"
Set filename=$replace($zstrip($E(pPivot,1,*-6),"*PC'W",,"/")_" - "_$zd($h,6),"/","-")_".xls"

Set tSC=##class(%DeepSee.Utils).%ExportExcelToFile(filename,.pParms)
}
Expand Down Expand Up @@ -102,4 +97,45 @@ ClassMethod SendEmail(pPivot As %String, pEmails As %String, pFrequency As %Inte
Quit tSC
}

/// This method is called each time a new subscription is created. It will create or update the task as needed
ClassMethod ConfigureTask() As %Status
{
Set tSC=$$$OK
//Does task exist? If so, update. Else, create
Set tFullName=..#TaskName_" - "_$NAMESPACE
Set tTaskID=##class(%SYS.Task).FindId(tFullName)
If tTaskID="" {
// Task is not present, need to create one
Set tTask=##class(%SYS.Task).%New()
Set tTask.Name=tFullName
Set tTask.NameSpace=$NAMESPACE
} Else {
// Task has already been defined
Quit tSC
}

Set tTask.TaskClass="PivotSubscriptions.Task"
Set tTask.RunAsUser="_SYSTEM"
Set tTask.Description="Executes PivotSubscriptions Task"

// Set schedule according to passed in parameters
Set tTask.TimePeriod=0
Set tTask.TimePeriodEvery=1
Set tTask.TimePeriodDay=""

// Build runs at most once every day
Set tTask.DailyFrequency=1
Set tTask.DailyFrequencyTime=0
Set tTask.DailyIncrement=15
Set tTask.DailyStartTime=0
Set tTask.DailyEndTime=0

// The task should be operational at the next available build time
Set tSC=tTask.StartDateSet(+$h)
If $$$ISERR(tSC) Quit

Set tSC=tTask.%Save()
Quit tSC
}

}
28 changes: 21 additions & 7 deletions PivotSubscriptions/UI/Dialog/EditSubscription.cls
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ XData dialogBody [ XMLNamespace = "http://www.intersystems.com/zen" ]
<pane xmlns="http://www.intersystems.com/zen" title="">
<label id="Label" label="Edit subscription for "/>
<text id="SubscriptionId" value="0" hidden="true"/>
<radioSet id="Frequency" label="Frequency" displayList="Daily,Weekly" valueList="1,7" value="1"/>
<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"/>
<select id="Minute" label="Minute" displayList="00,15,30,45" valueList="0,15,30,45"/>
</hgroup>
<radioSet id="Format" label="Format" displayList="Excel,PDF" valueList="Excel,PDF" value="Excel"/>
<textarea id="Emails" label="Email Addresses" hint="Comma separated list of email addresses. '@intersystems.com' appended if no domain supplied."/>
</pane>
Expand All @@ -46,7 +50,9 @@ Method %OnAfterCreatePage() As %Status
If ..SubscriptionId'=0 {
Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(..SubscriptionId)
Set ..%GetComponentById("SubscriptionId").value=..SubscriptionId
Set ..%GetComponentById("Frequency").value=tSubscription.Frequency
Set ..%GetComponentById("DayOfWeek").value=tSubscription.DayOfWeek
Set ..%GetComponentById("Hour").value=tSubscription.Hour
Set ..%GetComponentById("Minute").value=tSubscription.Minute
Set ..%GetComponentById("Format").value=tSubscription.Format
Set ..%GetComponentById("Emails").value=tSubscription.Emails
}
Expand All @@ -67,12 +73,14 @@ ClientMethod ondialogFinish(action) As %Boolean [ Language = javascript ]
try {

var subscriptionid=zen('SubscriptionId').getValue();
var frequency=zen('Frequency').getValue();
var dayofweek=zen('DayOfWeek').getValue();
var hour=zen('Hour').getValue();
var minute=zen('Minute').getValue();
var format=zen('Format').getValue();
var emails=zen('Emails').getValue();
var pivot=this.pivotName;

var status=zenPage.EditSubscription(subscriptionid,pivot,frequency,emails,format);
var status=zenPage.EditSubscription(subscriptionid,pivot,dayofweek,hour,minute,emails,format);
}
catch(ex) {
zenExceptionHandler(ex,arguments);
Expand All @@ -85,19 +93,25 @@ ClientMethod getDialogValue() [ Language = javascript ]
return '';
}

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

If pSubscriptionId'=0 {
Set tSubscription=##class(PivotSubscriptions.Subscription).%OpenId(pSubscriptionId)
} Else {
Set tSubscription=##class(PivotSubscriptions.Subscription).%New()
Set tSubscription.CreatedBy=$username
Set tSubscription.Pivot=pPivot
}
Set tSubscription.Frequency=pFrequency
Set tSubscription.DayOfWeek=pDayOfWeek
Set tSubscription.Hour=pHour
Set tSubscription.Minute=pMinute
Set tSubscription.Format=pFormat
Set tSubscription.Emails=pEmails
Quit tSubscription.%Save()
Set tSC=tSubscription.%Save()

Quit tSC
}

}
9 changes: 4 additions & 5 deletions PivotSubscriptions/UI/PivotList.cls
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ XData contentPane [ XMLNamespace = "http://www.intersystems.com/zen" ]
OnExecuteResultSet="ExecuteRS"
>
<column id="Owner" header="Owner" colName="POwner" width="10%" filterType="text"/>
<column id="Name" header="Name" colName="PName" width="50%" filterType="text" />
<column id="View" header="View in Analyzer" colName="PView" width="30%" link="./_DeepSee.UserPortal.Analyzer.zen?PIVOT=#(%query.PView)#"/>
<column id="Name" header="Name" colName="PName" width="30%" filterType="text" link="./_DeepSee.UserPortal.Analyzer.zen?PIVOT=#(%query.PName)#"/>
<column OnDrawCell="DrawAddSubscriptionLink"/>
</tablePane>
</pane>
Expand All @@ -39,7 +38,7 @@ Method ExecuteRS(pRS As %ResultSet, Output pSC As %Status, pInfo As %ZEN.Auxilia
ClientMethod launchAddSubscription(pivotName) [ Language = javascript ]
{
var url = zenLink('PivotSubscriptions.UI.Dialog.EditSubscription.zen')+'?SUBSCRIPTIONID=0&PIVOTNAME='+encodeURIComponent(pivotName);
zenPage.launchPopupWindow(url,'Add Subscription','status,scrollbars,resizable,width=500,height=500');
zenPage.launchPopupWindow(url,'Add Subscription','status,scrollbars,resizable,width=750,height=500');
}

ClassMethod DrawAddSubscriptionLink(pTable As %ZEN.Component.tablePane, pName As %String, pSeed As %String) As %Status [ Internal ]
Expand All @@ -49,7 +48,7 @@ ClassMethod DrawAddSubscriptionLink(pTable As %ZEN.Component.tablePane, pName As
Quit $$$OK
}

Query GetPivots(pOwner As %String = "", pName As %String = "") As %Query(ROWSPEC = "POwner:%String,PName:%String,PView:%String,PSubscription:%String")
Query GetPivots(pOwner As %String = "", pName As %String = "") As %Query(ROWSPEC = "POwner:%String,PName:%String,PSubscription:%String")
{
}

Expand Down Expand Up @@ -88,7 +87,7 @@ ClassMethod GetPivotsFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef A
Quit $$$OK
}

Set Row=$lb($LG(^||PivotSubscriptions.getPivotExecute(qHandle),10),$LG(^||PivotSubscriptions.getPivotExecute(qHandle),1),$ZCONVERT($LG(^||PivotSubscriptions.getPivotExecute(qHandle),1),"O","HTML"),"Subscription")
Set Row=$lb($LG(^||PivotSubscriptions.getPivotExecute(qHandle),10),$LG(^||PivotSubscriptions.getPivotExecute(qHandle),1),"Subscription")
Set AtEnd=0

Quit $$$OK
Expand Down
4 changes: 2 additions & 2 deletions PivotSubscriptions/UI/SubscriptionManager.cls
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ XData contentPane [ XMLNamespace = "http://www.intersystems.com/zen" ]
valueColumn="ID"
>
<column colName="ID" header="Subscription ID" />
<column colName="Pivot" header="Pivot" />
<column id="Pivot" header="Pivot" colName="Pivot" link="./_DeepSee.UserPortal.Analyzer.zen?PIVOT=#(%query.Pivot)#"/>
<column colName="Emails" header="Emails" />
<column onclick="zenPage.editSubscription(#(%query.ID)#,'#(%query.Pivot)#')" linkCaption="Edit" link="#"/>
<column onclick="return zenPage.deleteSubscription('#(%query.ID)#');" linkCaption="Delete" link="#" />
Expand Down Expand Up @@ -92,7 +92,7 @@ ClientMethod editSubscription(subscriptionId,pivotName) [ Internal, Language = j
MODE:"models",
};

zenLaunchPopupWindow('PivotSubscriptions.UI.Dialog.EditSubscription.cls?SUBSCRIPTIONID='+subscriptionId+'&PIVOTNAME='+pivotName,'PivotSubscriptions','status,resizable=yes,width=900,height=700',parms);
zenLaunchPopupWindow('PivotSubscriptions.UI.Dialog.EditSubscription.cls?SUBSCRIPTIONID='+subscriptionId+'&PIVOTNAME='+pivotName,'PivotSubscriptions','status,resizable=yes,width=750,height=500',parms);
}

/// Delete the selected subscription.
Expand Down

0 comments on commit 4eaaefc

Please sign in to comment.