From 314d69e82df7bad7d77a3474dd6b58bca30bcee1 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Sat, 17 Feb 2018 10:12:38 -0600 Subject: [PATCH] onboarding settings done --- admin/Gemfile | 3 + admin/Gemfile.lock | 9 ++ admin/README.md | 5 +- admin/app/admin/onboarders.rb | 92 +++++++++++++++++++ admin/app/admin/onboarding.rb | 8 +- admin/app/assets/javascripts/active_admin.js | 5 + .../assets/javascripts/active_admin.js.coffee | 8 ++ admin/app/helpers/application_helper.rb | 1 - admin/app/helpers/jam_sessions_helper.rb | 1 + db/manifest | 3 +- db/up/onboarder_limit.sql | 1 + 11 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 admin/app/admin/onboarders.rb create mode 100644 db/up/onboarder_limit.sql diff --git a/admin/Gemfile b/admin/Gemfile index 595d94904..29f0e2490 100644 --- a/admin/Gemfile +++ b/admin/Gemfile @@ -83,6 +83,9 @@ gem 'sendgrid_toolkit', '>= 1.1.1' gem 'stripe' gem 'zip-codes' gem 'email_validator' +gem 'best_in_place', github: 'bernat/best_in_place' + + #group :libv8 do # gem 'libv8', "~> 4.5.95" diff --git a/admin/Gemfile.lock b/admin/Gemfile.lock index d029ef2ce..e09bbeb57 100644 --- a/admin/Gemfile.lock +++ b/admin/Gemfile.lock @@ -1,3 +1,11 @@ +GIT + remote: git://github.com/bernat/best_in_place.git + revision: 1b779e60ea912ab9c39d5c999b00c8ac44a8e535 + specs: + best_in_place (3.1.1) + actionpack (>= 3.2) + railties (>= 3.2) + PATH remote: ../db/target/ruby_package specs: @@ -628,6 +636,7 @@ DEPENDENCIES amqp (= 0.9.8) aws-sdk (~> 1) bcrypt-ruby (= 3.0.1) + best_in_place! bootstrap-sass (= 2.0.4) bootstrap-will_paginate (= 0.0.6) bugsnag diff --git a/admin/README.md b/admin/README.md index 503c08107..badfd2200 100644 --- a/admin/README.md +++ b/admin/README.md @@ -11,8 +11,9 @@ Overtime we can add more administrative functions and views, but initially this Examples of: -Button on Show Page of Item: 'Send Client Update Notice' in jam_ruby_artifact_updates.rb +* Button on Show Page of Item: 'Send Client Update Notice' in jam_ruby_artifact_updates.rb +* Batch Updates in View page: onboarding.rb (CurrentlyOnboarding) Stuff that is probably breaky: -activeadmin_addons https://github.com/platanus/activeadmin_addons \ No newline at end of file +activeadmin_addons https://github.com/platanus/activeadmin_addons diff --git a/admin/app/admin/onboarders.rb b/admin/app/admin/onboarders.rb new file mode 100644 index 000000000..2f4174c6d --- /dev/null +++ b/admin/app/admin/onboarders.rb @@ -0,0 +1,92 @@ +ActiveAdmin.register JamRuby::User, :as => 'Onboarder' do + + menu :label => 'Onboarder Settings', :parent => 'JamClass' + + config.sort_order = 'created_at' + config.batch_actions = true + config.per_page = 100 + config.paginate = true + config.filters = false + config.clear_action_items! + batch_action :destroy, false + + scope("All Onboarders", default: true) { |scope| scope.where(is_onboarder: true).order(:created_at) } + + + controller do + active_admin_config.includes.push :onboarding_users + + def update + resource.max_onboardings = params[:jam_ruby_user][:max_onboardings] + resource.save! + success.json {} + end + end + + + + index do + def last_week + @last_week_result ||= calculate_last_week + end + + def calculate_last_week + start_day = Date.today.beginning_of_week(:sunday).yesterday.beginning_of_week(:sunday) + end_day = start_day.end_of_week(:sunday) + result = [start_day, end_day] + result + end + + def this_week + @this_week_result ||= calculate_this_week + end + + def calculate_this_week + start_day = Date.today.beginning_of_week(:sunday) + end_day = start_day.end_of_week(:sunday) + result = [start_day, end_day] + result + end + + def week_display(week) + start_day = week[0] + end_day = week[1] + mmyy = start_day.strftime('%b') + "#{mmyy} #{start_day.day}-#{end_day.day}" + end + + def onboarding_select + array = [] + 100.times do |i| + array.push [i.to_s, i.to_s] + end + array + end + column "Name" do |user| + div do + div do + link_to user.name, user.admin_url + end + div do + user.email + end + end + end + column "Max Onboardings" do |user| + best_in_place user, :max_onboardings, as: :select, url: admin_onboarder_path(user),:collection => onboarding_select + end + column "Current Week #{week_display(this_week)}" do |user| + start_date, last_date = this_week + user.onboarding_users.where(onboarder_assigned_at: start_date..last_date).count + end + column "Previous Week #{week_display(last_week)}" do |user| + start_date, last_date = last_week + user.onboarding_users.where(onboarder_assigned_at: start_date..last_date).count + end + column "Current Student WIP" do |user| + user.onboarding_users.where('onboarding_status = ? OR onboarding_status = ?', User::ONBOARDING_STATUS_ASSIGNED, User::ONBOARDING_STATUS_EMAILED).count + end + end + + +end \ No newline at end of file diff --git a/admin/app/admin/onboarding.rb b/admin/app/admin/onboarding.rb index 0adaf3285..7040629d0 100644 --- a/admin/app/admin/onboarding.rb +++ b/admin/app/admin/onboarding.rb @@ -1,6 +1,6 @@ -ActiveAdmin.register JamRuby::User, :as => 'CurrentlyOnboarding' do +ActiveAdmin.register JamRuby::User, :as => 'OnboarderManagement' do - menu :label => 'Currently Onboarding', :parent => 'JamClass' + menu :label => 'Onboarder Management', :parent => 'JamClass' config.sort_order = 'created_at desc' config.batch_actions = true @@ -11,7 +11,7 @@ ActiveAdmin.register JamRuby::User, :as => 'CurrentlyOnboarding' do batch_action :destroy, false batch_action :onboarder, form: -> { { - support_consultant: (User.where(is_onboarder: true).includes(:onboarding_users).map {|user| ["#{user.name} (#{user.onboarding_users.length})", user.id]}).to_a.unshift(['Unassign', '']) + support_consultant: (User.where(is_onboarder: true).includes(:onboarding_users).map {|user| ["#{user.name} (#{user.onboarding_users.where('onboarding_status = ? OR onboarding_status = ?', User::ONBOARDING_STATUS_ASSIGNED, User::ONBOARDING_STATUS_EMAILED).count})", user.id]}).to_a.unshift(['Unassign', '']) } } do |ids, inputs| onboarder = inputs[:support_consultant] if onboarder.blank? @@ -59,7 +59,7 @@ ActiveAdmin.register JamRuby::User, :as => 'CurrentlyOnboarding' do column "Escalated Reason", :onboarding_escalation_reason column "Support Consultant" do |user| if user.onboarder - link_to "#{user.onboarder.name} (#{user.onboarder.onboarding_users.count})", user.onboarder.admin_url + link_to "#{user.onboarder.name} (#{user.onboarder.onboarding_users.where('onboarding_status = ? OR onboarding_status = ?', User::ONBOARDING_STATUS_ASSIGNED, User::ONBOARDING_STATUS_EMAILED).count})", user.onboarder.admin_url else end end diff --git a/admin/app/assets/javascripts/active_admin.js b/admin/app/assets/javascripts/active_admin.js index 84a187b5a..df9db3400 100644 --- a/admin/app/assets/javascripts/active_admin.js +++ b/admin/app/assets/javascripts/active_admin.js @@ -12,3 +12,8 @@ // //= require autocomplete-rails //= require base //= require_tree . + + +$(document).ready(function() { + jQuery(".best_in_place").best_in_place() +}) diff --git a/admin/app/assets/javascripts/active_admin.js.coffee b/admin/app/assets/javascripts/active_admin.js.coffee index e211bdfe7..7d9d7acbd 100644 --- a/admin/app/assets/javascripts/active_admin.js.coffee +++ b/admin/app/assets/javascripts/active_admin.js.coffee @@ -1,2 +1,10 @@ #= require active_admin/base #= require jquery3 +#= require best_in_place +#= require jquery.purr +#= require best_in_place.purr + +$(document).ready -> + # IS NOT HAPPENING: USE ACTIVE_ADMIN.JS + console.log("DAT COFFEE INIT") + jQuery(".best_in_place").best_in_place() \ No newline at end of file diff --git a/admin/app/helpers/application_helper.rb b/admin/app/helpers/application_helper.rb index 80731359d..6e9385e59 100644 --- a/admin/app/helpers/application_helper.rb +++ b/admin/app/helpers/application_helper.rb @@ -1,5 +1,4 @@ module ApplicationHelper - end diff --git a/admin/app/helpers/jam_sessions_helper.rb b/admin/app/helpers/jam_sessions_helper.rb index bf244b019..9ef3f0789 100644 --- a/admin/app/helpers/jam_sessions_helper.rb +++ b/admin/app/helpers/jam_sessions_helper.rb @@ -1,2 +1,3 @@ module JamSessionsHelper + end \ No newline at end of file diff --git a/db/manifest b/db/manifest index 3429696ea..85801522a 100755 --- a/db/manifest +++ b/db/manifest @@ -384,4 +384,5 @@ alter_crash_dumps.sql onboarding.sql better_lesson_notices.sql teacher_search_control.sql -user_timezone.sql \ No newline at end of file +user_timezone.sql +onboarder_limit.sql \ No newline at end of file diff --git a/db/up/onboarder_limit.sql b/db/up/onboarder_limit.sql new file mode 100644 index 000000000..2a2e35ba9 --- /dev/null +++ b/db/up/onboarder_limit.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN max_onboardings INTEGER NOT NULL DEFAULT 0;