Skip to content

Commit

Permalink
Merge pull request #322 from compucorp/staging
Browse files Browse the repository at this point in the history
Sync master with staging
  • Loading branch information
davialexandre authored Jul 7, 2017
2 parents f27389a + e75c949 commit 513f1e7
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 49 deletions.
68 changes: 40 additions & 28 deletions civihr_employee_portal/civihr_employee_portal.module
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,13 @@ function _get_activity_type_ids_by_component($component) {
function _get_tasks_documents_sql_query(array $activityTypes) {
$civi_settings = parse_url(CIVICRM_DSN);
$civi_db_name = trim($civi_settings['path'], '/');
return "SELECT a.id, a.activity_type_id, a.subject, a.activity_date_time, acustom.expire_date, a.details, a.status_id, a.is_deleted, ca.case_id, COUNT(ef.id) AS file_count, acs.contact_id AS source_contact_id, contact_source.sort_name AS source_contact_name, act.contact_id AS target_contact_id, contact_target.sort_name AS target_contact_name, aca.contact_id AS assignee_contact_id, contact_assignee.sort_name AS assignee_contact_name

return "SELECT a.id, a.activity_type_id, a.subject, a.activity_date_time,
acustom.expire_date, a.details, a.status_id, a.is_deleted, ca.case_id,
COUNT(ef.id) AS file_count, acs.contact_id AS source_contact_id,
contact_source.sort_name AS source_contact_name, act.contact_id AS target_contact_id,
contact_target.sort_name AS target_contact_name, aca.contact_id AS assignee_contact_id,
contact_assignee.sort_name AS assignee_contact_name
FROM {$civi_db_name}.civicrm_activity a
LEFT JOIN {$civi_db_name}.civicrm_value_activity_custom_fields_11 acustom ON acustom.entity_id = a.id
LEFT JOIN {$civi_db_name}.civicrm_case_activity ca ON ca.activity_id = a.id
Expand All @@ -299,7 +305,7 @@ function _get_tasks_documents_sql_query(array $activityTypes) {
LEFT JOIN {$civi_db_name}.civicrm_activity_contact aca ON aca.activity_id = a.id AND aca.record_type_id = 1
LEFT JOIN {$civi_db_name}.civicrm_contact contact_assignee ON contact_assignee.id = aca.contact_id
WHERE a.is_deleted = 0 AND a.is_current_revision = 1 AND a.activity_type_id IN (" . implode(',', $activityTypes) . ")
GROUP BY a.id";
GROUP BY a.id, aca.contact_id";
}

/**
Expand Down Expand Up @@ -1094,41 +1100,47 @@ function get_task_statuses($status_id = NULL) {
*/
function get_activity_type_value($type_id = NULL) {

$activityTypes = &drupal_static(__FUNCTION__);
$activityTypes = &drupal_static(__FUNCTION__);

if (!isset($activityTypes)) {
if (!isset($activityTypes)) {

if ($cache = cache_get('civihr_activity_types')) {
$activityTypes = $cache->data;
}
else {
try {
// Civi init
civicrm_initialize();
if ($cache = cache_get('civihr_activity_types')) {
$activityTypes = $cache->data;
}
else {
try {
// Civi init
civicrm_initialize();

// Task types array
$activityTypes = civicrm_api3('Activity', 'getoptions', array(
'field' => "activity_type_id",
));
}
// Task types array
$activityTypes = civicrm_api3('Activity', 'getoptions', [
'field' => "activity_type_id",
]);

catch (CiviCRM_API3_Exception $e) {
$error = $e->getMessage();
}
// Document types array
$documentTypes = civicrm_api3('Document', 'getoptions', [
'field' => "activity_type_id",
]);

// Cache the task types for 5 minutes
cache_set('civihr_activity_types', $activityTypes, 'cache', time() + 360);
}
}
$activityTypes['values'] += $documentTypes['values'];
$activityTypes['count'] = count($activityTypes['values']);
} catch (CiviCRM_API3_Exception $e) {
$error = $e->getMessage();
}

if ($type_id === null) {
return $activityTypes['values'];
// Cache the task types for 5 minutes
cache_set('civihr_activity_types', $activityTypes, 'cache', time() + 360);
}
}

// Get the type values based on the type_id
$type_id_value = CRM_Utils_Array::value($type_id, $activityTypes['values']);
if ($type_id === NULL) {
return $activityTypes['values'];
}

// Get the type values based on the type_id
$type_id_value = CRM_Utils_Array::value($type_id, $activityTypes['values']);

return $type_id_value;
return $type_id_value;
}

function get_appraisal_cycle_type($type_id = NULL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ function civihr_default_permissions_user_default_permissions() {
'roles' => array(
'administrator' => 'administrator',
'civihr_admin_local' => 'civihr_admin_local',
'civihr_manager' => 'civihr_manager',
),
'module' => 'civihr_employee_portal',
);
Expand Down
50 changes: 40 additions & 10 deletions civihr_employee_portal/js/ta-documents-app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/* globals angular */

(function(angular) {
angular.module('taDocuments', ['civitasks.appDocuments'])
angular.module('taDocuments', ['civitasks.appDocuments', 'civitasks.directives'])
.config(function ($urlRouterProvider, $locationProvider) {
$locationProvider.html5Mode(true); // This is required to remove # for the URL
$urlRouterProvider.otherwise('/dashboard');
})
.controller('ModalController', ['$scope', '$rootScope', '$window', '$rootElement', '$log', '$uibModal',
'DocumentService', 'FileService', 'config', 'settings',
function($scope, $rootScope, $window, $rootElement, $log, $modal, DocumentService, FileService, config, settings) {
'DocumentService', 'FileService', 'config', 'settings', 'DateFormat',
function($scope, $rootScope, $window, $rootElement, $log, $modal, DocumentService, FileService, config,
settings, DateFormat) {
var vm = {};
var availableContacts = false;

vm.loadingModalData = false;

/**
* Gets Document for the given document id and
Expand All @@ -15,6 +23,9 @@
* @param {string} role
*/
vm.modalDocument = function (id, role) {
$rootScope.$broadcast('ct-spinner-show', 'document-' + id);
vm.loadingModalData = true;

DocumentService.get({ id: id })
.then(function(data) {
if (!data) {
Expand All @@ -35,12 +46,9 @@
});

// Get list of documents
DocumentService.get({
'status_id': {
'NOT IN': config.status.resolve.DOCUMENT
}
}).then(function (documents) {
// Getting and caching only the contacts
DocumentService.get().then(function (documents) {
//sets the date format for HR_settings.DATE_FORMAT
DateFormat.getDateFormat();
DocumentService.cacheContactsAndAssignments(documents, 'contacts');
});
})();
Expand All @@ -53,10 +61,13 @@
*/
function openModalDocument(data, role) {
var modalInstance = $modal.open({
appendTo: $rootElement.find('div').eq(0),
appendTo: $rootElement,
templateUrl: config.path.TPL + 'modal/document.html?v=3',
controller: 'ModalDocumentCtrl',
resolve: {
modalMode: function () {
return '';
},
role: function () {
return role;
},
Expand All @@ -72,8 +83,27 @@
}
}
});

modalInstance.opened.then(function () {
$rootScope.$broadcast('ct-spinner-hide');
vm.loadingModalData = false;
});
};

/**
* Watch for the changes in the list of $rootScope.cache.contact.arrSearch
* Display spinner and hide "open" button until the arrSearch is filled with contacts
*
* Note: $rootScope.cache.contact.arrSearch will always contain a
* contact data (curently logged in contact). So if there are documents,
* there must be more that one contacts conidering at aleast a target contact in a document
*/
$rootScope.$watch('cache.contact', function () {
availableContacts = $rootScope.cache.contact.arrSearch.length > 1;
$rootScope.$broadcast('ct-spinner-' + (availableContacts ? 'hide' : 'show'));
vm.loadingModalData = !availableContacts;
});

return vm;
}
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* Custom views handler to display Task / Document date in specific format.
*/
class civihr_employee_portal_handler_documents_date extends views_handler_field {
function render($values) {
$value = $this->get_value($values);
return date('M d Y', strtotime(strip_tags($value)));
function render($values) {
$value = $this->get_value($values);
if($value) {
return date('M d Y', strtotime(strip_tags($value)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@
<?php foreach ($statuses as $statusKey => $statusValue): ?>
<?php
$selected = '';
if ($statusKey == (int) strip_tags($content)):
if (strtolower($statusValue) == strip_tags($content)):
$selected = ' selected="selected"';
endif;
?>
<option value="<?php print $statusKey; ?>"<?php print $selected; ?>><?php print $statusValue; ?></option>
<?php printf('<option value="%s" %s>%s</option>', $statusKey, $selected, ucwords($statusValue)); ?>
<?php endforeach; ?>
</select>
<?php continue; ?>
Expand All @@ -94,10 +94,11 @@
<?php print strip_tags(html_entity_decode($content)); ?>
</td>
<?php endforeach; ?>
<td>
<td ct-spinner ct-spinner-id="document-<?php print strip_tags($row['id']); ?>">
<button
ng-click="document.modalDocument(<?php print strip_tags($row['id']); ?>, 'manager')"
class="btn btn-sm btn-default">
ng-show='!document.loadingModalData'
ng-click="document.modalDocument(<?php print strip_tags($row['id']); ?>, 'manager')"
class="btn btn-sm btn-default">
<i class="fa fa-upload"></i> Open
</button>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
$statusesCount[0] ++;
endforeach;
?>
<base href="/"> <!-- This is required to remove # for the URL-->
<div data-ta-documents ng-controller="ModalController as document" class="chr_table-w-filters chr_table-w-filters--documents row">
<div class="chr_table-w-filters__filters col-md-3">
<div class="chr_table-w-filters__filters__dropdown-wrapper">
Expand Down Expand Up @@ -95,18 +96,21 @@
continue;
endif;
?>

<?php print $content; ?>
</td>
<?php endforeach; ?>
<td>
<td ct-spinner ct-spinner-id="document-<?php print strip_tags($row['id']); ?>">
<?php if (strip_tags($row['status_id']) == 3): ?>
<button
ng-show='!document.loadingModalData'
class="btn btn-sm btn-default ctools-use-modal ctools-modal-civihr-default-style ctools-use-modal-processed"
disabled="disabled">
<i class="fa fa-upload"></i> Open
</button>
<?php else: ?>
<button
ng-show='!document.loadingModalData'
ng-click="document.modalDocument(<?php print strip_tags($row['id']); ?> , 'staff')"
class="btn btn-sm btn-default">
<i class="fa fa-upload"></i> Open
Expand Down
55 changes: 55 additions & 0 deletions civihr_employee_portal/views/views_export/views_documents.inc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,61 @@ $handler->display->display_options['arguments']['target_contact_id']['default_ar
$handler->display->display_options['arguments']['target_contact_id']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['target_contact_id']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['target_contact_id']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['merge_rows'] = TRUE;
$handler->display->display_options['field_config'] = array(
'id' => array(
'merge_option' => 'filter',
'separator' => ', ',
),
'activity_type_id' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'case_id' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'subject' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'activity_date_time' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'expire_date' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'details' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'file_count' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'status_id' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'target_contact_id' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'assignee_contact_id' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'target_contact_name' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
'assignee_contact_name' => array(
'merge_option' => 'merge_unique',
'separator' => ', ',
),
);

/* Display: Documents Dashboard Manager block */
$handler = $view->new_display('block', 'Documents Dashboard Manager block', 'block_1');
Expand Down
Loading

0 comments on commit 513f1e7

Please sign in to comment.