-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #613 from PRX/research/simple-calendar
simple calendar
- Loading branch information
Showing
15 changed files
with
315 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@import "shared/bootstrap-variables"; | ||
|
||
.simple-calendar { | ||
.table { | ||
display: grid; | ||
grid-template-columns: repeat(7, 1fr); | ||
grid-auto-rows: 1fr; | ||
|
||
:is(thead, tbody, tr) { | ||
display: contents; | ||
} | ||
|
||
:is(thead th, td) { | ||
display: grid; | ||
place-content: center; | ||
min-width: 6ch; | ||
border-width: 1px; | ||
line-height: 1; | ||
} | ||
|
||
.day.current-month:hover { | ||
background-color: $secondary !important; | ||
color: $light; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// App modules | ||
|
||
@import "audio-segmenter/index"; | ||
@import "calendar"; | ||
@import "uploads"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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)) { | ||
this.element.classList.remove("bg-danger") | ||
} | ||
event.target.classList.remove("bg-primary", "text-light") | ||
event.target.firstElementChild.disabled = true | ||
} else { | ||
if (this.isDraft(event.target.firstElementChild)) { | ||
event.target.classList.add("bg-danger", "text-light") | ||
} else { | ||
event.target.classList.add("bg-primary", "text-light") | ||
} | ||
event.target.firstElementChild.disabled = null | ||
} | ||
} | ||
|
||
isDisabled(el) { | ||
return el.disabled === true | ||
} | ||
|
||
isDraft(el) { | ||
return el.getAttribute("draft") === "true" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = ["page", "prev", "next"] | ||
static values = { | ||
currentPosition: { type: Number, default: 0 }, | ||
range: { type: Number, default: 6 }, | ||
step: { type: Number, default: 1 }, | ||
} | ||
|
||
currentPositionValueChanged() { | ||
this.pageTargets.forEach((el, index) => { | ||
if (this.inRange(index)) { | ||
el.classList.remove("d-none") | ||
} else { | ||
el.classList.add("d-none") | ||
} | ||
}) | ||
} | ||
|
||
inRange(index) { | ||
return index >= this.currentPositionValue && index < this.currentPositionValue + this.rangeValue | ||
} | ||
|
||
pageForward() { | ||
if (this.currentPositionValue < this.pageTargets.length - this.rangeValue) { | ||
this.currentPositionValue += this.stepValue | ||
this.prevTarget.disabled = false | ||
} | ||
if (this.currentPositionValue === this.pageTargets.length - this.rangeValue) { | ||
this.nextTarget.disabled = true | ||
} | ||
} | ||
|
||
pageBackward() { | ||
if (this.currentPositionValue > 0) { | ||
this.currentPositionValue -= this.stepValue | ||
this.nextTarget.disabled = false | ||
} | ||
if (this.currentPositionValue === 0) { | ||
this.prevTarget.disabled = true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="col <%= "d-none" if index >= range %>" data-pager-target="page"> | ||
<%= month_calendar(start_date: start_date) do |date| %> | ||
<% if date_is_in_month?(date, start_date.month) %> | ||
<%= date.day %> | ||
<%= form.hidden_field :selected_dates, multiple: true, data: {date_target: "preselected"}, value: date.to_datetime, disabled: !date_is_in_dates?(date, @planner.dates), draft: date_is_in_dates?(date, @draft_dates) %> | ||
<% end %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<%= render "podcasts/tabs" %> | ||
|
||
<div class="row my-4 px-2"> | ||
<div class="col-lg-8"> | ||
<div class="col-lg-4"> | ||
<%= render "form_main" %> | ||
</div> | ||
<div class="col-lg-4"> | ||
<div class="col-lg-8"> | ||
<%= render "form_side" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<div class="simple-calendar"> | ||
<div class="calendar-heading"> | ||
<%= link_to t("simple_calendar.previous", default: "Previous"), calendar.url_for_previous_view %> | ||
<span class="calendar-title"><%= t("date.month_names")[start_date.month] %> <%= start_date.year %></span> | ||
<%= link_to t("simple_calendar.next", default: "Next"), calendar.url_for_next_view %> | ||
</div> | ||
|
||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<% date_range.slice(0, 7).each do |day| %> | ||
<th><%= t("date.abbr_day_names")[day.wday] %></th> | ||
<% end %> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% date_range.each_slice(7) do |week| %> | ||
<%= content_tag :tr, class: calendar.tr_classes_for(week) do %> | ||
<% week.each do |day| %> | ||
<%= content_tag :td, class: calendar.td_classes_for(day) do %> | ||
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %> | ||
<% capture_haml(day, sorted_events.fetch(day, []), &passed_block) %> | ||
<% else %> | ||
<% passed_block.call day, sorted_events.fetch(day, []) %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> |
Oops, something went wrong.