mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Merge pull request #2685 from SchrodingersGat/date-format
Adds a user-configurable setting to configure how dates are displayed
This commit is contained in:
@ -81,7 +81,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ plugin.author }}</td>
|
||||
<td>{{ plugin.pub_date }}</td>
|
||||
<td>{% render_date plugin.pub_date %}</td>
|
||||
<td>{% if plugin.version %}{{ plugin.version }}{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -36,7 +36,7 @@
|
||||
<tr>
|
||||
<td><span class='fas fa-calendar-alt'></span></td>
|
||||
<td>{% trans "Date" %}</td>
|
||||
<td>{{ plugin.pub_date }}{% include "clip.html" %}</td>
|
||||
<td>{% render_date plugin.pub_date %}{% include "clip.html" %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class='fas fa-hashtag'></span></td>
|
||||
@ -101,7 +101,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class='fas fa-calendar-alt'></span></td>
|
||||
<td>{% trans "Commit Date" %}</td><td>{{ plugin.package.date }}{% include "clip.html" %}</td>
|
||||
<td>{% trans "Commit Date" %}</td><td>{% render_date plugin.package.date %}{% include "clip.html" %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class='fas fa-code-branch'></span></td>
|
||||
|
@ -28,7 +28,11 @@
|
||||
<div id='setting-{{ setting.pk }}'>
|
||||
<span id='setting-value-{{ setting.key.upper }}' fieldname='{{ setting.key.upper }}'>
|
||||
{% if setting.value %}
|
||||
{% if setting.is_choice %}
|
||||
<strong>{{ setting.as_choice }}</strong>
|
||||
{% else %}
|
||||
<strong>{{ setting.value }}</strong>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<em style='color: #855;'>{% trans "No value set" %}</em>
|
||||
{% endif %}
|
||||
|
@ -15,6 +15,7 @@
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tbody>
|
||||
{% include "InvenTree/settings/setting.html" with key="STICKY_HEADER" icon="fa-bars" user_setting=True %}
|
||||
{% include "InvenTree/settings/setting.html" with key="DATE_DISPLAY_FORMAT" icon="fa-calendar-alt" user_setting=True %}
|
||||
{% include "InvenTree/settings/setting.html" with key="FORMS_CLOSE_USING_ESCAPE" icon="fa-window-close" user_setting=True %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PART_SHOW_QUANTITY_IN_FORMS" icon="fa-hashtag" user_setting=True %}
|
||||
</tbody>
|
||||
|
@ -44,7 +44,7 @@
|
||||
{% if commit_date %}
|
||||
<tr>
|
||||
<td><span class='fas fa-calendar-alt'></span></td>
|
||||
<td>{% trans "Commit Date" %}</td><td>{{ commit_date }}{% include "clip.html" %}</td>
|
||||
<td>{% trans "Commit Date" %}</td><td>{% render_date commit_date %}{% include "clip.html" %}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
@ -7,6 +7,7 @@
|
||||
clearEvents,
|
||||
endDate,
|
||||
startDate,
|
||||
renderDate,
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -32,3 +33,33 @@ function clearEvents(calendar) {
|
||||
event.remove();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Render the provided date in the user-specified format.
|
||||
*
|
||||
* The provided "date" variable is a string, nominally ISO format e.g. 2022-02-22
|
||||
* The user-configured setting DATE_DISPLAY_FORMAT determines how the date should be displayed.
|
||||
*/
|
||||
|
||||
function renderDate(date, options={}) {
|
||||
|
||||
if (!date) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var fmt = user_settings.DATE_DISPLAY_FORMAT || 'YYYY-MM-DD';
|
||||
|
||||
if (options.showTime) {
|
||||
fmt += ' HH:mm';
|
||||
}
|
||||
|
||||
var m = moment(date);
|
||||
|
||||
if (m.isValid()) {
|
||||
return m.format(fmt);
|
||||
} else {
|
||||
// Invalid input string, simply return provided value
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
@ -40,12 +40,15 @@ function editSetting(pk, options={}) {
|
||||
url = `/api/settings/user/${pk}/`;
|
||||
}
|
||||
|
||||
var reload_required = false;
|
||||
|
||||
// First, read the settings object from the server
|
||||
inventreeGet(url, {}, {
|
||||
success: function(response) {
|
||||
|
||||
if (response.choices && response.choices.length > 0) {
|
||||
response.type = 'choice';
|
||||
reload_required = true;
|
||||
}
|
||||
|
||||
// Construct the field
|
||||
@ -89,7 +92,9 @@ function editSetting(pk, options={}) {
|
||||
|
||||
var setting = response.key;
|
||||
|
||||
if (response.type == 'boolean') {
|
||||
if (reload_required) {
|
||||
location.reload();
|
||||
} else if (response.type == 'boolean') {
|
||||
var enabled = response.value.toString().toLowerCase() == 'true';
|
||||
$(`#setting-value-${setting}`).prop('checked', enabled);
|
||||
} else {
|
||||
|
@ -165,6 +165,9 @@ function loadAttachmentTable(url, options) {
|
||||
{
|
||||
field: 'upload_date',
|
||||
title: '{% trans "Upload Date" %}',
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'actions',
|
||||
|
@ -1961,6 +1961,9 @@ function loadBuildTable(table, options) {
|
||||
field: 'creation_date',
|
||||
title: '{% trans "Created" %}',
|
||||
sortable: true,
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'issued_by',
|
||||
@ -1990,11 +1993,17 @@ function loadBuildTable(table, options) {
|
||||
field: 'target_date',
|
||||
title: '{% trans "Target Date" %}',
|
||||
sortable: true,
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'completion_date',
|
||||
title: '{% trans "Completion Date" %}',
|
||||
sortable: true,
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
],
|
||||
});
|
||||
|
@ -923,11 +923,17 @@ function loadPurchaseOrderTable(table, options) {
|
||||
field: 'creation_date',
|
||||
title: '{% trans "Date" %}',
|
||||
sortable: true,
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'target_date',
|
||||
title: '{% trans "Target Date" %}',
|
||||
sortable: true,
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'line_items',
|
||||
@ -1198,7 +1204,7 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
|
||||
title: '{% trans "Target Date" %}',
|
||||
formatter: function(value, row) {
|
||||
if (row.target_date) {
|
||||
var html = row.target_date;
|
||||
var html = renderDate(row.target_date);
|
||||
|
||||
if (row.overdue) {
|
||||
html += `<span class='fas fa-calendar-alt icon-red float-right' title='{% trans "This line item is overdue" %}'></span>`;
|
||||
@ -1207,7 +1213,7 @@ function loadPurchaseOrderLineItemTable(table, options={}) {
|
||||
return html;
|
||||
|
||||
} else if (row.order_detail && row.order_detail.target_date) {
|
||||
return `<em>${row.order_detail.target_date}</em>`;
|
||||
return `<em>${renderDate(row.order_detail.target_date)}</em>`;
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
@ -1371,16 +1377,25 @@ function loadSalesOrderTable(table, options) {
|
||||
sortable: true,
|
||||
field: 'creation_date',
|
||||
title: '{% trans "Creation Date" %}',
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'target_date',
|
||||
title: '{% trans "Target Date" %}',
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
field: 'shipment_date',
|
||||
title: '{% trans "Shipment Date" %}',
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
},
|
||||
{
|
||||
sortable: true,
|
||||
@ -1532,9 +1547,9 @@ function loadSalesOrderShipmentTable(table, options={}) {
|
||||
sortable: true,
|
||||
formatter: function(value, row) {
|
||||
if (value) {
|
||||
return value;
|
||||
return renderDate(value);
|
||||
} else {
|
||||
return '{% trans "Not shipped" %}';
|
||||
return '<em>{% trans "Not shipped" %}</em>';
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -2317,7 +2332,7 @@ function loadSalesOrderLineItemTable(table, options={}) {
|
||||
switchable: true,
|
||||
formatter: function(value, row) {
|
||||
if (row.target_date) {
|
||||
var html = row.target_date;
|
||||
var html = renderDate(row.target_date);
|
||||
|
||||
if (row.overdue) {
|
||||
html += `<span class='fas fa-calendar-alt icon-red float-right' title='{% trans "This line item is overdue" %}'></span>`;
|
||||
@ -2326,7 +2341,7 @@ function loadSalesOrderLineItemTable(table, options={}) {
|
||||
return html;
|
||||
|
||||
} else if (row.order_detail && row.order_detail.target_date) {
|
||||
return `<em>${row.order_detail.target_date}</em>`;
|
||||
return `<em>${renderDate(row.order_detail.target_date)}</em>`;
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
modalSetContent,
|
||||
modalSetTitle,
|
||||
modalSubmit,
|
||||
moment,
|
||||
openModal,
|
||||
printStockItemLabels,
|
||||
printTestReports,
|
||||
@ -1820,6 +1819,9 @@ function loadStockTable(table, options) {
|
||||
col = {
|
||||
field: 'stocktake_date',
|
||||
title: '{% trans "Stocktake" %}',
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
};
|
||||
|
||||
if (!options.params.ordering) {
|
||||
@ -1833,6 +1835,9 @@ function loadStockTable(table, options) {
|
||||
title: '{% trans "Expiry Date" %}',
|
||||
visible: global_settings.STOCK_ENABLE_EXPIRY,
|
||||
switchable: global_settings.STOCK_ENABLE_EXPIRY,
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
};
|
||||
|
||||
if (!options.params.ordering) {
|
||||
@ -1844,6 +1849,9 @@ function loadStockTable(table, options) {
|
||||
col = {
|
||||
field: 'updated',
|
||||
title: '{% trans "Last Updated" %}',
|
||||
formatter: function(value) {
|
||||
return renderDate(value);
|
||||
}
|
||||
};
|
||||
|
||||
if (!options.params.ordering) {
|
||||
@ -2649,14 +2657,7 @@ function loadStockTrackingTable(table, options) {
|
||||
title: '{% trans "Date" %}',
|
||||
sortable: true,
|
||||
formatter: function(value) {
|
||||
var m = moment(value);
|
||||
|
||||
if (m.isValid()) {
|
||||
var html = m.format('dddd MMMM Do YYYY'); // + '<br>' + m.format('h:mm a');
|
||||
return html;
|
||||
}
|
||||
|
||||
return '<i>{% trans "Invalid date" %}</i>';
|
||||
return renderDate(value, {showTime: true});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
InvenTree-Version: {% inventree_version %}
|
||||
Django Version: {% django_version %}
|
||||
{% inventree_commit_hash as hash %}{% if hash %}Commit Hash: {{ hash }}{% endif %}
|
||||
{% inventree_commit_date as commit_date %}{% if commit_date %}Commit Date: {{ commit_date }}{% endif %}
|
||||
{% inventree_commit_date as commit_date %}{% if commit_date %}Commit Date: {% render_date commit_date %}{% endif %}
|
||||
Database: {% inventree_db_engine %}
|
||||
Debug-Mode: {% inventree_in_debug_mode %}
|
||||
Deployed using Docker: {% inventree_docker_mode %}
|
Reference in New Issue
Block a user