From 7063d0094baa2e7444e20cf1b967865893ea6621 Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Wed, 24 Jul 2019 17:37:03 +0200 Subject: [PATCH 01/15] litigation sides dynamic list --- app/admin/litigations.rb | 3 ++ app/assets/stylesheets/active_admin.scss | 30 ++++++++++-- app/assets/stylesheets/admin/mixins.scss | 17 +++++++ app/assets/stylesheets/admin/settings.scss | 4 ++ app/javascript/controllers/tabs_controller.js | 24 ++++++++++ app/models/litigation.rb | 1 + app/models/litigation_side.rb | 2 + app/views/admin/documents/_list.html.erb | 4 +- app/views/admin/litigations/_form.html.erb | 47 ++++++++++++++----- .../admin/litigations/_side_fields.html.erb | 12 +++++ .../admin/litigations/_sides_list.html.erb | 15 ++++++ 11 files changed, 141 insertions(+), 18 deletions(-) create mode 100644 app/assets/stylesheets/admin/mixins.scss create mode 100644 app/javascript/controllers/tabs_controller.js create mode 100644 app/views/admin/litigations/_side_fields.html.erb create mode 100644 app/views/admin/litigations/_sides_list.html.erb diff --git a/app/admin/litigations.rb b/app/admin/litigations.rb index 5e8b9038a..6b88c61b1 100644 --- a/app/admin/litigations.rb +++ b/app/admin/litigations.rb @@ -4,6 +4,9 @@ decorate_with LitigationDecorator permit_params :title, :location_id, :document_type, :summary, :core_objective, + litigation_sides_attributes: [ + :id, :_destroy, :name, :side_type, :party_type + ], documents_attributes: [ :id, :_destroy, :name, :external_url, :type, :file ] diff --git a/app/assets/stylesheets/active_admin.scss b/app/assets/stylesheets/active_admin.scss index 038fa3df7..7d444bb37 100644 --- a/app/assets/stylesheets/active_admin.scss +++ b/app/assets/stylesheets/active_admin.scss @@ -1,4 +1,5 @@ @import 'admin/settings'; +@import 'admin/mixins'; @import 'trix/dist/trix'; @import 'activeadmin_addons/all'; @@ -109,6 +110,13 @@ form { list-style: disc; color: $am-theme-error; } + + fieldset.inputs { + > legend { + font-size: 18px; + font-weight: bold; + } + } } // Comments @@ -141,9 +149,7 @@ form { } } -// Documents - -.document-list { +.nested-list { &__actions { padding: 16px; } @@ -151,14 +157,14 @@ form { .inline-fields { display: flex; - justify-content: space-around; + justify-content: space-between; align-items: center; li { margin: 0; &.input:not(.error) { - input { + input, .select2, select { margin-bottom: 20px; } } @@ -168,3 +174,17 @@ form { flex-grow: 1; } } + +.litigation-sides-fields { + li[id*=side_type] { + min-width: 100px; + } + + li[id*=party_type] { + min-width: 250px; + } + + @include desktop-large { + width: 70%; + } +} diff --git a/app/assets/stylesheets/admin/mixins.scss b/app/assets/stylesheets/admin/mixins.scss new file mode 100644 index 000000000..35e1cb6ce --- /dev/null +++ b/app/assets/stylesheets/admin/mixins.scss @@ -0,0 +1,17 @@ +@mixin tablet { + @media (min-width: $breakpoint-tablet) { + @content; + } +} + +@mixin desktop { + @media (min-width: $breakpoint-desktop) { + @content; + } +} + +@mixin desktop-large { + @media (min-width: $breakpoint-desktop-large) { + @content; + } +} diff --git a/app/assets/stylesheets/admin/settings.scss b/app/assets/stylesheets/admin/settings.scss index f59ac6a24..64c338c2a 100644 --- a/app/assets/stylesheets/admin/settings.scss +++ b/app/assets/stylesheets/admin/settings.scss @@ -7,3 +7,7 @@ $admin-red: red; $am-theme-primary: #00689f; $am-theme-accent: #7dd2f7; $am-theme-accent-fallback: $admin-red; + +$breakpoint-tablet: 768px; +$breakpoint-desktop: 992px; +$breakpoint-desktop-large: 1200px; diff --git a/app/javascript/controllers/tabs_controller.js b/app/javascript/controllers/tabs_controller.js new file mode 100644 index 000000000..b88faed55 --- /dev/null +++ b/app/javascript/controllers/tabs_controller.js @@ -0,0 +1,24 @@ +import { Controller } from 'stimulus'; + +export default class extends Controller { + static targets = ['activeTab'] + + connect() { + $(this.element).tabs(); + + $(this.element.querySelectorAll('.nav-tabs a')).on('click', (event) => { + event.preventDefault(); + this._changeActiveTabTo(event.target.hash); + }); + + const activeTab = this.activeTabTarget.value; + if (activeTab) { + $(this.element).find(`.nav-tabs a[href="${activeTab}"]`).click(); + } + } + + _changeActiveTabTo(hash) { + window.location.hash = hash; + this.activeTabTarget.value = hash; + } +} diff --git a/app/models/litigation.rb b/app/models/litigation.rb index 2eeaa116c..a53953811 100644 --- a/app/models/litigation.rb +++ b/app/models/litigation.rb @@ -29,6 +29,7 @@ class Litigation < ApplicationRecord has_many :documents, as: :documentable, dependent: :destroy accepts_nested_attributes_for :documents, allow_destroy: true + accepts_nested_attributes_for :litigation_sides, allow_destroy: true validates_presence_of :title, :slug, :document_type end diff --git a/app/models/litigation_side.rb b/app/models/litigation_side.rb index ec6400841..8582593a5 100644 --- a/app/models/litigation_side.rb +++ b/app/models/litigation_side.rb @@ -24,5 +24,7 @@ class LitigationSide < ApplicationRecord enum side_type: array_to_enum_hash(SIDE_TYPES) enum party_type: array_to_enum_hash(PARTY_TYPES) + validates_presence_of :side_type, :party_type + belongs_to :litigation end diff --git a/app/views/admin/documents/_list.html.erb b/app/views/admin/documents/_list.html.erb index 390ce91a1..45a822f70 100644 --- a/app/views/admin/documents/_list.html.erb +++ b/app/views/admin/documents/_list.html.erb @@ -1,4 +1,4 @@ -
+