Merge branch 'styles-and-js-elements'

This commit is contained in:
2025-07-27 14:13:36 +03:00
10 changed files with 174 additions and 4 deletions
+1
View File
@@ -20,6 +20,7 @@ Style/StringLiterals:
# Mostly because of auto-generated files # Mostly because of auto-generated files
- Gemfile - Gemfile
- config/application.rb - config/application.rb
- config/importmap.rb
Bundler/OrderedGems: Bundler/OrderedGems:
Enabled: false Enabled: false
+13
View File
@@ -1,5 +1,18 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include Authentication include Authentication
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern allow_browser versions: :modern
helper_method :all_projects, :current_project
private
# Needed in projects selector (and can be used anywhere else)
def all_projects
Project.order(:name)
end
attr_accessor :current_project
end end
+1
View File
@@ -38,6 +38,7 @@ class ProjectsController < ApplicationController
def fetch_project! def fetch_project!
@project = Project.find_by!(code: params[:id]) @project = Project.find_by!(code: params[:id])
self.current_project = @project
end end
def project_params def project_params
+4 -3
View File
@@ -4,9 +4,9 @@ class TasksController < ApplicationController
before_action :fetch_task, only: %w[show edit update delete] before_action :fetch_task, only: %w[show edit update delete]
def index def index
@project = fetch_project self.current_project = fetch_project
@tasks = if @project @tasks = if current_project
@project.tasks current_project.tasks
else else
Task.all Task.all
end end
@@ -58,5 +58,6 @@ class TasksController < ApplicationController
def fetch_task def fetch_task
@task = Task.includes(:project).find_by_full_number_or_id!(params[:id]) @task = Task.includes(:project).find_by_full_number_or_id!(params[:id])
self.current_project = @task.project
end end
end end
+2
View File
@@ -1,2 +1,4 @@
# frozen_string_literal: true
module ApplicationHelper module ApplicationHelper
end end
@@ -0,0 +1,14 @@
import { Controller } from '@hotwired/stimulus'
class ProjectsSelectorController extends Controller {
static values = {
frame: String
}
changeProject(event) {
const href = event.target.value
Turbo.visit(href, {action: 'advance', frame: this.frameValue})
}
}
export default ProjectsSelectorController
@@ -0,0 +1,9 @@
<% if current_project %>
<section data-controller="projects-selector">
<select data-action="projects-selector#changeProject">
<% all_projects.each do |project| %>
<%= tag.option(project.name, value: project_path(project), selected: current_project == project) %>
<% end %>
</select>
</section>
<% end %>
+6 -1
View File
@@ -23,6 +23,11 @@
</head> </head>
<body> <body>
<%= yield %> <aside>
<%= render partial: 'projects_selector' %>
</aside>
<main>
<%= yield %>
</main>
</body> </body>
</html> </html>
+4
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Pin npm packages by running ./bin/importmap # Pin npm packages by running ./bin/importmap
pin "application" pin "application"
@@ -5,5 +7,7 @@ pin "@hotwired/turbo-rails", to: "turbo.min.js"
pin "@hotwired/stimulus", to: "stimulus.min.js" pin "@hotwired/stimulus", to: "stimulus.min.js"
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js" pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
pin_all_from "app/javascript/controllers", under: "controllers" pin_all_from "app/javascript/controllers", under: "controllers"
pin_all_from 'app/javascript/elements', under: 'elements'
pin "trix" pin "trix"
pin "@rails/actiontext", to: "actiontext.esm.js" pin "@rails/actiontext", to: "actiontext.esm.js"
pin 'lit', to: 'lit-all-3.3.1.min.js'
File diff suppressed because one or more lines are too long