2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

incr: add editor modal

- remove show hint button
This commit is contained in:
18alantom 2023-02-24 13:28:03 +05:30
parent c04098a3eb
commit c3dae8cce2

View File

@ -59,7 +59,7 @@
" "
> >
<!-- Print Template Fields --> <!-- Print Template Fields -->
<div class="p-4 flex flex-col gap-4"> <div class="p-4 flex flex-col gap-4 sticky top-0 bg-white border-b">
<FormControl <FormControl
class="w-full mx-auto" class="w-full mx-auto"
size="small" size="small"
@ -73,7 +73,7 @@
</div> </div>
<!-- Controls Section --> <!-- Controls Section -->
<div class="p-4 border-t"> <div class="p-4">
<div <div
class="flex justify-between items-center cursor-pointer select-none" class="flex justify-between items-center cursor-pointer select-none"
:class="helpersCollapsed ? '' : 'mb-4'" :class="helpersCollapsed ? '' : 'mb-4'"
@ -143,32 +143,39 @@
</div> </div>
<!-- Template Editor --> <!-- Template Editor -->
<textarea <div class="mt-4 relative">
v-if="!templateCollapsed" <textarea
style=" v-if="!templateCollapsed"
font-family: monospace; style="
white-space: pre; font-family: monospace;
overflow-wrap: normal; white-space: pre;
" overflow-wrap: normal;
:value="doc.template ?? ''" "
:spellcheck="false" :value="doc.template ?? ''"
rows="20" :spellcheck="false"
class=" rows="10"
overflow-auto class="
mt-4 overflow-auto
p-2 p-2
w-full w-full
border border
rounded rounded
text-sm text-gray-900 text-sm text-gray-900
focus-within:bg-gray-100 focus-within:bg-gray-100
outline-none outline-none
bg-gray-50 bg-gray-50
" "
@change=" @change="
async (e: Event) => await doc?.set('template', (e.target as HTMLTextAreaElement).value) async (e: Event) => await doc?.set('template', (e.target as HTMLTextAreaElement).value)
" "
/> />
<button
class="bg-gray-200 p-0.5 rounded absolute bottom-4 left-2"
@click="showEditor = true"
>
<feather-icon name="maximize" class="h-4 w-4 text-gray-600" />
</button>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -191,6 +198,47 @@
</div> </div>
</div> </div>
</Modal> </Modal>
<!-- Editor Modal -->
<Modal
v-if="doc"
@closemodal="() => (showEditor = false)"
:open-modal="showEditor"
>
<div>
<!-- Hint Modal Header -->
<FormHeader :form-title="t`Template Editor`" />
<hr />
<div class="p-4">
<textarea
v-if="!templateCollapsed"
style="
font-family: monospace;
white-space: pre;
overflow-wrap: normal;
resize: both;
"
:value="doc.template ?? ''"
:spellcheck="false"
cols="74"
rows="30"
class="
overflow-auto
p-2
border
rounded
text-sm text-gray-900
focus-within:bg-gray-100
outline-none
bg-gray-50
"
@change="
async (e: Event) => await doc?.set('template', (e.target as HTMLTextAreaElement).value)
"
></textarea>
</div>
</div>
</Modal>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -236,6 +284,7 @@ export default defineComponent({
return { return {
doc: null, doc: null,
showHint: false, showHint: false,
showEditor: false,
hint: null, hint: null,
values: null, values: null,
templateCollapsed: false, templateCollapsed: false,
@ -246,6 +295,7 @@ export default defineComponent({
hint: null | Record<string, unknown>; hint: null | Record<string, unknown>;
values: null | Record<string, unknown>; values: null | Record<string, unknown>;
doc: PrintTemplate | null; doc: PrintTemplate | null;
showEditor: boolean;
showHint: boolean; showHint: boolean;
displayDoc: PrintTemplate | null; displayDoc: PrintTemplate | null;
templateCollapsed: boolean; templateCollapsed: boolean;
@ -263,8 +313,9 @@ export default defineComponent({
if (this.fyo.store.isDevelopment) { if (this.fyo.store.isDevelopment) {
// @ts-ignore // @ts-ignore
window.tb = this; window.tb = this;
this.setDisplayDoc('SINV-1001');
} }
await this.setInitialDoc();
}, },
methods: { methods: {
async makePDF() { async makePDF() {
@ -281,6 +332,26 @@ export default defineComponent({
await getPathAndMakePDF(displayDoc.name!, innerHTML); await getPathAndMakePDF(displayDoc.name!, innerHTML);
}, },
async setInitialDoc() {
const schemaName = this.doc?.type;
if (!schemaName || this.displayDoc?.schemaName === schemaName) {
return;
}
const names = (await this.fyo.db.getAll(schemaName, {
limit: 1,
order: 'desc',
orderBy: 'created',
filters: { cancelled: false },
})) as { name: string }[];
const name = names[0]?.name;
if (!name) {
return;
}
await this.setDisplayDoc(name);
},
async sync() { async sync() {
const doc = this.doc; const doc = this.doc;
if (!doc) { if (!doc) {
@ -319,6 +390,7 @@ export default defineComponent({
if (!schemaName) { if (!schemaName) {
return; return;
} }
const displayDoc = await getDocFromNameIfExistsElseNew(schemaName, value); const displayDoc = await getDocFromNameIfExistsElseNew(schemaName, value);
this.hint = getPrintTemplatePropHints(displayDoc); this.hint = getPrintTemplatePropHints(displayDoc);
this.values = await getPrintTemplatePropValues(displayDoc); this.values = await getPrintTemplatePropValues(displayDoc);