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

Feature/documents #8

Merged
merged 14 commits into from
Jul 23, 2019
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true

Style/RescueModifier:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Expand Down
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ GEM
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_material (1.4.2)
activeadmin (2.1.0)
activeadmin (2.2.0)
arbre (~> 1.2, >= 1.2.1)
formtastic (~> 3.1)
formtastic_i18n (~> 0.4)
inherited_resources (~> 1.7)
jquery-rails (~> 4.2)
kaminari (~> 1.0, >= 1.0.1)
railties (>= 5.0, < 6.0)
railties (>= 5.0, < 6.1)
ransack (~> 2.1, >= 2.1.1)
sassc-rails (~> 2.1)
sprockets (>= 3.0, < 4.1)
Expand Down Expand Up @@ -84,7 +84,7 @@ GEM
arel (9.0.0)
ast (2.4.0)
aws-eventstream (1.0.3)
aws-partitions (1.184.0)
aws-partitions (1.191.0)
aws-sdk-core (3.59.0)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1.0)
Expand All @@ -110,15 +110,15 @@ GEM
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
bcrypt (3.1.13)
bindex (0.7.0)
bindex (0.8.1)
bootsnap (1.4.4)
msgpack (~> 1.0)
builder (3.2.3)
bullet (6.0.1)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
byebug (11.0.1)
capybara (3.25.0)
capybara (3.26.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand Down Expand Up @@ -247,7 +247,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (12.3.2)
rake (12.3.3)
ransack (2.1.1)
actionpack (>= 5.0)
activerecord (>= 5.0)
Expand All @@ -256,7 +256,7 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
regexp_parser (1.5.1)
regexp_parser (1.6.0)
request_store (1.4.1)
rack (>= 1.4)
require_all (1.5.0)
Expand All @@ -282,7 +282,7 @@ GEM
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
rubocop (0.72.0)
rubocop (0.73.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.6)
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The backoffice for laws and pathways

- Ruby v2.5.5
- Rails v5.2.3
- Node v10

## Local installation

Expand All @@ -15,6 +16,10 @@ These are the steps to run the project locally:

On the project's root run `bundle install`.

### Installing npm dependencies

`yarn`

### Database

#### Create database schema
Expand All @@ -23,7 +28,11 @@ On the project's root run `bundle install`.

### Run the server

`bundle exec rails s'` and access the project on `http://localhost:3000`
`yarn start'` and access the project on `http://localhost:3000`

### Run the tests

`yarn test`

## Docker

Expand Down
36 changes: 36 additions & 0 deletions app/admin/documents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ActiveAdmin.register Document do
menu priority: 3

decorate_with DocumentDecorator

filter :name_contains
filter :documentable_type, label: 'Attached to'

config.batch_actions = false

actions :all, except: [:new, :edit, :create, :update]

show do
attributes_table do
row :id
row :name
row :link, &:document_url_link
row :last_verified_on
row :created_at
row :updated_at
end
end

index do
column 'Name', &:document_page_link
column 'Attached To', :documentable
column :last_verified_on
actions
end

controller do
def scoped_collection
super.includes(:documentable)
end
end
end
22 changes: 9 additions & 13 deletions app/admin/litigations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

decorate_with LitigationDecorator

permit_params :title, :location_id, :document_type, :summary, :core_objective
permit_params :title, :location_id, :document_type, :summary, :core_objective,
documents_attributes: [
:id, :_destroy, :name, :external_url, :type, :file
]

filter :title_contains
filter :summary_contains
Expand Down Expand Up @@ -36,6 +39,7 @@
row :core_objective
row :created_at
row :updated_at
list_row 'Documents', :document_links
end
end

Expand All @@ -51,21 +55,13 @@
end
end

form do |f|
f.semantic_errors(*f.object.errors.keys)
form partial: 'form'

f.inputs do
f.input :title
f.input :location
f.input :document_type, as: :select, collection: array_to_select_collection(Litigation::DOCUMENT_TYPES)
f.input :summary, as: :trix
f.input :core_objective, as: :trix
controller do
def scoped_collection
super.includes(:location)
end

f.actions
end

controller do
def find_resource
scoped_collection.friendly.find(params[:id])
end
Expand Down
52 changes: 46 additions & 6 deletions app/assets/stylesheets/active_admin.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
$am-theme-primary: #00689f;
$am-theme-accent: #7dd2f7;
$am-theme-accent-fallback: #ff7547;

$padding: 20px;

@import 'admin/settings';
@import 'trix/dist/trix';
@import 'activeadmin_addons/all';

// SASS variable overrides must be declared before loading up Active Admin's styles.
//
// To view the variables that Active Admin provides, take a look at
Expand All @@ -23,6 +19,22 @@ $padding: 20px;
display: none;
}

.button {
margin: 0;

&--raised {
@include am-btn-raised;
}

&--red {
background-color: $admin-red;

&:hover {
background-color: lighten($admin-red, 20%);
}
}
}

.table_tools {
.scope {
margin: 0;
Expand Down Expand Up @@ -128,3 +140,31 @@ form {
}
}
}

// Documents

.document-list {
&__actions {
padding: 16px;
}
}

.inline-fields {
display: flex;
justify-content: space-around;
align-items: center;

li {
margin: 0;

&.input:not(.error) {
input {
margin-bottom: 20px;
}
}
}

.flex-grow-1 {
flex-grow: 1;
}
}
9 changes: 9 additions & 0 deletions app/assets/stylesheets/admin/settings.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$padding: 20px;

//Colors
$admin-red: red;

// Active Material Theme Colors Change
$am-theme-primary: #00689f;
$am-theme-accent: #7dd2f7;
$am-theme-accent-fallback: $admin-red;
17 changes: 17 additions & 0 deletions app/decorators/document_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class DocumentDecorator < Draper::Decorator
delegate_all

def document_page_link
h.link_to model.name, h.admin_document_path(model)
end

def document_url_link
h.link_to model.name, model.url, target: '_blank'
end

def last_verified_on
return 'N/A' if model.uploaded?

model.last_verified_on
end
end
8 changes: 8 additions & 0 deletions app/decorators/litigation_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ def summary
def core_objective
model.core_objective.html_safe
end

def document_links
return [] if model.documents.empty?

model.documents.map do |document|
h.link_to document.name, document.url, target: '_blank'
end
end
end
2 changes: 1 addition & 1 deletion app/javascript/controllers/dependent_input_controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller } from "stimulus";
import { Controller } from 'stimulus';

export default class extends Controller {
connect() {
Expand Down
42 changes: 42 additions & 0 deletions app/javascript/controllers/nested_list_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Controller } from 'stimulus';

export default class extends Controller {
static targets = ['links']

connect() {
this.wrapperClass = this.data.get('wrapperClass') || 'nested-fields';
}

addRecord(event) {
event.preventDefault();

const templateName = event.target.dataset['template'];
const content = this._getTemplateElement(templateName)
.innerHTML
.replace(/NEW_RECORD/g, new Date().getTime());

this.linksTarget.insertAdjacentHTML('beforebegin', content);
}

removeRecord(event) {
event.preventDefault();

const wrapper = event.target.closest('.' + this.wrapperClass);

// New records are simply removed from the page
if (wrapper.dataset.newRecord == 'true') {
wrapper.remove();

// Existing records are hidden and flagged for deletion
} else {
wrapper.querySelector('input[name*="_destroy"]').value = 1;
wrapper.style.display = 'none';
}
}

_getTemplateElement(name) {
if (!name) return this.element.querySelector('template');

return this.element.querySelector(`template[name*=${name}]`);
}
}