Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow hidden fields #87

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,28 @@
}, 300)
"
/>
<div class="hidden-toggle">
<label class="switch">
<input type="checkbox" :class="{ checked: hiddenFields }" :checked="hiddenFields"
@change="() => {
hiddenFields = !hiddenFields;
}"
@click="MainStore.isHiddenFieldsVisible = !MainStore.isHiddenFieldsVisible;"
>
<span class="slider round"></span>
</label>
<span>Hidden Fields</span>
</div>
</div>
<div class="form-message yellow" v-if="hiddenFields">
<div>Fields with <b>Print Hide</b> are now also visible and can be printed. please be careful while selecting fields </div>
</div>
<div class="container-main">
<div
v-for="(fields, fieldtype) in MainStore.getTypeWiseMetaFields({
selectedParentField: previewRef?.parentField,
search_string: search_text,
show_hidden_fields: hiddenFields,
})"
:key="fieldtype"
>
Expand Down Expand Up @@ -122,9 +138,29 @@ const search_text = ref("");
const doctype = ref("");
const selectedDoctypeLabel = ref("");
const fieldnames = ref([]);
const hiddenFields = ref(false);
const previewRef = ref(null);
const { isDynamic } = toRefs(MainStore.getCurrentElementsValues[0]);

const allowHiddenFieldDisable = watch(
() => hiddenFields.value,
(newValue, oldValue) => {
if (newValue == false && oldValue == true) {
let hidden_fields = fieldnames.value.filter((el) => el.print_hide).map((el) => el.label || el.fieldname);
if (!hidden_fields.length) return;
hiddenFields.value = true;
message = __("Please First remove hidden fields [ " + [...hidden_fields].join(", ") + " ]");
frappe.show_alert(
{
message: message,
indicator: "red",
},
5
);
}
}
);

const parentFieldWatcher = watch(
() => previewRef.value?.parentField,
() => {
Expand Down Expand Up @@ -152,6 +188,10 @@ onMounted(() => {
if (props.openBarcodeModal) {
fieldnames.value = props.openBarcodeModal.dynamicContent;
selectedDoctypeLabel.value = MainStore.doctype;
fieldnames.value.findIndex((fd) => fd.print_hide) != -1 && (hiddenFields.value = true);
if (!hiddenFields.value) {
hiddenFields.value = MainStore.isHiddenFieldsVisible
}
}
});

Expand Down Expand Up @@ -203,6 +243,7 @@ const selectField = async (field, fieldtype) => {
options: field.options,
value,
fieldtype,
print_hide: field.print_hide,
is_labelled: false,
is_static: false,
style: {},
Expand Down Expand Up @@ -364,11 +405,22 @@ small {
border-radius: 6px;
}
.searchbar-sticky {
display: flex;
margin-bottom: 0;
position: sticky;
top: 0;
z-index: 1;
background-color: var(--fg-color);

.searchbar {
flex: 5;
}

.hidden-toggle {
display: flex;
gap: 5px;
padding: var(--padding-sm);
}
}
.container-main {
padding: var(--padding-sm) 15px 0px var(--padding-sm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,29 @@
}, 300)
"
/>
<div class="hidden-toggle">
<label class="switch">
<input type="checkbox" :class="{ checked: hiddenFields }" :checked="hiddenFields"
@change="() => {
hiddenFields = !hiddenFields;
}"
@click="MainStore.isHiddenFieldsVisible = !MainStore.isHiddenFieldsVisible;"
>
<span class="slider round"></span>
</label>
<span>Hidden Fields</span>
</div>
</div>
<div class="form-message yellow" v-if="hiddenFields">
<div>Fields with <b>Print Hide</b> are now also visible and can be printed. please be careful while selecting fields </div>
</div>
<div class="container-main">
<div
v-for="(fields, fieldtype) in MainStore.getTypeWiseMetaFields({
selectedParentField: previewRef?.parentField,
selectedTable: table,
search_string: search_text,
show_hidden_fields: hiddenFields,
})"
:key="fieldtype"
>
Expand Down Expand Up @@ -137,8 +153,28 @@ const search_text = ref("");
const doctype = ref("");
const selectedDoctypeLabel = ref("");
const fieldnames = ref([]);
const hiddenFields = ref(false);
const previewRef = ref(null);

