|
| 1 | +module SupplementalResourcesHelper |
| 2 | + RESOURCE_LABELS = { |
| 3 | + "video" => "Video", |
| 4 | + "homework_solutions" => "HW Solutions", |
| 5 | + "exit_ticket_solutions" => "ET Solutions", |
| 6 | + "topic_quiz" => "Topic Quiz", |
| 7 | + "parent_newsletter" => "Parent Newsletter", |
| 8 | + "google_slides" => "Slides", |
| 9 | + "geogebra" => "GeoGebra", |
| 10 | + "lesson_pdf" => "Lesson PDF", |
| 11 | + "application_problems" => "Application Problems", |
| 12 | + "mid_module_review" => "Mid-Module Review", |
| 13 | + "end_module_review" => "End-of-Module Review", |
| 14 | + "pacing_guide" => "Pacing Guide", |
| 15 | + "fluency_games" => "Fluency Games", |
| 16 | + "vocabulary" => "Vocabulary", |
| 17 | + "number_talks" => "Number Talks", |
| 18 | + "downloadable_resources" => "Downloads", |
| 19 | + "eureka_essentials" => "Eureka Essentials", |
| 20 | + "khan_practice" => "Khan Academy" |
| 21 | + }.freeze |
| 22 | + |
| 23 | + # Resource types worth showing as external links. |
| 24 | + # Excludes proprietary formats (flipcharts, SMARTboard) and platform-dependent (GoFormative). |
| 25 | + DISPLAYABLE_TYPES = %w[ |
| 26 | + video |
| 27 | + homework_solutions |
| 28 | + exit_ticket_solutions |
| 29 | + google_slides |
| 30 | + geogebra |
| 31 | + topic_quiz |
| 32 | + parent_newsletter |
| 33 | + application_problems |
| 34 | + mid_module_review |
| 35 | + end_module_review |
| 36 | + pacing_guide |
| 37 | + fluency_games |
| 38 | + vocabulary |
| 39 | + number_talks |
| 40 | + eureka_essentials |
| 41 | + downloadable_resources |
| 42 | + khan_practice |
| 43 | + ].freeze |
| 44 | + |
| 45 | + def supplemental_label(resource) |
| 46 | + RESOURCE_LABELS[resource.resource_type] || resource.title |
| 47 | + end |
| 48 | + |
| 49 | + def supplemental_url(resource) |
| 50 | + resource.url || resource.source_page_url |
| 51 | + end |
| 52 | + |
| 53 | + def displayable_supplemental_resources(resources) |
| 54 | + resources |
| 55 | + .select { |r| r.resource_type.in?(DISPLAYABLE_TYPES) && supplemental_url(r).present? } |
| 56 | + .sort_by { |r| DISPLAYABLE_TYPES.index(r.resource_type) || 999 } |
| 57 | + end |
| 58 | + |
| 59 | + def youtube_video_id(url) |
| 60 | + return nil unless url |
| 61 | + match = url.match(%r{(?:embed/|v=|youtu\.be/)([^&?/]+)}) |
| 62 | + match[1] if match |
| 63 | + end |
| 64 | +end |
0 commit comments