Skip to content

Commit

Permalink
Switch to modal for AliasController#new
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-nathan committed Feb 2, 2025
1 parent dc8c31d commit 3c2bf02
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
20 changes: 17 additions & 3 deletions app/controllers/projects/aliases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ def show

def new
project_id = params.require(:project_id)
new_params = params.permit(:user_id, :target_type)
new_params[:project_id] = project_id
new_params = params.permit(:project_id, :target_type, :target_id,
:user_id, :location_id)
@project_alias = ProjectAlias.new(new_params)

respond_to do |format|
format.turbo_stream { render_modal_project_alias_form }
format.html
end
end

def edit
Expand Down Expand Up @@ -91,7 +96,7 @@ def destroy
def render_modal_project_alias_form
render(
partial: "shared/modal_form",
locals: { title: "Modal Title", identifier: modal_identifier,
locals: { title: modal_title, identifier: modal_identifier,
form: "projects/aliases/form", project_alias: @project_alias }
) and return
end
Expand All @@ -105,6 +110,15 @@ def modal_identifier
end
end

def modal_title
case action_name
when "new", "create"
:project_alias_new.l
when "edit", "update"
:project_alias_edit.l(name: @project_alias.name)
end
end

def project_alias_redirect(project_alias)
redirect_to(project_alias_path(
project_id: project_alias.project_id,
Expand Down
19 changes: 15 additions & 4 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,27 @@ def edit_project_alias_modal(project_id, name, id)
end
end

def unique_class_id(id)
@@counter ||= 0
@@counter += 1
"tab_#{@@counter}_#{id}"
def new_project_alias_modal(project_id, target_id, target_type)
tag.span(id: "project_alias") do
modal_link_to(
"project_alias", :ADD.t,
add_query_param(new_project_alias_path(project_id:,
target_id:,
target_type:)),
class: unique_class_id(target_id) + " btn btn-default")
end
end

#########

private

def unique_class_id(id)
@@counter ||= 0
@@counter += 1
"link_#{@@counter}_#{id}"
end

def violation_latitude_header(project)
return :form_violations_latitude_none.l unless project.location

Expand Down
6 changes: 2 additions & 4 deletions app/views/controllers/projects/_aliases.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<% project_id = project.id %>
<% project.alias_data(user).each do |name, id| %>
<%= edit_project_alias_modal(project_id, name, id) %>
<%= link_to(name, edit_project_alias_path(project_id:, id:)) %><br/>
<%= edit_project_alias_modal(project_id, name, id) %><br/>
<% end %>
<% if project.alias_data(user).any? %>
<br/>
<% end %>
<%= link_to(:ADD.t, new_project_alias_path(project_id:, user_id: user.id, target_type: User),
class: "btn btn-default") %>
<%= new_project_alias_modal(project_id, user.id, User) %><br/>
2 changes: 1 addition & 1 deletion app/views/controllers/projects/aliases/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
project_id = @project_alias.project_id
%>

<h1>Editing Project Alias</h1>
<h1><%= :project_alias_edit.l(name: @project_alias.name) %></h1>

<%= render('form', project_alias: @project_alias) %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/controllers/projects/aliases/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
project_id = @project_alias.project_id
%>

<h1>New Project Alias</h1>
<h1><%= :project_alias_new.l %></h1>

<%= render('form', project_alias: @project_alias) %>

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,7 @@
# Project Aliases
project_alias_created: Field slip was successfully created.
project_alias_destroyed: Field slip was successfully destroyed.
project_alias_edit: Edit Project Alias [name]
project_alias_new: New Project Alias
project_alias_type: Alias Type
project_alias_updated: Field slip was successfully updated.
Expand Down

0 comments on commit 3c2bf02

Please sign in to comment.