const allowHiddenFieldDisable = watch(
() => hiddenFields.value,
(newValue, oldValue) => {
if (newValue == false && oldValue == true) {
let hidden_fields = fieldnames.value.filter((el) => el.print_hide).map((el) => el.label || el.fieldname);
if (!hidden_fields.length) return;
hiddenFields.value = true;
message = __("Please First remove hidden fields [ " + [...hidden_fields].join(", ") + " ]");
frappe.show_alert(
{
message: message,
indicator: "red",
},
5
);
}
}
);

const parentFieldWatcher = watch(
() => previewRef.value?.parentField,
() => {
Expand Down Expand Up @@ -169,6 +205,10 @@ onMounted(() => {
if (props.table) {
fieldnames.value = props.openDynamicModal.dynamicContent || [];
}
fieldnames.value.findIndex((fd) => fd.print_hide) != -1 && (hiddenFields.value = true);
if (!hiddenFields.value) {
hiddenFields.value = MainStore.isHiddenFieldsVisible
}
}
});

Expand Down Expand Up @@ -264,6 +304,7 @@ const selectField = async (field, fieldtype) => {
label: props.table ? field.label : `${field.label} :`,
is_labelled: false,
is_static: false,
print_hide: field.print_hide,
style: {},
tableName: props.table?.fieldname,
labelStyle: {},
Expand Down Expand Up @@ -444,11 +485,34 @@ small {
border-radius: 6px;
}
.searchbar-sticky {
display: flex;
margin-bottom: 0;
position: sticky;
top: 0;
z-index: 1;
background-color: var(--fg-color);

.searchbar {
flex: 5;
}

.hidden-toggle {
display: flex;
gap: 5px;
padding: var(--padding-sm);

.switch > .checked {
& + .slider {
background-color: var(--invert-neutral);
}

& + .slider:before {
-webkit-transform: translateX(10px);
-ms-transform: translateX(10px);
transform: translateX(10px);
}
}
}
}
.container-main {
padding: var(--padding-sm) 15px 0px var(--padding-sm);
Expand Down
5 changes: 5 additions & 0 deletions print_designer/public/js/print_designer/store/MainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const useMainStore = defineStore("MainStore", {
lastCloned: null,
currentDrawListener: null,
isMoved: false,
isHiddenFieldsVisible: false,
currentPageSize: "A4",
pageSizes,
lastCreatedElement: null,
Expand Down Expand Up @@ -231,6 +232,7 @@ export const useMainStore = defineStore("MainStore", {
selectedParentField = null,
selectedTable = null,
search_string = null,
show_hidden_fields = false,
}) => {
let fields = {};
let metaFields = state.metaFields;
Expand All @@ -241,6 +243,9 @@ export const useMainStore = defineStore("MainStore", {
} else if (selectedTable) {
metaFields = selectedTable.childfields;
}
if (!show_hidden_fields){
metaFields = metaFields.filter((field) => !field["print_hide"]);
}
if (typeof search_string == "string" && search_string.length) {
metaFields = metaFields.filter(
(o) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ export const fetchMeta = () => {
MainStore.rawMeta = markRaw(frappe.get_meta(print_format.doc_type));
let metaFields = frappe.get_meta(print_format.doc_type).fields.filter((df) => {
if (
["Section Break", "Column Break", "Tab Break", "Image"].includes(df.fieldtype) ||
(df.print_hide == 1 && df.fieldtype != "Link")
["Section Break", "Column Break", "Tab Break", "Image"].includes(df.fieldtype)
) {
return false;
} else {
return true;
}
});
metaFields.map((field) => {
if (field["print_hide"] && field["fieldtype"] != "Link") return;

let obj = {};
["fieldname", "fieldtype", "label", "options"].forEach((attr) => {
["fieldname", "fieldtype", "label", "options", "print_hide"].forEach((attr) => {
obj[attr] = field[attr];
});
MainStore.metaFields.push({ ...obj });
});
metaFields.map((field) => {
if (field["fieldtype"] != "Table" || field["print_hide"]) return;
getMeta(field.options, field.fieldname);
if (field["fieldtype"] == "Table") {
getMeta(field.options, field.fieldname);
}
});
fetchDoc();
!MainStore.getTableMetaFields.length && (MainStore.controls.Table.isDisabled = true);
Expand Down