Skip to content

Commit 8f4cf41

Browse files
authored
Add reusable application_forms/index view and ApplicationFormsPresenter (#43)
- Add reusable application_forms/index view - Add ApplicationFormsPresenter - Add ApplicationFormPresenter
1 parent 8bbb396 commit 8f4cf41

12 files changed

Lines changed: 194 additions & 1 deletion

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Flex
2+
class ApplicationFormPresenter
3+
def initialize(view_context, application_form)
4+
@view_context = view_context
5+
@application_form = application_form
6+
end
7+
8+
def index
9+
{
10+
created_at: created_at,
11+
path: @view_context.polymorphic_path(@application_form),
12+
status: status
13+
}
14+
end
15+
16+
private
17+
18+
def created_at
19+
@application_form.created_at.strftime("%B %d, %Y at %I:%M %p")
20+
end
21+
22+
def status
23+
I18n.t("flex.application_forms.status.#{@application_form.status}")
24+
end
25+
end
26+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module Flex
2+
class ApplicationFormsPresenter
3+
attr_reader :application_forms
4+
5+
def initialize(view_context, application_forms)
6+
@view_context = view_context
7+
@application_forms = application_forms
8+
@i18n_path = view_context.controller_path.gsub("/", ".")
9+
end
10+
11+
def index
12+
{
13+
title: title,
14+
intro: intro,
15+
new_button_text: new_button_text,
16+
in_progress_applications_heading: in_progress_applications_heading,
17+
application_forms: application_forms.map { |application_form| Flex::ApplicationFormPresenter.new(@view_context, application_form).index }
18+
}
19+
end
20+
21+
private
22+
23+
def title
24+
I18n.t("#{@i18n_path}.index.title")
25+
end
26+
27+
def intro
28+
I18n.t("#{@i18n_path}.index.intro")
29+
end
30+
31+
def new_button_text
32+
I18n.t("#{@i18n_path}.index.new_button")
33+
end
34+
35+
def in_progress_applications_heading
36+
I18n.t("#{@i18n_path}.index.in_progress_applications.heading")
37+
end
38+
end
39+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<% content_for :title, title %>
2+
3+
<h1>
4+
<%= title %>
5+
</h1>
6+
7+
<p class="usa-intro">
8+
<%= intro %>
9+
</p>
10+
11+
<%= link_to new_button_text, "new", class: class_names("usa-button") %>
12+
13+
<% if not application_forms.empty? %>
14+
<h2 class="margin-top-6"><%= in_progress_applications_heading %></h2>
15+
16+
<section class="d-flex flex-column flex-md-row gap-4 align-items-start justify-content-between">
17+
<table class="usa-table usa-table--borderless width-full">
18+
<thead>
19+
<tr>
20+
<th scope="col">
21+
<%= t("flex.application_forms.index.col_created_at") %>
22+
</th>
23+
<th scope="col">
24+
<%= t("flex.application_forms.index.col_status") %>
25+
</th>
26+
<th scope="col">
27+
<%= t("flex.application_forms.index.col_actions") %>
28+
</th>
29+
</tr>
30+
</thead>
31+
<tbody>
32+
<% application_forms.each do |application| %>
33+
<tr>
34+
<td>
35+
<% # TODO show in local time %>
36+
<%= link_to application[:created_at], application[:path] %>
37+
</td>
38+
<td>
39+
<%= application[:status] %>
40+
</td>
41+
<td>
42+
TODO
43+
</td>
44+
</tr>
45+
<% end %>
46+
</tbody>
47+
</table>
48+
</section>
49+
<% end %>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
en:
2+
flex:
3+
application_forms:
4+
index:
5+
col_created_at: "Created At"
6+
col_status: "Status"
7+
col_actions: "Actions"
8+
status:
9+
in_progress: "In Progress"
10+
submitted: "Submitted"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
es-US:
2+
flex:
3+
application_forms:
4+
index:
5+
col_created_at: "Fecha de creación"
6+
col_status: "Estado"
7+
col_actions: "Acciones"
8+
status:
9+
in_progress: "En progreso"
10+
submitted: "Enviado"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class PassportApplicationFormsController < ApplicationController
2+
def index
3+
@passport_application_forms = PassportApplicationForm.all
4+
end
5+
6+
def show
7+
end
8+
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= render template: "flex/application_forms/index", locals: Flex::ApplicationFormsPresenter.new(self, @passport_application_forms).index %>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>PassportApplicationForms#show</h1>
2+
<p>Find me in app/views/passport_application_forms/show.html.erb</p>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
en:
2+
passport_application_forms:
3+
index:
4+
title: "Passport Applications"
5+
intro: "You can apply for a new passport or renew an existing passport."
6+
new_button: "New Application"
7+
in_progress_applications:
8+
heading: "Existing applications"
9+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Rails.application.routes.draw do
2-
get "passport_cases/show"
32
mount Flex::Engine => "/flex"
43

54
resources :passport_cases do
65
collection do
76
get :closed
87
end
98
end
9+
10+
resources :passport_application_forms, only: [ :index, :show ]
1011
end

0 commit comments

Comments
 (0)