mirror of
https://github.com/frappe/books.git
synced 2024-11-08 23:00:56 +00:00
fix(ux): show template on load
- show no entries message
This commit is contained in:
parent
7a22ab8946
commit
94f3425928
@ -42,24 +42,21 @@
|
|||||||
class="overflow-auto no-scrollbar flex flex-col"
|
class="overflow-auto no-scrollbar flex flex-col"
|
||||||
style="height: calc(100vh - var(--h-row-largest) - 1px)"
|
style="height: calc(100vh - var(--h-row-largest) - 1px)"
|
||||||
>
|
>
|
||||||
<!-- Display Hints -->
|
|
||||||
<p v-if="helperMessage" class="text-sm text-gray-700 p-4">
|
|
||||||
{{ helperMessage }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<!-- Template Container -->
|
<!-- Template Container -->
|
||||||
<div
|
<div v-if="canDisplayPreview" class="p-4 overflow-auto custom-scroll">
|
||||||
v-else-if="doc.template && values"
|
|
||||||
class="p-4 overflow-auto custom-scroll"
|
|
||||||
>
|
|
||||||
<PrintContainer
|
<PrintContainer
|
||||||
ref="printContainer"
|
ref="printContainer"
|
||||||
:template="doc.template"
|
:template="doc.template!"
|
||||||
:values="values"
|
:values="values!"
|
||||||
:scale="scale"
|
:scale="scale"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Display Hints -->
|
||||||
|
<p v-else-if="helperMessage" class="text-sm text-gray-700 p-4">
|
||||||
|
{{ helperMessage }}
|
||||||
|
</p>
|
||||||
|
|
||||||
<!-- Bottom Bar -->
|
<!-- Bottom Bar -->
|
||||||
<div
|
<div
|
||||||
class="
|
class="
|
||||||
@ -98,6 +95,7 @@
|
|||||||
|
|
||||||
<!-- Display Scale -->
|
<!-- Display Scale -->
|
||||||
<div
|
<div
|
||||||
|
v-if="canDisplayPreview"
|
||||||
class="flex ml-auto gap-2 px-2 w-36 justify-between flex-shrink-0"
|
class="flex ml-auto gap-2 px-2 w-36 justify-between flex-shrink-0"
|
||||||
>
|
>
|
||||||
<p class="text-sm text-gray-600 my-auto">{{ t`Display Scale` }}</p>
|
<p class="text-sm text-gray-600 my-auto">{{ t`Display Scale` }}</p>
|
||||||
@ -229,6 +227,7 @@ import {
|
|||||||
openSettings,
|
openSettings,
|
||||||
selectTextFile,
|
selectTextFile,
|
||||||
ShortcutKey,
|
ShortcutKey,
|
||||||
|
showMessageDialog,
|
||||||
showToast,
|
showToast,
|
||||||
} from 'src/utils/ui';
|
} from 'src/utils/ui';
|
||||||
import { Shortcuts } from 'src/utils/vueUtils';
|
import { Shortcuts } from 'src/utils/vueUtils';
|
||||||
@ -289,22 +288,14 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
await this.setDoc();
|
await this.initialize();
|
||||||
focusOrSelectFormControl(this.doc as Doc, this.$refs.nameField, false);
|
|
||||||
focusedDocsRef.add(this.doc);
|
focusedDocsRef.add(this.doc);
|
||||||
|
|
||||||
if (this.doc?.template == null) {
|
|
||||||
await this.doc?.set('template', baseTemplate);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.setDisplayInitialDoc();
|
|
||||||
|
|
||||||
if (this.fyo.store.isDevelopment) {
|
if (this.fyo.store.isDevelopment) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.tb = this;
|
window.tb = this;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
activated(): void {
|
async activated(): Promise<void> {
|
||||||
docsPathRef.value = docsPathMap.PrintTemplate ?? '';
|
docsPathRef.value = docsPathMap.PrintTemplate ?? '';
|
||||||
this.shortcuts.ctrl.set(['Enter'], this.setTemplate);
|
this.shortcuts.ctrl.set(['Enter'], this.setTemplate);
|
||||||
this.shortcuts.ctrl.set(['KeyE'], this.toggleEditMode);
|
this.shortcuts.ctrl.set(['KeyE'], this.toggleEditMode);
|
||||||
@ -324,6 +315,20 @@ export default defineComponent({
|
|||||||
this.shortcuts.ctrl.delete(['Minus']);
|
this.shortcuts.ctrl.delete(['Minus']);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async initialize() {
|
||||||
|
await this.setDoc();
|
||||||
|
if (this.doc?.type) {
|
||||||
|
this.hints = getPrintTemplatePropHints(this.doc.type, this.fyo);
|
||||||
|
}
|
||||||
|
|
||||||
|
focusOrSelectFormControl(this.doc as Doc, this.$refs.nameField, false);
|
||||||
|
|
||||||
|
if (!this.doc?.template) {
|
||||||
|
await this.doc?.set('template', baseTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.setDisplayInitialDoc();
|
||||||
|
},
|
||||||
getTemplateEditorState() {
|
getTemplateEditorState() {
|
||||||
const fallback = this.doc?.template ?? '';
|
const fallback = this.doc?.template ?? '';
|
||||||
|
|
||||||
@ -428,6 +433,13 @@ export default defineComponent({
|
|||||||
|
|
||||||
const name = names[0]?.name;
|
const name = names[0]?.name;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
|
const label = this.fyo.schemaMap[schemaName]?.label ?? schemaName;
|
||||||
|
await showMessageDialog({
|
||||||
|
message: this.t`No Display Entries Found`,
|
||||||
|
detail: this
|
||||||
|
.t`Please create a ${label} entry to view Template Preview`,
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,7 +489,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const displayDoc = await getDocFromNameIfExistsElseNew(schemaName, value);
|
const displayDoc = await getDocFromNameIfExistsElseNew(schemaName, value);
|
||||||
this.hints = getPrintTemplatePropHints(displayDoc);
|
this.hints = getPrintTemplatePropHints(schemaName, this.fyo);
|
||||||
this.values = await getPrintTemplatePropValues(displayDoc);
|
this.values = await getPrintTemplatePropValues(displayDoc);
|
||||||
this.displayDoc = displayDoc;
|
this.displayDoc = displayDoc;
|
||||||
},
|
},
|
||||||
@ -541,6 +553,17 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
canDisplayPreview(): boolean {
|
||||||
|
if (!this.displayDoc || !this.values) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.doc?.template) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
applyChangesShortcut() {
|
applyChangesShortcut() {
|
||||||
return [ShortcutKey.ctrl, ShortcutKey.enter];
|
return [ShortcutKey.ctrl, ShortcutKey.enter];
|
||||||
},
|
},
|
||||||
|
@ -60,21 +60,21 @@ export async function getPrintTemplatePropValues(
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPrintTemplatePropHints(doc: Doc) {
|
export function getPrintTemplatePropHints(schemaName: string, fyo: Fyo) {
|
||||||
const hints: PrintTemplateData = {};
|
const hints: PrintTemplateData = {};
|
||||||
const fyo = doc.fyo;
|
const schema = fyo.schemaMap[schemaName]!;
|
||||||
hints.doc = getPrintTemplateDocHints(doc.schema, doc.fyo);
|
hints.doc = getPrintTemplateDocHints(schema, fyo);
|
||||||
(hints.doc as PrintTemplateData).entryType = doc.fyo.t`Entry Type`;
|
(hints.doc as PrintTemplateData).entryType = fyo.t`Entry Type`;
|
||||||
(hints.doc as PrintTemplateData).entryLabel = doc.fyo.t`Entry Label`;
|
(hints.doc as PrintTemplateData).entryLabel = fyo.t`Entry Label`;
|
||||||
|
|
||||||
const printSettingsHints = getPrintTemplateDocHints(
|
const printSettingsHints = getPrintTemplateDocHints(
|
||||||
fyo.schemaMap[ModelNameEnum.PrintSettings]!,
|
fyo.schemaMap[ModelNameEnum.PrintSettings]!,
|
||||||
doc.fyo,
|
fyo,
|
||||||
printSettingsFields
|
printSettingsFields
|
||||||
);
|
);
|
||||||
const accountingSettingsHints = getPrintTemplateDocHints(
|
const accountingSettingsHints = getPrintTemplateDocHints(
|
||||||
fyo.schemaMap[ModelNameEnum.AccountingSettings]!,
|
fyo.schemaMap[ModelNameEnum.AccountingSettings]!,
|
||||||
doc.fyo,
|
fyo,
|
||||||
accountingSettingsFields
|
accountingSettingsFields
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ export function getPrintTemplatePropHints(doc: Doc) {
|
|||||||
...accountingSettingsHints,
|
...accountingSettingsHints,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (doc.schemaName?.endsWith('Invoice')) {
|
if (schemaName?.endsWith('Invoice')) {
|
||||||
(hints.doc as PrintTemplateData).totalDiscount = fyo.t`Total Discount`;
|
(hints.doc as PrintTemplateData).totalDiscount = fyo.t`Total Discount`;
|
||||||
(hints.doc as PrintTemplateData).showHSN = fyo.t`Show HSN`;
|
(hints.doc as PrintTemplateData).showHSN = fyo.t`Show HSN`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user