Skip to content

Commit

Permalink
feat: add print option in template builder
Browse files Browse the repository at this point in the history
  • Loading branch information
AbleKSaju committed Jan 14, 2025
1 parent 55606dc commit 960fd06
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/pages/PrintView/PrintView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
@change="onTemplateNameChange"
/>
<DropdownWithActions :actions="actions" :title="t`More`" />
<Button class="text-xs" type="primary" @click="savePDF">
<Button class="text-xs" type="primary" @click="savePDF()">
{{ t`Save as PDF` }}
</Button>
<Button class="text-xs" type="primary" @click="savePDF('print')">
{{ t`Print` }}
</Button>
</PageHeader>

<!-- Template Display Area -->
Expand Down Expand Up @@ -246,16 +249,16 @@ export default defineComponent({
this.templateList = list.map(({ name }) => name);
},
async savePDF() {
async savePDF(action?: 'print') {
const printContainer = this.$refs.printContainer as {
savePDF: (name?: string) => Promise<void>;
savePDF: (name?: string, action?: string) => Promise<void>;
};
if (!printContainer?.savePDF) {
return;
}
await printContainer.savePDF(this.doc?.name);
await printContainer.savePDF(this.doc?.name, action);
},
async setTemplateFromDefault() {
const defaultName =
Expand Down
5 changes: 3 additions & 2 deletions src/pages/TemplateBuilder/PrintContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default defineComponent({
getCodeFrame(loc: SourceLocation) {
return generateCodeFrame(this.template, loc.start.offset, loc.end.offset);
},
async savePDF(name?: string) {
async savePDF(name?: string, action?: 'print' | 'save') {
/* eslint-disable */
/**
Expand All @@ -193,7 +193,8 @@ export default defineComponent({
name ?? this.t`Entry`,
innerHTML,
this.width,
this.height
this.height,
action ?? 'save'
);
this.fyo.telemetry.log(Verb.Printed, this.printSchemaName);
Expand Down
11 changes: 7 additions & 4 deletions src/pages/TemplateBuilder/TemplateBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
@change="async (value) => await doc?.set('name', value)"
/>
</template>
<Button v-if="displayDoc && doc?.template" @click="savePDF">
<Button v-if="displayDoc && doc?.template" @click="savePDF()">
{{ t`Save as PDF` }}
</Button>
<Button v-if="displayDoc && doc?.template" @click="savePDF('print')">
{{ t`Print` }}
</Button>
<Button
v-if="doc && doc.isCustom && displayDoc"
:title="t`Toggle Edit Mode`"
Expand Down Expand Up @@ -636,16 +639,16 @@ export default defineComponent({
return Number(targetScale.toFixed(2));
},
savePDF() {
savePDF(action?: 'print') {
const printContainer = this.$refs.printContainer as {
savePDF: (name?: string) => void;
savePDF: (name?: string, action?:string) => void;
};
if (!printContainer?.savePDF) {
return;
}
printContainer.savePDF(this.displayDoc?.name);
printContainer.savePDF(this.doc?.name, action);
},
async setDisplayInitialDoc() {
const schemaName = this.doc?.type;
Expand Down

0 comments on commit 960fd06

Please sign in to comment.