Class: StudentProgress::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/student_progress/cli.rb

Instance Method Summary collapse

Instance Method Details



132
133
134
135
136
137
138
# File 'lib/student_progress/cli.rb', line 132

def add_periscope_link_for_cohort_data
  puts "Paste in the link to the periscope doc you'd like to use to import Cohort progress"
  @input = gets.strip
  @selected_cohort.periscope_url = @input
  @selected_cohort.save
  puts "Successfully added the periscope url to #{@selected_cohort.name}"
end

#add_students_to_cohort_viewObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/student_progress/cli.rb', line 108

def add_students_to_cohort_view
  puts "Enter the github usernames of the students you'd like to add as a comma separated list"
  @input = gets.strip
  return if ["back", "exit"].include?(@input.downcase)
  usernames = @input.chomp.split(',').map(&:strip)
  @selected_cohort.add_students(usernames)
  puts "Just added #{usernames.count} students to your cohort"
  puts "#{@selected_cohort.name} now has #{@selected_cohort.students.count} students"
  show_options_for_cohort
end

#callObject



2
3
4
5
6
7
8
# File 'lib/student_progress/cli.rb', line 2

def call
  puts "Hello from CLI"
   
  StudentProgress::Scraper.scrape_lessons
  main_menu
  goodbye
end

#delete_this_cohort_viewObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/student_progress/cli.rb', line 140

def delete_this_cohort_view 
  puts "Are you sure you want to delete the #{@selected_cohort.name} cohort?"
  puts "type 'yes' to confirm or 'no' to go back to the cohort menu"
  puts "You can also type 'back' to return to the main menu, or 'exit' to exit the CLI"
  @input = gets.strip
  return if ["back", "exit"].include?(@input.downcase)
  case @input.downcase 
  when 'yes'
    @selected_cohort.delete_and_unassign_students
    @selected_cohort = nil
    puts "cohort successfully deleted"
    list_choices
  when 'no'
    show_options_for_cohort
  else
    puts "Whoops! Didn't understand that."
    delete_this_cohort_view
  end
end

#display_studentsObject



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/student_progress/cli.rb', line 209

