Skip to content

Commit

Permalink
Merge from docusealco/wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBTurchyn authored Dec 30, 2024
2 parents ac9a5c9 + 2a240ce commit cc218fc
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
ruby-version: 3.4.1
- name: Cache gems
uses: actions/cache@v1
with:
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
ruby-version: 3.4.1
- name: Cache gems
uses: actions/cache@v1
with:
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.4
ruby-version: 3.4.1
- name: Set up Node
uses: actions/setup-node@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM ruby:3.3.4-alpine as fonts
FROM ruby:3.4.1-alpine as fonts

WORKDIR /fonts

RUN apk --no-cache add fontforge wget && wget https://github.com/satbyy/go-noto-universal/releases/download/v7.0/GoNotoKurrent-Regular.ttf && wget https://github.com/satbyy/go-noto-universal/releases/download/v7.0/GoNotoKurrent-Bold.ttf && wget https://github.com/impallari/DancingScript/raw/master/fonts/DancingScript-Regular.otf && wget https://cdn.jsdelivr.net/gh/notofonts/notofonts.github.io/fonts/NotoSansSymbols2/hinted/ttf/NotoSansSymbols2-Regular.ttf && wget https://github.com/Maxattax97/gnu-freefont/raw/master/ttf/FreeSans.ttf && wget https://github.com/impallari/DancingScript/raw/master/OFL.txt

RUN fontforge -lang=py -c 'font1 = fontforge.open("FreeSans.ttf"); font2 = fontforge.open("NotoSansSymbols2-Regular.ttf"); font1.mergeFonts(font2); font1.generate("FreeSans.ttf")'

FROM ruby:3.3.4-alpine as webpack
FROM ruby:3.4.1-alpine as webpack

ENV RAILS_ENV=production
ENV NODE_ENV=production
Expand All @@ -32,7 +32,7 @@ COPY ./app/views ./app/views

RUN echo "gem 'shakapacker'" > Gemfile && ./bin/shakapacker

FROM ruby:3.3.4-alpine as app
FROM ruby:3.4.1-alpine as app

ENV RAILS_ENV=production
ENV BUNDLE_WITHOUT="development:test"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source 'https://rubygems.org'

ruby '3.3.4'
ruby '3.4.1'

gem 'arabic-letter-connector', require: 'arabic-letter-connector/logic'
gem 'aws-sdk-s3', require: false
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ DEPENDENCIES
webmock

RUBY VERSION
ruby 3.3.4p94
ruby 3.4.1p0

BUNDLED WITH
2.5.3
2 changes: 1 addition & 1 deletion app/controllers/api/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def submissions_params
key = params.key?(:submission) ? :submission : :submissions

