Skip to content

Commit

Permalink
Merge pull request #8251 from dmarcoux/bootstrap-attributes
Browse files Browse the repository at this point in the history
Replace Bento by Bootstrap for attributes
  • Loading branch information
hennevogel committed Sep 3, 2019
2 parents b0d4482 + 5f95bff commit 8a51e90
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 352 deletions.
10 changes: 8 additions & 2 deletions src/api/app/controllers/webui/attribute_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class Webui::AttributeController < Webui::WebuiController
include Webui2::AttributeController

helper :all
before_action :set_container, only: [:index, :new, :edit]
before_action :set_attribute, only: [:update, :destroy]
Expand All @@ -25,6 +23,8 @@ def new

authorize @attribute, :create?

@attribute_types = AttribType.includes(:attrib_namespace).all.sort_by(&:fullname)

switch_to_webui2
end

Expand All @@ -40,6 +40,12 @@ def edit
(value_count - values_length).times { @attribute.values.build(attrib: @attribute) }
end

if @attribute.attrib_type.issue_list
@issue_trackers = IssueTracker.order(:name).all
end

@allowed_values = @attribute.attrib_type.allowed_values.map(&:value)

switch_to_webui2
end

Expand Down
13 changes: 0 additions & 13 deletions src/api/app/controllers/webui2/attribute_controller.rb

This file was deleted.

34 changes: 0 additions & 34 deletions src/api/app/views/webui/attribute/_attributes.html.haml

This file was deleted.

47 changes: 27 additions & 20 deletions src/api/app/views/webui/attribute/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
= form_for(@attribute) do |attribute_form|
- if @attribute.errors.any?
- value_fields_locals = { attribute: attribute, allowed_values: allowed_values }
- issue_fields_locals = { issue_trackers: issue_trackers }

= form_for(attribute) do |form|
= form.hidden_field(:attrib_type_id)

- errors = attribute.errors
- if errors.present?
#error-explanation
%h2
= pluralize(@attribute.errors.count, "error")
prohibited this attribute from being saved:
%h2 "#{pluralize(errors.count, 'error')} prohibited this attribute from being saved:"
%ul
- @attribute.errors.full_messages.each do |message|
%li
= message
- errors.full_messages.each do |message|
%li= message

#values
= attribute_form.fields_for :values do |value|
= render 'value_fields', f: value
- if @attribute.values_addable?
= form.fields_for :values do |value|
= render('value_fields', { f: value }.merge(value_fields_locals))
- if attribute.values_addable?
%p
= link_to_add_association('Add a value', attribute_form, :values)
- if @attribute.attrib_type.issue_list
= link_to_add_association(form, :values, render_options: { locals: value_fields_locals }, title: 'Add a value') do
%i.fas.fa-plus-circle.text-success
Add a value
- if issue_trackers
#issues
= attribute_form.fields_for :issues do |issue|
= render 'issue_fields', f: issue
%p
= link_to_add_association 'add issue', attribute_form, :issues
.actions
= attribute_form.hidden_field(:attrib_type_id)
= form.fields_for :issues do |issue|
= render('issue_fields', { f: issue }.merge(issue_fields_locals))
%p
= attribute_form.submit('Save')
= link_to_add_association(form, :issues, render_options: { locals: issue_fields_locals }, title: 'Add an issue') do
%i.fas.fa-plus-circle.text-primary
Add an issue

= link_to('Back', index_attribs_path, class: 'btn btn-outline-secondary', role: 'button')
= form.submit('Save', class: 'btn btn-primary')
15 changes: 10 additions & 5 deletions src/api/app/views/webui/attribute/_issue_fields.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.nested-fields
.field
= f.select :issue_tracker_id, IssueTracker.all.collect { |tracker| [tracker.name, tracker.id] }.sort, include_blank: false
= f.label :id
= f.text_field :name
= link_to_remove_association "remove issue", f
.field.form-row.form-group
.col-auto
= f.collection_select(:issue_tracker_id, issue_trackers, :id, :name, {}, class: 'form-control')
.col-auto.col-form-label
= f.label(:id, 'ID:')
.col
= f.text_field(:name, class: 'form-control')
.col-auto.col-form-label
= link_to_remove_association(f, title: 'Delete issue') do
%i.fas.fa-times-circle.text-danger
30 changes: 18 additions & 12 deletions src/api/app/views/webui/attribute/_value_fields.html.haml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
.nested-fields
.field
%p
- if @attribute.values_addable?
= f.label :position
= f.number_field :position, class: "attrib-position-input", size: 3
= f.label :value
- if @attribute.attrib_type.allowed_values.any?
= f.select :value, @attribute.attrib_type.allowed_values.map(&:value), { include_blank: false }, { id: 'attrib-default-select' }
- else
= f.text_area :value
- if @attribute.values_removeable?
= link_to_remove_association('Remove value', f)
.field.form-row.form-group
- if attribute.values_addable?
.col-auto.col-form-label
= f.label(:position, 'Position:')
.col-1
= f.number_field(:position, class: 'form-control', min: 1)
.col-auto.col-form-label
= f.label(:value, 'Value:')
- if allowed_values.present?
.col-auto
= f.select(:value, allowed_values, {}, class: 'form-control')
- else
.col
= f.text_area(:value, class: 'form-control')
- if attribute.values_removeable?
.col-auto.col-form-label
= link_to_remove_association(f, title: 'Delete value') do
%i.fas.fa-times-circle.text-danger
32 changes: 12 additions & 20 deletions src/api/app/views/webui/attribute/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
- @pagetitle = "Edit Attribute #{@attribute.fullname} on #{@container.class} #{@container.name}"
- project_bread_crumb
- if @package
- @crumb_list << link_to(@package, package_show_path(package: @package))
- @crumb_list << link_to('Attributes', index_attribs_path(project: @project.name, package: @package))
- else
- @crumb_list << link_to('Attributes', index_attribs_path(project: @project.name))
- @crumb_list << @attribute.fullname
- if @package
= render partial: "webui/package/tabs"
- else
= render partial: "webui/project/tabs"
%h2
= @pagetitle
%p
= @attribute.attrib_type.description
- if @attribute.values_editable?
= render 'form'
- else
%p
This attribute has no values to edit
.card
= render(partial: "webui/#{@container.model_name.singular}/tabs", locals: { project: @project, package: @package })

