Skip to content
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

Add edit functionality for datasets #204

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions app/controllers/datasets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,31 @@ def create

end

def update
def edit
@dataset = Dataset.find(params[:id])
@team = @dataset.team
authorize_for! @team

puts params
end


def update
@dataset = Dataset.find(params[:id])
@team = @dataset.team
authorize_for! @team

new_name = params.require(:dataset).permit(:name)[:name]

if @dataset.name != new_name && Dataset.exists?(name: new_name)
new_name = generate_unique_name(new_name)
end

if @dataset.update(name: new_name)
redirect_to team_datasets_url(@team)
else
render json: { errors: @dataset.errors.full_messages }, status: :unprocessable_entity
end
end

def destroy
@dataset = Dataset.find(params[:id])
@team = @dataset.team
Expand Down
10 changes: 10 additions & 0 deletions app/views/datasets/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="container">
<h3>Edit Dataset</h3>
<%= form_for @dataset do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<%= f.submit 'Update', class: 'btn btn-primary' %>
<% end %>
</div>
4 changes: 3 additions & 1 deletion app/views/datasets/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
</span>
</div>
<div>

<%= link_to edit_dataset_path(dataset), class: "px-3 py-2" do %>
<i class="fas fa-edit"></i>
<% end %>
<%= link_to dataset_path(dataset), method: :delete, data: { confirm: "Are you sure you want to delete '#{dataset.name}'? \n \nIf this is currently used on a project, it will become unavailable." }, class: "px-3 py-2 text-danger" do %>
<i class="fas fa-trash-alt"></i>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
resources :memberships
resources :overlays, only: [:index]

resources :datasets, only: [:index, :create, :show, :destroy, :update]
resources :datasets, only: [:index, :edit, :create, :show, :destroy, :update]

resources :label_schemas do
resources :duplicates, model_name: "LabelSchema"
Expand Down