Skip to content

Commit

Permalink
Add warning when no contexts are currently available.
Browse files Browse the repository at this point in the history
  • Loading branch information
liffiton committed Aug 31, 2024
1 parent a9cdce4 commit ba997fc
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/codehelp/templates/context_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ <h2 class="title is-size-4">Contexts</h2>
<p>See the <a href="{{ url_for('docs.page', name='contexts') }}">contexts documentation</a> for more information and suggestions.</p>
{% endif %}
<script type="text/javascript">
function datePassed(date) {
const now_datetime = new Date(); // automatically UTC
const target_date = new Date(date); // automatically UTC
target_date.setHours(target_date.getHours() - 12); // UTC-12 for anywhere on Earth
return now_datetime >= target_date;
}
function formatDate(date) {
// Add 'T00:00' to force parsing as local time so UTC-local shift doesn't change date
return new Date(date + 'T00:00').toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric' });
}
document.addEventListener('alpine:init', () => {
Alpine.data('reorderable', () => ({
items: {{ contexts | tojson }},
Expand Down Expand Up @@ -64,18 +74,8 @@ <h2 class="title is-size-4">Contexts</h2>
});
});
},
get status() { return this.ctx.available === '9999-12-31' ? 'Hidden' : this.datePassed(this.ctx.available) ? 'Now' : 'Scheduled'; },
get status() { return this.ctx.available === '9999-12-31' ? 'Hidden' : datePassed(this.ctx.available) ? 'Now' : 'Scheduled'; },
get min_date_str() { const min_date = new Date(); min_date.setDate(min_date.getDate() + 1); return min_date.toISOString().split('T')[0]; },
datePassed(date) {
const now_datetime = new Date(); // automatically UTC
const target_date = new Date(date); // automatically UTC
target_date.setHours(target_date.getHours() - 12); // UTC-12 for anywhere on Earth
return now_datetime >= target_date;
},
formatDate(date) {
// Add 'T00:00' to force parsing as local time so UTC-local shift doesn't change date
return new Date(date + 'T00:00').toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric' });
},
chooseScheduled() {
if (this.status === 'Scheduled') {
this.newDate = this.ctx.available;
Expand Down Expand Up @@ -247,6 +247,7 @@ <h3 class="title is-4">
</tr>
</template>
<tr x-show="items.length == 0"><td colspan=4 class="has-text-centered"><i>No contexts defined.</i></td></tr>
<tr x-show="items.length > 0 && items.every(item => !datePassed(item.available))"><td colspan=4 class="has-text-centered"><span class="tag is-warning">Warning: No contexts are currently available.</span></td></tr>
</tbody>
</table>
<div colspan=4 class="has-text-centered">
Expand Down

0 comments on commit ba997fc

Please sign in to comment.