From aaeaefff85ad9b0415f339e28f4d949d9a2bf32d Mon Sep 17 00:00:00 2001 From: Debarshi Bhaumik Date: Fri, 25 May 2018 11:33:13 +0530 Subject: [PATCH 01/11] PCHR-3714: Task Notification Badge Component --- .../civihr_employee_portal.module | 44 +++++++++++++++++++ .../templates/tasks_notification_badge.html | 8 ++++ 2 files changed, 52 insertions(+) create mode 100644 civihr_employee_portal/views/templates/tasks_notification_badge.html diff --git a/civihr_employee_portal/civihr_employee_portal.module b/civihr_employee_portal/civihr_employee_portal.module index 99199e8b..a9e9511f 100755 --- a/civihr_employee_portal/civihr_employee_portal.module +++ b/civihr_employee_portal/civihr_employee_portal.module @@ -6553,3 +6553,47 @@ function _civihr_employee_portal_create_default_reports_configuration() { ->execute(); } } + +/** + * Internal function for fetching custom markup from template and Angular Js. + * + * @param String + * Name of the resource to load template and angular js. + * + * @return String + * Custom markup from template file. + */ +function civihr_tasks_documents_get_markup($resource = '') { + $script = CRM_Core_Config::singleton()->debug ? "{$resource}.js" : "{$resource}.min.js"; + + // Adds RequireJS + AngularJS dependencies only once + if (!strpos(drupal_get_js('footer'), 'reqangular.min.js')) { + civicrm_resources_load('org.civicrm.reqangular', ['reqangular.min.js']); + } + + civicrm_resources_load('uk.co.compucorp.civicrm.tasksassignments', [$script]); + + return civihr_tasks_documents_load_file(str_replace('-', '_', $resource)); +} + +/** + * Internal function to load predefined template file. + * + * @param String + * File name to load the content. + * + * @return String + * File Content. + */ +function civihr_tasks_documents_load_file($template = '') { + + // Fetching custom markup from pre-defined template file. + $file_path = drupal_get_path('module', 'civihr_employee_portal') . '/views/templates/' . $template . '.html'; + + if (file_exists($file_path)) { + return @file_get_contents($file_path); + } + else { + return ''; + } +} diff --git a/civihr_employee_portal/views/templates/tasks_notification_badge.html b/civihr_employee_portal/views/templates/tasks_notification_badge.html new file mode 100644 index 00000000..c0ed8014 --- /dev/null +++ b/civihr_employee_portal/views/templates/tasks_notification_badge.html @@ -0,0 +1,8 @@ + + + + From 5de21dcf8de7b899f1bd7d09686ac68ab5b000ac Mon Sep 17 00:00:00 2001 From: Debarshi Bhaumik Date: Fri, 25 May 2018 13:09:10 +0530 Subject: [PATCH 02/11] PCHR-3714: Update Task Badge when tasks are completed from SSP --- civihr_employee_portal/js/tasks.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/civihr_employee_portal/js/tasks.js b/civihr_employee_portal/js/tasks.js index 6657e5a3..6d96ff18 100644 --- a/civihr_employee_portal/js/tasks.js +++ b/civihr_employee_portal/js/tasks.js @@ -191,6 +191,8 @@ $navTaskFilter .find('[data-task-filter="all"]') .find('.task-counter-filter').text(sum); + + document.dispatchEvent(new Event('TasksBadge:: Update Count')); } function buildTaskContactFilter() { From 7fd1bdd9a3750ac31a0a78c9033224e9e8b0d186 Mon Sep 17 00:00:00 2001 From: Debarshi Bhaumik Date: Mon, 28 May 2018 11:19:37 +0530 Subject: [PATCH 03/11] PCHR-3714: PR Feedback --- .../civihr_employee_portal.module | 24 +++++---- .../civihr_leave_absences.module | 53 +++---------------- .../templates/tasks_notification_badge.html | 0 3 files changed, 23 insertions(+), 54 deletions(-) rename civihr_employee_portal/{views => }/templates/tasks_notification_badge.html (100%) diff --git a/civihr_employee_portal/civihr_employee_portal.module b/civihr_employee_portal/civihr_employee_portal.module index a9e9511f..153ba5ca 100755 --- a/civihr_employee_portal/civihr_employee_portal.module +++ b/civihr_employee_portal/civihr_employee_portal.module @@ -6557,13 +6557,17 @@ function _civihr_employee_portal_create_default_reports_configuration() { /** * Internal function for fetching custom markup from template and Angular Js. * - * @param String + * @param string * Name of the resource to load template and angular js. + * @param string + * Name of the extension from where scripts are to be loaded + * @param string + * Name of the module from where html is to be loaded * - * @return String + * @return string * Custom markup from template file. */ -function civihr_tasks_documents_get_markup($resource = '') { +function civihr_employee_portal_get_markup_for_extension($resource = '', $scriptExtensionKey, $markupModuleName) { $script = CRM_Core_Config::singleton()->debug ? "{$resource}.js" : "{$resource}.min.js"; // Adds RequireJS + AngularJS dependencies only once @@ -6571,24 +6575,26 @@ function civihr_tasks_documents_get_markup($resource = '') { civicrm_resources_load('org.civicrm.reqangular', ['reqangular.min.js']); } - civicrm_resources_load('uk.co.compucorp.civicrm.tasksassignments', [$script]); + civicrm_resources_load($scriptExtensionKey, [$script]); - return civihr_tasks_documents_load_file(str_replace('-', '_', $resource)); + return civihr_employee_portal_load_html_file(str_replace('-', '_', $resource), $markupModuleName); } /** * Internal function to load predefined template file. * - * @param String + * @param string * File name to load the content. + * @param string + * Module Name * - * @return String + * @return string * File Content. */ -function civihr_tasks_documents_load_file($template = '') { +function civihr_employee_portal_load_html_file($template = '', $moduleName) { // Fetching custom markup from pre-defined template file. - $file_path = drupal_get_path('module', 'civihr_employee_portal') . '/views/templates/' . $template . '.html'; + $file_path = drupal_get_path('module', $moduleName) . '/templates/' . $template . '.html'; if (file_exists($file_path)) { return @file_get_contents($file_path); diff --git a/civihr_employee_portal/civihr_leave_absences/civihr_leave_absences.module b/civihr_employee_portal/civihr_leave_absences/civihr_leave_absences.module index bcb2d786..3764d6b1 100644 --- a/civihr_employee_portal/civihr_leave_absences/civihr_leave_absences.module +++ b/civihr_employee_portal/civihr_leave_absences/civihr_leave_absences.module @@ -30,10 +30,16 @@ function civihr_leave_absences_block_view($delta = '') { $block = []; switch ($delta) { case 'my_leave': - $block['content'] = civihr_leave_absences_get_markup('my-leave'); + $block['content'] = civihr_employee_portal_get_markup_for_extension( + 'my-leave', + 'uk.co.compucorp.civicrm.hrleaveandabsences', + 'civihr_leave_absences'); break; case 'manager_leave': - $block['content'] = civihr_leave_absences_get_markup('manager-leave'); + $block['content'] = civihr_employee_portal_get_markup_for_extension( + 'manager-leave', + 'uk.co.compucorp.civicrm.hrleaveandabsences', + 'civihr_leave_absences'); break; } return $block; @@ -64,49 +70,6 @@ function civihr_leave_absences_init() { } } -/** - * Internal function for fetching custom markup from template and Angular Js. - * - * @param String - * Name of the resource to load template and angular js. - * - * @return String - * Custom markup from template file. - */ -function civihr_leave_absences_get_markup($resource = '') { - $script = CRM_Core_Config::singleton()->debug ? "{$resource}.js" : "{$resource}.min.js"; - - // Adds RequireJS + AngularJS dependencies only once - if (!strpos(drupal_get_js('footer'), 'reqangular.min.js')) { - civicrm_resources_load('org.civicrm.reqangular', ['reqangular.min.js']); - } - - civicrm_resources_load('uk.co.compucorp.civicrm.hrleaveandabsences', [$script]); - - return civihr_leave_absences_load_file(str_replace('-', '_', $resource)); -} - -/** - * Internal function to load predefined template file. - * - * @param String - * File name to load the content. - * - * @return String - * File Content. - */ -function civihr_leave_absences_load_file($template = '') { - - // Fetching custom markup from pre-defined template file. - $file_path = drupal_get_path('module', 'civihr_leave_absences') . '/templates/' . $template . '.html'; - if (file_exists($file_path)) { - return @file_get_contents($file_path); - } - else { - return ''; - } -} - /** * Internal function to push the Leave & Absences permissions to the frontend. * diff --git a/civihr_employee_portal/views/templates/tasks_notification_badge.html b/civihr_employee_portal/templates/tasks_notification_badge.html similarity index 100% rename from civihr_employee_portal/views/templates/tasks_notification_badge.html rename to civihr_employee_portal/templates/tasks_notification_badge.html From 2775d5d2ec72a3207fbb1d5d367d099db1f2360a Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Thu, 31 May 2018 14:33:00 +0100 Subject: [PATCH 04/11] FAR-265: Fix wrong date filter field in leave and absence report view. --- .../civihr_employee_portal_features.views_default.inc | 11 ++--------- .../views_civihr_report_leave_and_absence.inc | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/civihr_employee_portal/features/civihr_employee_portal_features/civihr_employee_portal_features.views_default.inc b/civihr_employee_portal/features/civihr_employee_portal_features/civihr_employee_portal_features.views_default.inc index 14dd5aaa..ebc6fd43 100644 --- a/civihr_employee_portal/features/civihr_employee_portal_features/civihr_employee_portal_features.views_default.inc +++ b/civihr_employee_portal/features/civihr_employee_portal_features/civihr_employee_portal_features.views_default.inc @@ -502,10 +502,10 @@ function civihr_employee_portal_features_views_default_views() { $handler->display->display_options['filters']['period_end_date']['relationship'] = 'details_revision_id'; $handler->display->display_options['filters']['period_end_date']['operator'] = 'empty'; $handler->display->display_options['filters']['period_end_date']['group'] = 3; - /* Filter criterion: Date: Date (absence_activity) */ + /* Filter criterion: Absence Activity entity: Absence date */ $handler->display->display_options['filters']['date_filter']['id'] = 'date_filter'; $handler->display->display_options['filters']['date_filter']['table'] = 'absence_activity'; - $handler->display->display_options['filters']['date_filter']['field'] = 'date_filter'; + $handler->display->display_options['filters']['date_filter']['field'] = 'absence_date'; $handler->display->display_options['filters']['date_filter']['relationship'] = 'absence_activity'; $handler->display->display_options['filters']['date_filter']['operator'] = 'between'; $handler->display->display_options['filters']['date_filter']['exposed'] = TRUE; @@ -521,13 +521,6 @@ function civihr_employee_portal_features_views_default_views() { 17087012 => 0, 57573969 => 0, ); - $handler->display->display_options['filters']['date_filter']['form_type'] = 'date_popup'; - $handler->display->display_options['filters']['date_filter']['default_date'] = 'now -10 year'; - $handler->display->display_options['filters']['date_filter']['default_to_date'] = 'now +10 year'; - $handler->display->display_options['filters']['date_filter']['year_range'] = '-10:+10'; - $handler->display->display_options['filters']['date_filter']['date_fields'] = array( - 'absence_activity.absence_date' => 'absence_activity.absence_date', - ); /* Filter criterion: Absence Activity entity: Absence activity entity ID */ $handler->display->display_options['filters']['absence_activity_id']['id'] = 'absence_activity_id'; $handler->display->display_options['filters']['absence_activity_id']['table'] = 'absence_activity'; diff --git a/civihr_employee_portal/views/views_export/views_civihr_report_leave_and_absence.inc b/civihr_employee_portal/views/views_export/views_civihr_report_leave_and_absence.inc index 6f88953a..c4dd010f 100644 --- a/civihr_employee_portal/views/views_export/views_civihr_report_leave_and_absence.inc +++ b/civihr_employee_portal/views/views_export/views_civihr_report_leave_and_absence.inc @@ -497,10 +497,10 @@ $handler->display->display_options['filters']['period_end_date']['field'] = 'per $handler->display->display_options['filters']['period_end_date']['relationship'] = 'details_revision_id'; $handler->display->display_options['filters']['period_end_date']['operator'] = 'empty'; $handler->display->display_options['filters']['period_end_date']['group'] = 3; -/* Filter criterion: Date: Date (absence_activity) */ +/* Filter criterion: Absence Activity entity: Absence date */ $handler->display->display_options['filters']['date_filter']['id'] = 'date_filter'; $handler->display->display_options['filters']['date_filter']['table'] = 'absence_activity'; -$handler->display->display_options['filters']['date_filter']['field'] = 'date_filter'; +$handler->display->display_options['filters']['date_filter']['field'] = 'absence_date'; $handler->display->display_options['filters']['date_filter']['relationship'] = 'absence_activity'; $handler->display->display_options['filters']['date_filter']['operator'] = 'between'; $handler->display->display_options['filters']['date_filter']['exposed'] = TRUE; @@ -516,13 +516,6 @@ $handler->display->display_options['filters']['date_filter']['expose']['remember 17087012 => 0, 57573969 => 0, ); -$handler->display->display_options['filters']['date_filter']['form_type'] = 'date_popup'; -$handler->display->display_options['filters']['date_filter']['default_date'] = 'now -10 year'; -$handler->display->display_options['filters']['date_filter']['default_to_date'] = 'now +10 year'; -$handler->display->display_options['filters']['date_filter']['year_range'] = '-10:+10'; -$handler->display->display_options['filters']['date_filter']['date_fields'] = array( - 'absence_activity.absence_date' => 'absence_activity.absence_date', -); /* Filter criterion: Absence Activity entity: Absence activity entity ID */ $handler->display->display_options['filters']['absence_activity_id']['id'] = 'absence_activity_id'; $handler->display->display_options['filters']['absence_activity_id']['table'] = 'absence_activity'; From 5296b502d38f24db4b1bd8c21b4cfc46f5cefb7d Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Thu, 31 May 2018 14:55:31 +0100 Subject: [PATCH 05/11] FAR-265: Set default result set filter to last 30 days and fetch results for same. --- civihr_employee_portal/js/reports.js | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/civihr_employee_portal/js/reports.js b/civihr_employee_portal/js/reports.js index 467d0ab0..f957d199 100644 --- a/civihr_employee_portal/js/reports.js +++ b/civihr_employee_portal/js/reports.js @@ -406,6 +406,25 @@ this.applyFilters(); }; + /** + * Gets the default query parameters for fetching results for the + * Leave and absence report. It basically defaults to parameters + * for fetching results for the last 30 days starting from current + * date. + * + * @returns {String} + */ + HRReport.prototype.getDefaultFilterQueryForLeaveReport = function () { + var toDate = moment().format("YYYY-MM-DD"); + var fromDate = moment().subtract(1, 'months').format("YYYY-MM-DD"); + var defaultFilterValues = [ + { name: "absence_date_filter[min]", value: fromDate }, + { name: "absence_date_filter[max]", value: toDate } + ]; + + return '?' + $.param(defaultFilterValues); + } + /** * Refresh JSON data and Pivot Tables using provided filter values * @@ -416,6 +435,12 @@ if (!this.jsonUrl) { return; } + + //On load of page the form values are not appended to query string. + if(filterValues === '?' && that.reportName === 'leave_and_absence') { + filterValues = that.getDefaultFilterQueryForLeaveReport() + } + $.ajax({ url: this.jsonUrl + filterValues, error: function () { @@ -454,6 +479,12 @@ if (!this.tableUrl) { return; } + + //On load of page the form values are not appended to query string. + if(filterValues === '?' && that.reportName === 'leave_and_absence') { + filterValues = that.getDefaultFilterQueryForLeaveReport() + } + var tableDomId = this.getReportTableDomID(); $.ajax({ url: that.tableUrl + filterValues, @@ -851,7 +882,9 @@ } if (REPORT_NAME === 'leave_and_absence') { - initCurrentAbsencePeriodFilterDates().then(resolve, reject); + formFiltersStore.values.fromDate = moment().subtract(1, 'months').toDate(); + formFiltersStore.values.toDate = moment().toDate(); + resolve(); } else { formFiltersStore.values.date = new Date(); resolve(); From 272b5c7640e2a573add916097d2b2be029809bcf Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Thu, 31 May 2018 14:59:13 +0100 Subject: [PATCH 06/11] FAR-265: Add handler for the absence_date field for the between operation filter since the operator uses timestamp for comparison by default. --- .../civihr_employee_portal.info | 1 + .../views/civihr_employee_portal.views.inc | 2 +- ...between_operation_dates_filter_handler.inc | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 civihr_employee_portal/views/includes/views_between_operation_dates_filter_handler.inc diff --git a/civihr_employee_portal/civihr_employee_portal.info b/civihr_employee_portal/civihr_employee_portal.info index 81c21eef..e03cc0a1 100644 --- a/civihr_employee_portal/civihr_employee_portal.info +++ b/civihr_employee_portal/civihr_employee_portal.info @@ -61,6 +61,7 @@ files[] = views/includes/civihr_employee_portal_handler_appraisal_due_date.inc files[] = views/includes/civihr_employee_portal_handler_tasks_date.inc files[] = views/includes/civihr_employee_portal_handler_documents_date.inc files[] = views/includes/views_between_dates_filter_handler.inc +files[] = views/includes/views_between_operation_dates_filter_handler.inc ; Reports Views handlers diff --git a/civihr_employee_portal/views/civihr_employee_portal.views.inc b/civihr_employee_portal/views/civihr_employee_portal.views.inc index f2fa4f55..fe28a1bc 100755 --- a/civihr_employee_portal/views/civihr_employee_portal.views.inc +++ b/civihr_employee_portal/views/civihr_employee_portal.views.inc @@ -209,7 +209,7 @@ function civihr_employee_portal_views_data_alter(&$data) { 'handler' => 'views_handler_sort_date', ), 'filter' => array( - 'handler' => 'views_handler_filter_date', + 'handler' => 'views_between_operation_dates_filter_handler', ), ); diff --git a/civihr_employee_portal/views/includes/views_between_operation_dates_filter_handler.inc b/civihr_employee_portal/views/includes/views_between_operation_dates_filter_handler.inc new file mode 100644 index 00000000..36067649 --- /dev/null +++ b/civihr_employee_portal/views/includes/views_between_operation_dates_filter_handler.inc @@ -0,0 +1,24 @@ +view); + $a = intval(strtotime($this->value['min'], $query_substitutions['***CURRENT_TIME***'])); + $b = intval(strtotime($this->value['max'], $query_substitutions['***CURRENT_TIME***'])); + + $a = date('Y-m-d', $a); + $b = date('Y-m-d', $b); + + // This is safe because we are manually scrubbing the values. + // It is necessary to do it this way because $a and $b are formulas when using an offset. + $operator = strtoupper($this->operator); + $this->query->add_where_expression($this->options['group'], "$field $operator '$a' AND '$b'"); + } +} From 301b5b6778ff6f894ab6c7ada99dad095b5064c8 Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Thu, 31 May 2018 15:50:13 +0100 Subject: [PATCH 07/11] FAR-265: Added process filter value function. Remove unused function. --- civihr_employee_portal/js/reports.js | 47 ++++++++++++---------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/civihr_employee_portal/js/reports.js b/civihr_employee_portal/js/reports.js index f957d199..8ff74d47 100644 --- a/civihr_employee_portal/js/reports.js +++ b/civihr_employee_portal/js/reports.js @@ -425,6 +425,24 @@ return '?' + $.param(defaultFilterValues); } + + /** + * Processes the filter values and replaces with default values + * for the leave reports when the filter values does not have a + * query parameter appended. + * + * @returns string {String} + */ + HRReport.prototype.processFilterValues = function (filterValues) { + var that = this; + //On load of page the form values are not appended to query string. + if (filterValues === '?' && that.reportName === 'leave_and_absence') { + return that.getDefaultFilterQueryForLeaveReport() + } + + return filterValues; + } + /** * Refresh JSON data and Pivot Tables using provided filter values * @@ -436,10 +454,7 @@ return; } - //On load of page the form values are not appended to query string. - if(filterValues === '?' && that.reportName === 'leave_and_absence') { - filterValues = that.getDefaultFilterQueryForLeaveReport() - } + filterValues = that.processFilterValues(filterValues); $.ajax({ url: this.jsonUrl + filterValues, @@ -480,10 +495,7 @@ return; } - //On load of page the form values are not appended to query string. - if(filterValues === '?' && that.reportName === 'leave_and_absence') { - filterValues = that.getDefaultFilterQueryForLeaveReport() - } + filterValues = that.processFilterValues(filterValues); var tableDomId = this.getReportTableDomID(); $.ajax({ @@ -849,25 +861,6 @@ }); })(); - /** - * Loads and sets the dates in the date filters using the start and - * end dates for the current absence period. - * - * @return {Promise} - Resolves to an empty promise after the current - * period dates have been initialized. - */ - function initCurrentAbsencePeriodFilterDates () { - return AbsencePeriod.getCurrent() - .then(function (currentPeriod) { - if (!currentPeriod) { - return; - } - - formFiltersStore.values.fromDate = moment(currentPeriod.start_date).toDate(); - formFiltersStore.values.toDate = moment(currentPeriod.end_date).toDate(); - }); - } - /** * If form filters have not been initialized, they'll get their default * values depending on the current report. From 44c68d34749bb872176fa50199389fe1fbfb27bd Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Thu, 31 May 2018 16:28:30 +0100 Subject: [PATCH 08/11] FAR-265: Default Date filter and result query to current year. --- civihr_employee_portal/js/reports.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/civihr_employee_portal/js/reports.js b/civihr_employee_portal/js/reports.js index 8ff74d47..8d515e82 100644 --- a/civihr_employee_portal/js/reports.js +++ b/civihr_employee_portal/js/reports.js @@ -415,11 +415,11 @@ * @returns {String} */ HRReport.prototype.getDefaultFilterQueryForLeaveReport = function () { - var toDate = moment().format("YYYY-MM-DD"); - var fromDate = moment().subtract(1, 'months').format("YYYY-MM-DD"); + var toDate = moment().dayOfYear(1).add(1, 'year').subtract(1, 'day').format('YYYY-MM-DD'); + var fromDate = moment().dayOfYear(1).format('YYYY-MM-DD'); var defaultFilterValues = [ - { name: "absence_date_filter[min]", value: fromDate }, - { name: "absence_date_filter[max]", value: toDate } + { name: 'absence_date_filter[min]', value: fromDate }, + { name: 'absence_date_filter[max]', value: toDate } ]; return '?' + $.param(defaultFilterValues); @@ -875,8 +875,8 @@ } if (REPORT_NAME === 'leave_and_absence') { - formFiltersStore.values.fromDate = moment().subtract(1, 'months').toDate(); - formFiltersStore.values.toDate = moment().toDate(); + formFiltersStore.values.fromDate = moment().dayOfYear(1).toDate(); + formFiltersStore.values.toDate = moment().dayOfYear(1).add(1, 'year').subtract(1, 'day').toDate(); resolve(); } else { formFiltersStore.values.date = new Date(); From a4221de4b9174591ae7b9753f92d588517692ff6 Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Thu, 31 May 2018 17:01:22 +0100 Subject: [PATCH 09/11] FAR-265: FE PR fixes --- civihr_employee_portal/js/reports.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/civihr_employee_portal/js/reports.js b/civihr_employee_portal/js/reports.js index 8d515e82..8c7bf767 100644 --- a/civihr_employee_portal/js/reports.js +++ b/civihr_employee_portal/js/reports.js @@ -412,11 +412,11 @@ * for fetching results for the last 30 days starting from current * date. * - * @returns {String} + * @return {String} */ HRReport.prototype.getDefaultFilterQueryForLeaveReport = function () { - var toDate = moment().dayOfYear(1).add(1, 'year').subtract(1, 'day').format('YYYY-MM-DD'); var fromDate = moment().dayOfYear(1).format('YYYY-MM-DD'); + var toDate = moment().dayOfYear(1).add(1, 'year').subtract(1, 'day').format('YYYY-MM-DD'); var defaultFilterValues = [ { name: 'absence_date_filter[min]', value: fromDate }, { name: 'absence_date_filter[max]', value: toDate } @@ -430,14 +430,15 @@ * Processes the filter values and replaces with default values * for the leave reports when the filter values does not have a * query parameter appended. + * On load of page the form values are not appended to query string + * hence filterValues has a value of '?' * - * @returns string {String} + * @param {String} filterValues + * @return {String} */ HRReport.prototype.processFilterValues = function (filterValues) { - var that = this; - //On load of page the form values are not appended to query string. - if (filterValues === '?' && that.reportName === 'leave_and_absence') { - return that.getDefaultFilterQueryForLeaveReport() + if (filterValues === '?' && this.reportName === 'leave_and_absence') { + return this.getDefaultFilterQueryForLeaveReport() } return filterValues; From 0b98aa5a0cd9984a4b9285e29ff4b0b0fe0d8523 Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Fri, 1 Jun 2018 10:42:11 +0100 Subject: [PATCH 10/11] FAR-265: Set default date parameter to People report API request. --- civihr_employee_portal/js/reports.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/civihr_employee_portal/js/reports.js b/civihr_employee_portal/js/reports.js index 8c7bf767..b54f7d02 100644 --- a/civihr_employee_portal/js/reports.js +++ b/civihr_employee_portal/js/reports.js @@ -409,8 +409,7 @@ /** * Gets the default query parameters for fetching results for the * Leave and absence report. It basically defaults to parameters - * for fetching results for the last 30 days starting from current - * date. + * for fetching results for the current year * * @return {String} */ @@ -425,11 +424,26 @@ return '?' + $.param(defaultFilterValues); } + /** + * Gets the default query parameters for fetching results for the + * People report. It basically defaults the date parameter to the + * current date. + * + * @return {String} + */ + HRReport.prototype.getDefaultFilterQueryForPeopleReport = function () { + var currentDate = moment().format('YYYY-MM-DD'); + var defaultFilterValues = [ + { name: 'between_date_filter[value]', value: currentDate } + ]; + + return '?' + $.param(defaultFilterValues); + } /** * Processes the filter values and replaces with default values - * for the leave reports when the filter values does not have a - * query parameter appended. + * for the people and leave reports when the filter values does + * not have a query parameter appended. * On load of page the form values are not appended to query string * hence filterValues has a value of '?' * @@ -441,6 +455,10 @@ return this.getDefaultFilterQueryForLeaveReport() } + if (filterValues === '?' && this.reportName === 'people') { + return this.getDefaultFilterQueryForPeopleReport() + } + return filterValues; } From cc70963525e502a4e0c4db2e055e0d91fedc183a Mon Sep 17 00:00:00 2001 From: Tunbola Ogunwande Date: Fri, 1 Jun 2018 11:08:11 +0100 Subject: [PATCH 11/11] FAR-265: Use human readable variable names in handler. Remove unnecessary comment. --- .../views_between_operation_dates_filter_handler.inc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/civihr_employee_portal/views/includes/views_between_operation_dates_filter_handler.inc b/civihr_employee_portal/views/includes/views_between_operation_dates_filter_handler.inc index 36067649..dfb8ad4a 100644 --- a/civihr_employee_portal/views/includes/views_between_operation_dates_filter_handler.inc +++ b/civihr_employee_portal/views/includes/views_between_operation_dates_filter_handler.inc @@ -10,15 +10,13 @@ class views_between_operation_dates_filter_handler extends views_handler_filter_ function op_between($field) { // Use the substitutions to ensure a consistent timestamp. $query_substitutions = views_views_query_substitutions($this->view); - $a = intval(strtotime($this->value['min'], $query_substitutions['***CURRENT_TIME***'])); - $b = intval(strtotime($this->value['max'], $query_substitutions['***CURRENT_TIME***'])); + $from = intval(strtotime($this->value['min'], $query_substitutions['***CURRENT_TIME***'])); + $to = intval(strtotime($this->value['max'], $query_substitutions['***CURRENT_TIME***'])); - $a = date('Y-m-d', $a); - $b = date('Y-m-d', $b); + $from = date('Y-m-d', $from); + $to = date('Y-m-d', $to); - // This is safe because we are manually scrubbing the values. - // It is necessary to do it this way because $a and $b are formulas when using an offset. $operator = strtoupper($this->operator); - $this->query->add_where_expression($this->options['group'], "$field $operator '$a' AND '$b'"); + $this->query->add_where_expression($this->options['group'], "$field $operator '$from' AND '$to'"); } }