-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project aliases #2644
Draft
mo-nathan
wants to merge
40
commits into
main
Choose a base branch
from
njw-project-aliases
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+529
−15
Draft
Project aliases #2644
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c94f5e2
Generate model ProjectAlias
mo-nathan b8f3756
Rubocop
mo-nathan 3ac26fb
Hookup ProjectAlias class
mo-nathan 2229d1c
Fix migration to use integers for references
mo-nathan 12c738d
Rubocop
mo-nathan 5aac91a
Merge branch 'main' into njw-project-aliases
mo-nathan fd9e403
Some simple tests
mo-nathan 744d015
Merge branch 'main' into njw-project-aliases
mo-nathan f5e79bb
Merge branch 'main' into njw-project-aliases
mo-nathan 2ebaf43
Merge branch 'main' into njw-project-aliases
mo-nathan ec1e816
First pass at CRUD
mo-nathan 829ea96
Rejigger ProjectAliases
mo-nathan 6fe4e88
Merge branch 'main' into njw-project-aliases
mo-nathan a1ce799
Rubocop
mo-nathan 8482da1
Merge branch 'main' into njw-project-aliases
mo-nathan 33946f2
Project Alias improvements
mo-nathan bd5baf9
Merge branch 'main' into njw-project-aliases
mo-nathan 24233b7
Merge branch 'main' into njw-project-aliases
mo-nathan fb4e4b7
Merge branch 'main' into njw-project-aliases
mo-nathan 2ad9e33
Merge branch 'main' into njw-project-aliases
mo-nathan ab0ccf8
Get autocompleter to switch from location to user
mo-nathan 16236da
Autocomplete fixes
mo-nathan 441c144
Fix new action for ProjectAliases
mo-nathan 9493462
Merge branch 'main' into njw-project-aliases
mo-nathan 35a2c25
Project Alias form fixes
mo-nathan 339eb57
Add more parens
mo-nathan ea2d105
Fixes for Project Alias delete routes
mo-nathan 12a46ed
Add tests for Project Alias controller
mo-nathan edecd37
Rubocop
mo-nathan bdb6a9e
Merge branch 'main' into njw-project-aliases
mo-nathan d8f0ba4
PR feedback
mo-nathan e6ed733
Switch to underscore test names
mo-nathan ebd42a5
Switch to submit button and cleanup button name
mo-nathan 15d7e37
Add links to targets and remove show link
mo-nathan e63b77e
Add alias lookup when saving a field slip form
mo-nathan aff4fd3
Fix broken tests
mo-nathan cd9ad1b
Merge branch 'main' into njw-project-aliases
mo-nathan 120b5c2
Merge branch 'main' into njw-project-aliases
mo-nathan d9fd3a0
Update user_str based on new interface for lookup_unique_text_name
mo-nathan 8ed460f
Merge branch 'main' into njw-project-aliases
mo-nathan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# frozen_string_literal: true | ||
|
||
module Projects | ||
class AliasesController < ApplicationController | ||
before_action :login_required | ||
before_action :pass_query_params, except: [:index] | ||
before_action :set_project_alias, only: [:show, :edit, :update, :destroy] | ||
|
||
def index | ||
@project = Project.find(params[:project_id]) | ||
@project_aliases = ProjectAlias.all | ||
respond_to do |format| | ||
format.html | ||
format.json { render(json: @project_aliases) } | ||
end | ||
end | ||
|
||
def show | ||
respond_to do |format| | ||
format.html | ||
format.json { render(json: @project_alias) } | ||
end | ||
end | ||
|
||
def new | ||
@project_alias = ProjectAlias.new(project_id: params.require(:project_id)) | ||
end | ||
|
||
def edit; end | ||
|
||
def create | ||
@project_alias = ProjectAlias.new(project_alias_params) | ||
|
||
respond_to do |format| | ||
if @project_alias.save | ||
format.html do | ||
project_alias_redirect(@project_alias) | ||
end | ||
else | ||
@project_alias = ProjectAlias.new(project_id: params[:project_id]) | ||
format.html { render(:new) } | ||
format.json do | ||
render(json: @project_alias.errors, status: :unprocessable_entity) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @project_alias.update(project_alias_params) | ||
format.html do | ||
redirect_to(project_alias_path( | ||
project_id: @project_alias.project_id, | ||
id: @project_alias.id | ||
), | ||
notice: :project_alias_updated.t) | ||
end | ||
format.json { render(json: @project_alias) } | ||
else | ||
format.html { render(:edit) } | ||
format.json do | ||
render(json: @project_alias.errors, status: :unprocessable_entity) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
project_id = @project_alias.project_id | ||
@project_alias.destroy | ||
respond_to do |format| | ||
format.html do | ||
redirect_to(project_aliases_path(project_id:), | ||
notice: :project_alias_destroyed.t) | ||
end | ||
format.json { head(:no_content) } | ||
end | ||
end | ||
|
||
private | ||
|
||
def project_alias_redirect(project_alias) | ||
redirect_to(project_alias_path( | ||
project_id: project_alias.project_id, | ||
id: project_alias.id | ||
), | ||
notice: :project_alias_created.t) | ||
end | ||
|
||
def set_project_alias | ||
@project_alias = ProjectAlias.find(params[:id]) | ||
end | ||
|
||
def project_alias_params | ||
params.require(:project_alias).permit(:name, :project_id, :target_type, | ||
:location_id, :user_id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class ProjectAlias < ApplicationRecord | ||
belongs_to :target, polymorphic: true | ||
belongs_to :project | ||
|
||
validates :name, presence: true | ||
|
||
def location_id=(id) | ||
self.target_id = id | ||
end | ||
|
||
def user_id=(id) | ||
self.target_id = id | ||
end | ||
|
||
def target_type=(type) | ||
self[:target_type] = type.capitalize | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<% | ||
@container = :text | ||
type = (project_alias.target_type || :location).downcase.to_sym | ||
value = project_alias.target&.name || "" | ||
%> | ||
<%= form_with(model: project_alias, | ||
data: { controller: :autocompleter, type: }) do |form| %> | ||
<% if project_alias.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(project_alias.errors.count, "error") %> prohibited this project alias from being saved:</h2> | ||
<ul> | ||
<% project_alias.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= text_field_with_label(form:, field: :name, label: "#{:Name.t}:", inline: true) %> | ||
</div> | ||
mo-nathan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<div class="field"> | ||
<%= form.hidden_field(:project_id, value: project_alias.project_id) %> | ||
</div> | ||
|
||
<%= tag.div(class: "form-group dropdown", | ||
data: { autocompleter_target: "wrap" } ) do %> | ||
<div class="field"> | ||
<%= select_with_label(form:, | ||
field: :target_type, | ||
label: "#{:project_alias_type.t}:", | ||
options: [[:USER.l, :user], [:LOCATION.l, :location]], | ||
inline: true, | ||
selected: type, | ||
data: { autocompleter_target: "select", | ||
action: "autocompleter#swap" }) %> | ||
</div> | ||
|
||
<%= autocompleter_hidden_field(form:, type:, hidden_value: project_alias.target_id) %> | ||
<%= form.text_field( | ||
:term, value: value, class: "form-control", | ||
data: { autocompleter_target: "input" } | ||
) %> | ||
<%= autocompleter_dropdown %> | ||
<% end %> | ||
|
||
<div class="actions"> | ||
<%= form.submit %> | ||
</div> | ||
mo-nathan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<% | ||
add_project_banner(@project_alias.project) | ||
@container = :wide | ||
mo-nathan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
project_id = @project_alias.project_id | ||
%> | ||
|
||
<h1>Editing Project Alias</h1> | ||
|
||
<%= render('form', project_alias: @project_alias) %> | ||
|
||
<%= link_to 'Show', project_alias_path(project_id:, id: @project_alias.id) %> | | ||
<%= link_to 'Back', project_aliases_path(project_id:) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<% | ||
add_project_banner(@project) | ||
@container = :wide | ||
project_id = @project.id | ||
%> | ||
|
||
<h1>Project Aliases</h1> | ||
|
||
<table class="table table-striped table-project-members mt-3"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Target Type</th> | ||
<th>Target</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @project_aliases.each do |project_alias| %> | ||
<tr> | ||
<td><%= project_alias.name %></td> | ||
<td><%= project_alias.target_type %></td> | ||
<td><%= project_alias.target.try(:name) %></td> | ||
<td> | ||
<%= link_to('Show', project_alias_path(project_id:, id: project_alias.id)) %> | ||
<%= link_to('Edit', edit_project_alias_path(project_id:, id: project_alias.id)) %> | ||
<%= link_to('Delete', project_alias_path(project_id:, id: project_alias.id), | ||
data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }) %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<%= link_to 'New Project Alias', new_project_alias_path(project_id:) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% | ||
add_project_banner(@project_alias.project) | ||
@container = :wide | ||
mo-nathan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
project_id = @project_alias.project_id | ||
%> | ||
|
||
<h1>New Project Alias</h1> | ||
|
||
<%= render('form', project_alias: @project_alias) %> | ||
|
||
<%= link_to('Back', project_aliases_path(project_id: @project_alias.project_id)) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% | ||
add_project_banner(@project_alias.project) | ||
@container = :wide | ||
project_id = @project_alias.project_id | ||
%> | ||
|
||
<p> | ||
<strong>Name:</strong> | ||
<%= @project_alias.name %> | ||
</p> | ||
|
||
<p> | ||
<strong>Target Type:</strong> | ||
<%= @project_alias.target_type %> | ||
</p> | ||
|
||
<p> | ||
<strong>Target:</strong> | ||
<%= @project_alias.target.try(:name) %> | ||
</p> | ||
|
||
<%= link_to 'Edit', edit_project_alias_path(project_id:, id: @project_alias.id) %> | | ||
<%= link_to 'Back', project_aliases_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateProjectAliases < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table(:project_aliases) do |t| | ||
t.integer(:project_id, null: false) | ||
t.integer(:target_id, null: false) | ||
t.string(:target_type, null: false) | ||
t.string(:name) | ||
|
||
t.timestamps | ||
|
||
t.foreign_key(:projects) | ||
t.index([:target_type, :target_id]) | ||
t.index(:project_id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this Stimulus controller has a method
verbose
. If you switch yourto
and then uncomment the actual method body of
verbose
, it will log a whole trace of what it's executing (as defined by wherever Jason and I left lines that saythis.verbose("Say something");
However that may give you more info than you want.