.card-body
%h3= @pagetitle
%p
= @attribute.attrib_type.description
- if @attribute.values_editable?
= render(partial: 'form', locals: { attribute: @attribute, issue_trackers: @issue_trackers, allowed_values: @allowed_values })
- else
%p
This attribute has no values to edit
56 changes: 46 additions & 10 deletions src/api/app/views/webui/attribute/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
- @pagetitle = "Attributes"
- project_bread_crumb
- if @package
- @crumb_list << link_to(@package, package_show_path(package: @package))
- @crumb_list << "Attributes"
- if @package
= render partial: "webui/package/tabs"
- else
= render partial: "webui/project/tabs"
= render partial: "attributes"
- @pagetitle = "Attributes of #{@package ? "#{@package} (Project #{@project})" : "Project #{@project}"}"
- can_update_container = policy(@container).update?

.card
= render(partial: "webui/#{@container.model_name.singular}/tabs", locals: { project: @project, package: @package })

.card-body
%h3= @pagetitle
- if @attributes.present?
%table.responsive.table.table-bordered.table-hover.w-100#attributes
%thead
%tr
%th Attributes
%th Values
- if can_update_container
%th Actions
%tbody
- @attributes.each do |attribute|
%tr
%td.text-word-break-all= attribute.fullname
%td
%ul
- unless attribute.values.empty?
- attribute.values.each do |v|
%li.value
%pre.d-inline= v.value
- unless attribute.issues.empty?
%li= attribute.issues.map(&:name).to_sentence
- if can_update_container
%td
- if attribute.values_editable?
= link_to(edit_attribs_path(project: @project.name, package: @package, attribute: attribute.fullname), title: 'Edit values') do
%i.fas.fa-edit.text-secondary
= link_to('#', title: 'Delete attribute',
data: { toggle: 'modal', target: '#delete-attribute-modal', action: attrib_path(attribute), fullname: attribute.fullname }) do
%i.fas.fa-times-circle.text-danger
- else
%p
%em No attributes set

- if can_update_container
%p
= link_to(new_attribs_path(project: @project.name, package: @package), title: 'Add a new attribute') do
%i.fas.fa-plus-circle.text-primary
Add a new attribute
= render(partial: 'delete_dialog')
50 changes: 20 additions & 30 deletions src/api/app/views/webui/attribute/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
- @pagetitle = "Add Attribute"
- project_bread_crumb
- if @package
- @crumb_list << link_to(@package, package_show_path(package: @package))
- @crumb_list << link_to('Attributes', index_attribs_path(project: @project.name, package: @package))
- else
- @crumb_list << link_to('Attributes', index_attribs_path(project: @project.name))
- @crumb_list << "Add"
- if @package
= render partial: "webui/package/tabs"
- else
= render partial: "webui/project/tabs"
%h2
= @pagetitle
= form_for(@attribute) do |f|
.field
%p
= f.select :attrib_type_id, AttribType.includes(:attrib_namespace).collect { |a| [a.fullname, a.id] }.sort, include_blank: false
= hidden_field_tag("attrib[project_id]", @attribute.project_id)
= hidden_field_tag("attrib[package_id]", @attribute.package_id) if @attribute.package_id
%p.help-block#first-help
= AttribType.all.to_a.sort_by { |t| t.fullname }.first.description
= "Sorry, this attribute has no description" if AttribType.all.to_a.sort_by { |t| t.fullname }.first.description.blank?
- AttribType.all.each do |type|
%p.help-block.attrib-type{ id: "#{type.id}-help" }
= type.description
= "Sorry, this attribute has no description" if type.description.blank?
.actions
%p
= f.submit('Add')
- @pagetitle = 'Add Attribute'

.card
= render(partial: "webui/#{@container.model_name.singular}/tabs", locals: { project: @project, package: @package })

.card-body
%h3= @pagetitle
= form_for(@attribute) do |form|
.form-row
= form.hidden_field(:project_id)
- if @attribute.package_id
= form.hidden_field(:package_id)
.col-12.col-md-auto
= form.collection_select(:attrib_type_id, @attribute_types, :id, :fullname, {}, class: 'form-control custom-select')
.col-form-label.col-12.col-md
- @attribute_types.each do |attribute_type|
%p.d-none{ id: "attribute_type-description-#{attribute_type.id}" }
= attribute_type.description.presence || 'Sorry, this attribute has no description'
= link_to('Back', index_attribs_path, class: 'btn btn-outline-secondary', role: 'button')
= form.submit('Add', class: 'btn btn-primary')
33 changes: 0 additions & 33 deletions src/api/app/views/webui2/webui/attribute/_form.html.haml

This file was deleted.

11 changes: 0 additions & 11 deletions src/api/app/views/webui2/webui/attribute/_issue_fields.html.haml

This file was deleted.

19 changes: 0 additions & 19 deletions src/api/app/views/webui2/webui/attribute/_value_fields.html.haml

This file was deleted.

Loading

0 comments on commit 8a51e90

Please sign in to comment.