Skip to content

Commit

Permalink
#118 [Dashboard] add: Select user on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jan 31, 2023
1 parent 80f432b commit 5a77351
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
6 changes: 2 additions & 4 deletions class/dashboarddolisirhstats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function show_dashboard($load_timespent = 1)
print '<div class="opened-dash-board-wrap"><div class="box-flex-container">' . $openedDashBoard . '</div></div>';
}

print '<div class="box-flex-container">';
print '<div class="box-flex-container graph-dashboard">';

if (is_array($dashboard_data['graphs']) && !empty($dashboard_data['graphs'])) {
foreach ($dashboard_data['graphs'] as $keyelement => $datagraph) {
Expand Down Expand Up @@ -189,9 +189,7 @@ public function show_dashboard($load_timespent = 1)
$graph->setShowLegend(2);
$graph->draw($filename[$keyelement], $fileurl[$keyelement]);
print '<div class="box-flex-item">';
print '<div class="titre inline-block">';
print $datagraph['picto'] . ' ' . $datagraph['title'];
print '</div>';
print load_fiche_titre($datagraph['title'], $datagraph['morehtmlright'], $datagraph['picto']);
print $graph->show();
print '</div>';
}
Expand Down
24 changes: 16 additions & 8 deletions class/dolisirhstats.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ public function getTimeSpendingInfos()

global $db, $langs, $user;

$userID = GETPOSTISSET('search_userid') ? GETPOST('search_userid', 'int') : $user->id;

$firstdaytoshow = dol_get_first_day(date('Y'), date('m'));
$lastdayofmonth = strtotime(date('Y-m-t', $firstdaytoshow));

Expand All @@ -643,7 +645,7 @@ public function getTimeSpendingInfos()
$isavailable = [];
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $user->id)) {
if (isDayAvailable($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning'=>1, 'afternoon'=>1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning'=>false, 'afternoon'=>false, 'morning_reason'=>'week_end', 'afternoon_reason'=>'week_end'];
Expand All @@ -653,9 +655,9 @@ public function getTimeSpendingInfos()
}

$workinghours = new Workinghours($db);
$workingHours = $workinghours->fetchCurrentWorkingHours($user->id, 'user');
$workingHours = $workinghours->fetchCurrentWorkingHours($userID, 'user');

$timeSpendingInfos = loadTimeSpendingInfosWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $workingHours, $isavailable, $user->id);
$timeSpendingInfos = loadTimeSpendingInfosWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $workingHours, $isavailable, $userID);

// Planned working time
$planned_working_time = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
Expand Down Expand Up @@ -694,11 +696,17 @@ public function getTimeSpentReport()

$startmonth = $conf->global->SOCIETE_FISCAL_MONTH_START;

$array['title'] = $langs->transnoentities('TimeSpentReportByFiscalYear');
$array['picto'] = '<i class="fas fa-clock"></i>';
$userID = GETPOSTISSET('search_userid') ? GETPOST('search_userid', 'int') : $user->id;

// Graph Title parameters
$array['title'] = $langs->transnoentities('TimeSpentReportByFiscalYear');
$array['picto'] = 'clock';

// Graph parameters
$array['width'] = 800;
$array['height'] = 400;
$array['type'] = 'bars';

