Skip to content

Commit

Permalink
Create label templates
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni committed Aug 7, 2024
1 parent 7ad94cf commit dd60207
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/api/app/assets/stylesheets/webui/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
@import 'subscriptions';
@import 'build-log';
@import 'mixin';
@import 'validations';

html {
overflow-y: scroll !important;
Expand Down
3 changes: 3 additions & 0 deletions src/api/app/assets/stylesheets/webui/validations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.error-message {
color: var(--bs-danger-text-emphasis);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,24 @@ def index
@label_templates = @project.label_templates
end

def new
@label_template = authorize @project.label_templates.new
end

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

def create
@label_template = authorize @project.label_templates.new(label_template_params)

if @label_template.save
redirect_to project_label_templates_path(@project)
else
render :new
end
end

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

Expand Down
9 changes: 9 additions & 0 deletions src/api/app/helpers/webui/validation_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Webui::ValidationHelper
def classes_with_validation(model, field)
if model.errors.where(field).any?
'form-control is-invalid'
else
'form-control'
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 @@ -6,6 +6,14 @@ def index?
true
end

def new?
index?
end

def create?
index?
end

def edit?
index?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
= link_to(edit_project_label_template_path(@project, label_template)) do
%i.fas.fa-edit
Edit
.pt-4
= link_to new_project_label_template_path(@project) do
%i.fas.fa-plus-circle.text-primary
Create Label Template
24 changes: 24 additions & 0 deletions src/api/app/views/webui/projects/label_templates/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- @pagetitle = "Create label template 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], method: :post) do |f|
.row
.col-12.col-md-10.col-lg-9
.mb-3#name
= f.label(:name, 'Name:', class: 'form-label')
= f.text_field(:name, class: classes_with_validation(@label_template, :name))
- @label_template.errors.where(:name).each do |error|
.error-message= error.message.capitalize
.mb-3#color
= f.label(:color, 'Color:', class: 'form-label')
= f.color_field(:color, class: classes_with_validation(@label_template, :color))
- @label_template.errors.where(:color).each do |error|
.error-message= error.message.capitalize
.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('Create', class: 'btn btn-primary px-4 mt-3 mt-sm-0')
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 edit update], constraints: cons
resources :label_templates, controller: 'webui/projects/label_templates', constraints: cons
end

controller 'webui/request' do
Expand Down

0 comments on commit dd60207

Please sign in to comment.