mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
Editable logbook templates; component times follow the airframe time
- Templates move to the database (Admin -> Logbook templates: add, edit, delete, restore the built-in ones). The built-in preventive maintenance set is added once on first use; deletions stick. A template can set the entry type, logbook (picking the matching component) and certificate - Template list shows "Name — Part 43 App. A (c)(6), (c)(23)" instead of the doubled parentheses - Component total time and time since overhaul are worked out from the entry's airframe total time (current times shifted by the difference); blank when the entry predates the overhaul; typing them stops the automatic updates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a51f78ebf3
commit
72e1d7760f
22 files changed
+366
-74
No files matched your search
@@ -0,0 +1,48 @@
|
||||
class Admin::LogbookTemplatesController < ApplicationController
|
||||
before_action :require_admin!
|
||||
before_action :set_template, only: %i[edit update destroy]
|
||||
|
||||
def index
|
||||
LogbookTemplate.ensure_defaults!
|
||||
@templates = LogbookTemplate.ordered
|
||||
end
|
||||
|
||||
def new
|
||||
@template = LogbookTemplate.new(position: (LogbookTemplate.maximum(:position) || 0) + 1)
|
||||
end
|
||||
|
||||
def create
|
||||
@template = LogbookTemplate.new(template_params)
|
||||
if @template.save
|
||||
redirect_to admin_logbook_templates_path, notice: "Template added."
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @template.update(template_params)
|
||||
redirect_to admin_logbook_templates_path, notice: "Template updated."
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@template.destroy!
|
||||
redirect_to admin_logbook_templates_path, notice: "Template deleted."
|
||||
end
|
||||
|
||||
def restore
|
||||
added = LogbookTemplate.restore_defaults!
|
||||
redirect_to admin_logbook_templates_path, notice: added.positive? ? "Restored #{helpers.pluralize(added, 'built-in template')}." : "All the built-in templates are already here."
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_template = @template = LogbookTemplate.find(params[:id])
|
||||
|
||||
def template_params = params.require(:logbook_template).permit(:name, :reference, :text, :entry_type, :log_type, :certificate_type, :position)
|
||||
end
|
||||
@@ -2,18 +2,18 @@ class Admin::SettingsController < ApplicationController
|
||||
before_action :require_admin!
|
||||
|
||||
def edit
|
||||
@values = Setting::INTEGERS.keys.index_with { Setting.integer(_1) }
|
||||
@values = { "max_upload_mb" => Setting.max_upload_mb }
|
||||
end
|
||||
|
||||
def update
|
||||
submitted = params.fetch(:settings, {}).permit(*Setting::INTEGERS.keys).to_h
|
||||
submitted = params.fetch(:settings, {}).permit(:max_upload_mb).to_h
|
||||
records = Setting.update_integers(submitted)
|
||||
@errors = records.flat_map { _1.errors.full_messages }
|
||||
if @errors.empty?
|
||||
Rails.logger.info("[settings] #{current_user.email_address} changed #{submitted.inspect}")
|
||||
redirect_to edit_admin_settings_path, notice: "Settings saved."
|
||||
else
|
||||
@values = Setting::INTEGERS.keys.index_with { Setting.integer(_1) }.merge(submitted)
|
||||
@values = { "max_upload_mb" => Setting.max_upload_mb }.merge(submitted)
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user