$array['labels'] = [
0 => [
'label' => $langs->transnoentities('ExpectedWorkedHours'),
Expand All @@ -711,7 +719,7 @@ public function getTimeSpentReport()
];

$workinghours = new Workinghours($db);
$workingHours = $workinghours->fetchCurrentWorkingHours($user->id, 'user');
$workingHours = $workinghours->fetchCurrentWorkingHours($userID, 'user');

for ($i = 1; $i < 13; $i++) {
$firstdaytoshow = dol_get_first_day(date('Y'), $i);
Expand All @@ -729,7 +737,7 @@ public function getTimeSpentReport()
$isavailable = [];
for ($idw = 0; $idw < $daysInMonth; $idw++) {
$dayInLoop = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
if (isDayAvailable($dayInLoop, $user->id)) {
if (isDayAvailable($dayInLoop, $userID)) {
$isavailable[$dayInLoop] = ['morning'=>1, 'afternoon'=>1];
} else if (date('N', $dayInLoop) >= 6) {
$isavailable[$dayInLoop] = ['morning'=>false, 'afternoon'=>false, 'morning_reason'=>'week_end', 'afternoon_reason'=>'week_end'];
Expand All @@ -739,7 +747,7 @@ public function getTimeSpentReport()
}

$planned_working_time = loadPlannedTimeWithinRange($firstdaytoshow, dol_time_plus_duree($lastdayofmonth, 1, 'd'), $workingHours, $isavailable);
$worked_time = loadTimeSpentWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $isavailable, $user->id);
$worked_time = loadTimeSpentWithinRange($firstdaytoshow, dol_time_plus_duree($lastdaytoshow, 1, 'd'), $isavailable, $userID);

$planned_working_time_data = (($planned_working_time['minutes'] != 0) ? convertSecondToTime($planned_working_time['minutes'] * 60, 'fullhour') : 0);
$worked_time_data = convertSecondToTime($worked_time['total'], 'fullhour');
Expand Down
8 changes: 7 additions & 1 deletion dolisirhindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
$modDoliSIRH = new modDoliSIRH($db);
$stats = new DashboardDolisirhStats($db);

// Initialize view objects
$form = new Form($db);

// Get parameters
$action = GETPOST('action', 'alpha');
$userID = GETPOSTISSET('search_userid') ? GETPOST('search_userid', 'int') : $user->id;

// Security check
$permissiontoread = $user->rights->dolisirh->read;
Expand All @@ -64,7 +68,9 @@

llxHeader('', $title . ' ' . $modDoliSIRH->version, $help_url, '', 0, 0, $morejs, $morecss);

print load_fiche_titre($title . ' ' . $modDoliSIRH->version, '', 'dolisirh_red.png@dolisirh');
$morehtmlright = img_picto($langs->trans('Filter') . ' ' . $langs->trans('User'), 'user', 'class="paddingright pictofixedwidth"') . $form->select_dolusers($userID, 'search_userid', '', null, 0, '', null, 0, 0, 0, ' AND u.employee = 1', 0, '', 'maxwidth300 select-user-dashboard', 1);

print load_fiche_titre($title . ' ' . $modDoliSIRH->version, $morehtmlright, 'dolisirh_red.png@dolisirh');

if ($conf->global->DOLISIRH_HR_PROJECT_SET == 0) : ?>
<div class="wpeo-notice notice-info">
Expand Down
28 changes: 28 additions & 0 deletions js/dolisirh.js
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,7 @@ window.eoxiaJS.dashboard.init = function() {
window.eoxiaJS.dashboard.event = function() {
$( document ).on( 'change', '.add-dashboard-widget', window.eoxiaJS.dashboard.addDashBoardInfo );
$( document ).on( 'click', '.close-dashboard-widget', window.eoxiaJS.dashboard.closeDashBoardInfo );
$( document ).on( 'change', '.select-user-dashboard', window.eoxiaJS.dashboard.selectUserDashboard );
};

/**
Expand Down Expand Up @@ -1316,3 +1317,30 @@ window.eoxiaJS.dashboard.closeDashBoardInfo = function() {
}
});
};

/**
* Select user for dashboard info.
*
* @since 1.2.1
* @version 1.2.1
*
* @return {void}
*/
window.eoxiaJS.dashboard.selectUserDashboard = function() {
let userID = this.value;

let querySeparator = '?';
let token = $('.dashboard').find('input[name="token"]').val();
document.URL.match(/\?/) ? querySeparator = '&' : 1

$.ajax({
url: document.URL + querySeparator + 'action=selectuserdashboar&token=' + token + '&search_userid=' + userID,
type: "POST",
processData: false,
contentType: false,
success: function(resp) {
$('.fichecenter').replaceWith($(resp).find('.fichecenter'));
},
error: function() {}
});
};

0 comments on commit 5a77351

Please sign in to comment.