Skip to content

Commit

Permalink
Merge pull request #475 from compucorp/staging
Browse files Browse the repository at this point in the history
Sync master with staging
  • Loading branch information
davialexandre authored Jun 5, 2018
2 parents 7e7e202 + 6336674 commit ca78566
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 84 deletions.
1 change: 1 addition & 0 deletions civihr_employee_portal/civihr_employee_portal.info
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
50 changes: 50 additions & 0 deletions civihr_employee_portal/civihr_employee_portal.module
Original file line number Diff line number Diff line change
Expand Up @@ -6553,3 +6553,53 @@ 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.
* @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
* Custom markup from template file.
*/
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
if (!strpos(drupal_get_js('footer'), 'reqangular.min.js')) {
civicrm_resources_load('org.civicrm.reqangular', ['reqangular.min.js']);
}

civicrm_resources_load($scriptExtensionKey, [$script]);

return civihr_employee_portal_load_html_file(str_replace('-', '_', $resource), $markupModuleName);
}

/**
* Internal function to load predefined template file.
*
* @param string
* File name to load the content.
* @param string
* Module Name
*
* @return string
* File Content.
*/
function civihr_employee_portal_load_html_file($template = '', $moduleName) {

// Fetching custom markup from pre-defined template file.
$file_path = drupal_get_path('module', $moduleName) . '/templates/' . $template . '.html';

if (file_exists($file_path)) {
return @file_get_contents($file_path);
}
else {
return '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand Down
85 changes: 65 additions & 20 deletions civihr_employee_portal/js/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,62 @@
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 current year
*
* @return {String}
*/
HRReport.prototype.getDefaultFilterQueryForLeaveReport = function () {
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 }
];

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 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 '?'
*
* @param {String} filterValues
* @return {String}
*/
HRReport.prototype.processFilterValues = function (filterValues) {
if (filterValues === '?' && this.reportName === 'leave_and_absence') {
return this.getDefaultFilterQueryForLeaveReport()
}

if (filterValues === '?' && this.reportName === 'people') {
return this.getDefaultFilterQueryForPeopleReport()
}

return filterValues;
}

/**
* Refresh JSON data and Pivot Tables using provided filter values
*
Expand All @@ -416,6 +472,9 @@
if (!this.jsonUrl) {
return;
}

filterValues = that.processFilterValues(filterValues);

$.ajax({
url: this.jsonUrl + filterValues,
error: function () {
Expand Down Expand Up @@ -454,6 +513,9 @@
if (!this.tableUrl) {
return;
}

filterValues = that.processFilterValues(filterValues);

var tableDomId = this.getReportTableDomID();
$.ajax({
url: that.tableUrl + filterValues,
Expand Down Expand Up @@ -818,25 +880,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.
Expand All @@ -851,7 +894,9 @@
}

if (REPORT_NAME === 'leave_and_absence') {
initCurrentAbsencePeriodFilterDates().then(resolve, reject);
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();
resolve();
Expand Down
2 changes: 2 additions & 0 deletions civihr_employee_portal/js/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<span data-tasks-notification-badge>
<tasks-notification-badge></tasks-notification-badge>
</span>
<script>
CRM.tasksAssignments = {
extensionPath: Drupal.settings.tasksAssignments.extensionPath
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* @file
* A filter that allows the between operator to compare dates in 'Y-m-d' format
* rather than the default timestamp comparison since absence dates are stored
* in 'Y-m-d' format in the db.
*/

class views_between_operation_dates_filter_handler extends views_handler_filter_date {
function op_between($field) {
// Use the substitutions to ensure a consistent timestamp.
$query_substitutions = views_views_query_substitutions($this->view);
$from = intval(strtotime($this->value['min'], $query_substitutions['***CURRENT_TIME***']));
$to = intval(strtotime($this->value['max'], $query_substitutions['***CURRENT_TIME***']));

$from = date('Y-m-d', $from);
$to = date('Y-m-d', $to);

$operator = strtoupper($this->operator);
$this->query->add_where_expression($this->options['group'], "$field $operator '$from' AND '$to'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand Down

0 comments on commit ca78566

Please sign in to comment.