diff --git a/app/controllers/job_applications_controller.rb b/app/controllers/job_applications_controller.rb index 96ca3d9..7f77a03 100644 --- a/app/controllers/job_applications_controller.rb +++ b/app/controllers/job_applications_controller.rb @@ -78,10 +78,21 @@ def destroy format.html { redirect_to root_path, success: "Job application was successfully deleted." } format.turbo_stream { flash.now[:success] = "Job application was successfully deleted." + + # Reapply filters, sorting, and pagination + @job_applications = filter_and_sort_job_applications + @job_applications = @job_applications.paginate(page: params[:page], per_page: 10) + + @pagination_info = { + total_pages: @job_applications.total_pages, + current_page: @job_applications.current_page, + total_entries: @job_applications.total_entries + } + render turbo_stream: [ - turbo_stream.remove(@job_application), - turbo_stream.update("job_application_count", JobApplication.count), - turbo_stream.update("flash_messages", partial: "flash_messages") + turbo_stream.update("flash_messages", partial: "flash_messages"), + turbo_stream.update("job_applications_content", partial: "empty_or_table"), + turbo_stream.update("job_application_count", JobApplication.count) ] } end diff --git a/app/views/job_applications/_empty_or_table.html.erb b/app/views/job_applications/_empty_or_table.html.erb new file mode 100644 index 0000000..55eb3d6 --- /dev/null +++ b/app/views/job_applications/_empty_or_table.html.erb @@ -0,0 +1,62 @@ +<% if JobApplication.exists? %> +
+ <%= link_to 'New Job Application', new_job_application_path, class: 'text-sm bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded cursor-pointer', data: { turbo_frame: "_top" } %> +
+ <%= form_with url: job_applications_path, method: :get, data: { controller: "job-filter", turbo_frame: "job_applications_table" } do |form| %> +
+
+ <%= form.label :search, "Search", class: "sr-only" %> + <%= form.text_field :search, value: params[:search], class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Search", data: { action: "input->job-filter#submit" } %> +
+
+ <%= form.label :method_of_contact, "Contact Method", class: "sr-only" %> + <%= form.select :method_of_contact, + options_for_select([["All Contact Methods", ""]] + JobApplication.method_of_contacts.map { |k, v| [k.humanize, v] }, params[:method_of_contact]), + {}, + class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", + data: { action: "change->job-filter#submit" } + %> +
+
+ <%= form.label :position_type, "Position Type", class: "sr-only" %> + <%= form.select :position_type, + options_for_select([["All Position Types", ""]] + JobApplication.position_types.map { |k, v| [display_position_type(k), v] }, params[:position_type]), + {}, + class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", + data: { action: "change->job-filter#submit" } + %> +
+
+ <%= form.label :claimed_for_unemployment, "Unemployment Claim", class: "sr-only" %> + <%= form.select :claimed_for_unemployment, + options_for_select([["All Claims", ""], ["Claimed", "true"], ["Not Claimed", "false"]], params[:claimed_for_unemployment]), + {}, + class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", + data: { action: "change->job-filter#submit" } + %> +
+
+ <%= form.label :status, "Application Status", class: "sr-only" %> + <%= form.select :status, + options_for_select([["All Statuses", ""]] + JobApplication.statuses.map { |k, v| [k.humanize, v] }, params[:status]), + {}, + class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", + data: { action: "change->job-filter#submit" } + %> +
+
+ <%= form.button "Reset Filters", type: "button", class: "w-full bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-pointer", data: { action: "click->job-filter#reset" } %> +
+
+ <% end %> + <%= turbo_frame_tag "job_applications_table" do %> + <%= render partial: "job_applications_table", locals: { job_applications: @job_applications } %> + <% if @job_applications.any? %> + + <% end %> + <% end %> +<% else %> + <%= render 'empty_state' %> +<% end %> diff --git a/app/views/job_applications/_empty_state.html.erb b/app/views/job_applications/_empty_state.html.erb new file mode 100644 index 0000000..13a5b40 --- /dev/null +++ b/app/views/job_applications/_empty_state.html.erb @@ -0,0 +1,8 @@ +
+ +

No job applications

+

Get started by creating a new job application.

+ <%= link_to 'New Job Application', new_job_application_path, class: 'text-sm bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded cursor-pointer', data: { turbo_frame: "_top" } %> +
diff --git a/app/views/job_applications/_job_applications_table.html.erb b/app/views/job_applications/_job_applications_table.html.erb index 293f1ef..0d2b877 100644 --- a/app/views/job_applications/_job_applications_table.html.erb +++ b/app/views/job_applications/_job_applications_table.html.erb @@ -52,7 +52,7 @@

- <%= "No results match your search criteria." if params[:search].present? || params[:method_of_contact].present? || params[:position_type].present? %> + No results match your search criteria.

<% end %> diff --git a/app/views/job_applications/_pagination.html.erb b/app/views/job_applications/_pagination.html.erb index 2c58ded..678d9c0 100644 --- a/app/views/job_applications/_pagination.html.erb +++ b/app/views/job_applications/_pagination.html.erb @@ -1,17 +1,18 @@ -<% if @pagination_info[:total_pages] > 1 %> +<% if @pagination_info && @pagination_info[:total_pages] && @pagination_info[:total_pages] > 1 %>
+ Showing <%= @pagination_info[:current_page] %> of <%= @pagination_info[:total_pages] %> pages
<%= will_paginate @job_applications, - renderer: CustomPaginationRenderer, - previous_label: 'Previous', - next_label: 'Next', - inner_window: 0, - outer_window: 0, - class: 'pagination', - previous_page_class: 'px-3 py-1 rounded-md text-sm font-medium text-gray-700 bg-white border border-gray-300 hover:bg-gray-50', - next_page_class: 'px-3 py-1 rounded-md text-sm font-medium text-gray-700 bg-white border border-gray-300 hover:bg-gray-50' %> + renderer: CustomPaginationRenderer, + previous_label: 'Previous', + next_label: 'Next', + inner_window: 0, + outer_window: 0, + class: 'pagination', + previous_page_class: 'px-3 py-1 rounded-md text-sm font-medium text-gray-700 bg-white border border-gray-300 hover:bg-gray-50', + next_page_class: 'px-3 py-1 rounded-md text-sm font-medium text-gray-700 bg-white border border-gray-300 hover:bg-gray-50' %>
<% end %> diff --git a/app/views/job_applications/index.html.erb b/app/views/job_applications/index.html.erb index 2f65bd3..ad630b6 100644 --- a/app/views/job_applications/index.html.erb +++ b/app/views/job_applications/index.html.erb @@ -6,70 +6,18 @@
<%= image_tag(asset_path('apple-touch-icon.png'), - height: '32', - width: '32', - class: "rounded-full object-cover shadow-sm border-2 border-gray-200 mr-2", - aria: { label: "Job Tracker logo" }, - title: "Job Tracker logo") %> + height: '32', + width: '32', + class: "rounded-full object-cover shadow-sm border-2 border-gray-200 mr-2", + aria: { label: "Job Tracker logo" }, + title: "Job Tracker logo") %>
- <%= link_to 'New Job Application', new_job_application_path, class: 'text-sm bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded cursor-pointer', data: { turbo_frame: "_top" } %>
- <%= form_with url: job_applications_path, method: :get, data: { controller: "job-filter", turbo_frame: "job_applications_table" } do |form| %> -
-
- <%= form.label :search, "Search", class: "sr-only" %> - <%= form.text_field :search, value: params[:search], class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", placeholder: "Search", data: { action: "input->job-filter#submit" } %> -
-
- <%= form.label :method_of_contact, "Contact Method", class: "sr-only" %> - <%= form.select :method_of_contact, - options_for_select([["All Contact Methods", ""]] + JobApplication.method_of_contacts.map { |k, v| [k.humanize, v] }, params[:method_of_contact]), - {}, - class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", - data: { action: "change->job-filter#submit" } - %> -
-
- <%= form.label :position_type, "Position Type", class: "sr-only" %> - <%= form.select :position_type, - options_for_select([["All Position Types", ""]] + JobApplication.position_types.map { |k, v| [display_position_type(k), v] }, params[:position_type]), - {}, - class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", - data: { action: "change->job-filter#submit" } - %> -
-
- <%= form.label :claimed_for_unemployment, "Unemployment Claim", class: "sr-only" %> - <%= form.select :claimed_for_unemployment, - options_for_select([["All Claims", ""], ["Claimed", "true"], ["Not Claimed", "false"]], params[:claimed_for_unemployment]), - {}, - class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", - data: { action: "change->job-filter#submit" } - %> -
-
- <%= form.label :status, "Application Status", class: "sr-only" %> - <%= form.select :status, - options_for_select([["All Statuses", ""]] + JobApplication.statuses.map { |k, v| [k.humanize, v] }, params[:status]), - {}, - class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline", - data: { action: "change->job-filter#submit" } - %> -
-
- <%= form.button "Reset Filters", type: "button", class: "w-full bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-pointer", data: { action: "click->job-filter#reset" } %> -
-
- <% end %> - <%= turbo_frame_tag "job_applications_table" do %> - <%= render partial: "job_applications_table", locals: { job_applications: @job_applications } %> - - <% end %> - <%= turbo_frame_tag "new_job_application" %> +
+ <%= render 'empty_or_table' %> +
<% end %>