params.permit(
key => [permitted_attrs]
{ key => [permitted_attrs] }, { key => permitted_attrs }
).fetch(key, [])
end
end
Expand Down
31 changes: 29 additions & 2 deletions app/javascript/template_builder/area.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div
class="absolute overflow-visible group"
:style="positionStyle"
:class="{ 'z-[1]': isMoved || isDragged }"
@pointerdown.stop
@mousedown="startMouseMove"
@touchstart="startTouchDrag"
Expand Down Expand Up @@ -316,6 +317,11 @@ export default {
required: false,
default: false
},
maxPage: {
type: Number,
required: false,
default: null
},
defaultField: {
type: Object,
required: false,
Expand Down Expand Up @@ -720,12 +726,18 @@ export default {
const rect = page.getBoundingClientRect()
this.area.x = Math.min(Math.max((this.dragFrom.x + e.touches[0].clientX - rect.left) / rect.width, 0), 1 - this.area.w)
this.area.y = Math.min(Math.max((this.dragFrom.y + e.touches[0].clientY - rect.top) / rect.height, 0), 1 - this.area.h)
this.area.y = (this.dragFrom.y + e.touches[0].clientY - rect.top) / rect.height
if ((this.area.page === 0 && this.area.y < 0) || (this.area.page === this.maxPage && this.area.y > 1 - this.area.h)) {
this.area.y = Math.min(Math.max(this.area.y, 0), 1 - this.area.h)
}
},
stopTouchDrag () {
this.$el.getRootNode().removeEventListener('touchmove', this.touchDrag)
this.$el.getRootNode().removeEventListener('touchend', this.stopTouchDrag)
this.maybeChangeAreaPage(this.area)
if (this.isDragged) {
this.save()
}
Expand Down Expand Up @@ -773,12 +785,18 @@ export default {
const rect = page.getBoundingClientRect()
this.area.x = Math.min(Math.max((this.dragFrom.x + e.clientX - rect.left) / rect.width, 0), 1 - this.area.w)
this.area.y = Math.min(Math.max((this.dragFrom.y + e.clientY - rect.top) / rect.height, 0), 1 - this.area.h)
this.area.y = (this.dragFrom.y + e.clientY - rect.top) / rect.height
if ((this.area.page === 0 && this.area.y < 0) || (this.area.page === this.maxPage && this.area.y > 1 - this.area.h)) {
this.area.y = Math.min(Math.max(this.area.y, 0), 1 - this.area.h)
}
},
stopMouseMove (e) {
this.$el.getRootNode().removeEventListener('mousemove', this.mouseMove)
this.$el.getRootNode().removeEventListener('mouseup', this.stopMouseMove)
this.maybeChangeAreaPage(this.area)
if (this.isMoved) {
this.save()
}
Expand All @@ -788,6 +806,15 @@ export default {
this.$emit('stop-drag')
},
maybeChangeAreaPage (area) {
if (area.y < -(area.h / 2)) {
area.page -= 1
area.y = 1 + area.y + (16.0 / this.$parent.$refs.mask.previousSibling.offsetHeight)
} else if (area.y > 1 - (area.h / 2)) {
area.page += 1
area.y = area.y - 1 - (16.0 / this.$parent.$refs.mask.previousSibling.offsetHeight)
}
},
stopDrag () {
this.$el.getRootNode().removeEventListener('mousemove', this.drag)
this.$el.getRootNode().removeEventListener('mouseup', this.stopDrag)
Expand Down
1 change: 1 addition & 0 deletions app/javascript/template_builder/document.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:draw-field="drawField"
:draw-field-type="drawFieldType"
:selected-submitter="selectedSubmitter"
:total-pages="sortedPreviewImages.length"
:image="image"
@drop-field="$emit('drop-field', {...$event, attachment_uuid: document.uuid })"
@remove-area="$emit('remove-area', $event)"
Expand Down
5 changes: 5 additions & 0 deletions app/javascript/template_builder/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
:with-field-placeholder="withFieldPlaceholder"
:default-field="defaultFields.find((f) => f.name === item.field.name)"
:default-submitters="defaultSubmitters"
:max-page="totalPages - 1"
@start-resize="resizeDirection = $event"
@stop-resize="resizeDirection = null"
@remove="$emit('remove-area', item.area)"
Expand Down Expand Up @@ -88,6 +89,10 @@ export default {
required: false,
default: false
},
totalPages: {
type: Number,
required: true
},
drawFieldType: {
type: String,
required: false,
Expand Down
4 changes: 2 additions & 2 deletions lib/submissions/generate_preview_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def call(submission, values_hash: nil, submitter: nil)
submission.submitters.where(completed_at: nil)
end

submitters.preload(attachments_attachments: :blob).each do |s|
submitters.preload(attachments_attachments: :blob).each_with_index do |s, index|
GenerateResultAttachments.fill_submitter_fields(s, submission.account, pdfs_index,
with_signature_id:, is_flatten:)
with_signature_id:, is_flatten:, with_headings: index.zero?)
end

template = submission.template
Expand Down
8 changes: 6 additions & 2 deletions lib/submissions/generate_result_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,18 @@ def generate_pdfs(submitter)
fill_submitter_fields(submitter, submitter.account, pdfs_index, with_signature_id:, is_flatten:)
end

def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is_flatten:)
def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is_flatten:, with_headings: nil)
cell_layouter = HexaPDF::Layout::TextLayouter.new(text_valign: :center, text_align: :center)

attachments_data_cache = {}

return pdfs_index if submitter.submission.template_fields.blank?

with_headings = find_last_submitter(submitter.submission, submitter:).blank? if with_headings.nil?

submitter.submission.template_fields.each do |field|
next if field['submitter_uuid'] != submitter.uuid
next if field['type'] == 'heading' && !with_headings
next if field['submitter_uuid'] != submitter.uuid && field['type'] != 'heading'

field.fetch('areas', []).each do |area|
pdf = pdfs_index[area['attachment_uuid']]
Expand Down Expand Up @@ -188,6 +191,7 @@ def fill_submitter_fields(submitter, account, pdfs_index, with_signature_id:, is
font = pdf.fonts.add(field.dig('preferences', 'font').presence || FONT_NAME)

value = submitter.values[field['uuid']]
value = field['default_value'] if field['type'] == 'heading'

text_align = field.dig('preferences', 'align').to_s.to_sym.presence ||
(value.to_s.match?(RTL_REGEXP) ? :right : :left)
Expand Down
2 changes: 1 addition & 1 deletion spec/signing_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def draw_canvas
ctx.lineTo(150, 150);
ctx.stroke();
JS
sleep 1
sleep 0.5
end

def field_value(submitter, field_name)
Expand Down
2 changes: 1 addition & 1 deletion spec/system/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

expect do
click_button 'Submit'
sleep 2
page.driver.wait_for_network_idle
end.to change(Account, :count).by(1).and change(User, :count).by(1).and change(EncryptedConfig, :count).by(2)

user = User.last
Expand Down

0 comments on commit cc218fc

Please sign in to comment.