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

Export PDF des recommandations #357

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
Draft
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
54 changes: 40 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
FROM ruby:3.3.5-slim AS base
WORKDIR /app
RUN apt update -y && apt install -y \
build-essential \
ca-certificates \

# Install necessary dependencies
RUN apt-get update -y && \
apt-get install -y --no-install-recommends \
curl \
gnupg \
wget \
gnupg2 && \
curl -fsSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
curl -fsSL https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
apt-get update -y && \
apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
libpq-dev \
wkhtmltopdf \
imagemagick \
tzdata \
gnupg2 && \
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt update -y && apt install -y yarn && \
apt clean && \
rm -rf /var/lib/apt/lists/* && \
ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime && \
ln -sf /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf && \
chmod +x /usr/local/bin/wkhtmltopdf
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-freefont-ttf \
libxss1 \
yarn \
google-chrome-stable && \
ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime && \
ln -sf /usr/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf && \
chmod +x /usr/local/bin/wkhtmltopdf && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Add and set up dumb-init
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

# Environment variables for Puppeteer
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
GROVER_NO_SANDBOX=true

# Set entrypoint
ENTRYPOINT ["dumb-init", "--"]

FROM base AS dev
COPY . .
Expand All @@ -42,12 +65,15 @@ RUN bin/docker ${DB_ADAPTER:-postgres} && \
rm -rf node_modules && \
bundle config set --local without 'mysql thin test ci aws development build' && \
bundle install
RUN mkdir -p .ssl && \
openssl req -new -newkey rsa:2048 -sha1 -subj "/CN=`hostname`" -days 730 -nodes -x509 -keyout ./.ssl/cert.key -out ./.ssl/cert.crt

FROM base AS production
COPY . .
COPY --from=production-builder /app/public ./public
COPY --from=production-builder /app/config ./config
COPY --from=production-builder /usr/local/bundle /usr/local/bundle
COPY --from=production-builder /app/.ssl ./.ssl
EXPOSE 3000
RUN chmod a+x /app/bin/run
CMD [ "/app/bin/run" ]
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ group :development do
end

gem 'net-smtp'

# ======================#
# MADMP OPIDOR FEATURES #
# ===================== #
Expand All @@ -380,6 +379,7 @@ group :build do
gem 'activerecord-nulldb-adapter', git: 'https://github.com/taylorthurlow/nulldb',
branch: 'fix/activerecord72-register-adapter'
end
gem 'grover', '~> 1.1'

gem 'graphiql-rails', '~> 1.10'
gem 'graphql', '~> 2.3'
Expand Down
21 changes: 16 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ GEM
debug_inspector (>= 1.2.0)
bootsnap (1.18.4)
msgpack (~> 1.2)
brakeman (6.2.1)
brakeman (6.2.2)
racc
builder (3.3.0)
bullet (7.2.0)
Expand Down Expand Up @@ -141,6 +141,9 @@ GEM
open4 (~> 1.3)
coderay (1.1.3)
colored2 (3.1.2)
combine_pdf (1.0.26)
matrix
ruby-rc4 (>= 0.1.5)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
contact_us (1.2.0)
Expand All @@ -154,7 +157,8 @@ GEM
cssbundling-rails (1.4.1)
railties (>= 6.0.0)
csv (3.3.0)
danger (9.5.0)
danger (9.5.1)
base64 (~> 0.2)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
Expand All @@ -165,6 +169,7 @@ GEM
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.0)
octokit (>= 4.0)
pstore (~> 0.1)
terminal-table (>= 1, < 4)
database_cleaner (2.0.2)
database_cleaner-active_record (>= 2, < 3)
Expand Down Expand Up @@ -204,7 +209,7 @@ GEM
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faker (3.4.2)
faker (3.5.1)
i18n (>= 1.8.11, < 2)
faraday (2.12.0)
faraday-net_http (>= 2.0, < 3.4)
Expand Down Expand Up @@ -255,6 +260,9 @@ GEM
graphql (2.3.18)
base64
fiber-storage
grover (1.1.11)
combine_pdf (~> 1.0)
nokogiri (~> 1.0)
guard (2.18.1)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
Expand Down Expand Up @@ -419,6 +427,7 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pstore (0.1.3)
psych (5.1.2)
stringio
public_suffix (6.0.1)
Expand Down Expand Up @@ -513,7 +522,7 @@ GEM
rouge (4.4.0)
rspec-collection_matchers (1.2.1)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (3.13.1)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
Expand Down Expand Up @@ -554,6 +563,7 @@ GEM
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
ruby-rc4 (0.1.5)
ruby2_keywords (0.0.5)
ruby_dig (0.0.2)
rubyzip (2.3.2)
Expand Down Expand Up @@ -633,7 +643,7 @@ GEM
yard-tomdoc (0.7.1)
tomparse (>= 0.4.0)
yard
zeitwerk (2.7.0)
zeitwerk (2.7.1)

PLATFORMS
x86_64-linux
Expand Down Expand Up @@ -668,6 +678,7 @@ DEPENDENCIES
fuubar
graphiql-rails (~> 1.10)
graphql (~> 2.3)
grover (~> 1.1)
guard
htmltoword
httparty
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/dmpopidor/paginable/guidance_group_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Dmpopidor
module Paginable
# Customized code for Paginable GuidanceGroupsController
module GuidanceGroupsController
# GET /paginable/guidance_groups/publicly_visible/:page (AJAX)
# -----------------------------------------------------
def publicly_visible
# We want the pagination/sort/search to be retained in the URL so redirect instead
# of processing this as a JSON
paginable_params = params.permit(:page, :search, :sort_field, :sort_direction)
redirect_to public_guidance_groups_path(paginable_params.to_h)
end
end
end
end
33 changes: 33 additions & 0 deletions app/controllers/dmpopidor/public_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,39 @@ def template_index
.where(id: templates.uniq.flatten)
.unarchived.published.order('orgs.name asc').page(1)
end

def guidance_group_index
@guidance_groups_query_params = {
page: paginable_params.fetch(:page, 1),
search: paginable_params.fetch(:search, ''),
sort_field: paginable_params.fetch(:sort_field, 'guidance_groups.name'),
sort_direction: paginable_params.fetch(:sort_direction, 'asc')
}

guidance_groups = ::GuidanceGroup.where(published: true).pluck(:id)

@guidance_groups = ::GuidanceGroup.includes(:org)
.where(id: guidance_groups.uniq.flatten).order('orgs.name asc').page(1)
end

def guidance_group_export
@guidance_group = ::GuidanceGroup.includes(guidances: :themes).find(params[:id])
@guidances = @guidance_group.guidances.joins(:themes).all
@themes = ::Theme.all.order(:number)
@formatting = Settings::Template::DEFAULT_SETTINGS[:formatting]
html = render_to_string({
template: 'guidance_group_exports/guidance_group_export',
layout: false
})
file_name = @guidance_group.name.gsub(/[^a-zA-Z\d\s]/, '').tr(' ', '_')
respond_to do |format|
format.html do
pdf = Grover.new(html).to_pdf
send_data(pdf, disposition: 'inline', filename: "#{file_name}.pdf",
type: 'application/pdf')
end
end
end
# rubocop:enable Metrics/AbcSize
end
end
6 changes: 5 additions & 1 deletion app/controllers/paginable/themes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class ThemesController < ApplicationController
# /paginable/themes/index/:page
def index
authorize(Theme)
paginable_renderise(partial: 'index', scope: Theme.all, format: :json)
paginable_renderise(
partial: 'index',
query_params: { sort_field: 'themes.number', sort_direction: :asc },
scope: Theme.all,
format: :json)
end
end
end
12 changes: 11 additions & 1 deletion app/controllers/super_admin/themes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ThemesController < ApplicationController
def index
authorize(Theme)
@locales = Language.all
render(:index, locals: { themes: Theme.all.page(1) })
render(:index, locals: { themes: Theme.all.order(:number).page(1) })
end

def new
Expand Down Expand Up @@ -63,6 +63,16 @@ def destroy
render :edit
end
end


def sort
authorize(Theme)
params[:updated_order].each_with_index do |id, index|
::Theme.find(id).update(number: index + 1)
end
head :ok
end

# Private instance methods

private
Expand Down
26 changes: 26 additions & 0 deletions app/javascript/src/superAdmin/themes/newEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,30 @@ import { Tinymce } from '../../utils/tinymce.js';

$(() => {
Tinymce.init({ selector: '#theme_description' });

const sortableThemes = () => {
$('#themes').sortable({
items: '.theme',
handle: '.theme-actions .handle',
update: () => {
const updatedOrder = [];
$('#themes .theme').each(function callback() {
updatedOrder.push($(this).find('.handle').data('theme-id'));
});
$.ajax({
url: '/super_admin/themes/sort',
method: 'post',
data: {
updated_order: updatedOrder,
},
});
}
});
};

// Needs to re-apply sortable function after ajax paginable call
$('body').on('ajax:success',
'a.paginable-action[data-remote="true"]',
sortableThemes);
sortableThemes();
});
2 changes: 2 additions & 0 deletions app/models/guidance_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class GuidanceGroup < ApplicationRecord
# ================

belongs_to :org
belongs_to :language

belongs_to :language

Expand Down Expand Up @@ -130,6 +131,7 @@ def self.all_viewable(user)
def self.create_org_default(org)
GuidanceGroup.create!(
name: org.abbreviation? ? org.abbreviation : org.name,
language_id: Language.find_by(abbreviation: 'fr-FR').id,
org: org,
optional_subset: false,
language_id: 1
Expand Down
4 changes: 4 additions & 0 deletions app/policies/theme_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ def update?
def destroy?
@user.can_super_admin?
end

def sort?
@user.can_super_admin?
end
end
Loading
Loading