Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added color of certificate element #438

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/certificate_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def certificate_template_params
id
align
certificate_template_font_id
color
character_spacing
font_size
template
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/pdf_exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ def text_blocks(certificate, certificate_template)
text_box_options: {
character_spacing: entry.character_spacing,
size: entry.font_size,
color: format_color(entry.color),
at: [entry.x, entry.y],
align: entry.align.to_sym
}
}
end
end

def format_color(color)
color.start_with?('#') ? color.slice(1, color.length - 1) : color
end

def image_blocks(certificate_template)
certificate_template.certificate_template_images.includes(:signature).map do |image|
{
Expand Down
6 changes: 6 additions & 0 deletions app/inputs/color_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ColorInput < SimpleForm::Inputs::Base
def input(wrapper_options)
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
@builder.text_field(attribute_name, merged_input_options.merge(type: 'color'))
end
end
6 changes: 6 additions & 0 deletions app/models/certificate_template_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class CertificateTemplateEntry < ApplicationRecord

enum align: %i[center left right justify].freeze

HEX_COLOR_REGEX = /\A#(?:[0-9a-fA-F]{3}){1,2}\z/.freeze

validates :align,
:certificate_template_font,
:character_spacing,
Expand All @@ -13,5 +15,9 @@ class CertificateTemplateEntry < ApplicationRecord
:y,
presence: true

validates :color,
presence: true,
format: { with: HEX_COLOR_REGEX }

has_paper_trail
end
3 changes: 2 additions & 1 deletion app/views/certificate_templates/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
= simple_nested_form_for @certificate_template do |f|
= render 'shared/error_messages', object: f.object

.form-inputs
= f.input :title
= f.input :file, wrapper: :vertical_file_input, as: :file
= f.association :institution, include_blank: false
= f.input :program_type, collection: CertificateTemplate.program_types.keys, include_blank: false


- if f.object.file.present?
.embed-responsive.embed-responsive-4by3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
.row
.col-xs-12
= e.input :template
.col-xs-12
.col-xs-10
= e.association :certificate_template_font
.col-xs-2
= e.input :color, as: :color

.row
.col-xs-6
Expand Down
1 change: 1 addition & 0 deletions app/views/pdf_exports/certificate.pdf.prawn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ prawn_document(size: 'A4', page_layout: :landscape, template: @template_path) do
case block[:type]
when :text_block
pdf.font(block[:font])
pdf.fill_color(block[:text_box_options][:color])
pdf.text_box(block[:text], block[:text_box_options])
when :image_block
pdf.rotate(block[:angle], origin: block[:rotation_origin]) do
Expand Down
2 changes: 2 additions & 0 deletions config/locales/active_record.ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ru:
certificate_template_entries:
align: 'Выравнивание элемента шаблона'
certificate_template_font: 'Шрифт элемента шаблона'
color: 'Цвет элемента шаблона'
character_spacing: 'Межсимвольный интервал элемента шаблона'
font_size: 'Размер шрифта элемента шаблона'
template: 'Текст элемента шаблона'
Expand All @@ -28,6 +29,7 @@ ru:
certificate_template_entry:
align: 'Выравнивание'
certificate_template_font: 'Шрифт'
color: 'Цвет'
character_spacing: 'Межсимвольный интервал'
font_size: 'Размер шрифта'
template: 'Текст элемента'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/active_record.uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ uk:
certificate_template_entries:
align: 'Вирівнювання елементу шаблону'
certificate_template_font: 'Шрифт елементу шаблону'
color: 'Колір елементу шаблону'
character_spacing: 'Міжсимвольний інтервал елементу шаблону'
font_size: 'Розмір шрифту елементу шаблону'
template: 'Текст елементу шаблону'
Expand All @@ -28,6 +29,7 @@ uk:
certificate_template_entry:
align: 'Вирівнювання'
certificate_template_font: 'Шрифт'
color: 'Колір'
character_spacing: 'Міжсимвольний інтервал'
font_size: 'Розмір шрифту'
template: 'Текст елементу'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddColorToCertificateTemplateEntries < ActiveRecord::Migration[5.0]
def change
add_column :certificate_template_entries, :color, :string, default: "#000000", null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20231231091716) do
ActiveRecord::Schema.define(version: 20241126112155) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -72,6 +72,7 @@
t.integer "align", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "color"
t.index ["certificate_template_font_id"], name: "index_certificate_template_entries_on_font_id", using: :btree
t.index ["certificate_template_id"], name: "index_certificate_template_entries_on_template_id", using: :btree
end
Expand Down
7 changes: 5 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ CREATE TABLE public.certificate_template_entries (
font_size integer DEFAULT 16,
align integer DEFAULT 0,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
updated_at timestamp without time zone NOT NULL,
color character varying
);


Expand Down Expand Up @@ -2145,6 +2146,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230306054610'),
('20231225134459'),
('20231225144737'),
('20231231091716');
('20231231091716'),
('20241125123456'),
('20241126112155');


23 changes: 22 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ services:
ports:
- 6379:6379
command: redis-server --appendonly yes
depends_on:
- postgres

app:
build:
context: '.'
context: "."
dockerfile: docker/akadem_students/Dockerfile
target: development
ports:
Expand All @@ -41,10 +43,29 @@ services:
RAILS_ENV: development
entrypoint: /home/app/students_crm/bin/start_dev.sh

pgadmin:
container_name: pgadmin
image: dpage/pgadmin4:6.12
depends_on:
- postgres
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
PGADMIN_CONFIG_SERVER_MODE: "False"
volumes:
- pgadmin-data:/var/lib/pgadmin
ports:
- 80:80
restart: unless-stopped
env_file:
- path: .env
required: true

volumes:
assets-javascript-generated:
bundle:
client-node-modules:
node-modules:
postgres-data:
redis-data:
pgadmin-data:
Loading