-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6040 from usu/feat/checklist-print-react
feat(print): render checklists in react pdf
- Loading branch information
Showing
3 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<template> | ||
<View class="content-node"> | ||
<InstanceName :content-node="contentNode" /> | ||
|
||
<View v-for="entry in checklistsWithItems" class="checklist"> | ||
<Text class="checklist-title">{{ entry.checklist.name }}</Text> | ||
<View v-for="item in entry.items" class="checklist-item"> | ||
<View class="checklist-item-column checklist-item-column-1"> | ||
<Text>{{ item.number }}</Text> | ||
</View> | ||
<View class="checklist-item-column checklist-item-column-2"> | ||
<Text>{{ item.text }}</Text> | ||
</View> | ||
</View> | ||
</View> | ||
</View> | ||
</template> | ||
|
||
<script setup> | ||
import uniqWith from 'lodash/uniqWith.js' | ||
import sortBy from 'lodash/sortBy.js' | ||
const props = defineProps({ | ||
contentNode: { type: Object, required: true }, | ||
}) | ||
function calculateItemNumber(item) { | ||
if (!item.parent) { | ||
return item.position + 1 | ||
} | ||
return calculateItemNumber(item.parent()) + '.' + (item.position + 1) | ||
} | ||
const items = props.contentNode.checklistItems().items.map((item) => { | ||
const number = calculateItemNumber(item) | ||
return { | ||
...item, | ||
number, | ||
} | ||
}) | ||
const checklists = uniqWith( | ||
props.contentNode | ||
.checklistItems() | ||
.items.map((checklistItem) => checklistItem.checklist()), | ||
function (checklist1, checklist2) { | ||
return checklist1._meta.self === checklist2._meta.self | ||
} | ||
) | ||
const checklistsWithItems = checklists.map((checklist) => ({ | ||
checklist, | ||
items: sortBy( | ||
items.filter((item) => item.checklist()._meta.self === checklist._meta.self), | ||
'number' | ||
), | ||
})) | ||
</script> | ||
|
||
<script> | ||
import PdfComponent from '@/PdfComponent.js' | ||
import InstanceName from '../InstanceName.vue' | ||
export default { | ||
name: 'Checklist', | ||
components: { InstanceName }, | ||
extends: PdfComponent, | ||
} | ||
</script> | ||
<pdf-style> | ||
.checklist { | ||
display: flex; | ||
flex-direction: column; | ||
margin-bottom:8pt; | ||
} | ||
.checklist-title{ | ||
font-weight:bold; | ||
margin-bottom:3pt; | ||
margin-top:2pt; | ||
} | ||
.checklist-item { | ||
display: flex; | ||
flex-direction: row; | ||
padding-bottom:5pt; | ||
} | ||
.checklist-item-column { | ||
flex-grow: 1; | ||
} | ||
.checklist-item-column-1 { | ||
flex-basis: 300pt; | ||
padding-right: 2pt; | ||
font-variant-numeric: tabular-nums; | ||
} | ||
.checklist-item-column-2 { | ||
flex-basis: 9700pt; | ||
padding-left: 2pt; | ||
} | ||
</pdf-style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters