mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
This *absolute commit monster* does the following things: - Introduce gulp to build javascript and css files. This includes moving node_modules out of the public/ folder. Use `gulp --tasks` to get a list of all tasks; however some of them are automatically generated. Use `gulp live` to watch for changes and automatically recompile what's needed. - Upgrade to yarn2 - Upgrade FullCalendar to 4.4.2 I know that 5.x is the current version, but two major version upgrades are too much right now. Also v5 would break any custom css as they renamed a bunch of classes. - Move Styles to sass (Most) global styles are now included in one sass file. This also means that we now compile our own bootstrap. - Javascript is now in strict mode Because everything is a module now, `use strict` is now in effect for all javascript files. There are probably still some parts left where implicit variable declarations were used. - grocy*.js were split up in modules. `window.Grocy` is now an instance of GrocyClass. API-wise nothing has changed (albeit some functions were added regarding Undo actions) At the Moment, this leaks a whole bunch of functions into window (that was easier than tracking those down). - FindObjectIn... style functions were removed. Array.prototype.find and Array.prototype.filter suffice. - Use babel to preprocess javascript. - Use rollup to bundle javascript. rollup bundles and tree-shakes es6 javascript bundles. It also allows to "import" css files and generate css files specific to this javascript file. This is used in viewjs scripts, for example when importing FullCalendar, to generate an associated viewcss file. - Use postcss to post-process css files. postcss uses autoprefixer to handle browser compatiblity. Internally this uses the package `browserslist`; and is currently configured to the default setting. - Minify assets when building in production `gulp publish` builds all assets in production mode, that is, the assets get minified. This includes javascript as well as css files. - css bundling concatCss is used to pull @imports of non-sass-files into one grocy.css - animate.css is now in the main bundle animate.css was used in so many places that it is now located in the main style bundle.
234 lines
7.0 KiB
JavaScript
234 lines
7.0 KiB
JavaScript
var choresOverviewTable = $('#chores-overview-table').DataTable({
|
|
'order': [[2, 'asc']],
|
|
'columnDefs': [
|
|
{ 'orderable': false, 'targets': 0 },
|
|
{ 'searchable': false, "targets": 0 },
|
|
{ "type": "html", "targets": 5 },
|
|
{ "type": "html", "targets": 2 },
|
|
{ "type": "html", "targets": 3 }
|
|
].concat($.fn.dataTable.defaults.columnDefs)
|
|
});
|
|
$('#chores-overview-table tbody').removeClass("d-none");
|
|
choresOverviewTable.columns.adjust().draw();
|
|
|
|
$("#search").on("keyup", Delay(function()
|
|
{
|
|
var value = $(this).val();
|
|
if (value === "all")
|
|
{
|
|
value = "";
|
|
}
|
|
|
|
choresOverviewTable.search(value).draw();
|
|
}, 200));
|
|
|
|
$("#status-filter").on("change", function()
|
|
{
|
|
var value = $(this).val();
|
|
if (value === "all")
|
|
{
|
|
value = "";
|
|
}
|
|
|
|
// Transfer CSS classes of selected element to dropdown element (for background)
|
|
$(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control");
|
|
|
|
choresOverviewTable.column(5).search(value).draw();
|
|
});
|
|
|
|
$("#user-filter").on("change", function()
|
|
{
|
|
var value = $(this).val();
|
|
if (value === "all")
|
|
{
|
|
value = "";
|
|
}
|
|
|
|
// Transfer CSS classes of selected element to dropdown element (for background)
|
|
$(this).attr("class", $("#" + $(this).attr("id") + " option[value='" + value + "']").attr("class") + " form-control");
|
|
|
|
choresOverviewTable.column(6).search(value).draw();
|
|
|
|
if (!value.isEmpty())
|
|
{
|
|
UpdateUriParam("user", $("#user-filter option:selected").data("user-id"));
|
|
}
|
|
});
|
|
|
|
$("#clear-filter-button").on("click", function()
|
|
{
|
|
$("#search").val("");
|
|
$("#status-filter").val("all");
|
|
$("#user-filter").val("all");
|
|
choresOverviewTable.column(5).search("").draw();
|
|
choresOverviewTable.column(6).search("").draw();
|
|
choresOverviewTable.search("").draw();
|
|
});
|
|
|
|
$(".status-filter-message").on("click", function()
|
|
{
|
|
var value = $(this).data("status-filter");
|
|
$("#status-filter").val(value);
|
|
$("#status-filter").trigger("change");
|
|
});
|
|
|
|
$(".user-filter-message").on("click", function()
|
|
{
|
|
var value = $(this).data("user-filter");
|
|
$("#user-filter").val(value);
|
|
$("#user-filter").trigger("change");
|
|
});
|
|
|
|
$(document).on('click', '.track-chore-button', function(e)
|
|
{
|
|
e.preventDefault();
|
|
|
|
// Remove the focus from the current button
|
|
// to prevent that the tooltip stays until clicked anywhere else
|
|
document.activeElement.blur();
|
|
|
|
Grocy.FrontendHelpers.BeginUiBusy();
|
|
|
|
var choreId = $(e.currentTarget).attr('data-chore-id');
|
|
var choreName = $(e.currentTarget).attr('data-chore-name');
|
|
|
|
Grocy.Api.Get('objects/chores/' + choreId,
|
|
function(chore)
|
|
{
|
|
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
if (chore.track_date_only == 1)
|
|
{
|
|
trackedTime = moment().format('YYYY-MM-DD');
|
|
}
|
|
|
|
Grocy.Api.Post('chores/' + choreId + '/execute', { 'tracked_time': trackedTime },
|
|
function()
|
|
{
|
|
Grocy.Api.Get('chores/' + choreId,
|
|
function(result)
|
|
{
|
|
var choreRow = $('#chore-' + choreId + '-row');
|
|
var nextXDaysThreshold = moment().add($("#info-due-chores").data("next-x-days"), "days");
|
|
var now = moment();
|
|
var nextExecutionTime = moment(result.next_estimated_execution_time);
|
|
|
|
choreRow.removeClass("table-warning");
|
|
choreRow.removeClass("table-danger");
|
|
$('#chore-' + choreId + '-due-filter-column').html("");
|
|
if (nextExecutionTime.isBefore(now))
|
|
{
|
|
choreRow.addClass("table-danger");
|
|
$('#chore-' + choreId + '-due-filter-column').html("overdue");
|
|
}
|
|
else if (nextExecutionTime.isBefore(nextXDaysThreshold))
|
|
{
|
|
choreRow.addClass("table-warning");
|
|
$('#chore-' + choreId + '-due-filter-column').html("duesoon");
|
|
}
|
|
|
|
animateCSS("#chore-" + choreId + "-row td:not(:first)", "shake");
|
|
|
|
$('#chore-' + choreId + '-last-tracked-time').text(trackedTime);
|
|
$('#chore-' + choreId + '-last-tracked-time-timeago').attr('datetime', trackedTime);
|
|
|
|
if (result.chore.period_type == "dynamic-regular")
|
|
{
|
|
$('#chore-' + choreId + '-next-execution-time').text(result.next_estimated_execution_time);
|
|
$('#chore-' + choreId + '-next-execution-time-timeago').attr('datetime', result.next_estimated_execution_time);
|
|
}
|
|
|
|
if (result.chore.next_execution_assigned_to_user_id != null)
|
|
{
|
|
$('#chore-' + choreId + '-next-execution-assigned-user').text(result.next_execution_assigned_user.display_name);
|
|
}
|
|
|
|
Grocy.FrontendHelpers.EndUiBusy();
|
|
toastr.success(__t('Tracked execution of chore %1$s on %2$s', choreName, trackedTime));
|
|
RefreshStatistics();
|
|
|
|
// Delay due to delayed/animated set of new timestamps above
|
|
setTimeout(function()
|
|
{
|
|
RefreshContextualTimeago("#chore-" + choreId + "-row");
|
|
|
|
// Refresh the DataTable to re-apply filters
|
|
choresOverviewTable.rows().invalidate().draw(false);
|
|
$(".input-group-filter").trigger("change");
|
|
}, 550);
|
|
},
|
|
function(xhr)
|
|
{
|
|
Grocy.FrontendHelpers.EndUiBusy();
|
|
console.error(xhr);
|
|
}
|
|
);
|
|
},
|
|
function(xhr)
|
|
{
|
|
Grocy.FrontendHelpers.EndUiBusy();
|
|
console.error(xhr);
|
|
}
|
|
);
|
|
},
|
|
function(xhr)
|
|
{
|
|
Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
|
|
console.error(xhr);
|
|
}
|
|
);
|
|
});
|
|
|
|
$(document).on("click", ".chore-name-cell", function(e)
|
|
{
|
|
Grocy.Components.ChoreCard.Refresh($(e.currentTarget).attr("data-chore-id"));
|
|
$("#choresoverview-chorecard-modal").modal("show");
|
|
});
|
|
|
|
function RefreshStatistics()
|
|
{
|
|
var nextXDays = $("#info-due-chores").data("next-x-days");
|
|
Grocy.Api.Get('chores',
|
|
function(result)
|
|
{
|
|
var dueCount = 0;
|
|
var overdueCount = 0;
|
|
var assignedToMeCount = 0;
|
|
var now = moment();
|
|
var nextXDaysThreshold = moment().add(nextXDays, "days");
|
|
result.forEach(element =>
|
|
{
|
|
var date = moment(element.next_estimated_execution_time);
|
|
if (date.isBefore(now))
|
|
{
|
|
overdueCount++;
|
|
}
|
|
else if (date.isBefore(nextXDaysThreshold))
|
|
{
|
|
dueCount++;
|
|
}
|
|
|
|
if (parseInt(element.next_execution_assigned_to_user_id) == Grocy.UserId)
|
|
{
|
|
assignedToMeCount++;
|
|
}
|
|
});
|
|
|
|
$("#info-due-chores").html('<span class="d-block d-md-none">' + dueCount + ' <i class="fas fa-clock"></i></span><span class="d-none d-md-block">' + __n(dueCount, '%s chore is due to be done', '%s chores are due to be done') + ' ' + __n(nextXDays, 'within the next day', 'within the next %s days'));
|
|
$("#info-overdue-chores").html('<span class="d-block d-md-none">' + overdueCount + ' <i class="fas fa-times-circle"></i></span><span class="d-none d-md-block">' + __n(overdueCount, '%s chore is overdue to be done', '%s chores are overdue to be done'));
|
|
$("#info-assigned-to-me-chores").html('<span class="d-block d-md-none">' + assignedToMeCount + ' <i class="fas fa-exclamation-circle"></i></span><span class="d-none d-md-block">' + __n(assignedToMeCount, '%s chore is assigned to me', '%s chores are assigned to me'));
|
|
},
|
|
function(xhr)
|
|
{
|
|
console.error(xhr);
|
|
}
|
|
);
|
|
}
|
|
|
|
if (GetUriParam("user") !== undefined)
|
|
{
|
|
$("#user-filter").val("xx" + GetUriParam("user") + "xx");
|
|
$("#user-filter").trigger("change");
|
|
}
|
|
|
|
RefreshStatistics();
|