From 7ecb126ecda598883c7de10dead43057e595979f Mon Sep 17 00:00:00 2001 From: Edwin Chandra Date: Wed, 3 Jun 2015 10:02:42 +0530 Subject: [PATCH] Email trigger functionality completed and fixed bugs --- api/controllers/ENEmailManagerController.js | 41 +- api/models/ENNotification.js | 4 +- .../EmailNotifications/EmailNotifications.css | 2 +- .../controllers/EmailNotifications.js | 11 +- .../EmailNotifications/controllers/Wizard.js | 8 +- .../controllers/WizardNotifications.js | 97 +++-- .../EmailNotifications (another copy).ejs | 367 ------------------ .../EmailNotifications (copy).ejs | 367 ------------------ .../EmailNotifications/EmailNotifications.ejs | 2 +- 9 files changed, 105 insertions(+), 794 deletions(-) delete mode 100755 assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications (another copy).ejs delete mode 100755 assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications (copy).ejs diff --git a/api/controllers/ENEmailManagerController.js b/api/controllers/ENEmailManagerController.js index 718d583..e34dfca 100755 --- a/api/controllers/ENEmailManagerController.js +++ b/api/controllers/ENEmailManagerController.js @@ -29,16 +29,14 @@ module.exports = { var currentDate = new Date().toISOString().slice(0,10); //Find notification based on schedule date + var filterQuery = " SELECT id, emailSubject, fromName, fromEmail, templateDesignId, recipientId FROM en_notification WHERE CURDATE() >= startFROM AND CURDATE()<= repeatUntil AND ( notificationSendDate < CURDATE() OR notificationSendDate IS NULL) AND status='Active' AND setupType='Basic'"; - ENNotification.find().where({"repeatUntil":{ ">=":currentDate}, "nextNotificationDate":currentDate,"status":"Active","setupType":"Basic"}).then(function(notifications){ + ENNotification.query(filterQuery, function(err,notifications){ if(notifications.length > 0){ notifications.forEach(function(notify){ - - //ENNotification.update(''); - self.updateNotificationSchedule(notify); // update next schedule date - + //Find the recipient List for notification ENRecipient.findOne({id:notify.recipientId}).then(function(recipient){ @@ -81,7 +79,7 @@ module.exports = { obj.log = response; // log //Create notification log self.createNotificationLog(obj); //set notification log - //console.log('sent email'); + self.updateNotificationSchedule(notify); // update next schedule date }); @@ -89,11 +87,7 @@ module.exports = { }); }); - }else{ - - console.log('No Email Scheduled'); - - } + } }); }, @@ -113,9 +107,7 @@ module.exports = { //Create notification log ENNotificationLog.create(obj).fail(function(err){ console.log(err); - }).then(function(response){ - console.log(response); - }); + }).then(function(response){ }); }, @@ -129,31 +121,26 @@ module.exports = { * @since 15 May 2015 */ - updateNotificationSchedule : function(notification){ - - var notificationFrequency = notification.emailFrequency; + updateNotificationSchedule : function(notification){ var currentDate = new Date(); - var nextSchedule = ''; + var notificationFrequency = notification.emailFrequency; + var nextSchedule = currentDate; if(notificationFrequency == 'Everyday'){ - nextSchedule = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()+1); // New date +1 day ahead + nextSchedule = currentDate; }else if(notificationFrequency == 'Monthly'){ - nextSchedule = new Date(currentDate.getFullYear(), currentDate.getMonth()+1, currentDate.getDate()); // New date +1 month ahead + nextSchedule = new Date(currentDate.getFullYear(), currentDate.getMonth()+1, currentDate.getDate()-1); // New date +1 month ahead }else if(notificationFrequency == 'Yearly'){ - nextSchedule = new Date(currentDate.getFullYear()+1, currentDate.getMonth(), currentDate.getDate()); // New date +1 Year ahead + nextSchedule = new Date(currentDate.getFullYear()+1, currentDate.getMonth(), currentDate.getDate()-1); // New date +1 Year ahead } - - //Update the schedule date - ENNotification.update(notification.id,{'nextNotificationDate': nextSchedule}).then(function(){ - console.log('Schedule updated'); - - }); + + ENNotification.update(notification.id,{'notificationSendDate': nextSchedule}).then( function(){}); } }; diff --git a/api/models/ENNotification.js b/api/models/ENNotification.js index 3301173..e5fe075 100755 --- a/api/models/ENNotification.js +++ b/api/models/ENNotification.js @@ -30,7 +30,9 @@ module.exports = { repeatUntil : { type: 'date' }, - nextNotificationDate : { type: 'date' }, + notificationSendDate : { type: 'date' }, + + isForever : {type:'integer', size: 2, defaultsTo:0}, templateDesignId :{ diff --git a/assets/opstools/EmailNotifications/EmailNotifications.css b/assets/opstools/EmailNotifications/EmailNotifications.css index f760632..ca48dfd 100755 --- a/assets/opstools/EmailNotifications/EmailNotifications.css +++ b/assets/opstools/EmailNotifications/EmailNotifications.css @@ -964,7 +964,7 @@ button.close { background-color:#fff; border:1px solid #ccc; padding:10px; - overflow: scroll; + overflow-y: scroll; } .en-table-recipients tbody .active { diff --git a/assets/opstools/EmailNotifications/controllers/EmailNotifications.js b/assets/opstools/EmailNotifications/controllers/EmailNotifications.js index 9ee0a38..a32be72 100755 --- a/assets/opstools/EmailNotifications/controllers/EmailNotifications.js +++ b/assets/opstools/EmailNotifications/controllers/EmailNotifications.js @@ -100,13 +100,18 @@ steal( CtrlNotification.form.find('#dateStartFrom').val(new Date(self.wizardData.notification.startFrom).toLocaleDateString()); CtrlNotification.form.find('#emailFrequency').val(self.wizardData.notification.emailFrequency); - if(self.wizardData.notification.repeatUntil!='0000-00-00'){ + if(self.wizardData.notification.isForever === 0){ CtrlNotification.form.find('#dateRepeatUntil').val(new Date(self.wizardData.notification.repeatUntil).toLocaleDateString()); }else{ - - CtrlNotification.form.find('#neverEnd').attr('checked',true); + //reset value if selected never end + CtrlNotification.form.find('#neverEnd').prop('checked',true); + CtrlNotification.form.find('#dateRepeatUntil').val(' '); + CtrlNotification.form.find('#dateRepeatUntil').attr('disabled', true); + CtrlNotification.form.find('#dateRepeatUntil').hide(); + CtrlNotification.form.find('#no-date').show(); + CtrlNotification.form.find('#repeatUntil .input-group-addon').hide(); } diff --git a/assets/opstools/EmailNotifications/controllers/Wizard.js b/assets/opstools/EmailNotifications/controllers/Wizard.js index 312416f..897df0a 100755 --- a/assets/opstools/EmailNotifications/controllers/Wizard.js +++ b/assets/opstools/EmailNotifications/controllers/Wizard.js @@ -134,8 +134,12 @@ steal( this.controllers.Notifications.form.find('#dateStartFrom').val(''); this.controllers.Notifications.form.find('#emailFrequency').val('Everyday'); this.controllers.Notifications.form.find('#dateRepeatUntil').val(''); + this.controllers.Notifications.form.find('#neverEnd').prop('checked',false); + this.controllers.Notifications.form.find('#dateRepeatUntil').show(); + this.controllers.Notifications.form.find('#no-date').hide(); + this.controllers.Notifications.form.find('#dateRepeatUntil').attr('disabled', false); + this.controllers.Notifications.form.find('#repeatUntil .input-group-addon ').show(); this.controllers.Notifications.form.find('#basic-settings').html('The Notification will be sent Everyday'); - this.controllers.Notifications.element.find('.tabbable ul li:nth-child(2)').removeClass('active'); this.controllers.Notifications.element.find('.tabbable ul li:nth-child(1)').addClass('active'); this.controllers.Notifications.element.find('#basic').addClass('active'); @@ -355,7 +359,7 @@ steal( var setupShortDesc = notification.emailFrequency; setupShortDesc += ' from '; setupShortDesc += new Date(notification.startFrom).toDateString(); - if (notification.repeatUntil != '0000-00-00') { + if (notification.isForever == 0) { setupShortDesc += ' to ' + new Date(notification.repeatUntil).toDateString(); } else { setupShortDesc += ''; diff --git a/assets/opstools/EmailNotifications/controllers/WizardNotifications.js b/assets/opstools/EmailNotifications/controllers/WizardNotifications.js index b5c20fa..2e503b7 100755 --- a/assets/opstools/EmailNotifications/controllers/WizardNotifications.js +++ b/assets/opstools/EmailNotifications/controllers/WizardNotifications.js @@ -82,7 +82,6 @@ steal( if(this.element.find('.tabbable ul li').eq(0).hasClass('active')) { obj.setupType = 'Basic'; obj.eventTrigger = ''; - obj.nextNotificationDate = obj.startFrom; } else { obj.setupType = 'System'; obj.startFrom = null; @@ -152,18 +151,24 @@ steal( if (this.validateFormData(obj) && this.validateBasicTab(obj)) { var Model = AD.Model.get('opstools.EmailNotifications.ENNotification'); obj.recipientId = self.options.wizardData.recipient.id; + // Check for Never end + if(obj.neverEnd=='on'){ + obj.repeatUntil = this.getFutureDate(); + obj.isForever = '1'; + }else{ + obj.isForever = '0'; + } + if (obj.startFrom != '') { obj.setupType = 'Basic'; - obj.eventTrigger = ''; - obj.nextNotificationDate = obj.startFrom; + obj.eventTrigger = ''; + obj.notificationSendDate = this.updateNotificationSchedule(obj); + } else { obj.setupType = 'System'; } - if(obj.neverEnd=='on'){ - obj.repeatUntil = ''; - } - + var notificationId = self.options.wizardData.notification.id; if (notificationId) { Model.update(notificationId, obj); //Update notificationId @@ -397,24 +402,35 @@ steal( * */ '#neverEnd click': function($el, ev) { - var obj = this.formValues(); - var self = this; - if (obj.neverEnd == 'on') { - this.element.find('#dateRepeatUntil').val(' '); - this.element.find('#dateRepeatUntil').attr('disabled', true); - this.element.find('#dateRepeatUntil').hide(); - this.element.find('#no-date').show(); - this.element.find('#repeatUntil .input-group-addon').hide(); - } else { - this.element.find('#dateRepeatUntil').show(); - this.element.find('#no-date').hide(); - this.element.find('#dateRepeatUntil').attr('disabled', false); - this.element.find('#repeatUntil .input-group-addon ').show(); - } - self.updateNotificationBar(); + var self = this; + self.clearRepeatUntil(); // clear repeat until field + self.updateNotificationBar(); // update notification bar }, - + /** + * @clearRepeatUntil + * @to clear repeat until field + * + * + */ + + clearRepeatUntil: function(){ + var neverEnd = this.element.find('#neverEnd').is(':checked'); + if (neverEnd) { + this.element.find('#dateRepeatUntil').val(' '); + this.element.find('#dateRepeatUntil').attr('disabled', true); + this.element.find('#dateRepeatUntil').hide(); + this.element.find('#no-date').show(); + this.element.find('#repeatUntil .input-group-addon').hide(); + } else { + this.element.find('#dateRepeatUntil').show(); + this.element.find('#no-date').hide(); + this.element.find('#dateRepeatUntil').attr('disabled', false); + this.element.find('#repeatUntil .input-group-addon ').show(); + } + + }, + /** * @updateNotificationBar * @ to update notification bar @@ -493,6 +509,18 @@ steal( }, /** + * @ getFutureDate + * @ to get futuredate if repeatUntil is blank + * @ param $el + * @ param ev + * return void + */ + + getFutureDate :function(){ + var currentDate = new Date(); //current date + return new Date(currentDate.getFullYear()+100, currentDate.getMonth(), currentDate.getDate()); + }, + /** * @ emailFrequency change * @ to chage the notification bar * @ param $el @@ -502,8 +530,27 @@ steal( '#emailFrequency change': function($el, ev) { var self = this; self.updateNotificationBar(); - } - + }, + + /**@ updateNotificationSchedule + * + * @param obj + * + * @return void + * + * @author Edwin + * @since 15 May 2015 + */ + + updateNotificationSchedule : function(notification){ + var self = this; + var notificationDate = new Date(notification.startFrom); //get start from date + var oneDayless = new Date(notificationDate.getFullYear(), notificationDate.getMonth(), notificationDate.getDate()-1); + var notificationSendDate = (self.options.wizardData.notification.notificationSendDate) ? new Date(self.options.wizardData.notification.notificationSendDate) : oneDayless;// schedule date on database + + return notificationSendDate; + } + }); }); diff --git a/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications (another copy).ejs b/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications (another copy).ejs deleted file mode 100755 index e7743c6..0000000 --- a/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications (another copy).ejs +++ /dev/null @@ -1,367 +0,0 @@ - - -
-
- -
-

Notification Lists

-
-
- - - - - - - - - - - - - - - - - - - - - - - -
List TitleLast Updated
[[= notification.attr('notificationTitle') ]][[= notification.attr('status') ]][[= new Date(notification.attr('updatedAt')).toDateString() ]] - Modify - Delete -
Finanace Team1/11/2015 - Modify - Delete -
-
-
-
- - - -
- - - - - -
-
-
-

Recipient Lists

-
- -
- Create New List - - - - - - - - - - - - - - - - - - - - - - - -
List TitleLast Updated
[[= recipient.attr('title') ]][[= new Date(recipient.attr('updatedAt')).toDateString() ]] - Modify - Delete -
Finanace Team1/11/2015 - Modify - Delete -
-
-
- Next -
-
-
- - - - -
-
-
-

Notification Setup

-
-
- -
- - -
-
- - -
-
- - -
-
- - -
- -
-
-

Select how you want to send notifications:

-
- -
-
-
-

Basic

-
-
- -
-
- - -
-
-
-
- -
-
- -
-
-
-
- -
-
- - - -
-
- Never End -
-
-
-

The Notification will be sent Everyday from 1/12/2015 to 6/12/2015

- Next -
-
-
-
-
-

System

-
-
- Select the event you want to use to trigger the notification being sent: -
-
-
-
- -
-
-
-

You are sending 13 month report

- Next -
-
-
-
-
-
-
-
- - - -
-
-
-

Select a Template

-
-
-
- One Column Layout -

One Column

- -
-
-
-
- - - -
-
-
-

Design a Template

-
-
- -
- - -
- -
-
-
- HTML -
-

Enter Your Text

- -
- -
-
-
-
- - - -
-
-
-

Confirm Notification

-
-
-

Please recheck the notification details:

-
    -
  • [[= numRecipients]] Recipients are selected
  • -
  • Subject is "[[= notification.notificationSubject]]"
  • -
  • Sending conditions based on "[[=notification.setupShortDesc]]"
  • -
  • Template selected is "[[= notification.selectedTemplate]]"
  • -
  • HTML text is given using the "[[= notification.templateType]]" Design
  • -
-
-
-

This is the preview of the notification you are sending:

-
-
-

Subject: [[=notification.templateSubject]]

-
[[=notification.templateBody]]
-
-
-

Please confirm your Notification

- - Draft - - - Confirm - -
-
-
-
-
- -
- - - diff --git a/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications (copy).ejs b/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications (copy).ejs deleted file mode 100755 index 1112e6b..0000000 --- a/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications (copy).ejs +++ /dev/null @@ -1,367 +0,0 @@ - - -
-
- -
-

Notification Lists

-
-
- - - - - - - - - - - - - - - - - - - - - - - -
List TitleLast Updated
[[= notification.attr('notificationTitle') ]][[= notification.attr('status') ]][[= new Date(notification.attr('updatedAt')).toDateString() ]] - Modify - Delete -
Finanace Team1/11/2015 - Modify - Delete -
-
-
-
- - - -
- - - - - -
-
-
-

Recipient Lists

-
- -
- Create New List - - - - - - - - - - - - - - - - - - - - - - - -
List TitleLast Updated
[[= recipient.attr('title') ]][[= new Date(recipient.attr('updatedAt')).toDateString() ]] - Modify - Delete -
Finanace Team1/11/2015 - Modify - Delete -
-
-
- Next -
-
-
- - - - -
-
-
-

Notification Setup

-
-
- -
- - -
-
- - -
-
- - -
-
- - -
- -
-
-

Select how you want to send notifications:

-
- -
-
-
-

Basic

-
-
- -
-
- - -
-
-
-
- -
-
- -
-
-
-
- -
-
- - - -
-
- Never End -
-
-
-

The Notification will be sent Everyday from 1/12/2015 to 6/12/2015

- Next -
-
-
-
-
-

System

-
-
- Select the event you want to use to trigger the notification being sent: -
-
-
-
- -
-
-
-

You are sending 13 month report

- Next -
-
-
-
-
-
-
-
- - - -
-
-
-

Select a Template

-
-
-
- One Column Layout -

One Column

- -
-
-
-
- - - -
-
-
-

Design a Template

-
-
- -
- - -
- -
-
-
- HTML -
-

Enter Your Text

- -
- -
-
-
-
- - - -
-
-
-

Confirm Notification

-
-
-

Please recheck the notification details:

-
    -
  • [[= numRecipients]] Recipients are selected
  • -
  • Subject is "[[= notification.notificationSubject]]"
  • -
  • Sending conditions based on "[[=notification.setupShortDesc]]"
  • -
  • Template selected is "[[= notification.selectedTemplate]]"
  • -
  • HTML text is given using the "[[= notification.templateType]]" Design
  • -
-
-
-

This is the preview of the notification you are sending:

-
-
-

Subject: [[=notification.templateSubject]]

-
[[=notification.templateBody]]
-
-
-

Please confirm your Notification

- - Draft - - - Confirm - -
-
-
-
-
- -
- - - diff --git a/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications.ejs b/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications.ejs index 194834c..4617b0b 100755 --- a/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications.ejs +++ b/assets/opstools/EmailNotifications/views/EmailNotifications/EmailNotifications.ejs @@ -340,7 +340,7 @@

Subject: [[= notification.notificationSubject]]

-
[[=notification.templateDesignId.templateBody]]
+
[[== notification.templateDesignId.templateBody]]

Please confirm your Notification