From 38100e236f03edf79960e392bf6c034e0ddc8037 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Tue, 14 Feb 2017 16:39:53 -0600 Subject: [PATCH] quiz results sortable --- .../ic_arrow_drop_down_black_24dp_1x.png | Bin 0 -> 94 bytes .../ic_arrow_drop_down_black_24dp_2x.png | Bin 0 -> 119 bytes .../images/ic_arrow_drop_up_black_24dp_1x.png | Bin 0 -> 95 bytes .../images/ic_arrow_drop_up_black_24dp_2x.png | Bin 0 -> 119 bytes app/assets/images/ic_sort_black_24dp_1x.png | Bin 0 -> 89 bytes app/assets/images/ic_sort_black_24dp_2x.png | Bin 0 -> 103 bytes app/assets/stylesheets/molecules/_tables.scss | 44 ++++++++++++++++++ app/controllers/admin/result_controller.rb | 15 +++++- app/helpers/application_helper.rb | 7 +++ app/views/admin/result/index.html.erb | 8 ++-- 10 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 app/assets/images/ic_arrow_drop_down_black_24dp_1x.png create mode 100644 app/assets/images/ic_arrow_drop_down_black_24dp_2x.png create mode 100644 app/assets/images/ic_arrow_drop_up_black_24dp_1x.png create mode 100644 app/assets/images/ic_arrow_drop_up_black_24dp_2x.png create mode 100644 app/assets/images/ic_sort_black_24dp_1x.png create mode 100644 app/assets/images/ic_sort_black_24dp_2x.png diff --git a/app/assets/images/ic_arrow_drop_down_black_24dp_1x.png b/app/assets/images/ic_arrow_drop_down_black_24dp_1x.png new file mode 100644 index 0000000000000000000000000000000000000000..4b1be1c43b43628f20c2ecc0ca0b6d3b08731485 GIT binary patch literal 94 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1RZkbkkP60RiG>LwCI)}pn|YUH rW-6SW#&${On!}{{h60PmKn8~8dJ=ChHi}*XYGCkm^>bP0l+XkK?wc9J literal 0 HcmV?d00001 diff --git a/app/assets/images/ic_arrow_drop_down_black_24dp_2x.png b/app/assets/images/ic_arrow_drop_down_black_24dp_2x.png new file mode 100644 index 0000000000000000000000000000000000000000..feb901aed2cfbd876444451321295b1a6eab163e GIT binary patch literal 119 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}a}tJ5LwKkP61Pmk$au2#7FWjQ>^E zClvE7;f*(A+YuWD&q)Tam3Fv4xX1K;VZrVLYo*HrcPu{oSG=cVvWmRdCdQKt$;-Fs Snb-qOV(@hJb6Mw<&;$Us6DJS= literal 0 HcmV?d00001 diff --git a/app/assets/images/ic_arrow_drop_up_black_24dp_1x.png b/app/assets/images/ic_arrow_drop_up_black_24dp_1x.png new file mode 100644 index 0000000000000000000000000000000000000000..8416ffb041dce96f8eb13256ef0e3f7cfdab5c24 GIT binary patch literal 95 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1HBT4EkP60RiMRw269z@kQ~#M0 snLSS_MtKDGU2ux9oHb35(~Xhg^i_$sil0tQ2kKz(boFyt=akR{0M5V}7ytkO literal 0 HcmV?d00001 diff --git a/app/assets/images/ic_arrow_drop_up_black_24dp_2x.png b/app/assets/images/ic_arrow_drop_up_black_24dp_2x.png new file mode 100644 index 0000000000000000000000000000000000000000..3d24376125059ee2f6c36d9544453c062784985e GIT binary patch literal 119 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}a}tJ5LwKkP61PXLfTQ2w-TvV7_bi z^WeLjEee#GzAt?|gj(Vu%%Jd2q3d{17!wfV?Oph*m#u6{1- HoD!M?MkP61Pmkk9O9C(-xe$W4< z+^EJn^QP;8P@4v;`b?%mk&jP27I4gy;gn%FaGWFe;jVkH7f>gIr>mdKI;Vst0N14) Ad;kCd literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/molecules/_tables.scss b/app/assets/stylesheets/molecules/_tables.scss index 2f23953..c1962a1 100644 --- a/app/assets/stylesheets/molecules/_tables.scss +++ b/app/assets/stylesheets/molecules/_tables.scss @@ -9,6 +9,50 @@ th { font-weight: 600; padding: $small-spacing 0; text-align: left; + + a { + display: inline-block; + margin-right: 18px; + padding-right: 5px; + position: relative; + text-decoration: none; + + &::after { + background-image: asset_data_url("ic_sort_black_24dp_2x.png"); + background-repeat: no-repeat; + background-size: contain; + content: ""; + display: block; + height: 18px; + left: 100%; + opacity: 0.5; + position: absolute; + top: 4px; + width: 18px; + } + + &.asc { + &::after { + background-image: asset_data_url("ic_arrow_drop_up_black_24dp_2x.png"); + height: 25px; + left: calc(100% - 5px); + opacity: 1; + top: 1px; + width: 25px; + } + } + + &.desc { + &::after { + background-image: asset_data_url("ic_arrow_drop_down_black_24dp_2x.png"); + height: 25px; + left: calc(100% - 5px); + opacity: 1; + top: 1px; + width: 25px; + } + } + } } td { diff --git a/app/controllers/admin/result_controller.rb b/app/controllers/admin/result_controller.rb index 67be27a..f217cd0 100644 --- a/app/controllers/admin/result_controller.rb +++ b/app/controllers/admin/result_controller.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true module Admin class ResultController < AdminController - # + helper_method :sort_column, :sort_direction + # TODO: change context from Candidate to Quiz # bypass pundit lockdowns until completed after_action :skip_policy_scope @@ -12,7 +13,7 @@ module Admin def index @candidates = Candidate.where(completed: true) .includes(:recruiter) - .order(:review_status, completed_at: :desc) + .order("#{sort_column} #{sort_direction}") end def view @@ -22,5 +23,15 @@ module Admin @comments = QuizComment.includes(:user).where(test_hash: @candidate.test_hash).order(:created_at) @comment = QuizComment.new end + + private + + def sort_column + Candidate.column_names.include?(params[:sort]) ? params[:sort] : 'completed_at' + end + + def sort_direction + %w(asc desc).include?(params[:direction]) ? params[:direction] : 'desc' + end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 11f160f..9afc636 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -44,4 +44,11 @@ module ApplicationHelper @js_blocks << code_label content_for :custom_javascipt, &block end + + def sortable(column, title = nil) + title ||= column.titleize + css_class = column == sort_column ? sort_direction.to_s : nil + direction = column == sort_column && sort_direction == "desc" ? "asc" : "desc" + link_to title, { sort: column, direction: direction }, class: css_class + end end diff --git a/app/views/admin/result/index.html.erb b/app/views/admin/result/index.html.erb index 6faa58f..1561f60 100644 --- a/app/views/admin/result/index.html.erb +++ b/app/views/admin/result/index.html.erb @@ -5,11 +5,11 @@
- - - + + + - +
Test IDExperienceClient/Project<%= sortable "test_hash", "Test ID" %><%= sortable "experience" %><%= sortable "project", "Client/Project" %> RecruiterSubmitted on<%= sortable "completed_at", "Submitted on" %> Interview?