fix: change 'show' duration options to 'hide' for consistency
This commit is contained in:
parent
20200b8812
commit
3a0aa88f4b
9 changed files with 50 additions and 58 deletions
|
|
@ -4,14 +4,14 @@ context('Control Duration', () => {
|
|||
cy.visit('/desk#workspace/Website');
|
||||
});
|
||||
|
||||
function get_dialog_with_duration(show_days=1, show_seconds=1) {
|
||||
function get_dialog_with_duration(hide_days=0, hide_seconds=0) {
|
||||
return cy.dialog({
|
||||
title: 'Duration',
|
||||
fields: [{
|
||||
'fieldname': 'duration',
|
||||
'fieldtype': 'Duration',
|
||||
'show_seconds': show_days,
|
||||
'show_days': show_seconds
|
||||
'hide_days': hide_days,
|
||||
'hide_seconds': hide_seconds
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ context('Control Duration', () => {
|
|||
});
|
||||
|
||||
it('should hide days or seconds according to duration options', () => {
|
||||
get_dialog_with_duration(0, 0).as('dialog');
|
||||
get_dialog_with_duration(1, 1).as('dialog');
|
||||
cy.get('.frappe-control[data-fieldname=duration] input').first().click();
|
||||
cy.get('.duration-input[data-duration=days]').should('not.be.visible');
|
||||
cy.get('.duration-input[data-duration=seconds]').should('not.be.visible');
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@
|
|||
"fieldname",
|
||||
"precision",
|
||||
"length",
|
||||
"show_days",
|
||||
"show_seconds",
|
||||
"hide_days",
|
||||
"hide_seconds",
|
||||
"reqd",
|
||||
"search_index",
|
||||
"in_list_view",
|
||||
|
|
@ -453,18 +453,18 @@
|
|||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"depends_on": "eval:doc.fieldtype === \"Duration\";",
|
||||
"fieldname": "show_days",
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.fieldtype=='Duration'",
|
||||
"fieldname": "hide_days",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Days"
|
||||
"label": "Hide Days"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"depends_on": "eval:doc.fieldtype === \"Duration\";",
|
||||
"fieldname": "show_seconds",
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.fieldtype=='Duration'",
|
||||
"fieldname": "hide_seconds",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Seconds"
|
||||
"label": "Hide Seconds"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
|
|
@ -477,7 +477,7 @@
|
|||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-05-15 09:06:25.224411",
|
||||
"modified": "2020-02-06 09:06:25.224413",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Core",
|
||||
"name": "DocField",
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@
|
|||
"column_break_6",
|
||||
"fieldtype",
|
||||
"precision",
|
||||
"show_seconds",
|
||||
"show_days",
|
||||
"hide_seconds",
|
||||
"hide_days",
|
||||
"options",
|
||||
"fetch_from",
|
||||
"fetch_if_empty",
|
||||
|
|
@ -383,22 +383,18 @@
|
|||
"label": "In Preview"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"depends_on": "eval:doc.fieldtype === \"Duration\";",
|
||||
"fieldname": "show_seconds",
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.fieldtype=='Duration'",
|
||||
"fieldname": "hide_seconds",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Seconds",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"label": "Hide Seconds"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"depends_on": "eval:doc.fieldtype === \"Duration\";",
|
||||
"fieldname": "show_days",
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.fieldtype=='Duration'",
|
||||
"fieldname": "hide_days",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Days",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"label": "Hide Days"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
|
|
@ -411,7 +407,7 @@
|
|||
"icon": "fa fa-glass",
|
||||
"idx": 1,
|
||||
"links": [],
|
||||
"modified": "2020-05-15 23:43:00.123572",
|
||||
"modified": "2020-02-06 23:43:00.123575",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Custom",
|
||||
"name": "Custom Field",
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
"label",
|
||||
"fieldtype",
|
||||
"fieldname",
|
||||
"show_seconds",
|
||||
"show_days",
|
||||
"hide_seconds",
|
||||
"hide_days",
|
||||
"reqd",
|
||||
"unique",
|
||||
"in_list_view",
|
||||
|
|
@ -393,22 +393,18 @@
|
|||
"label": "In Preview"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"depends_on": "eval:doc.fieldtype === \"Duration\";",
|
||||
"fieldname": "show_seconds",
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.fieldtype=='Duration'",
|
||||
"fieldname": "hide_seconds",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Seconds",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"label": "Hide Seconds"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"depends_on": "eval:doc.fieldtype === \"Duration\";",
|
||||
"fieldname": "show_days",
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.fieldtype=='Duration'",
|
||||
"fieldname": "hide_days",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Days",
|
||||
"show_days": 1,
|
||||
"show_seconds": 1
|
||||
"label": "Hide Days"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
|
|
@ -421,7 +417,7 @@
|
|||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-05-15 23:45:46.810869",
|
||||
"modified": "2020-06-02 23:45:46.810868",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Custom",
|
||||
"name": "Customize Form Field",
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ frappe.ui.form.ControlDuration = frappe.ui.form.ControlData.extend({
|
|||
</div>`
|
||||
);
|
||||
this.$wrapper.append(this.$picker);
|
||||
this.build_numeric_input("days", !this.duration_options.show_days);
|
||||
this.build_numeric_input("days", this.duration_options.hide_days);
|
||||
this.build_numeric_input("hours", false);
|
||||
this.build_numeric_input("minutes", false);
|
||||
this.build_numeric_input("seconds", !this.duration_options.show_seconds);
|
||||
this.build_numeric_input("seconds", this.duration_options.hide_seconds);
|
||||
this.set_duration_picker_value(this.value);
|
||||
this.$picker.hide();
|
||||
this.bind_events();
|
||||
|
|
@ -130,10 +130,10 @@ frappe.ui.form.ControlDuration = frappe.ui.form.ControlData.extend({
|
|||
if (this.inputs) {
|
||||
total_duration.minutes = parseInt(this.inputs.minutes.val());
|
||||
total_duration.hours = parseInt(this.inputs.hours.val());
|
||||
if (this.duration_options.show_days) {
|
||||
if (!this.duration_options.hide_days) {
|
||||
total_duration.days = parseInt(this.inputs.days.val());
|
||||
}
|
||||
if (this.duration_options.show_seconds) {
|
||||
if (!this.duration_options.hide_seconds) {
|
||||
total_duration.seconds = parseInt(this.inputs.seconds.val());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -202,8 +202,8 @@ frappe.ui.FilterList = Class.extend({
|
|||
value = {0:"No", 1:"Yes"}[cint(value)];
|
||||
} else if (field.df.original_type === "Duration") {
|
||||
let duration_options = {
|
||||
show_days: field.df.show_days,
|
||||
show_seconds: field.df.show_seconds
|
||||
hide_days: field.df.hide_days,
|
||||
hide_seconds: field.df.hide_seconds
|
||||
};
|
||||
value = frappe.utils.get_formatted_duration(value, duration_options);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -856,7 +856,7 @@ Object.assign(frappe.utils, {
|
|||
minutes: Math.floor(secs % 3600 / 60),
|
||||
seconds: Math.floor(secs % 60)
|
||||
};
|
||||
if (!duration_options.show_days) {
|
||||
if (duration_options.hide_days) {
|
||||
total_duration.hours = Math.floor(secs / 3600);
|
||||
total_duration.days = 0;
|
||||
}
|
||||
|
|
@ -882,8 +882,8 @@ Object.assign(frappe.utils, {
|
|||
|
||||
get_duration_options: function(docfield) {
|
||||
let duration_options = {
|
||||
show_days: docfield.show_days,
|
||||
show_seconds: docfield.show_seconds
|
||||
hide_days: docfield.hide_days,
|
||||
hide_seconds: docfield.hide_seconds
|
||||
};
|
||||
return duration_options;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ def format_datetime(datetime_string, format_string=None):
|
|||
formatted_datetime = datetime.strftime('%Y-%m-%d %H:%M:%S')
|
||||
return formatted_datetime
|
||||
|
||||
def format_duration(seconds, show_days=True):
|
||||
def format_duration(seconds, hide_days=False):
|
||||
total_duration = {
|
||||
'days': math.floor(seconds / (3600 * 24)),
|
||||
'hours': math.floor(seconds % (3600 * 24) / 3600),
|
||||
|
|
@ -344,7 +344,7 @@ def format_duration(seconds, show_days=True):
|
|||
'seconds': math.floor(seconds % 60)
|
||||
}
|
||||
|
||||
if not show_days:
|
||||
if hide_days:
|
||||
total_duration['hours'] = math.floor(seconds / 3600)
|
||||
total_duration['days'] = 0
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ def format_value(value, df=None, doc=None, currency=None, translated=False):
|
|||
return ', '.join(values)
|
||||
|
||||
elif df.get("fieldtype") == "Duration":
|
||||
show_days = df.show_days
|
||||
return format_duration(value, show_days)
|
||||
hide_days = df.hide_days
|
||||
return format_duration(value, hide_days)
|
||||
|
||||
return value
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue