nitro_kit 2.0.0.beta.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +37 -0
- data/LICENSE +21 -28
- data/README.md +10 -9
- data/app/assets/stylesheets/nitro_kit.css +1660 -1401
- data/app/components/nitro_kit/accordion.rb +1 -13
- data/app/components/nitro_kit/app_navigation.rb +0 -12
- data/app/components/nitro_kit/app_shell.rb +5 -11
- data/app/components/nitro_kit/appearance_picker.rb +1 -7
- data/app/components/nitro_kit/combobox.rb +366 -21
- data/app/components/nitro_kit/command_palette.rb +7 -20
- data/app/components/nitro_kit/details_table.rb +5 -11
- data/app/components/nitro_kit/dropzone.rb +3 -15
- data/app/components/nitro_kit/field.rb +20 -2
- data/app/components/nitro_kit/pagination.rb +2 -8
- data/app/components/nitro_kit/settings_layout.rb +3 -9
- data/app/javascript/controllers/nk/app_shell_controller.js +2 -2
- data/app/javascript/controllers/nk/combobox_controller.js +308 -22
- data/app/javascript/controllers/nk/combobox_remote.js +70 -0
- data/app/javascript/controllers/nk/dropzone_controller.js +2 -2
- data/app/javascript/controllers/nk/tabs_controller.js +2 -2
- data/config/locales/en.yml +3 -0
- data/docs/agent_guide.md +43 -13
- data/docs/component_contracts.md +90 -61
- data/docs/customization.md +173 -35
- data/docs/initialization_prompt.md +4 -5
- data/docs/migration_1_to_2.md +10 -8
- data/docs/patterns/application_foundation.md +5 -0
- data/docs/patterns/composition.md +61 -0
- data/docs/patterns/crud_resource.md +5 -0
- data/docs/patterns/inset_workspace.md +21 -22
- data/docs/patterns/resource_form.md +65 -0
- data/docs/rails_integration.md +214 -2
- data/lib/generators/nitro_kit/install_generator.rb +5 -4
- data/lib/nitro_kit/installation.rb +327 -68
- data/lib/nitro_kit/migration_inventory.rb +18 -3
- data/lib/nitro_kit/version.rb +1 -1
- data/lib/rails/commands/nitro_kit/nitro_kit_command.rb +2 -2
- data/patterns/README.md +21 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/account_deletion.rb +72 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/base.rb +44 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/page.rb +57 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/preferences.rb +68 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/profile.rb +86 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/security.rb +69 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/sessions.rb +86 -0
- data/patterns/account-settings/files/app/controllers/settings/account_deletions_controller.rb +35 -0
- data/patterns/account-settings/files/app/controllers/settings/base_controller.rb +12 -0
- data/patterns/account-settings/files/app/controllers/settings/other_sessions_controller.rb +8 -0
- data/patterns/account-settings/files/app/controllers/settings/preferences_controller.rb +27 -0
- data/patterns/account-settings/files/app/controllers/settings/profiles_controller.rb +20 -0
- data/patterns/account-settings/files/app/controllers/settings/securities_controller.rb +37 -0
- data/patterns/account-settings/files/app/controllers/settings/sessions_controller.rb +31 -0
- data/patterns/account-settings/files/app/models/account_settings/account_closure.rb +33 -0
- data/patterns/account-settings/files/app/models/account_settings/password_change.rb +42 -0
- data/patterns/account-settings/files/app/models/account_settings/session_summary.rb +45 -0
- data/patterns/account-settings/files/app/models/concerns/user/account_configurable.rb +18 -0
- data/patterns/account-settings/files/config/routes/account_settings.rb +10 -0
- data/patterns/account-settings/files/db/migrate/20260731020000_add_account_settings.rb +27 -0
- data/patterns/account-settings/files/test/controllers/settings/account_settings_flow_test.rb +84 -0
- data/patterns/account-settings/files/test/models/account_settings/password_change_test.rb +40 -0
- data/patterns/account-settings/files/test/system/account_settings_test.rb +52 -0
- data/patterns/account-settings/item.yml +4 -0
- data/patterns/account-settings/pattern.md +44 -0
- data/patterns/application-shell/files/app/assets/stylesheets/ui/application_shell.css +267 -0
- data/patterns/application-shell/files/app/components/ui/application_shell.rb +184 -0
- data/patterns/application-shell/item.yml +4 -0
- data/patterns/application-shell/pattern.md +110 -0
- data/patterns/authentication/files/app/components/ui/authentication/base.rb +11 -0
- data/patterns/authentication/files/app/components/ui/authentication/page.rb +53 -0
- data/patterns/authentication/files/app/components/ui/email_verifications/show.rb +62 -0
- data/patterns/authentication/files/app/components/ui/password_resets/new.rb +65 -0
- data/patterns/authentication/files/app/components/ui/passwords/edit.rb +72 -0
- data/patterns/authentication/files/app/components/ui/sessions/new.rb +58 -0
- data/patterns/authentication/files/app/components/ui/verification_emails/new.rb +59 -0
- data/patterns/authentication/files/app/controllers/concerns/authentication.rb +66 -0
- data/patterns/authentication/files/app/controllers/concerns/safe_return_navigation.rb +37 -0
- data/patterns/authentication/files/app/controllers/email_verifications_controller.rb +39 -0
- data/patterns/authentication/files/app/controllers/password_resets_controller.rb +33 -0
- data/patterns/authentication/files/app/controllers/passwords_controller.rb +51 -0
- data/patterns/authentication/files/app/controllers/sessions_controller.rb +42 -0
- data/patterns/authentication/files/app/controllers/verification_emails_controller.rb +33 -0
- data/patterns/authentication/files/app/jobs/authentication_delivery_job.rb +17 -0
- data/patterns/authentication/files/app/mailers/authentication_mailer.rb +15 -0
- data/patterns/authentication/files/app/models/authentication/credentials.rb +16 -0
- data/patterns/authentication/files/app/models/authentication/email_request.rb +17 -0
- data/patterns/authentication/files/app/models/concerns/user/email_verifiable.rb +40 -0
- data/patterns/authentication/files/app/models/session.rb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.text.erb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.text.erb +5 -0
- data/patterns/authentication/files/config/routes/authentication.rb +11 -0
- data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb +13 -0
- data/patterns/authentication/files/test/controllers/authentication_flow_test.rb +103 -0
- data/patterns/authentication/files/test/controllers/safe_return_navigation_test.rb +18 -0
- data/patterns/authentication/files/test/mailers/authentication_mailer_test.rb +21 -0
- data/patterns/authentication/files/test/models/user_email_verifiable_test.rb +36 -0
- data/patterns/authentication/files/test/system/authentication_flow_test.rb +23 -0
- data/patterns/authentication/item.yml +12 -0
- data/patterns/authentication/pattern.md +54 -0
- data/patterns/crud-resource/files/app/assets/stylesheets/ui/projects.css +4 -0
- data/patterns/crud-resource/files/app/components/ui/projects/form.rb +89 -0
- data/patterns/crud-resource/files/app/components/ui/projects/index.rb +161 -0
- data/patterns/crud-resource/files/app/components/ui/projects/show.rb +84 -0
- data/patterns/crud-resource/files/app/controllers/projects/archivals_controller.rb +23 -0
- data/patterns/crud-resource/files/app/controllers/projects_controller.rb +70 -0
- data/patterns/crud-resource/files/app/models/project/archival.rb +8 -0
- data/patterns/crud-resource/files/app/models/project/event.rb +12 -0
- data/patterns/crud-resource/files/app/models/project/filter.rb +41 -0
- data/patterns/crud-resource/files/app/models/project.rb +41 -0
- data/patterns/crud-resource/files/app/views/projects/edit.html.erb +19 -0
- data/patterns/crud-resource/files/app/views/projects/index.html.erb +18 -0
- data/patterns/crud-resource/files/app/views/projects/new.html.erb +16 -0
- data/patterns/crud-resource/files/app/views/projects/show.html.erb +28 -0
- data/patterns/crud-resource/files/config/routes/crud_resource.rb +7 -0
- data/patterns/crud-resource/files/db/migrate/20260720000000_create_crud_resource.rb +37 -0
- data/patterns/crud-resource/files/test/controllers/projects_controller_test.rb +64 -0
- data/patterns/crud-resource/files/test/models/project_test.rb +34 -0
- data/patterns/crud-resource/files/test/support/crud_resource_test_helpers.rb +25 -0
- data/patterns/crud-resource/files/test/system/projects_crud_test.rb +87 -0
- data/patterns/crud-resource/item.yml +6 -0
- data/patterns/crud-resource/pattern.md +48 -0
- data/patterns/file-uploads/files/app/assets/stylesheets/ui/uploads.css +133 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/base.rb +30 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/index.rb +188 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/page.rb +33 -0
- data/patterns/file-uploads/files/app/controllers/uploads/base_controller.rb +29 -0
- data/patterns/file-uploads/files/app/controllers/uploads/direct_uploads_controller.rb +55 -0
- data/patterns/file-uploads/files/app/controllers/uploads/retries_controller.rb +14 -0
- data/patterns/file-uploads/files/app/controllers/uploads_controller.rb +40 -0
- data/patterns/file-uploads/files/app/jobs/upload_blob_cleanup_job.rb +9 -0
- data/patterns/file-uploads/files/app/jobs/upload_processing_job.rb +10 -0
- data/patterns/file-uploads/files/app/jobs/upload_repair_job.rb +17 -0
- data/patterns/file-uploads/files/app/models/concerns/team/uploadable.rb +9 -0
- data/patterns/file-uploads/files/app/models/upload.rb +295 -0
- data/patterns/file-uploads/files/config/recurring/uploads.yml +7 -0
- data/patterns/file-uploads/files/config/routes/uploads.rb +5 -0
- data/patterns/file-uploads/files/db/migrate/20260802000000_add_file_uploads.rb +30 -0
- data/patterns/file-uploads/files/test/controllers/uploads_flow_test.rb +77 -0
- data/patterns/file-uploads/files/test/fixtures/files/workspace.png.base64 +1 -0
- data/patterns/file-uploads/files/test/fixtures/uploads.yml +17 -0
- data/patterns/file-uploads/files/test/models/upload_test.rb +55 -0
- data/patterns/file-uploads/files/test/system/file_uploads_test.rb +30 -0
- data/patterns/file-uploads/item.yml +4 -0
- data/patterns/file-uploads/pattern.md +71 -0
- data/patterns/nitro-kit-1-upgrade/files/docs/nitro_kit_1_upgrade.md +57 -0
- data/patterns/nitro-kit-1-upgrade/item.yml +4 -0
- data/patterns/nitro-kit-1-upgrade/pattern.md +30 -0
- data/patterns/onboarding/files/app/assets/stylesheets/ui/onboarding.css +55 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/base.rb +11 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/branch_form.rb +36 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/details_form.rb +67 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/invitation_plan_form.rb +48 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/page.rb +75 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/review.rb +51 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/show.rb +32 -0
- data/patterns/onboarding/files/app/controllers/concerns/requires_finished_onboarding.rb +14 -0
- data/patterns/onboarding/files/app/controllers/onboarding/base_controller.rb +30 -0
- data/patterns/onboarding/files/app/controllers/onboarding/branches_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/completions_controller.rb +13 -0
- data/patterns/onboarding/files/app/controllers/onboarding/details_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/invitation_plans_controller.rb +20 -0
- data/patterns/onboarding/files/app/controllers/onboardings_controller.rb +7 -0
- data/patterns/onboarding/files/app/jobs/onboarding_invitation_delivery_job.rb +15 -0
- data/patterns/onboarding/files/app/models/concerns/team/onboardable.rb +23 -0
- data/patterns/onboarding/files/app/models/onboarding/completion.rb +17 -0
- data/patterns/onboarding/files/app/models/onboarding/invitation_delivery.rb +14 -0
- data/patterns/onboarding/files/app/models/onboarding.rb +174 -0
- data/patterns/onboarding/files/config/routes/onboarding.rb +11 -0
- data/patterns/onboarding/files/db/migrate/20260731010000_create_onboarding.rb +60 -0
- data/patterns/onboarding/files/test/controllers/onboarding_flow_test.rb +62 -0
- data/patterns/onboarding/files/test/fixtures/onboarding_completions.yml +3 -0
- data/patterns/onboarding/files/test/fixtures/onboardings.yml +25 -0
- data/patterns/onboarding/files/test/jobs/onboarding_invitation_delivery_job_test.rb +18 -0
- data/patterns/onboarding/files/test/models/onboarding_test.rb +60 -0
- data/patterns/onboarding/files/test/system/onboarding_flow_test.rb +39 -0
- data/patterns/onboarding/item.yml +4 -0
- data/patterns/onboarding/pattern.md +53 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/base.rb +39 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/checkout_result.rb +64 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/page.rb +33 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/show.rb +149 -0
- data/patterns/subscription-billing/files/app/controllers/billing/base_controller.rb +16 -0
- data/patterns/subscription-billing/files/app/controllers/billing/checkouts_controller.rb +65 -0
- data/patterns/subscription-billing/files/app/controllers/billing/portals_controller.rb +18 -0
- data/patterns/subscription-billing/files/app/controllers/billing_controller.rb +17 -0
- data/patterns/subscription-billing/files/app/controllers/webhooks/stripe_events_controller.rb +21 -0
- data/patterns/subscription-billing/files/app/jobs/billing/stripe_event_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_sweep_job.rb +9 -0
- data/patterns/subscription-billing/files/app/models/billing/checkout.rb +58 -0
- data/patterns/subscription-billing/files/app/models/billing/plan.rb +19 -0
- data/patterns/subscription-billing/files/app/models/billing/stripe_event.rb +73 -0
- data/patterns/subscription-billing/files/app/models/billing/subscription.rb +106 -0
- data/patterns/subscription-billing/files/app/models/concerns/team/billable.rb +36 -0
- data/patterns/subscription-billing/files/config/initializers/stripe.rb +29 -0
- data/patterns/subscription-billing/files/config/routes/subscription_billing.rb +10 -0
- data/patterns/subscription-billing/files/db/migrate/20260801000000_add_subscription_billing.rb +61 -0
- data/patterns/subscription-billing/files/test/controllers/billing_flow_test.rb +60 -0
- data/patterns/subscription-billing/files/test/models/billing/subscription_test.rb +40 -0
- data/patterns/subscription-billing/files/test/system/subscription_billing_test.rb +28 -0
- data/patterns/subscription-billing/item.yml +4 -0
- data/patterns/subscription-billing/pattern.md +59 -0
- data/patterns/team-management/files/app/components/ui/invitations/acceptance.rb +33 -0
- data/patterns/team-management/files/app/components/ui/teams/index.rb +87 -0
- data/patterns/team-management/files/app/components/ui/teams/invitation_form.rb +51 -0
- data/patterns/team-management/files/app/components/ui/teams/member_form.rb +78 -0
- data/patterns/team-management/files/app/components/ui/teams/members.rb +125 -0
- data/patterns/team-management/files/app/controllers/invitations/acceptances_controller.rb +29 -0
- data/patterns/team-management/files/app/controllers/teams/base_controller.rb +18 -0
- data/patterns/team-management/files/app/controllers/teams/invitations_controller.rb +42 -0
- data/patterns/team-management/files/app/controllers/teams/memberships_controller.rb +53 -0
- data/patterns/team-management/files/app/controllers/teams_controller.rb +30 -0
- data/patterns/team-management/files/app/mailers/team_invitation_mailer.rb +10 -0
- data/patterns/team-management/files/app/models/concerns/current_team.rb +13 -0
- data/patterns/team-management/files/app/models/concerns/user_teams.rb +37 -0
- data/patterns/team-management/files/app/models/invitation.rb +41 -0
- data/patterns/team-management/files/app/models/membership.rb +45 -0
- data/patterns/team-management/files/app/models/team.rb +25 -0
- data/patterns/team-management/files/app/views/invitations/acceptances/show.html.erb +1 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.html.erb +10 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.text.erb +7 -0
- data/patterns/team-management/files/app/views/teams/index.html.erb +15 -0
- data/patterns/team-management/files/app/views/teams/invitations/new.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/edit.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/index.html.erb +20 -0
- data/patterns/team-management/files/config/routes/team_management.rb +11 -0
- data/patterns/team-management/files/db/migrate/20260717000000_create_team_management.rb +31 -0
- data/patterns/team-management/files/test/models/invitation_test.rb +28 -0
- data/patterns/team-management/files/test/models/membership_test.rb +29 -0
- data/patterns/team-management/files/test/models/team_test.rb +31 -0
- data/patterns/team-management/files/test/support/team_management_test_helpers.rb +22 -0
- data/patterns/team-management/item.yml +4 -0
- data/patterns/team-management/pattern.md +47 -0
- data/patterns/webhook-deliveries/files/app/assets/stylesheets/ui/webhooks.css +179 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/base.rb +38 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/delivery.rb +160 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/endpoint.rb +149 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/form.rb +75 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/index.rb +142 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/page.rb +33 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/secret.rb +38 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries/replays_controller.rb +13 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries_controller.rb +7 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints/secrets_controller.rb +41 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints_controller.rb +67 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhooks/base_controller.rb +15 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_job.rb +9 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_repair_job.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/concerns/team/webhookable.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/attempt.rb +30 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/delivery.rb +268 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/endpoint.rb +58 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/event.rb +98 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/secret_reveal.rb +53 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/signature.rb +22 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/transport.rb +176 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_deliveries/show.html.erb +5 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/edit.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/index.html.erb +6 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/secrets/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/show.html.erb +7 -0
- data/patterns/webhook-deliveries/files/config/recurring/webhooks.yml +4 -0
- data/patterns/webhook-deliveries/files/config/routes/webhook_deliveries.rb +10 -0
- data/patterns/webhook-deliveries/files/db/migrate/20260803000000_add_webhook_deliveries.rb +126 -0
- data/patterns/webhook-deliveries/files/test/controllers/webhook_endpoints_flow_test.rb +48 -0
- data/patterns/webhook-deliveries/files/test/models/webhook/delivery_test.rb +70 -0
- data/patterns/webhook-deliveries/files/test/system/webhook_deliveries_test.rb +29 -0
- data/patterns/webhook-deliveries/item.yml +4 -0
- data/patterns/webhook-deliveries/pattern.md +120 -0
- data/plugins/nitro-kit/.codex-plugin/plugin.json +4 -4
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/SKILL.md +7 -9
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-rails/SKILL.md +10 -9
- data/plugins/nitro-kit/skills/nitro-kit-rails/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-ui/SKILL.md +27 -16
- data/plugins/nitro-kit/skills/nitro-kit-ui/agents/openai.yaml +1 -1
- data/src/stylesheets/nitro_kit/components/accordion.css +40 -40
- data/src/stylesheets/nitro_kit/components/alert.css +7 -6
- data/src/stylesheets/nitro_kit/components/app_navigation.css +50 -41
- data/src/stylesheets/nitro_kit/components/app_shell.css +371 -280
- data/src/stylesheets/nitro_kit/components/appearance_picker.css +38 -38
- data/src/stylesheets/nitro_kit/components/avatar.css +3 -3
- data/src/stylesheets/nitro_kit/components/avatar_stack.css +18 -18
- data/src/stylesheets/nitro_kit/components/badge.css +5 -2
- data/src/stylesheets/nitro_kit/components/button.css +57 -49
- data/src/stylesheets/nitro_kit/components/button_group.css +14 -14
- data/src/stylesheets/nitro_kit/components/checkbox.css +24 -24
- data/src/stylesheets/nitro_kit/components/checkbox_group.css +13 -13
- data/src/stylesheets/nitro_kit/components/combobox.css +152 -25
- data/src/stylesheets/nitro_kit/components/command_palette.css +59 -59
- data/src/stylesheets/nitro_kit/components/control_group.css +71 -54
- data/src/stylesheets/nitro_kit/components/details_table.css +9 -9
- data/src/stylesheets/nitro_kit/components/dialog.css +8 -12
- data/src/stylesheets/nitro_kit/components/dropdown.css +22 -26
- data/src/stylesheets/nitro_kit/components/dropzone.css +97 -100
- data/src/stylesheets/nitro_kit/components/empty_state.css +1 -0
- data/src/stylesheets/nitro_kit/components/field.css +26 -30
- data/src/stylesheets/nitro_kit/components/fieldset.css +2 -2
- data/src/stylesheets/nitro_kit/components/input.css +6 -14
- data/src/stylesheets/nitro_kit/components/layout.css +165 -165
- data/src/stylesheets/nitro_kit/components/page_header.css +3 -3
- data/src/stylesheets/nitro_kit/components/pagination.css +66 -49
- data/src/stylesheets/nitro_kit/components/pagination_bar.css +6 -6
- data/src/stylesheets/nitro_kit/components/palette.css +24 -22
- data/src/stylesheets/nitro_kit/components/progressive_image.css +38 -41
- data/src/stylesheets/nitro_kit/components/radio_button.css +19 -19
- data/src/stylesheets/nitro_kit/components/radio_button_group.css +43 -43
- data/src/stylesheets/nitro_kit/components/rich_text_area.css +4 -4
- data/src/stylesheets/nitro_kit/components/select.css +2 -2
- data/src/stylesheets/nitro_kit/components/settings_layout.css +17 -18
- data/src/stylesheets/nitro_kit/components/settings_section.css +12 -12
- data/src/stylesheets/nitro_kit/components/sheet.css +10 -10
- data/src/stylesheets/nitro_kit/components/stat_grid.css +9 -9
- data/src/stylesheets/nitro_kit/components/switch.css +23 -23
- data/src/stylesheets/nitro_kit/components/table.css +27 -27
- data/src/stylesheets/nitro_kit/components/tabs.css +32 -34
- data/src/stylesheets/nitro_kit/components/toolbar.css +6 -6
- data/src/stylesheets/nitro_kit/components/tooltip.css +26 -28
- data/src/stylesheets/nitro_kit/layers.css +2 -1
- data/src/stylesheets/nitro_kit/reset.css +9 -9
- data/src/stylesheets/nitro_kit/tailwind.css +6 -2
- data/src/stylesheets/nitro_kit/tokens.css +18 -9
- metadata +238 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
version: 1.0.0
|
|
2
|
+
title: Authentication and recovery
|
|
3
|
+
summary: Sign-in, email verification, password recovery, and safe return navigation for Rails.
|
|
4
|
+
tags: [authentication, sessions, password-recovery, email-verification, rails]
|
|
5
|
+
variants:
|
|
6
|
+
- id: centered-card
|
|
7
|
+
summary: One calm, focused card centered on the page.
|
|
8
|
+
default: true
|
|
9
|
+
- id: split-screen
|
|
10
|
+
summary: Two-column layout pairing the sign-in card with a large brand or image panel.
|
|
11
|
+
- id: minimal
|
|
12
|
+
summary: Bare sign-in stripped to the form and an unadorned brand mark.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Authentication and recovery
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Use this pattern when a Rails 8.1 application owns password authentication and needs one coherent path through sign-in, email verification, and password recovery. It starts with Rails' generated authentication primitives, keeps policy in the host application, and uses `NitroKit::AuthShell` only for the narrow standalone form surface.
|
|
6
|
+
|
|
7
|
+
## Domain boundary
|
|
8
|
+
|
|
9
|
+
- Include `User::EmailVerifiable` beside the host's existing `has_secure_password`. Rails owns password-reset token signing, expiry, and invalidation when the password changes; the concern adds an independently purposed verification token bound to the normalized address and verification timestamp.
|
|
10
|
+
- Keep `Session` persistence and `Current` integration application-owned. The included controller concern shows a plain user session; adapt `start_new_session_for`, `revoke_sessions_for`, and `default_authenticated_path` rather than selecting a team or membership implicitly.
|
|
11
|
+
- Queue `AuthenticationDeliveryJob` for every valid recovery or verification request. The job performs the user lookup so known and unknown addresses receive the same HTTP response and request-time work.
|
|
12
|
+
- Do not disclose whether an address exists. Malformed input receives ordinary validation; every well-formed address receives the same sent state.
|
|
13
|
+
|
|
14
|
+
## Token lifecycle
|
|
15
|
+
|
|
16
|
+
Password-reset tokens come from Rails 8.1 `has_secure_password`. They expire after 15 minutes and are bound to the password salt, so a successful update invalidates every outstanding reset link. Email-verification tokens expire after two days and are bound to both `email_address` and `email_verified_at`; changing or verifying the address invalidates old links.
|
|
17
|
+
|
|
18
|
+
Mail links open a confirmation form. `GET` validates and explains; `PATCH` mutates. This avoids consuming credentials when mail scanners follow links. Invalid, expired, wrong-purpose, and already-used links share a neutral unusable state because signed tokens intentionally do not reveal why verification failed. Every failure screen offers a fresh request path.
|
|
19
|
+
|
|
20
|
+
## Session and return navigation
|
|
21
|
+
|
|
22
|
+
Remember only same-origin HTML `GET` destinations. Store the path server-side, validate it again with Rails `url_from`, reject authentication-loop destinations, consume it once, and fall back to the host's authenticated root. Never redirect to a `return_to` parameter.
|
|
23
|
+
|
|
24
|
+
Rotate the Rails session before creating an authenticated session record. Sign the persistent record cookie, mark it `HttpOnly` and `SameSite=Lax`, and use `Secure` over HTTPS. A password reset revokes every persisted session and does not sign the user in automatically.
|
|
25
|
+
|
|
26
|
+
## Rendering
|
|
27
|
+
|
|
28
|
+
Each route renders one application-owned Card inside `NitroKit::AuthShell`. Use `NitroKit::FormBuilder`, preserve only the email address after validation, and never render a password value. Keep `email`, `current-password`, and `new-password` autocomplete values accurate. Turbo Drive handles normal submissions and 422 replacements; no authentication-specific JavaScript or Turbo Frame is required.
|
|
29
|
+
|
|
30
|
+
## Variants
|
|
31
|
+
|
|
32
|
+
Variants share this pattern's entire core — controllers, models, security rules, token lifecycle, and return navigation. They differ only in the view/layout of the sign-in (other authentication screens follow the same family). Structural differences, such as magic-link sign-in instead of password, are separate patterns, not variants.
|
|
33
|
+
|
|
34
|
+
Choose a variant by product context:
|
|
35
|
+
|
|
36
|
+
- **centered-card** *(default)* — One calm, focused `Card` centered in `AuthShell`. Use when sign-in is the page's single job and the product wants no distraction: most internal tools, minimal apps, and anything where the form itself must carry the attention.
|
|
37
|
+
- **split-screen** — A two-column layout pairing the sign-in `Card` with a large brand/image/benefit panel on the other side. Use for consumer-facing or marketing-adjacent products where sign-in doubles as an on-brand moment: a product screenshot, a photo, or a benefit headline.
|
|
38
|
+
- **minimal** — Chrome stripped to the bare form plus an unadorned brand mark; no panel, minimal copy. Use where quiet confidence fits — high-trust contexts, logged-out pages that should feel effortless, or designs that avoid visual furniture entirely.
|
|
39
|
+
|
|
40
|
+
Keep `autocomplete` values, error handling, and non-disclosure behavior identical across every variant; only the surrounding layout changes.
|
|
41
|
+
|
|
42
|
+
## Adaptation
|
|
43
|
+
|
|
44
|
+
Mount `config/routes/authentication.rb` from the host route set, include `User::EmailVerifiable`, and merge the migration with the host user/session schema. Replace product copy and mailer sender. Override the session hooks for tenant selection and destination policy. Add token parameters to `config.filter_parameters`; the exemplar filter list is included in the route fragment comments.
|
|
45
|
+
|
|
46
|
+
## Verification
|
|
47
|
+
|
|
48
|
+
- Compare wrong-password and unknown-address responses; they must use identical status, copy, and field treatment.
|
|
49
|
+
- Prove known and unknown recovery requests enqueue the same job and render the same sent response.
|
|
50
|
+
- Exercise valid, expired, tampered, wrong-purpose, and reused links without mutating on `GET`.
|
|
51
|
+
- Verify password mismatch returns 422, a valid update revokes sessions, and the old token no longer resolves.
|
|
52
|
+
- Verify email change invalidates a verification token and successful verification does not create a session.
|
|
53
|
+
- Test local, external, protocol-relative, malformed, repeated, and authentication-loop return destinations.
|
|
54
|
+
- Browser-test keyboard use, Turbo validation, mail-to-reset and mail-to-verify paths, 390px layout, both appearances, and password-value absence.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Projects
|
|
5
|
+
class Form < Base
|
|
6
|
+
def initialize(project:)
|
|
7
|
+
@project = project
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.form_id(project)
|
|
11
|
+
ActionView::RecordIdentifier.dom_id(project, :form)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def view_template
|
|
15
|
+
Container(size: :lg) do
|
|
16
|
+
Flex(dir: :col, gap: 8, align: :stretch) do
|
|
17
|
+
render_form
|
|
18
|
+
render_deletion if project.persisted?
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
attr_reader :project
|
|
26
|
+
|
|
27
|
+
def render_form
|
|
28
|
+
Fieldset(
|
|
29
|
+
legend: "Project details",
|
|
30
|
+
description: "Keep the record concise enough to scan in a table."
|
|
31
|
+
) do
|
|
32
|
+
render_errors
|
|
33
|
+
form_with(
|
|
34
|
+
model: project,
|
|
35
|
+
builder: NitroKit::FormBuilder,
|
|
36
|
+
id: self.class.form_id(project)
|
|
37
|
+
) do |form|
|
|
38
|
+
form.group do
|
|
39
|
+
form.field(:name, required: true, control_html: { autofocus: true })
|
|
40
|
+
form.field(:description, as: :textarea, rows: 8)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def render_errors
|
|
47
|
+
return unless project.errors.any?
|
|
48
|
+
|
|
49
|
+
render NitroKit::Alert.new(variant: :destructive) do |alert|
|
|
50
|
+
alert.title("Please review the highlighted fields")
|
|
51
|
+
alert.description(project.errors.full_messages.to_sentence)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def render_deletion
|
|
56
|
+
DangerZone(
|
|
57
|
+
title: "Delete project",
|
|
58
|
+
description: "This permanently removes the project and its history."
|
|
59
|
+
) do |zone|
|
|
60
|
+
zone.confirmation do
|
|
61
|
+
Dialog(id: dom_id(project, :delete_dialog)) do |dialog|
|
|
62
|
+
dialog.trigger("Review deletion", variant: :destructive)
|
|
63
|
+
dialog.panel(
|
|
64
|
+
title: "Delete #{project.name}?",
|
|
65
|
+
description: "This action cannot be undone."
|
|
66
|
+
) do
|
|
67
|
+
Flex(dir: :row, gap: 2, justify: :end, wrap: :wrap) do
|
|
68
|
+
Button("Cancel", html: { command: "close", commandfor: "#{dialog.id}-panel" })
|
|
69
|
+
form_with(model: project, method: :delete) do
|
|
70
|
+
Button(
|
|
71
|
+
"Delete project",
|
|
72
|
+
type: :submit,
|
|
73
|
+
variant: :destructive,
|
|
74
|
+
data: { turbo_submits_with: "Deleting…" }
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
zone.escape NitroKit::Button.new(
|
|
82
|
+
"Keep project",
|
|
83
|
+
href: project_path(project)
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Projects
|
|
5
|
+
class Index < Base
|
|
6
|
+
def initialize(projects:, filter:, pagy:)
|
|
7
|
+
@projects = projects
|
|
8
|
+
@filter = filter
|
|
9
|
+
@pagy = pagy
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def view_template
|
|
13
|
+
Flex(dir: :col, gap: 6, align: :stretch) do
|
|
14
|
+
render_filters
|
|
15
|
+
render_results
|
|
16
|
+
render_pagination if pagy.pages > 1
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
attr_reader :projects, :filter, :pagy
|
|
23
|
+
|
|
24
|
+
def render_filters
|
|
25
|
+
form_with(
|
|
26
|
+
model: filter,
|
|
27
|
+
scope: :filter,
|
|
28
|
+
url: projects_path,
|
|
29
|
+
method: :get,
|
|
30
|
+
builder: NitroKit::FormBuilder,
|
|
31
|
+
data: { turbo_action: "replace" },
|
|
32
|
+
html: { role: "search" }
|
|
33
|
+
) do |form|
|
|
34
|
+
Grid(cols: "1 md:3", gap: 3) do
|
|
35
|
+
form.field(
|
|
36
|
+
:query,
|
|
37
|
+
as: :search,
|
|
38
|
+
label: "Search projects",
|
|
39
|
+
placeholder: "Name",
|
|
40
|
+
autocomplete: "off"
|
|
41
|
+
)
|
|
42
|
+
form.field(
|
|
43
|
+
:state,
|
|
44
|
+
as: :select,
|
|
45
|
+
label: "State",
|
|
46
|
+
options: [
|
|
47
|
+
[ "All projects", "all" ],
|
|
48
|
+
[ "Active", "active" ],
|
|
49
|
+
[ "Archived", "archived" ]
|
|
50
|
+
]
|
|
51
|
+
)
|
|
52
|
+
Flex(dir: :row, gap: 2, align: :end, justify: :end) do
|
|
53
|
+
if filter.active?
|
|
54
|
+
Button(
|
|
55
|
+
"Reset",
|
|
56
|
+
href: projects_path,
|
|
57
|
+
data: { turbo_action: "replace" }
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
form.submit(
|
|
61
|
+
"Apply filters",
|
|
62
|
+
data: { turbo_submits_with: "Filtering…" }
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def render_results
|
|
70
|
+
return render_table if projects.any?
|
|
71
|
+
|
|
72
|
+
EmptyState(
|
|
73
|
+
title: filter.active? ? "No projects match" : "No projects yet",
|
|
74
|
+
description: empty_description,
|
|
75
|
+
level: 2
|
|
76
|
+
) do |empty|
|
|
77
|
+
empty.icon NitroKit::Icon.new(:folder, size: :lg)
|
|
78
|
+
if filter.active?
|
|
79
|
+
empty.action NitroKit::Button.new(
|
|
80
|
+
"Clear filters",
|
|
81
|
+
href: projects_path,
|
|
82
|
+
data: { turbo_action: "replace" }
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def empty_description
|
|
89
|
+
if filter.active?
|
|
90
|
+
"Try a broader search or clear the current filters."
|
|
91
|
+
else
|
|
92
|
+
"Use the persistent New project action to create the first one."
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def render_table
|
|
97
|
+
Table(data: { ui: "projects-table" }, table_aria: { label: "Projects" }) do |table|
|
|
98
|
+
table.thead do
|
|
99
|
+
table.tr do
|
|
100
|
+
table.th("Project", data: { projects_column: "name" })
|
|
101
|
+
table.th("State", data: { projects_column: "status" })
|
|
102
|
+
table.th("Created by", data: { projects_column: "creator" })
|
|
103
|
+
table.th("Updated", data: { projects_column: "updated" })
|
|
104
|
+
table.th("Actions", align: :right, data: { projects_column: "actions" })
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
table.tbody { projects.each { |project| render_row(table, project) } }
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def render_row(table, project)
|
|
112
|
+
table.tr do
|
|
113
|
+
table.th(project.name, scope: :row, data: { projects_column: "name" })
|
|
114
|
+
table.td(data: { projects_column: "status" }) do
|
|
115
|
+
Badge(
|
|
116
|
+
project.archived? ? "Archived" : "Active",
|
|
117
|
+
color: project.archived? ? :neutral : :success,
|
|
118
|
+
variant: :outline,
|
|
119
|
+
size: :sm
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
table.td(project.creator.name, data: { projects_column: "creator" })
|
|
123
|
+
table.td(data: { projects_column: "updated" }) do
|
|
124
|
+
time(datetime: project.updated_at.iso8601) do
|
|
125
|
+
project.updated_at.to_date.to_fs(:long)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
table.td(align: :right, data: { projects_column: "actions" }) do
|
|
129
|
+
Flex(dir: :row, gap: 1, align: :stretch, justify: :end) do
|
|
130
|
+
Button(
|
|
131
|
+
"View",
|
|
132
|
+
href: project_path(project),
|
|
133
|
+
size: :sm
|
|
134
|
+
)
|
|
135
|
+
Button(
|
|
136
|
+
"Edit",
|
|
137
|
+
href: edit_project_path(project),
|
|
138
|
+
size: :sm
|
|
139
|
+
)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def render_pagination
|
|
146
|
+
PaginationBar do |bar|
|
|
147
|
+
first = ((pagy.page - 1) * pagy.limit) + 1
|
|
148
|
+
last = [ pagy.page * pagy.limit, pagy.count ].min
|
|
149
|
+
bar.summary("Showing #{first}–#{last} of #{pagy.count} projects")
|
|
150
|
+
bar.pagination NitroKit::Pagination.new(
|
|
151
|
+
pagy:,
|
|
152
|
+
page_url: ->(page) do
|
|
153
|
+
projects_path(page:, filter: filter.parameters)
|
|
154
|
+
end,
|
|
155
|
+
label: "Project pages"
|
|
156
|
+
)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Projects
|
|
5
|
+
class Show < Base
|
|
6
|
+
def initialize(project:, events:)
|
|
7
|
+
@project = project
|
|
8
|
+
@events = events
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.archival_form_id(project)
|
|
12
|
+
ActionView::RecordIdentifier.dom_id(project, :archival_form)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def view_template
|
|
16
|
+
Flex(dir: :col, gap: 8, align: :stretch) do
|
|
17
|
+
render_summary
|
|
18
|
+
render_archival_form
|
|
19
|
+
render_history
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
attr_reader :project, :events
|
|
26
|
+
|
|
27
|
+
def render_summary
|
|
28
|
+
DetailsTable(project) do |details|
|
|
29
|
+
details.field(:status, value: project.archived?) do |archived|
|
|
30
|
+
Badge(
|
|
31
|
+
archived ? "Archived" : "Active",
|
|
32
|
+
color: archived ? :neutral : :success,
|
|
33
|
+
variant: :outline
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
details.field(:description)
|
|
37
|
+
details.field(:creator, label: "Created by")
|
|
38
|
+
details.field(:created_at, label: "Created")
|
|
39
|
+
details.field(:updated_at, label: "Last updated")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def render_archival_form
|
|
44
|
+
form_with(
|
|
45
|
+
url: project_archival_path(project),
|
|
46
|
+
method: project.archived? ? :delete : :post,
|
|
47
|
+
id: self.class.archival_form_id(project)
|
|
48
|
+
) { }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def render_history
|
|
52
|
+
DataSection(
|
|
53
|
+
title: "History",
|
|
54
|
+
description: "Lifecycle changes remain attached to this project."
|
|
55
|
+
) do |section|
|
|
56
|
+
section.table NitroKit::Table.new(
|
|
57
|
+
table_aria: { label: "Project history" }
|
|
58
|
+
) do |table|
|
|
59
|
+
table.thead do
|
|
60
|
+
table.tr do
|
|
61
|
+
table.th("Change")
|
|
62
|
+
table.th("By")
|
|
63
|
+
table.th("When")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
table.tbody do
|
|
67
|
+
events.each do |event|
|
|
68
|
+
table.tr do
|
|
69
|
+
table.th(event.action.humanize, scope: :row)
|
|
70
|
+
table.td(event.actor.name)
|
|
71
|
+
table.td do
|
|
72
|
+
time(datetime: event.created_at.iso8601) do
|
|
73
|
+
event.created_at.to_fs(:long)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Projects
|
|
4
|
+
class ArchivalsController < ApplicationController
|
|
5
|
+
before_action :set_project
|
|
6
|
+
|
|
7
|
+
def create
|
|
8
|
+
@project.archive!
|
|
9
|
+
redirect_to @project, status: :see_other, notice: "Project archived"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def destroy
|
|
13
|
+
@project.restore!
|
|
14
|
+
redirect_to @project, status: :see_other, notice: "Project restored"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def set_project
|
|
20
|
+
@project = Current.team.projects.find(params[:project_id])
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class ProjectsController < ApplicationController
|
|
4
|
+
PER_PAGE = 12
|
|
5
|
+
|
|
6
|
+
before_action :set_project, only: %i[show edit update destroy]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@filter = Project::Filter.new(filter_params)
|
|
10
|
+
projects = @filter.apply(Current.team.projects.with_details.reverse_chronologically)
|
|
11
|
+
@pagy = Pagy::Offset.new(
|
|
12
|
+
count: projects.count,
|
|
13
|
+
page: params.fetch(:page, 1),
|
|
14
|
+
limit: PER_PAGE
|
|
15
|
+
)
|
|
16
|
+
@projects = projects.offset(@pagy.offset).limit(@pagy.limit)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def show
|
|
20
|
+
@events = @project.events.includes(:actor).reverse_chronologically
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def new
|
|
24
|
+
@project = Current.team.projects.build
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create
|
|
28
|
+
@project = Current.team.projects.build(
|
|
29
|
+
project_params.merge(creator: Current.user)
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
if @project.save
|
|
33
|
+
@project.record_event!("created")
|
|
34
|
+
redirect_to @project, status: :see_other, notice: "Project created"
|
|
35
|
+
else
|
|
36
|
+
render :new, status: :unprocessable_entity
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def edit
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def update
|
|
44
|
+
if @project.update(project_params)
|
|
45
|
+
@project.record_event!("updated")
|
|
46
|
+
redirect_to @project, status: :see_other, notice: "Project updated"
|
|
47
|
+
else
|
|
48
|
+
render :edit, status: :unprocessable_entity
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def destroy
|
|
53
|
+
@project.destroy!
|
|
54
|
+
redirect_to projects_path, status: :see_other, notice: "Project deleted"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def set_project
|
|
60
|
+
@project = Current.team.projects.with_details.find(params[:id])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def project_params
|
|
64
|
+
params.expect(project: %i[name description])
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def filter_params
|
|
68
|
+
params.fetch(:filter, {}).permit(:query, :state)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Project::Event < ApplicationRecord
|
|
4
|
+
ACTIONS = %w[created updated archived restored].freeze
|
|
5
|
+
|
|
6
|
+
belongs_to :project, inverse_of: :events
|
|
7
|
+
belongs_to :actor, class_name: "User"
|
|
8
|
+
|
|
9
|
+
validates :action, inclusion: { in: ACTIONS }
|
|
10
|
+
|
|
11
|
+
scope :reverse_chronologically, -> { order(created_at: :desc, id: :desc) }
|
|
12
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Project::Filter
|
|
4
|
+
include ActiveModel::Model
|
|
5
|
+
include ActiveModel::Attributes
|
|
6
|
+
|
|
7
|
+
STATES = %w[all active archived].freeze
|
|
8
|
+
|
|
9
|
+
attribute :query, :string
|
|
10
|
+
attribute :state, :string, default: "all"
|
|
11
|
+
|
|
12
|
+
validates :query, length: { maximum: 120 }
|
|
13
|
+
validates :state, inclusion: { in: STATES }
|
|
14
|
+
|
|
15
|
+
def apply(scope)
|
|
16
|
+
scope = search(scope)
|
|
17
|
+
|
|
18
|
+
case state
|
|
19
|
+
when "active" then scope.active
|
|
20
|
+
when "archived" then scope.archived
|
|
21
|
+
else scope
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def active?
|
|
26
|
+
query.present? || state != "all"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def parameters
|
|
30
|
+
{ query: query.presence, state: state == "all" ? nil : state }.compact
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def search(scope)
|
|
36
|
+
return scope if query.blank?
|
|
37
|
+
|
|
38
|
+
pattern = "%#{ActiveRecord::Base.sanitize_sql_like(query.downcase)}%"
|
|
39
|
+
scope.where("LOWER(projects.name) LIKE ?", pattern)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Project < ApplicationRecord
|
|
4
|
+
belongs_to :team
|
|
5
|
+
belongs_to :creator, class_name: "User"
|
|
6
|
+
has_one :archival, dependent: :destroy, inverse_of: :project
|
|
7
|
+
has_many :events, dependent: :destroy, inverse_of: :project
|
|
8
|
+
|
|
9
|
+
validates :name, presence: true
|
|
10
|
+
|
|
11
|
+
scope :with_details, -> { includes(:creator, :archival) }
|
|
12
|
+
scope :reverse_chronologically, -> { order(updated_at: :desc, id: :desc) }
|
|
13
|
+
scope :active, -> { where.missing(:archival) }
|
|
14
|
+
scope :archived, -> { joins(:archival) }
|
|
15
|
+
|
|
16
|
+
def archived?
|
|
17
|
+
archival.present?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def active?
|
|
21
|
+
!archived?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def archive!(actor: Current.user)
|
|
25
|
+
transaction do
|
|
26
|
+
create_archival!(actor:)
|
|
27
|
+
record_event!("archived", actor:)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def restore!(actor: Current.user)
|
|
32
|
+
transaction do
|
|
33
|
+
archival.destroy!
|
|
34
|
+
record_event!("restored", actor:)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def record_event!(action, actor: Current.user)
|
|
39
|
+
events.create!(action:, actor:)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<% content_for :title, "Edit #{@project.name}" %>
|
|
2
|
+
<%= render UI::ApplicationShell.new(
|
|
3
|
+
title: "Edit #{@project.name}",
|
|
4
|
+
current: :projects,
|
|
5
|
+
back: {
|
|
6
|
+
label: "Back to project",
|
|
7
|
+
href: project_path(@project)
|
|
8
|
+
},
|
|
9
|
+
actions: [
|
|
10
|
+
{
|
|
11
|
+
label: "Save changes",
|
|
12
|
+
form: UI::Projects::Form.form_id(@project),
|
|
13
|
+
type: :submit,
|
|
14
|
+
variant: :primary
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
) do %>
|
|
18
|
+
<%= render UI::Projects::Form.new(project: @project) %>
|
|
19
|
+
<% end %>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<% content_for :title, "Projects" %>
|
|
2
|
+
<%= render UI::ApplicationShell.new(
|
|
3
|
+
title: "Projects",
|
|
4
|
+
current: :projects,
|
|
5
|
+
actions: [
|
|
6
|
+
{
|
|
7
|
+
label: "New project",
|
|
8
|
+
href: new_project_path,
|
|
9
|
+
variant: :primary
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
) do %>
|
|
13
|
+
<%= render UI::Projects::Index.new(
|
|
14
|
+
projects: @projects,
|
|
15
|
+
filter: @filter,
|
|
16
|
+
pagy: @pagy
|
|
17
|
+
) %>
|
|
18
|
+
<% end %>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<% content_for :title, "New project" %>
|
|
2
|
+
<%= render UI::ApplicationShell.new(
|
|
3
|
+
title: "New project",
|
|
4
|
+
current: :projects,
|
|
5
|
+
back: { label: "Back to projects", href: projects_path },
|
|
6
|
+
actions: [
|
|
7
|
+
{
|
|
8
|
+
label: "Create project",
|
|
9
|
+
form: UI::Projects::Form.form_id(@project),
|
|
10
|
+
type: :submit,
|
|
11
|
+
variant: :primary
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
) do %>
|
|
15
|
+
<%= render UI::Projects::Form.new(project: @project) %>
|
|
16
|
+
<% end %>
|