Skip to content

Commit

Permalink
#23 [TimeSpent] add: change global conf timespent by user conf
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jan 31, 2023
1 parent 223a192 commit 385da00
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 44 deletions.
44 changes: 30 additions & 14 deletions js/dolisirh.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,55 +679,71 @@ window.eoxiaJS.task.divideTimeSpent = function( event ) {
* Active/désactive la configuration pour n'afficher que les tâches favorites
*
* @since 1.0.0
* @version 1.0.0
* @version 1.2.1
*
* @param {MouseEvent} event [description]
* @return {void}
*/
window.eoxiaJS.task.showOnlyFavoriteTasks = function( event ) {
window.eoxiaJS.task.showOnlyFavoriteTasks = function() {
let token = $('.id-container').find('input[name="token"]').val();
let querySeparator = '?';

document.URL.match(/\?/) ? querySeparator = '&' : 1

let showOnlyFavoriteTasks;
if ($(this).is(':checked')) {
showOnlyFavoriteTasks = 1;
} else {
showOnlyFavoriteTasks = 0;
}

$.ajax({
url: document.URL + querySeparator + "action=showOnlyFavoriteTasks&token=" + token,
type: "POST",
processData: false,
data: JSON.stringify({
showOnlyFavoriteTasks: showOnlyFavoriteTasks
}),
contentType: false,
success: function ( resp ) {
window.location.reload()
success: function() {
window.location.reload();
},
error: function ( ) {
}
error: function() {}
});
};

/**
* Active/désactive la configuration pour n'afficher que les tâches avec du temps pointé
*
* @since 1.1.0
* @version 1.1.0
* @version 1.2.1
*
* @param {MouseEvent} event [description]
* @return {void}
*/
window.eoxiaJS.task.showOnlyTasksWithTimeSpent = function( event ) {
window.eoxiaJS.task.showOnlyTasksWithTimeSpent = function() {
let token = $('.id-container').find('input[name="token"]').val();
let querySeparator = '?';

document.URL.match(/\?/) ? querySeparator = '&' : 1

let showOnlyTasksWithTimeSpent;
if ($(this).is(':checked')) {
showOnlyTasksWithTimeSpent = 1;
} else {
showOnlyTasksWithTimeSpent = 0;
}

$.ajax({
url: document.URL + querySeparator + "action=showOnlyTasksWithTimeSpent&token=" + token,
type: "POST",
processData: false,
data: JSON.stringify({
showOnlyTasksWithTimeSpent: showOnlyTasksWithTimeSpent
}),
contentType: false,
success: function ( resp ) {
window.location.reload()
success: function() {
window.location.reload();
},
error: function ( ) {
}
error: function() {}
});
};

Expand Down
32 changes: 18 additions & 14 deletions view/timespent_month.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,23 @@
}

if ($action == 'showOnlyFavoriteTasks') {
if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS == 1) {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_FAVORITE_TASKS', 0, 'integer', 0, '', $conf->entity);
} else {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_FAVORITE_TASKS', 1, 'integer', 0, '', $conf->entity);
}
$data = json_decode(file_get_contents('php://input'), true);

$showOnlyFavoriteTasks = $data['showOnlyFavoriteTasks'];

$tabparam['DOLISIRH_SHOW_ONLY_FAVORITE_TASKS'] = $showOnlyFavoriteTasks;

dol_set_user_param($db, $conf, $user, $tabparam);
}

if ($action == 'showOnlyTasksWithTimeSpent') {
if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT == 1) {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT', 0, 'integer', 0, '', $conf->entity);
} else {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT', 1, 'integer', 0, '', $conf->entity);
}
$data = json_decode(file_get_contents('php://input'), true);

$showOnlyTasksWithTimeSpent = $data['showOnlyTasksWithTimeSpent'];

$tabparam['DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT'] = $showOnlyTasksWithTimeSpent;

dol_set_user_param($db, $conf, $user, $tabparam);
}

if ($action == 'addTimeSpent' && $permissiontoadd) {
Expand All @@ -374,7 +378,7 @@
$object->timespent_fk_user = $user->id;

if ($object->timespent_duration > 0) {
$object->addTimeSpent($user, false);
$object->addTimeSpent($user);
}
}

Expand Down Expand Up @@ -508,15 +512,15 @@

print '<div class="clearboth" style="padding-bottom: 20px;"></div>';
print $langs->trans('ShowOnlyFavoriteTasks');
print '<input type="checkbox" class="show-only-favorite-tasks"'. ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS ? ' checked' : '').' >';
if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
print '<input type="checkbox" class="show-only-favorite-tasks"'. ($user->conf->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS ? ' checked' : '').' >';
if ($user->conf->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS > 0) {
print '<br>';
print '<div class="opacitymedium"><i class="fas fa-exclamation-triangle"></i>'.' '.$langs->trans('WarningShowOnlyFavoriteTasks').'</div>';
}

print '<div class="clearboth" style="padding-bottom: 20px;"></div>';
print $langs->trans('ShowOnlyTasksWithTimeSpent');
print '<input type="checkbox" class="show-only-tasks-with-timespent"'. ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT ? ' checked' : '').' >';
print '<input type="checkbox" class="show-only-tasks-with-timespent"'. ($user->conf->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT ? ' checked' : '').' >';

