code improvements

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

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

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

@ -733,7 +733,7 @@ export default {
stepPromise().then(async () => { stepPromise().then(async () => {
const emptyRequiredField = this.stepFields.find((fields, index) => { 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' fields[0].required = 'false'
return false return false
} else { } else {

@ -564,7 +564,7 @@ export default {
} }
}, },
scrollIntoDocument (item, page) { 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) documentRef.scrollIntoDocument(page)
}, },
onKeyUp (e) { onKeyUp (e) {
@ -942,7 +942,7 @@ export default {
body: JSON.stringify({ body: JSON.stringify({
template: this.template.id, template: this.template.id,
attachment_id: imageId, attachment_id: imageId,
documentId document_id: documentId
}) })
}) })
.then((response) => { .then((response) => {

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

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

@ -86,7 +86,7 @@
> >
<img <img
v-if="modelValue || computedPreviousValue" 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" class="mx-auto bg-white border border-base-300 rounded max-h-72 w-full"
> >
<canvas <canvas
@ -184,8 +184,8 @@ export default {
async mounted () { async mounted () {
this.$nextTick(() => { this.$nextTick(() => {
if (this.$refs.canvas) { if (this.$refs.canvas) {
this.$refs.canvas.width = this.$refs.canvas.parentNode.clientWidth this.$refs.canvas.width = this.$refs.canvas?.parentNode?.clientWidth
this.$refs.canvas.height = this.$refs.canvas.parentNode.clientWidth / 3 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:) 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'].in?(%w[redact my_check])
value = submitter.values[field['uuid']] || template.values[field['uuid']]
if !field['type']=='redact'
next if Array.wrap(value).compact_blank.blank? next if Array.wrap(value).compact_blank.blank?
end end

@ -220,30 +220,5 @@ module Templates
File.delete(temp_file_path) if File.exist?(temp_file_path) File.delete(temp_file_path) if File.exist?(temp_file_path)
end 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
end end

Loading…
Cancel
Save