Skip to content

Commit

Permalink
Merge branch 'main' into feat/episode_media_tab
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Aug 3, 2023
2 parents bfa43a7 + 900913b commit abd2052
Show file tree
Hide file tree
Showing 83 changed files with 740 additions and 435 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/shared/bootstrap-variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $white: #fff;
$black: #000;

$gray-100: #f5f5f5;
$gray-200: #e9e9ec;
$gray-200: #eee;
$gray-300: #dddde0;
$gray-400: #bebec2;
$gray-500: #98989c;
Expand Down
20 changes: 20 additions & 0 deletions app/assets/stylesheets/shared/busy.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.prx-show-busy {
display: none !important;
}
.prx-visible-busy {
visibility: hidden !important;
}
turbo-frame[busy] {
.prx-show-busy {
display: initial !important;
}
.prx-hide-busy {
display: none !important;
}
.prx-visible-busy {
visibility: initial !important;
}
.prx-invisible-busy {
visibility: hidden !important;
}
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/shared/shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// global layout
@import "mixins";
@import "reboot";
@import "busy";
@import "button";
@import "card";
@import "episode-card";
Expand Down
44 changes: 37 additions & 7 deletions app/controllers/podcast_planner_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,51 @@ def set_beginning_of_week
Date.beginning_of_week = :sunday
end

# Only allow a list of trusted parameters through.
# Make params match PodcastPlanner interface
def planner_params
p = permit_params
p[:podcast_id] = @podcast.id
p[:date_range_condition] = p[:number_of_episodes].present? ? "episodes" : "date"
p[:segment_count] = p[:ad_breaks].to_i + 1 if p[:ad_breaks].present?

# translate selected weeks into monthly weeks
monthly_weeks = monthly_week_options(p[:selected_weeks])
periodic_weeks = periodic_week_options(p[:selected_weeks])
if monthly_weeks.any?
p[:week_condition] = "monthly"
p[:monthly_weeks] = monthly_weeks
elsif periodic_weeks.any?
p[:week_condition] = "periodic"
p[:period] = periodic_weeks.first
end

p
end

# Only allow a list of trusted parameters through.
def permit_params
params.permit(
:podcast_id,
:week_condition,
:period,
:start_date,
:date_range_condition,
:number_of_episodes,
:end_date,
:publish_time,
:segment_count,
:medium,
:ad_breaks,
selected_days: [],
monthly_weeks: [],
selected_weeks: [],
selected_dates: []
)
end

def monthly_week_options(selected_weeks)
PodcastPlannerHelper::MONTHLY_WEEKS.filter_map.with_index do |val, idx|
idx + 1 if selected_weeks&.include?(val.to_s)
end
end

def periodic_week_options(selected_weeks)
PodcastPlannerHelper::PERIODIC_WEEKS.filter_map.with_index do |val, idx|
idx + 1 if selected_weeks&.include?(val.to_s)
end
end
end
8 changes: 8 additions & 0 deletions app/helpers/embed_player_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module EmbedPlayerHelper
include PrxAccess

EMBED_PLAYER_LANDING_PATH = "/listen"
EMBED_PLAYER_PATH = "/e"
EMBED_PLAYER_FEED = "uf"
EMBED_PLAYER_GUID = "ge"
Expand All @@ -12,6 +13,13 @@ module EmbedPlayerHelper
EMBED_PLAYER_AUDIO_URL = "ua"
DOVETAIL_TOKEN = "_t"

def embed_player_landing_url(podcast, ep = nil)
params = {}
params[EMBED_PLAYER_FEED] = podcast&.public_url
params[EMBED_PLAYER_GUID] = ep.item_guid if ep.present?
"#{play_root}#{EMBED_PLAYER_LANDING_PATH}?#{params.to_query}"
end

def embed_player_episode_url(ep, type = nil, preview = false)
params = {}

Expand Down
40 changes: 20 additions & 20 deletions app/helpers/podcast_planner_helper.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
# frozen_string_literal: true

module PodcastPlannerHelper
PERIODIC_WEEKS = I18n.t([:every_one, :every_two, :every_three, :every_four], scope: [:podcast_planner, :helper, :period_options])
MONTHLY_WEEKS = I18n.t([:first, :second, :third, :fourth, :fifth], scope: [:podcast_planner, :helper, :monthly_options])
MONTHLY_WEEKS = [:first, :second, :third, :fourth, :fifth]
PERIODIC_WEEKS = [:every_one, :every_two, :every_three, :every_four]
DATE_CONTROLLER = "date"
TOGGLE_ACTION = "click->date#toggleSelect"
RECOUNT_ACTION = "click->count#recount"
RECOUNT_ACTION = "click->planner#recount"

def day_options
DateTime::DAYNAMES.map.with_index { |day, i| [day, i] }
end

def periodic_weeks_options
PERIODIC_WEEKS.map.with_index { |opt, i| [opt, i + 1] }
end

def monthly_weeks_options
MONTHLY_WEEKS.map.with_index { |opt, i| [opt, i + 1] }
end

def end_condition_options
[[I18n.t(".podcast_planner.helper.episodes"), "episodes"],
[I18n.t(".podcast_planner.helper.end_date"), "date"]]
end

def week_condition_options
[[I18n.t(".podcast_planner.helper.month"), "monthly"],
[I18n.t(".podcast_planner.helper.period"), "periodic"]]
def week_options
monthly = MONTHLY_WEEKS.map { |v| [t("podcast_planner.helper.monthly_options.#{v}"), v] }
periodic = PERIODIC_WEEKS.map { |v| [t("podcast_planner.helper.period_options.#{v}"), v] }
monthly + periodic
end

def time_options
Expand Down Expand Up @@ -58,12 +46,24 @@ def date_is_in_month?(date, month)

def calendar_day_tag(day:, month:, calendar:, &block)
data = {}
cls = []

if date_is_in_month?(day, month)
data[:controller] = DATE_CONTROLLER
data[:action] = [TOGGLE_ACTION, RECOUNT_ACTION].join(" ")

is_new = date_is_in_dates?(day, @planner.dates)
is_existing = date_is_in_dates?(day, @draft_dates)
if is_new && is_existing
cls = ["bg-warning", "bg-danger", "text-light"]
elsif is_new
cls = ["bg-primary", "text-light"]
elsif is_existing
cls = ["bg-warning"]
end
end

content_tag(:td, class: calendar.td_classes_for(day), data: data) do
content_tag(:td, class: calendar.td_classes_for(day) + cls, data: data) do
block.call
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/uploads_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ def upload_processing?(rec)
%w[started created processing retrying].include?(rec&.status)
end

def upload_stalled?(rec)
upload_processing?(rec) && rec.retryable?
end

def upload_complete?(rec)
%w[complete].include?(rec.status)
end
Expand Down
11 changes: 10 additions & 1 deletion app/javascript/controllers/click_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["submit"]
static values = { immediate: Boolean }
static values = { immediate: Boolean, debounce: Number }

connect() {
if (this.immediateValue) {
Expand All @@ -11,6 +11,15 @@ export default class extends Controller {
}

submit() {
if (this.debounceValue) {
clearTimeout(this.timer)
this.timer = setTimeout(() => this.doClick(), this.debounceValue)
} else {
this.doClick()
}
}

doClick() {
if (this.hasSubmitTarget) {
this.submitTarget.click()
} else if (this.element) {
Expand Down
16 changes: 0 additions & 16 deletions app/javascript/controllers/date_controller.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["preselected"]

connect() {
if (!this.isDisabled(this.preselectedTarget)) {
if (this.isDraft(this.preselectedTarget)) {
this.element.classList.add("bg-danger", "text-light")
} else {
this.element.classList.add("bg-primary", "text-light")
}
}

if (this.preselectedTarget.getAttribute("draft") === "true") {
this.element.classList.add("bg-warning")
}
}

toggleSelect(event) {
if (!this.isDisabled(event.target.firstElementChild)) {
if (this.isDraft(event.target.firstElementChild)) {
Expand Down
50 changes: 50 additions & 0 deletions app/javascript/controllers/planner_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["adBreaks", "button", "count", "counter", "label"]
static values = { datesCount: Number }

datesCountValueChanged() {
this.recount()
}

setMedium(event) {
if (event.target.value === "video") {
this.adBreaksTarget.value = ""
this.adBreaksTarget.disabled = true
} else {
this.adBreaksTarget.disabled = false
}
this.recount()
}

setAdBreaks(event) {
this.recount()
}

recount() {
const num = this.countSelectedTargets()

// update label
this.countTarget.innerHTML = num
if (num === 1) {
this.labelTarget.innerHTML = this.labelTarget.dataset.singular
} else {
this.labelTarget.innerHTML = this.labelTarget.dataset.plural
}

// enable button IF we have > 1 selected and a adBreak count
if (num > 0 && (this.adBreaksTarget.disabled || parseInt(this.adBreaksTarget.value) >= 0)) {
this.buttonTarget.disabled = false
} else {
this.buttonTarget.disabled = true
}
}

countSelectedTargets() {
const selectedTargets = this.counterTargets.filter((el) => {
return !el.disabled
})
return selectedTargets.length
}
}
13 changes: 9 additions & 4 deletions app/javascript/controllers/polling_controller.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Controller } from "@hotwired/stimulus"

const DEFAULT_DEBOUNCE = 1000
const DEFAULT_MAX = 120

export default class extends Controller {
static values = { debounce: Number }
static values = { debounce: Number, max: Number }

connect() {
this.count = 0
this.frame = this.element.closest("turbo-frame")
this.interval = setInterval(() => {
this.clickOrTurbo()
}, this.debounceValue || DEFAULT_DEBOUNCE)
this.interval = setInterval(() => this.clickOrTurbo(), this.debounceValue || DEFAULT_DEBOUNCE)
}

disconnect() {
Expand All @@ -18,6 +18,11 @@ export default class extends Controller {

// use a turbo-frame to reload if possible, to dodge document.click events
clickOrTurbo() {
this.count += 1
if (this.count > (this.maxValue || DEFAULT_MAX)) {
return this.disconnect()
}

if (this.frame && this.frame.src) {
this.frame.reload()
} else if (this.frame && this.element.href) {
Expand Down
24 changes: 23 additions & 1 deletion app/javascript/controllers/slim_select_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"
import SlimSelect from "slim-select"

export default class extends Controller {
static values = { groupSelect: Boolean }
static values = { groupSelect: Boolean, exclusive: Array }

connect() {
this.select = new SlimSelect({
Expand All @@ -23,6 +23,28 @@ export default class extends Controller {
}
this.element.dispatchEvent(new Event("blur"))
},
beforeChange: (newOpts, oldOpts) => {
if (this.exclusiveValue.length) {
const newVals = newOpts.map((o) => o.value)
const oldVals = oldOpts.map((o) => o.value)
const added = newVals.find((v) => !oldVals.includes(v))
const addedExclusive = this.exclusiveValue.includes(added) ? added : null
const addedNonExclusive = !this.exclusiveValue.includes(added) ? added : null

// deselect when adding an exclusive
if (addedExclusive && oldVals.length) {
this.select.setSelected([addedExclusive])
return false
}

// deselect if exclusive is selected and we added non-exclusive
if (oldVals.find((v) => this.exclusiveValue.includes(v)) && addedNonExclusive) {
this.select.setSelected([addedNonExclusive])
return false
}
}
return true
},
},
})
}
Expand Down
21 changes: 21 additions & 0 deletions app/javascript/controllers/toggle_blank_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["toggle"]

toggleTargetConnected(el) {
const action = el.dataset.action || ""
el.dataset.action = `${action} change->toggle-blank#toggle`
}

toggle(event) {
if (event.target.value) {
for (const target of this.toggleTargets) {
if (target !== event.target) {
target.value = ""
target.dispatchEvent(new Event("blur"))
}
}
}
}
}
Loading

0 comments on commit abd2052

Please sign in to comment.