// Get if user is available or not for each day
$isavailable = array();
Expand Down
36 changes: 20 additions & 16 deletions view/timespent_week.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,23 @@
}

if ($action == 'showOnlyFavoriteTasks') {
if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS == 1) {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_FAVORITE_TASKS', 0, 'integer', 0, '', $conf->entity);
} else {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_FAVORITE_TASKS', 1, 'integer', 0, '', $conf->entity);
}
$data = json_decode(file_get_contents('php://input'), true);

$showOnlyFavoriteTasks = $data['showOnlyFavoriteTasks'];

$tabparam['DOLISIRH_SHOW_ONLY_FAVORITE_TASKS'] = $showOnlyFavoriteTasks;

dol_set_user_param($db, $conf, $user, $tabparam);
}

if ($action == 'showOnlyTasksWithTimeSpent') {
if ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT == 1) {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT', 0, 'integer', 0, '', $conf->entity);
} else {
dolibarr_set_const($db, 'DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT', 1, 'integer', 0, '', $conf->entity);
}
$data = json_decode(file_get_contents('php://input'), true);

$showOnlyTasksWithTimeSpent = $data['showOnlyTasksWithTimeSpent'];

$tabparam['DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT'] = $showOnlyTasksWithTimeSpent;

dol_set_user_param($db, $conf, $user, $tabparam);
}

if ($action == 'addTimeSpent' && $permissiontoadd) {
Expand All @@ -370,7 +374,7 @@
$object->timespent_fk_user = $user->id;

if ($object->timespent_duration > 0) {
$object->addTimeSpent($user, false);
$object->addTimeSpent($user);
}
}

Expand Down Expand Up @@ -499,15 +503,15 @@

print '<div class="clearboth" style="padding-bottom: 20px;"></div>';
print $langs->trans('ShowOnlyFavoriteTasks');
print '<input type="checkbox" class="show-only-favorite-tasks"'. ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS ? ' checked' : '').' >';
if ($conf->global->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS) {
print '<br>';
print '<div class="opacitymedium"><i class="fas fa-exclamation-triangle"></i>'.' '.$langs->trans('WarningShowOnlyFavoriteTasks').'</div>';
print '<input type="checkbox" class="show-only-favorite-tasks"'. ($user->conf->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS ? ' checked' : '').' >';
if ($user->conf->DOLISIRH_SHOW_ONLY_FAVORITE_TASKS > 0) {
print '<br>';
print '<div class="opacitymedium"><i class="fas fa-exclamation-triangle"></i>'.' '.$langs->trans('WarningShowOnlyFavoriteTasks').'</div>';
}

print '<div class="clearboth" style="padding-bottom: 20px;"></div>';
print $langs->trans('ShowOnlyTasksWithTimeSpent');
print '<input type="checkbox" class="show-only-tasks-with-timespent"'. ($conf->global->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT ? ' checked' : '').' >';
print '<input type="checkbox" class="show-only-tasks-with-timespent"'. ($user->conf->DOLISIRH_SHOW_ONLY_TASKS_WITH_TIMESPENT ? ' checked' : '').' >';

// Get if user is available or not for each day
$isavailable = array();
Expand Down

0 comments on commit 385da00

Please sign in to comment.