mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
download project to markdown file
This commit is contained in:
parent
11a079b3e2
commit
82823dd4cc
2
Gemfile
2
Gemfile
@ -149,3 +149,5 @@ gem 'acts_as_list'
|
||||
# Error reporting
|
||||
gem 'sentry-rails'
|
||||
gem 'sentry-ruby'
|
||||
|
||||
gem "reverse_markdown"
|
@ -82,7 +82,7 @@ GEM
|
||||
rails (>= 4.1)
|
||||
ast (2.4.2)
|
||||
attr_required (1.0.1)
|
||||
awesome_print (1.8.0)
|
||||
awesome_print (1.9.2)
|
||||
axiom-types (0.1.1)
|
||||
descendants_tracker (~> 0.0.4)
|
||||
ice_nine (~> 0.11.0)
|
||||
@ -269,6 +269,8 @@ GEM
|
||||
net-smtp (0.3.3)
|
||||
net-protocol
|
||||
nio4r (2.5.8)
|
||||
nokogiri (1.14.3-x86_64-darwin)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.14.3-x86_64-linux)
|
||||
racc (~> 1.4)
|
||||
oauth2 (1.4.4)
|
||||
@ -396,6 +398,8 @@ GEM
|
||||
responders (3.1.0)
|
||||
actionpack (>= 5.2)
|
||||
railties (>= 5.2)
|
||||
reverse_markdown (2.1.1)
|
||||
nokogiri
|
||||
rexml (3.2.5)
|
||||
rolify (5.3.0)
|
||||
rubocop (1.31.2)
|
||||
@ -524,6 +528,7 @@ GEM
|
||||
zeitwerk (2.6.7)
|
||||
|
||||
PLATFORMS
|
||||
x86_64-darwin-21
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
@ -587,6 +592,7 @@ DEPENDENCIES
|
||||
redis-session-store
|
||||
repost
|
||||
responders (~> 3.0)
|
||||
reverse_markdown
|
||||
rolify
|
||||
rubocop (~> 1.31)
|
||||
rubocop-rails
|
||||
|
@ -18,6 +18,12 @@ class API::ProjectsController < API::APIController
|
||||
@project = Project.friendly.find(params[:id])
|
||||
end
|
||||
|
||||
def markdown
|
||||
@project = Project.friendly.find(params[:id])
|
||||
authorize @project
|
||||
send_data ProjectToMarkdown.new(@project).call, filename: "#{@project.name.parameterize}-#{@project.id}.md", disposition: 'attachment', type: 'text/markdown'
|
||||
end
|
||||
|
||||
def create
|
||||
@project = Project.new(project_params.merge(author_statistic_profile_id: current_user.statistic_profile.id))
|
||||
if @project.save
|
||||
|
@ -174,12 +174,17 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="widget b-t">
|
||||
<div class="text-center m m-b-lg" ng-if="projectEditableBy(currentUser) || isAuthorized('admin')">
|
||||
<a class="btn btn-default" ng-href="api/projects/{{ project.id}}/markdown" target="_blank">
|
||||
<i class="fa fa-download"></i> {{ 'app.public.projects_show.markdown_file' | translate }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="widget-content text-center m-t">
|
||||
<a ng-click="signalAbuse($event)"><i class="fa fa-warning"></i> {{ 'app.public.projects_show.report_an_abuse' | translate }}</a>
|
||||
</div>
|
||||
</section>
|
||||
<section class="widget b-t">
|
||||
<div class="widget-content text-center m-t">
|
||||
<a ng-click="signalAbuse($event)"><i class="fa fa-warning"></i> {{ 'app.public.projects_show.report_an_abuse' | translate }}</a>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -19,6 +19,10 @@ class ProjectPolicy < ApplicationPolicy
|
||||
user.admin? or record.author.user_id == user.id or record.users.include?(user)
|
||||
end
|
||||
|
||||
def markdown?
|
||||
user.admin? or record.author.user_id == user.id or record.users.include?(user)
|
||||
end
|
||||
|
||||
def destroy?
|
||||
user.admin? or record.author.user_id == user.id
|
||||
end
|
||||
|
83
app/services/project_to_markdown.rb
Normal file
83
app/services/project_to_markdown.rb
Normal file
@ -0,0 +1,83 @@
|
||||
class ProjectToMarkdown
|
||||
attr_reader :project
|
||||
|
||||
def initialize(project)
|
||||
@project = project
|
||||
end
|
||||
|
||||
def call
|
||||
md = []
|
||||
|
||||
md << "# #{project.name}"
|
||||
|
||||
md << "})" if project.project_image
|
||||
|
||||
md << ReverseMarkdown.convert(project.description.to_s)
|
||||
|
||||
project_steps = project.project_steps.order(:step_nb)
|
||||
|
||||
if project_steps.present?
|
||||
md << "## #{I18n.t('app.shared.project.steps')}"
|
||||
|
||||
project_steps.each do |project_step|
|
||||
md << "### #{I18n.t('app.shared.project.step_N').gsub('{INDEX}', project_step.step_nb.to_s)} : #{project_step.title}"
|
||||
md << ReverseMarkdown.convert(project_step.description.to_s)
|
||||
|
||||
project_step.project_step_images.each_with_index do |image, i|
|
||||
md << "})"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if project.themes.present?
|
||||
md << "## #{I18n.t('app.shared.project.themes')}"
|
||||
md << project.themes.map(&:name).join(', ')
|
||||
end
|
||||
|
||||
if project.project_caos.present?
|
||||
md << "## #{I18n.t('app.shared.project.CAD_files')}"
|
||||
project.project_caos.each do |cao|
|
||||
md << "})"
|
||||
end
|
||||
end
|
||||
|
||||
md << "## #{I18n.t('app.shared.project.status')}"
|
||||
md << project.status.name
|
||||
|
||||
if project.machines.present?
|
||||
md << "## #{I18n.t('app.shared.project.employed_machines')}"
|
||||
md << project.machines.map(&:name).join(', ')
|
||||
end
|
||||
|
||||
if project.components.present?
|
||||
md << "## #{I18n.t('app.shared.project.employed_materials')}"
|
||||
md << project.components.map(&:name).join(', ')
|
||||
end
|
||||
|
||||
if project.project_users.present?
|
||||
md << "## #{I18n.t('app.shared.project.collaborators')}"
|
||||
md << project.project_users.map { |pu| pu.user.profile.full_name }.join(', ')
|
||||
end
|
||||
|
||||
if project.licence.present?
|
||||
md << "## #{I18n.t('app.shared.project.licence')}"
|
||||
md << project.licence.name
|
||||
end
|
||||
|
||||
if project.tags.present?
|
||||
md << "## #{I18n.t('app.shared.project.tags')}"
|
||||
md << project.tags
|
||||
end
|
||||
|
||||
|
||||
md = md.reject { |line| line.blank? }
|
||||
|
||||
md.join("\n\n")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def full_url(path)
|
||||
"#{Rails.application.routes.url_helpers.root_url[...-1]}#{path}"
|
||||
end
|
||||
end
|
@ -216,6 +216,7 @@ en:
|
||||
report: "Report"
|
||||
do_you_really_want_to_delete_this_project: "Do you really want to delete this project?"
|
||||
status: "Status"
|
||||
markdown_file: "Markdown file"
|
||||
#list of machines
|
||||
machines_list:
|
||||
the_fablab_s_machines: "The machines"
|
||||
|
@ -216,6 +216,7 @@ fr:
|
||||
report: "Signaler"
|
||||
do_you_really_want_to_delete_this_project: "Êtes-vous sur de vouloir supprimer ce projet ?"
|
||||
status: "Statut"
|
||||
markdown_file: "Fichier Markdown"
|
||||
#list of machines
|
||||
machines_list:
|
||||
the_fablab_s_machines: "Les machines"
|
||||
|
@ -131,6 +131,7 @@ en:
|
||||
illustration: "Visual"
|
||||
add_an_illustration: "Add an illustration"
|
||||
CAD_file: "CAD file"
|
||||
CAD_files: "CAD files"
|
||||
allowed_extensions: "Allowed extensions:"
|
||||
add_a_new_file: "Add a new file"
|
||||
description: "Description"
|
||||
@ -138,6 +139,7 @@ en:
|
||||
steps: "Steps"
|
||||
step_N: "Step {INDEX}"
|
||||
step_title: "Step title"
|
||||
step_image: "Image"
|
||||
add_a_picture: "Add a picture"
|
||||
change_the_picture: "Change the picture"
|
||||
delete_the_step: "Delete the step"
|
||||
@ -150,6 +152,7 @@ en:
|
||||
employed_machines: "Employed machines"
|
||||
collaborators: "Collaborators"
|
||||
creative_commons_licences: "Creative Commons licences"
|
||||
licence: "Licence"
|
||||
themes: "Themes"
|
||||
tags: "Tags"
|
||||
save_as_draft: "Save as draft"
|
||||
|
@ -131,6 +131,7 @@ fr:
|
||||
illustration: "Illustration"
|
||||
add_an_illustration: "Ajouter un visuel"
|
||||
CAD_file: "Fichier CAO"
|
||||
CAD_files: "Fichiers CAO"
|
||||
allowed_extensions: "Extensions autorisées :"
|
||||
add_a_new_file: "Ajouter un nouveau fichier"
|
||||
description: "Description"
|
||||
@ -138,6 +139,7 @@ fr:
|
||||
steps: "Étapes"
|
||||
step_N: "Étape {INDEX}"
|
||||
step_title: "Titre de l'étape"
|
||||
step_image: "Image"
|
||||
add_a_picture: "Ajouter une image"
|
||||
change_the_picture: "Modifier l'image"
|
||||
delete_the_step: "Supprimer l'étape"
|
||||
@ -150,6 +152,7 @@ fr:
|
||||
employed_machines: "Machines utilisées"
|
||||
collaborators: "Les collaborateurs"
|
||||
creative_commons_licences: "Licences Creative Commons"
|
||||
licence: "Licence"
|
||||
themes: "Thématiques"
|
||||
tags: "Étiquettes"
|
||||
save_as_draft: "Enregistrer comme brouillon"
|
||||
|
@ -38,6 +38,7 @@ Rails.application.routes.draw do
|
||||
get :last_published
|
||||
get :search
|
||||
end
|
||||
get :markdown, on: :member
|
||||
end
|
||||
resources :openlab_projects, only: :index
|
||||
resources :machines
|
||||
|
Loading…
x
Reference in New Issue
Block a user