def display_students
  output = []
  now = DateTime.now
  output << now.strftime('%b %e, %Y %l:%M %p')
  @selected_cohort ||= StudentProgress::Student.all
  @selected_cohort.run_progress_report
  if @goal
    output << "\n"
    output << "Students should #{@goal[:goal]} by the end of the week"
    output << "To do that, they'll have completed #{@goal[:lessons]} lessons and #{@goal[:labs]} labs"
  end
  headers = ['Student Name', 'Current Lab', 'Current Topic', 'Lessons', 'Labs']
  report = @selected_cohort.progress_reports.last
  rows = report.student_reports.collect.with_index(1) do |student_report|
    student_report.generate_current_topic_status
    [student_report.student_name, student_report.current_lab, student_report.current_topic_status, student_report.lessons_complete, student_report.labs_complete]
  end
  table = Terminal::Table.new headings: headers, rows: rows
  output << table

  if @goal
    split_by_progress = report.on_track(@goal, @selected_cohort)
    on_track = split_by_progress[:on_track].collect.with_index(1) do |student_report|
      [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
    end
    behind = split_by_progress[:behind].collect.with_index(1) do |student_report|
      [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
    end
    ahead = split_by_progress[:ahead].collect.with_index(1) do |student_report|
      [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete]
    end
    behind_table = Terminal::Table.new headings: headers, rows: behind
    on_track_table = Terminal::Table.new headings: headers, rows: on_track
    ahead_table = Terminal::Table.new headings: headers, rows: ahead
    output << "BEHIND"
    output << behind_table
    output << "ON TRACK"
    output << on_track_table
    output << "Ahead"
    output << ahead_table
  end
  report.content = output.join("\n")
  report.save
  puts output
end

#goodbyeObject



281
282
283
284
# File 'lib/student_progress/cli.rb', line 281

def goodbye
  puts "\n"
  puts "Thanks for using the Student Tracker CLI! See you next time!!!"
end

#list_choicesObject



52
53
54
55
56
57
58
59
60
# File 'lib/student_progress/cli.rb', line 52

def list_choices
  puts "Choose an option below by number"
  puts "1. Manage Cohorts"
  puts "2. Add Cohort"
  puts "3. Set goal for the week"
  puts "4. To view a list of past reports"
  puts "'exit' to leave the program"
  puts "type 'menu' at any point if you'd like to see these options again"
end

#list_cohortsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/student_progress/cli.rb', line 62

def list_cohorts
  @selected_cohort = nil
  until @selected_cohort || @input == "exit"
    puts "Please select the cohort you'd like to view details for"
    StudentProgress::Cohort.all.each.with_index(1) do |cohort, index|
      puts "#{index}. #{cohort.name}"
    end
    @input = gets.strip
    if @input.to_i > 0 && @input.to_i <= StudentProgress::Cohort.count 
      @selected_cohort = StudentProgress::Cohort.all[@input.to_i - 1]
    elsif @input == "exit" || @input == "back"
      return
    else
      puts "Whoops! Didn't understand that input"
    end
  end
  show_options_for_cohort
end

#list_previous_reportsObject



275
276
277
278
279
# File 'lib/student_progress/cli.rb', line 275

def list_previous_reports
  DB[:progress_reports].each do |p|
    puts "#{p[:id]}. #{p[:created_at].strftime('%b %e, %Y %l:%M %p')}" if p[:created_at]
  end
end


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/student_progress/cli.rb', line 23

def main_menu
  @input = nil
  @goal = nil
  @selected_cohort = nil 
  list_choices
  while @input != "exit" 
    puts "type 'exit' at any point to quit or 'menu' to see your options"
    @input = gets.strip
    if @input == 'menu'
      list_choices
    elsif @input == '1'
      list_cohorts
    elsif @input == '2'
      prompt_for_cohort_name
    elsif @input == '3'
      prompt_for_goal
    elsif @input == '4'
      prompt_for_reports
    elsif @input == 'exit'
      break
    elsif @input == 'debug'
      binding.pry
    else
      puts "Whoops! I didn't understand that"
      list_choices 
    end
  end
end

#prompt_for_cohort_nameObject



160
161
162
163
164
165
# File 'lib/student_progress/cli.rb', line 160

def prompt_for_cohort_name
  puts "Please enter the name of the cohort you'd like to create"
  name = gets.chomp
  @new_cohort = StudentProgress::Cohort.find_or_create(name: name)
  prompt_for_usernames
end

#prompt_for_goalObject



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/student_progress/cli.rb', line 175

def prompt_for_goal 
  @goal = nil
  puts "Which topic should students be working in at the end of the week?"
  StudentProgress::Topic.all.each.with_index(1) {|t,i| puts "#{i}. #{t.title}"}
  @input = gets.strip
  if @input == "exit" 
    return
  elsif @input.to_i <= 0 
    puts "Make sure you enter a number in range"
    prompt_for_goal
  elsif topic = StudentProgress::Topic.all[@input.to_i-1]
    puts "Great! We'll be looking within #{topic.title}"
  else
    puts "Whoops! Don't have that option"
    prompt_for_goal
  end
  while @input != "exit" && @goal.nil?
    puts "Which unit should students finish by the end of the week?"
    topic.units.each.with_index(1) {|t,i| puts "#{i}. #{t.title}"}
    @input = gets.strip
    if @input == "exit" 
      return
    elsif @input.to_i <= 0 
      puts "Make sure you enter a number in range"
      prompt_for_goal
    elsif unit = topic.units[@input.to_i-1]
      puts "Great! We'll set the goal for the week"
      @goal = StudentProgress::Lesson.progress_when_unit_complete(unit.title)
    else
      puts "Whoops! Don't have that option"
    end
  end
end

#prompt_for_loginObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/student_progress/cli.rb', line 10

def 
  puts "Log in to your learn.co account:"
  print "Email: "
  email = gets.strip
  puts "\n"
  print "Password: "
  password = STDIN.noecho(&:gets).chomp
  unless StudentProgress::Scraper.(email, password)
    
  end
  true
end

#prompt_for_reportsObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/student_progress/cli.rb', line 255

def prompt_for_reports 
  list_previous_reports
  
  @input = nil 
  until @input == "exit" || @input == "back"
    puts "Enter the number of the report you'd like to view (type 'back' to return to main menu)"
    puts "You can also type 'list' to see the list of reports again"
    @input = gets.strip
    if DB[:progress_reports].first(id: @input.to_i)
      puts DB[:progress_reports].first(id: @input.to_i)[:content]
    elsif @input == "list"
      list_previous_reports
    elsif @input == "exit" || @input == "back"
      break
    else
      put "Whoops! I didn't understand that."
    end
  end
end

#prompt_for_usernamesObject



167
168
169
170
171
172
173
# File 'lib/student_progress/cli.rb', line 167

def prompt_for_usernames
  puts "Please enter the GitHub usernames for the students you'd like info about (separated by commas)"
  usernames = gets.chomp.split(',').map(&:strip).map(&:downcase)
  puts "Hang on a sec, adding #{usernames.count} students"
  @new_cohort.add_students(usernames)
  puts "All done!"
end

#remove_students_from_cohort_viewObject



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/student_progress/cli.rb', line 119

def remove_students_from_cohort_view 
  puts "Enter the github usernames of the students you'd like to remove as a comma separated list"
  puts "Current usernames:"
  puts @selected_cohort.students.collect{|s| s.github_username}.join(', ')
  @input = gets.strip
  return if ["back", "exit"].include?(@input.downcase)
  usernames = @input.chomp.split(',').map(&:strip)
  removed = @selected_cohort.remove_students(usernames)
  puts "Just removed #{removed} students from the cohort"
  puts "#{@selected_cohort.name} now has #{@selected_cohort.students.count} students"
  show_options_for_cohort
end

#show_options_for_cohortObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/student_progress/cli.rb', line 81

def show_options_for_cohort
  puts "What would you like to do with the cohort?"
  puts "1. Create Progress Report"
  puts "2. Add a member(s) to the cohort"
  puts "3. Remove a member from the cohort"
  puts "4. Add a periscope URL to scrape progress from"
  puts "5. Delete this cohort"
  puts "type 'back' to return to the main menu or 'exit' to exit the CLI"
  @input = gets.strip.downcase
  return if ["back", "exit"].include?(@input)
  case @input.to_i 
  when 1
    display_students
  when 2 
    add_students_to_cohort_view
  when 3
    remove_students_from_cohort_view
  when 4
    add_periscope_link_for_cohort_data
  when 5
    delete_this_cohort_view
  else
    puts "Whoops! didn't understand that input"
    show_options_for_cohort
  end
end