code improvements

pull/150/merge^2
iozeey 2 years ago
parent b65bf49da0
commit 6d27609427

@ -7,7 +7,7 @@ module Api
def create
record = if params[:template_slug].present?
Template.find_by(slug: params[:template_slug])
Template.find_by!(slug: params[:template_slug])
else
Submitter.find_by!(slug: params[:submitter_slug])
end

@ -26,7 +26,7 @@ module Api
def del_image
template = Template.find(params[:template_id])
document = template.documents.find(params[:documentId])
document = template.documents.find(params[:document_id])
img_attachment_id = params[:attachment_id]
page_number = document.preview_images.find_index { |pic| pic.id == img_attachment_id }
if page_number

@ -733,7 +733,7 @@ export default {
stepPromise().then(async () => {
const emptyRequiredField = this.stepFields.find((fields, index) => {
if (['redact', 'my_text', 'my_signature', 'my_initials', 'my_date', 'my_check'].includes(fields[0].type)) {
if (['redact', 'my_text', 'my_signature', 'my_initials', 'my_date', 'my_check'].includes(fields[0]?.type)) {
fields[0].required = 'false'
return false
} else {

@ -564,7 +564,7 @@ export default {
}
},
scrollIntoDocument (item, page) {
const documentRef = this.documentRefs.find((e) => e.document.uuid === item.attachment_uuid)
const documentRef = this.documentRefs.find((e) => e.document?.uuid === item.attachment_uuid)
documentRef.scrollIntoDocument(page)
},
onKeyUp (e) {
@ -942,7 +942,7 @@ export default {
body: JSON.stringify({
template: this.template.id,
attachment_id: imageId,
documentId
document_id: documentId
})
})
.then((response) => {

@ -111,7 +111,7 @@ export default {
this.pageRefs[area.page].areaRefs.find((e) => e.area === area).$el.scrollIntoView({ behavior: 'smooth', block: 'center' })
},
scrollIntoDocument (page) {
const ref = this.pageRefs.find((e) => e.image.uuid === page.uuid)
const ref = this.pageRefs.find((e) => e.image?.uuid === page.uuid)
ref.$el.scrollIntoView({ behavior: 'smooth', block: 'start' })
},
setPageRefs (el) {

@ -57,7 +57,7 @@
</span>
</span>
<button
v-if="submitters.length > 1 && editable && submitter.name !== 'Me'"
v-if="submitters?.length > 1 && editable && submitter.name !== 'Me'"
class="px-2"
@click.stop="remove(submitter)"
>
@ -65,7 +65,7 @@
</button>
</a>
</li>
<li v-if="submitters.length < 11 && editable">
<li v-if="submitters?.length < 11 && editable">
<a
href="#"
class="flex px-2"
@ -76,7 +76,7 @@
:stroke-width="1.6"
/>
<span class="py-1">
Add {{ names[submitters.length] }}
Add {{ names[submitters?.length] }}
</span>
</a>
</li>
@ -157,7 +157,7 @@
</span>
</span>
<button
v-if="!compact && submitters.length > 1 && editable && submitter.name !== 'Me'"
v-if="!compact && submitters?.length > 1 && editable && submitter.name !== 'Me'"
class="hidden group-hover:block px-2"
@click.stop="remove(submitter)"
>
@ -165,7 +165,7 @@
</button>
</a>
</li>
<li v-if="submitters.length < 11 && editable">
<li v-if="submitters?.length < 11 && editable">
<a
href="#"
class="flex px-2"
@ -176,7 +176,7 @@
:stroke-width="1.6"
/>
<span class="py-1">
Add {{ names[submitters.length] }}
Add {{ names[submitters?.length] }}
</span>
</a>
</li>
@ -288,13 +288,13 @@ export default {
if (window.confirm('Are you sure?')) {
this.$emit('remove', submitter)
}
if (this.submitters.length === 1) {
if (this.submitters?.length === 1) {
this.$emit('add-prefills', this.submitters[0].name)
}
},
addSubmitter () {
const newSubmitter = {
name: this.names[this.submitters.length],
name: this.names[this.submitters?.length],
uuid: v4()
}

@ -86,7 +86,7 @@
>
<img
v-if="modelValue || computedPreviousValue"
:src="attachmentsIndex[modelValue || computedPreviousValue].url"
:src="attachmentsIndex[modelValue || computedPreviousValue]?.url"
class="mx-auto bg-white border border-base-300 rounded max-h-72 w-full"
>
<canvas
@ -184,8 +184,8 @@ export default {
async mounted () {
this.$nextTick(() => {
if (this.$refs.canvas) {
this.$refs.canvas.width = this.$refs.canvas.parentNode.clientWidth
this.$refs.canvas.height = this.$refs.canvas.parentNode.clientWidth / 3
this.$refs.canvas.width = this.$refs.canvas?.parentNode?.clientWidth
this.$refs.canvas.height = this.$refs.canvas?.parentNode?.clientWidth / 3
}
})

@ -59,9 +59,8 @@ module Submissions
layouter = HexaPDF::Layout::TextLayouter.new(valign: :center, font: pdf.fonts.add(FONT_NAME), font_size:)
value = submitter.values[field['uuid']] || template.values[field['uuid']]
if !field['type']=='redact'
if !field['type'].in?(%w[redact my_check])
value = submitter.values[field['uuid']] || template.values[field['uuid']]
next if Array.wrap(value).compact_blank.blank?
end

@ -219,31 +219,6 @@ module Templates
ensure
File.delete(temp_file_path) if File.exist?(temp_file_path)
end
# def generate_blank_image
# # here height and width should be equal to height and width from existing pdf pages
# height = 2000
# width = MAX_WIDTH
# Vips::Image.new_from_array([[255]* width] * height, 255)
# end
# # def create_blob_from_image(image, attachment)
# def create_image_blob(image, attachment)
# begin
# previews_count = attachment.preview_images.count
# ActiveStorage::Attachment.create!(
# blob: ActiveStorage::Blob.create_and_upload!(
# io: StringIO.new(image.write_to_buffer(FORMAT, Q: Q, interlace: true)),
# filename: "#{previews_count}#{FORMAT}",
# metadata: { analyzed: true, identified: true, width: image.width, height: image.height }
# ),
# name: ATTACHMENT_NAME,
# record: attachment
# )
# rescue => e
# Rails.logger.error("Error creating blob from image: #{e.message}")
# end
# end
end
end

Loading…
Cancel
Save