Skip to content

Commit

Permalink
Merge pull request openSUSE#16642 from danidoni/edit-label-templates
Browse files Browse the repository at this point in the history
Edit label templates
  • Loading branch information
danidoni authored Aug 7, 2024
2 parents 4f0cd6d + 9995770 commit 7ad94cf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ def index

@label_templates = @project.label_templates
end

def edit
@label_template = authorize @project.label_templates.find(params[:id])
end

def update
@label_template = authorize @project.label_templates.find(params[:id])

if @label_template.update(label_template_params)
redirect_to project_label_templates_path(@project)
else
render :edit
end
end

private

def label_template_params
params.require(:label_template).permit(:name, :color)
end
end
end
end
8 changes: 8 additions & 0 deletions src/api/app/policies/label_template_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@ def index?

true
end

def edit?
index?
end

def update?
index?
end
end
20 changes: 20 additions & 0 deletions src/api/app/views/webui/projects/label_templates/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- @pagetitle = "Edit label template \"#{@label_template.name}\" for #{@project}"
.card
= render(partial: 'webui/project/tabs', locals: { project: @project })

.card-body
%h3= @pagetitle
.row
.col-12.col-md-10.col-lg-8
= form_with(model: @label_template, url: project_label_template_path(project_name: @project, id: @label_template), method: :put) do |f|
.row
.col-12.col-md-10.col-lg-9
.mb-3#name
= f.label(:name, 'Name:')
= f.text_field(:name, class: 'form-control')
.mb-3#color
= f.label(:color, 'Color:')
= f.color_field(:color, class: 'form-control')
.actions
= link_to('Cancel', project_label_templates_path(@project), title: 'Cancel', class: 'btn btn-outline-secondary px-4 me-3 mt-3 mt-sm-0')
= f.submit('Update', class: 'btn btn-primary px-4 mt-3 mt-sm-0')
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
- @label_templates.each do |label_template|
%li.mb-2
= render partial: 'webui/shared/label', locals: { label: label_template }
= link_to(edit_project_label_template_path(@project, label_template)) do
%i.fas.fa-edit
Edit
2 changes: 1 addition & 1 deletion src/api/config/routes/webui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
end
end
put 'toggle_watched_item', controller: 'webui/watched_items', constraints: cons
resources :label_templates, controller: 'webui/projects/label_templates', only: %i[index], constraints: cons
resources :label_templates, controller: 'webui/projects/label_templates', only: %i[index edit update], constraints: cons
end

controller 'webui/request' do
Expand Down

0 comments on commit 7ad94cf

Please sign in to comment.