Skip to content

Commit

Permalink
chore: merge develop into main (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
maharshivpatel authored Jun 18, 2024
2 parents 7d28f18 + fdee4b9 commit 074e411
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 225 deletions.
63 changes: 41 additions & 22 deletions print_designer/patches/convert_formats_for_recursive_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,52 @@ def patch_format():
if not is_older_schema(settings=settings, current_version="1.1.0") and is_older_schema(
settings=settings, current_version="1.3.0"
):
pf_print_format = frappe.json.loads(pf.print_designer_print_format)
pf_print_format = frappe.json.loads(pf.print_designer_print_format or "{}")

for headerType in ["firstPage", "oddPage", "evenPage", "lastPage"]:
for row in pf_print_format["header"][headerType]:
row["layoutType"] = "row"
for column in row["childrens"]:
column["layoutType"] = "column"
if pf_print_format.get("header", False):
if type(pf_print_format["header"]) == list:
# issue #285
pf_print_format["header"] = {
"firstPage": pf_print_format["header"],
"oddPage": pf_print_format["header"],
"evenPage": pf_print_format["header"],
"lastPage": pf_print_format["header"],
}
for headerType in ["firstPage", "oddPage", "evenPage", "lastPage"]:
for row in pf_print_format["header"][headerType]:
row["layoutType"] = "row"
for column in row["childrens"]:
column["layoutType"] = "column"

for footerType in ["firstPage", "oddPage", "evenPage", "lastPage"]:
for row in pf_print_format["footer"][footerType]:
if pf_print_format.get("footer", False):
if type(pf_print_format["footer"]) == list:
# issue #285
pf_print_format["footer"] = {
"firstPage": pf_print_format["footer"],
"oddPage": pf_print_format["footer"],
"evenPage": pf_print_format["footer"],
"lastPage": pf_print_format["footer"],
}
for footerType in ["firstPage", "oddPage", "evenPage", "lastPage"]:
for row in pf_print_format["footer"][footerType]:
row["layoutType"] = "row"
for column in row["childrens"]:
column["layoutType"] = "column"

if pf_print_format.get("body", False):
for row in pf_print_format["body"]:
row["layoutType"] = "row"
for column in row["childrens"]:
column["layoutType"] = "column"

for row in pf_print_format["body"]:
row["layoutType"] = "row"
for column in row["childrens"]:
column["layoutType"] = "column"
# body elements should be inside page object forgot to add it in patch move_header_footers_to_new_schema
pf_print_format["body"] = [
{
"index": 0,
"type": "page",
"childrens": pf_print_format["body"],
"isDropZone": True,
}
]
# body elements should be inside page object forgot to add it in patch move_header_footers_to_new_schema
pf_print_format["body"] = [
{
"index": 0,
"type": "page",
"childrens": pf_print_format["body"],
"isDropZone": True,
}
]

frappe.set_value(
"Print Format",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
{%- set value = _(frappe.db.get_value(field.doctype, doc[field.parentField], field.fieldname)) -%}
{{ frappe.format(value, {'fieldtype': field.fieldtype, 'options': field.options}) }}
{%- elif row -%}
{%- if field.fieldtype == "Image" and row.get(field['options']) -%}
<img class="print-item-image" src="{{ row.get(field['options']) }}" alt="">
{%- else -%}
{{row.get_formatted(field.fieldname)}}
{%- endif -%}
{%- else -%}
{{doc.get_formatted(field.fieldname)}}
{%- endif -%}
Expand Down
38 changes: 15 additions & 23 deletions print_designer/public/images/print-designer-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions print_designer/public/js/print_designer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ watchEffect(() => {
justify-content: space-between;
margin: 0;
cursor: default;
--primary: #6f5f35;
--primary-color: #6f5f35;
--primary: #7b4b57;
--primary-color: #7b4b57;
.app-sections {
flex: 1;
height: calc(100vh - var(--navbar-height));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ export const createPropertiesPanel = () => {
fieldtype: "Int",
label: "No",
options: undefined,
tableName: currentEL["table"],
};
if (value && currentEL) {
currentEL["table"] = MainStore.metaFields.find(
Expand Down Expand Up @@ -755,6 +756,9 @@ export const createPropertiesPanel = () => {
dlKeys[index]
],
];
col.dynamicContent.forEach((dc) => {
dc.tableName = currentEL["table"].fieldname;
});
col.label =
col.dynamicContent[0].label ||
col.dynamicContent[0].fieldname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<script setup>
import { useMainStore } from "../../store/MainStore";
import { ref, watch, onMounted } from "vue";
import { getFormattedValue } from "../../utils";
const selectDynamicText = (isLabel = false) => {
props.field.labelStyleEditing = isLabel;
Expand Down Expand Up @@ -101,7 +102,7 @@ const props = defineProps({
});
const parsedValue = ref("");
const row = ref({});
const row = ref(null);
onMounted(() => {
watch(
Expand All @@ -116,43 +117,6 @@ onMounted(() => {
);
});
const parseJinja = async () => {
if (props.field.value != "" && props.field.parseJinja) {
try {
// call render_user_text_withdoc method using frappe.call and return the result
const MainStore = useMainStore();
let result = await frappe.call({
method: "print_designer.print_designer.page.print_designer.print_designer.render_user_text_withdoc",
args: {
string: props.field.value,
doctype: MainStore.doctype,
docname: MainStore.currentDoc,
row: row.value,
send_to_jinja: MainStore.mainParsedJinjaData || {},
},
});
result = result.message;
if (result.success) {
parsedValue.value = result.message;
} else {
console.error("Error From User Provided Jinja String\n\n", result.error);
}
} catch (error) {
console.error("Error in Jinja Template\n", { value_string: props.field.value, error });
frappe.show_alert(
{
message: "Unable Render Jinja Template. Please Check Console",
indicator: "red",
},
5
);
parsedValue.value = props.field.value;
}
} else {
parsedValue.value = props.field.value;
}
};
watch(
() => [
props.field.value,
Expand All @@ -162,39 +126,7 @@ watch(
row.value,
],
async () => {
const isDataAvailable = props.table
? row.value
: Object.keys(MainStore.docData).length > 0;
if (props.field.is_static) {
if (props.field.parseJinja) {
parseJinja();
return;
}
parsedValue.value = props.field.value;
return;
} else if (props.table) {
if (isDataAvailable && typeof row.value[props.field.fieldname] != "undefined") {
parsedValue.value = frappe.format(
row.value[props.field.fieldname],
{ fieldtype: props.field.fieldtype, options: props.field.options },
{ inline: true },
row.value
);
} else {
parsedValue.value =
["Image, Attach Image"].indexOf(props.field.fieldtype) != -1
? null
: `{{ ${props.field.fieldname} }}`;
}
return;
} else {
parsedValue.value =
props.field.value ||
`{{ ${props.field.parentField ? props.field.parentField + "." : ""}${
props.field.fieldname
} }}`;
return;
}
parsedValue.value = await getFormattedValue(props.field, row);
},
{ immediate: true, deep: true }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
>
<div
:style="['overflow: hidden;', widthHeightStyle(width, height)]"
@click.stop.self="
@click.self="
() => {
selectedColumn = null;
selectedDynamicText = null;
Expand Down Expand Up @@ -49,7 +49,7 @@
@dragleave="dragleave"
@dragover="allowDrop"
@contextmenu.prevent="handleMenu($event, index)"
@mousedown.self="handleColumnClick(column)"
@mousedown="handleColumnClick(column)"
@dblclick.stop="handleDblClick(table, column)"
:ref="
(el) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import { useMainStore } from "../../store/MainStore";
import AppModal from "./AppModal.vue";
import IconsUse from "../../icons/IconsUse.vue";
import AppDynamicPreviewModal from "./AppDynamicPreviewModal.vue";
import { getFormattedValue } from "../../utils";
const MainStore = useMainStore();
const props = defineProps({
openDynamicModal: {
Expand Down Expand Up @@ -215,15 +216,21 @@ const parentFieldWatcher = watch(
onMounted(() => {
if (props.openDynamicModal) {
fieldnames.value = props.openDynamicModal.dynamicContent;
fieldnames.value = props.openDynamicModal.dynamicContent || [];
selectedDoctypeLabel.value = MainStore.doctype;
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;
}
fieldnames.value.forEach(async (field) => {
let rowValue = null;
if (props.table) {
rowValue = MainStore.docData[props.table.fieldname][0];
field.value = await getFormattedValue(field, rowValue);
} else {
field.value = await getFormattedValue(field, null);
}
});
}
});
Expand Down Expand Up @@ -270,28 +277,11 @@ const selectField = async (field, fieldtype) => {
});
if (isRemoved) return;
let index = fieldnames.value.length;
let value = previewRef.value.parentField
? await getValue(
doctype.value,
MainStore.docData[previewRef.value.parentField],
field.fieldname
)
: props.table
? MainStore.docData[props.table.fieldname]?.length &&
typeof MainStore.docData[props.table.fieldname][0][field.fieldname] != "undefined"
? frappe.format(
MainStore.docData[props.table.fieldname][0][field.fieldname],
{ fieldtype: field.fieldtype, options: field.options },
{ inline: true },
MainStore.docData
)
: `{{ ${field.fieldname} }}`
: frappe.format(
MainStore.docData[field.fieldname],
{ fieldtype: field.fieldtype, options: field.options },
{ inline: true },
MainStore.docData
);
let rowValue = null;
if (props.table) {
rowValue = MainStore.docData[props.table.fieldname][0];
}
let value = await getFormattedValue(field, rowValue);
if (!value) {
if (["Image, Attach Image"].indexOf(field.fieldtype) != -1) {
value = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ onUnmounted(() => {
</style>
<style lang="scss" scoped>
.modal-dialog {
--primary: #6f5f35;
--primary-color: #6f5f35;
--primary: #7b4b57;
--primary-color: #7b4b57;
display: flex;
font-size: 0.75rem;
position: absolute;
Expand Down
3 changes: 2 additions & 1 deletion print_designer/public/js/print_designer/store/MainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export const useMainStore = defineStore("MainStore", {
fieldtype: "Int",
label: "No",
options: undefined,
table: selectedTable,
},
];
}
Expand Down Expand Up @@ -468,7 +469,7 @@ export const useMainStore = defineStore("MainStore", {
) {
return object.selectedDynamicText?.[styleEditMode][propertyName];
}
if (state.isValidValue(object.selectedColumn?.["style"][propertyName])) {
if (state.isValidValue(object.selectedColumn?.["style"]?.[propertyName])) {
return object.selectedColumn?.["style"][propertyName];
}
if (state.isValidValue(object[styleEditMode][propertyName])) {
Expand Down
Loading

0 comments on commit 074e411

Please sign in to comment.