Skip to content
Merged
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
7 changes: 7 additions & 0 deletions app/controllers/print_hosts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def destroy
end
end

def print
@file = ModelFile.find_param(params[:file_id])
authorize @file
@print_host.print_later(file: @file)
redirect_back_or_to model_model_file_path(@file.model, @file), notice: t(".sent"), status: :see_other
end

private

def print_host_params
Expand Down
33 changes: 33 additions & 0 deletions app/helpers/model_files_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
module ModelFilesHelper
prepend MemoWise

def can_print?(file)
print_hosts_for(file.mime_type).any?
end

def print_hosts_for(mime_type)
policy_scope(PrintHost).all.select { mime_type.in? it.input_types }
end
memo_wise :print_hosts_for

def print_links(file)
safe_join(
print_hosts_for(file.mime_type).map do |print_host|
content_tag(:li, role: "presentation") {
link_to safe_join(
[
Icon(icon: "printer", role: "presentation"),
t("model_files.print.link", print_host_name: print_host.name)
], " "
),
print_print_host_path(print_host, file_id: file.public_id),
method: "post",
role: "menuitem",
class: "dropdown-item",
data: {
confirm: translate("model_files.print.confirm")
}
}
end
)
end

def app_links(file)
handlers = FileHandlers.handlers_for(environment: :client, mime_type: file.mime_type)
safe_join(
Expand Down
4 changes: 4 additions & 0 deletions app/models/print_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ def service
def input_types
PROTOCOLS[protocol]::INPUT_TYPES
end

def print_later(file:)
SendFileToPrintHostJob.perform_later(print_host: self, file: file)
end
end
4 changes: 4 additions & 0 deletions app/policies/model_file_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def raw?
show?
end

def print?
show?
end

def create?
can_update_model?
end
Expand Down
4 changes: 4 additions & 0 deletions app/policies/print_host_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ def update?
def destroy?
index?
end

def print?
index?
end
end
8 changes: 8 additions & 0 deletions app/views/model_files/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@
<% end %>
<% end %>

<% if can_print? @file %>
<%= card("secondary", t(".print_card.heading")) do %>
<ul class="list-unstyled">
<%= print_links(@file) %>
</ul>
<% end %>
<% end %>

<%= render partial: "problems_card", locals: {problems: @file.problems.visible(problem_settings)} %>

</div>
Expand Down
4 changes: 4 additions & 0 deletions app/views/models/_file.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<%= app_links(file.presupported_version) %>
<%= DropdownDivider() %>
<% end %>
<% if can_print? file %>
<%= print_links(file) %>
<%= DropdownDivider() %>
<% end %>
<%= DropdownItem icon: "pencil-fill", label: t(".edit"), path: edit_model_model_file_path(@model, file) if policy(file).edit? %>
<%= DropdownItem icon: "image", label: t(".set_as_preview"), path: model_path(@model, "model[preview_file_id]": file.id), method: :patch if policy(@model).edit? && Components::Renderers::Three.supports?(file) || file.is_image? %>
<%= DropdownItem icon: "trash", label: t(".delete"), path: model_model_file_path(@model, file), method: :delete, confirm: translate("model_files.destroy.confirm") if policy(file).destroy? %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ cs:
help:
protocol:
help:
print:
sent:
protocols:
moonraker:
update:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,8 @@ de:
help:
protocol:
help:
print:
sent:
protocols:
moonraker:
update:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ en:
help: A friendly name for your printer
protocol:
help: The printer's API protocol
print:
sent: File sent to printer
protocols:
moonraker: Moonraker / Klipper
update:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ es:
help:
protocol:
help:
print:
sent:
protocols:
moonraker:
update:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ fr:
help:
protocol:
help:
print:
sent:
protocols:
moonraker:
update:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ ja:
help:
protocol:
help:
print:
sent:
protocols:
moonraker:
update:
Expand Down
5 changes: 5 additions & 0 deletions config/locales/model_files/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ cs:
help_html: Můžete použít <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a>.
general:
edit: Upravit informace o souboru
print:
confirm:
link:
relationship_fields:
delete:
edit_related:
Expand All @@ -47,6 +50,8 @@ cs:
download:
menu_header: Možnosti stahování
notes_heading: Poznámky
print_card:
heading:
update:
failure: Došlo k chybě a údaje o souboru nelze uložit.
success: Detaily souboru uloženy.
5 changes: 5 additions & 0 deletions config/locales/model_files/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ de:
help_html: 'Du kannst <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a> verwenden. '
general:
edit: Dateiinformationen bearbeiten
print:
confirm:
link:
relationship_fields:
delete: Beziehung entfernen
edit_related: Zugehörige Datei bearbeiten
Expand All @@ -47,6 +50,8 @@ de:
download:
menu_header: Download optionen
notes_heading: Notizen
print_card:
heading:
update:
failure: Es ist ein Fehler aufgetreten und die Dateidetails konnten nicht gespeichert werden.
success: Dateieigenschaften gespeichert.
5 changes: 5 additions & 0 deletions config/locales/model_files/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ en:
help_html: You can use <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a>.
general:
edit: Edit File Information
print:
confirm: Are you sure this file is correctly set up for your printer? Manyfold doesn't check what you're sending!
link: Print using %{print_host_name}
relationship_fields:
delete: Remove relationship
edit_related: Edit related file
Expand All @@ -47,6 +50,8 @@ en:
download:
menu_header: Download options
notes_heading: Notes
print_card:
heading: Print
update:
failure: An error occurred and file details could not be saved.
success: File details saved.
5 changes: 5 additions & 0 deletions config/locales/model_files/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ es:
help_html: Puedes utilizar <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a>.
general:
edit: Editar la información del archivo
print:
confirm:
link:
relationship_fields:
delete: Eliminar relación
edit_related: Editar archivo relacionado
Expand All @@ -47,6 +50,8 @@ es:
download:
menu_header: Opciones de Descarga
notes_heading: Notas
print_card:
heading:
update:
failure: Se ha producido un error y no se ha podido guardar la información del fichero.
success: Información del fichero guardada.
5 changes: 5 additions & 0 deletions config/locales/model_files/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ fr:
help_html: Vous pouvez utiliser du <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a>.
general:
edit: Modifier les informations du fichier
print:
confirm:
link:
relationship_fields:
delete:
edit_related:
Expand All @@ -47,6 +50,8 @@ fr:
download:
menu_header: Options de téléchargement
notes_heading: Notes
print_card:
heading:
update:
failure: Une erreur s'est produite et les détails du fichier n'ont pas pu être sauvegardés.
success: Détails du fichier sauvegardé.
5 changes: 5 additions & 0 deletions config/locales/model_files/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ ja:
help_html:
general:
edit:
print:
confirm:
link:
relationship_fields:
delete:
edit_related:
Expand All @@ -47,6 +50,8 @@ ja:
download:
menu_header:
notes_heading:
print_card:
heading:
update:
failure:
success:
5 changes: 5 additions & 0 deletions config/locales/model_files/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ nl:
help_html: Je kunt <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a> gebruiken.
general:
edit: Bestandsinformatie Bewerken
print:
confirm:
link:
relationship_fields:
delete:
edit_related:
Expand All @@ -47,6 +50,8 @@ nl:
download:
menu_header:
notes_heading: Notities
print_card:
heading:
update:
failure: Er is een fout opgetreden en de bestandsdetails konden niet worden opgeslagen.
success: Bestandsdetails opgeslagen.
5 changes: 5 additions & 0 deletions config/locales/model_files/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pl:
help_html: Możesz używać <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a>.
general:
edit: Edytuj informacje o pliku
print:
confirm:
link:
relationship_fields:
delete:
edit_related:
Expand All @@ -47,6 +50,8 @@ pl:
download:
menu_header: Opcje pobierania
notes_heading: Notatki
print_card:
heading:
update:
failure: Wystąpił błąd i nie można było zapisać szczegółów pliku.
success: Szczegóły pliku zostały zapisane.
5 changes: 5 additions & 0 deletions config/locales/model_files/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pt:
help_html:
general:
edit:
print:
confirm:
link:
relationship_fields:
delete:
edit_related:
Expand All @@ -47,6 +50,8 @@ pt:
download:
menu_header:
notes_heading:
print_card:
heading:
update:
failure:
success:
5 changes: 5 additions & 0 deletions config/locales/model_files/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ ru:
help_html:
general:
edit:
print:
confirm:
link:
relationship_fields:
delete:
edit_related:
Expand All @@ -47,6 +50,8 @@ ru:
download:
menu_header:
notes_heading:
print_card:
heading:
update:
failure:
success:
5 changes: 5 additions & 0 deletions config/locales/model_files/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ zh-CN:
help_html: 您可以使用<a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a>。
general:
edit: 编辑文件信息
print:
confirm:
link:
relationship_fields:
delete:
edit_related:
Expand All @@ -47,6 +50,8 @@ zh-CN:
download:
menu_header: 下载选项
notes_heading: 说明
print_card:
heading:
update:
failure: 发生错误,无法保存文件详细信息。
success: 保存成功。
2 changes: 2 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ nl:
help:
protocol:
help:
print:
sent:
protocols:
moonraker:
update:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ pl:
help:
protocol:
help:
print:
sent:
protocols:
moonraker:
update:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,8 @@ pt:
help:
protocol:
help:
print:
sent:
protocols:
moonraker:
update:
Expand Down
Loading
Loading