Skip to content

Commit

Permalink
Edit page shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Nov 6, 2024
1 parent a8578cf commit 4b13e30
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 241 deletions.
3 changes: 3 additions & 0 deletions resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ Alpine.data('MainApp', () => ({
}
}));

import CalendarEditPage from "./calendar/calendar_edit_page.js";
Alpine.data('calendar_edit_page', CalendarEditPage);

import ContextMenu from './context-menu.js';
Alpine.data('context_menu', ContextMenu);

Expand Down
187 changes: 187 additions & 0 deletions resources/js/calendar/calendar_edit_page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import { do_error_check } from "./calendar_inputs_edit.js";
import _ from "lodash";

export default (calendar_structure) => ({

last_mouse_move: false,
poll_timer: false,
instapoll: false,
new_dynamic_change: false,

init() {

window.Perms = new Perms(
calendar_structure.userId,
calendar_structure.owned,
calendar_structure.paymentLevel,
calendar_structure.userRole
);

window.dark_theme = calendar_structure.dark_theme;

window.hash = calendar_structure.hash;

window.calendar_name = calendar_structure.calendar_name;
window.calendar_id = calendar_structure.calendar_id;
window.static_data = calendar_structure.static_data;
window.dynamic_data = calendar_structure.dynamic_data;

window.is_linked = calendar_structure.is_linked;
window.has_parent = calendar_structure.has_parent;
window.parent_hash = calendar_structure.parent_hash;
window.parent_offset = calendar_structure.parent_offset;

window.events = calendar_structure.events;
window.event_categories = calendar_structure.event_categories;

window.last_static_change = new Date(calendar_structure.last_static_change)
window.last_dynamic_change = new Date(calendar_structure.last_dynamic_change)

window.advancement = {
advancement_enabled: calendar_structure.advancement_enabled,
advancement_real_rate: calendar_structure.advancement_real_rate,
advancement_real_rate_unit: calendar_structure.advancement_real_rate_unit,
advancement_rate: calendar_structure.advancement_rate,
advancement_rate_unit: calendar_structure.advancement_rate_unit,
advancement_webhook_url: calendar_structure.advancement_webhook_url,
advancement_timezone: calendar_structure.advancement_timezone
}

window.preview_date = _.cloneDeep(calendar_structure.dynamic_data);
window.preview_date.follow = true;

rebuild_calendar('calendar', dynamic_data);

set_up_edit_inputs();
set_up_edit_values();
set_up_view_values();
set_up_visitor_values();

bind_calendar_events();

if (window.has_parent) {

this.last_mouse_move = Date.now();
this.poll_timer = setTimeout(this.check_dates.bind(this), 5000);
this.instapoll = false;

window.addEventListener('focus', () => {
this.check_dates();
});

window.registered_mousemove_callbacks['view_update'] = () => {
this.last_mouse_move = Date.now();
if (this.instapoll) {
this.instapoll = false;
this.check_dates();
}
}

}

this.$nextTick(
() => this.$dispatch(
'calendar-loaded', {
hash: window.hash,
calendar_name: window.calendar_name,
calendar_id: window.calendar_id,
static_data: window.static_data,
dynamic_data: window.dynamic_data,
is_linked: window.is_linked,
has_parent: window.has_parent,
parent_hash: window.parent_hash,
parent_offset: window.parent_offset,
events: window.events,
event_categories: window.event_categories,
last_static_change: window.last_static_change,
last_dynamic_change: window.last_dynamic_change,
advancement: window.advancement
}
)
);

window.dispatchEvent(new CustomEvent("events-changed"));
},

check_dates() {

if ((document.hasFocus() && (Date.now() - this.last_mouse_move) < 10000) || window.advancement.advancement_enabled) {

this.instapoll = false;

check_last_change(window.hash, (result) => {

this.new_dynamic_change = new Date(result.last_dynamic_change)

if (this.new_dynamic_change > window.last_dynamic_change) {

window.last_dynamic_change = this.new_dynamic_change

get_dynamic_data(window.hash, (result) => {

if (result.error) {
throw result.message;
}

window.dynamic_data = _.cloneDeep(result.dynamic_data);

this.check_update(false);
evaluate_settings();
eval_clock();
this.poll_timer = setTimeout(this.check_dates.bind(this), 5000);

});

} else {

this.poll_timer = setTimeout(this.check_dates.bind(this), 5000);

}

});

} else {

this.instapoll = true;

}

},

check_update(rebuild) {

let data = window.dynamic_date_manager.compare(window.dynamic_data);

window.dynamic_date_manager = new date_manager(window.dynamic_data.year, window.dynamic_data.timespan, window.dynamic_data.day);

if (window.preview_date.follow) {
window.preview_date = _.cloneDeep(window.dynamic_data);
window.preview_date.follow = true;
window.preview_date_manager = new date_manager(window.preview_date.year, window.preview_date.timespan, window.preview_date.day);
}

window.current_year.val(window.dynamic_data.year);

repopulate_timespan_select(window.current_timespan, window.dynamic_data.timespan, false);

repopulate_day_select(window.current_day, window.dynamic_data.day, false);

display_preview_back_button();

if (rebuild || ((data.rebuild || window.static_data.settings.only_reveal_today) && window.preview_date.follow)) {
rebuild_calendar('calendar', window.dynamic_data);
set_up_visitor_values();
} else {
update_current_day(false);
}

set_up_view_values();

},

rerenderRequested($event) {

do_error_check("calendar", $event.details.rerender);

}
});
122 changes: 61 additions & 61 deletions resources/js/calendar/calendar_inputs_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,39 +358,39 @@ export function set_up_edit_inputs() {
}
});

$('#enable_clock').change(function() {

window.static_data.clock.enabled = $(this).is(':checked');
window.static_data.clock.render = $(this).is(':checked');
$('#render_clock').prop('checked', window.static_data.clock.render);

window.dynamic_data.hour = 0;
window.dynamic_data.minute = 0;

evaluate_clock_inputs();

$('#create_season_events').prop('disabled', !window.static_data.clock.enabled);

var no_locations = (window.static_data.seasons.data.length == 0 || !window.static_data.seasons.global_settings.enable_weather) && !window.static_data.clock.enabled;
$('#locations_warning_hidden').toggleClass('hidden', no_locations).find('select, input').prop('disabled', no_locations);
$('#locations_warning').toggleClass('hidden', !no_locations);

$('.season_middle_btn').toggleClass('hidden', !window.static_data.clock.enabled || window.static_data.seasons.data.length < 3);
$('.location_middle_btn').toggleClass('hidden', (!window.static_data.seasons.global_settings.enable_weather && !window.static_data.clock.enabled) || window.static_data.seasons.data.length < 3);

eval_clock();

window.dispatchEvent(new CustomEvent("clock-changed", { detail: { enabled: window.static_data.clock.enabled } }));

});
// $('#enable_clock').change(function() {
//
// window.static_data.clock.enabled = $(this).is(':checked');
// window.static_data.clock.render = $(this).is(':checked');
// $('#render_clock').prop('checked', window.static_data.clock.render);
//
// window.dynamic_data.hour = 0;
// window.dynamic_data.minute = 0;
//
// evaluate_clock_inputs();
//
// $('#create_season_events').prop('disabled', !window.static_data.clock.enabled);
//
// var no_locations = (window.static_data.seasons.data.length == 0 || !window.static_data.seasons.global_settings.enable_weather) && !window.static_data.clock.enabled;
// $('#locations_warning_hidden').toggleClass('hidden', no_locations).find('select, input').prop('disabled', no_locations);
// $('#locations_warning').toggleClass('hidden', !no_locations);
//
// $('.season_middle_btn').toggleClass('hidden', !window.static_data.clock.enabled || window.static_data.seasons.data.length < 3);
// $('.location_middle_btn').toggleClass('hidden', (!window.static_data.seasons.global_settings.enable_weather && !window.static_data.clock.enabled) || window.static_data.seasons.data.length < 3);
//
// eval_clock();
//
// window.dispatchEvent(new CustomEvent("clock-changed", { detail: { enabled: window.static_data.clock.enabled } }));
//
// });

$('#collapsible_clock').change(function() {
if ($(this).is(':checked')) {
$('#clock').appendTo($(this).parent().children('.collapsible-content'));
} else {
$('#clock').prependTo($('#collapsible_date').parent().children('.collapsible-content'));
}
});
// $('#collapsible_clock').change(function() {
// if ($(this).is(':checked')) {
// $('#clock').appendTo($(this).parent().children('.collapsible-content'));
// } else {
// $('#clock').prependTo($('#collapsible_date').parent().children('.collapsible-content'));
// }
// });

/* ------------------- Layout callbacks ------------------- */

Expand Down Expand Up @@ -2819,7 +2819,7 @@ function update_data(e) {
refresh = refresh === "true" || refresh === undefined;

if (type.includes('clock')) {
evaluate_clock_inputs();
// evaluate_clock_inputs();
}

if (key == "year_zero_exists") {
Expand Down Expand Up @@ -5454,29 +5454,29 @@ function populate_calendar_lists() {
});
}

export function evaluate_clock_inputs() {
$('.clock_inputs :input, .clock_inputs :button, .render_clock').not('[clocktype]').prop('disabled', !window.static_data.clock.enabled);
$('.clock_inputs, .render_clock').toggleClass('hidden', !window.static_data.clock.enabled);

$('.do_render_clock :input, .do_render_clock :button').prop('disabled', !window.static_data.clock.render);
$('.do_render_clock').toggleClass('hidden', !window.static_data.clock.render);

$('.hour_input').each(function() {
$(this).prop('min', 0).prop('max', window.static_data.clock.hours).not('[clocktype]').prop('disabled', !window.static_data.clock.enabled).toggleClass('hidden', !window.static_data.clock.enabled);
});
$('.minute_input').each(function() {
$(this).prop('min', 1).prop('max', window.static_data.clock.minutes - 1).not('[clocktype]').prop('disabled', !window.static_data.clock.enabled).toggleClass('hidden', !window.static_data.clock.enabled);
});

$('input[clocktype="timezone_hour"]').each(function() {
$(this).prop('min', window.static_data.clock.hours * -0.5).prop('max', window.static_data.clock.hours * 0.5).prop('disabled', !window.static_data.clock.enabled).toggleClass('hidden', !window.static_data.clock.enabled);
});
$('input[clocktype="timezone_minute"]').each(function() {
$(this).prop('min', window.static_data.clock.minutes * -0.5).prop('max', window.static_data.clock.minutes * 0.5).prop('disabled', !window.static_data.clock.enabled).toggleClass('hidden', !window.static_data.clock.enabled);
});

$('#create_season_events').prop('disabled', window.static_data.seasons.data.length == 0 && !window.static_data.clock.enabled);
}
// export function evaluate_clock_inputs() {
// $('.clock_inputs :input, .clock_inputs :button, .render_clock').not('[clocktype]').prop('disabled', !window.static_data.clock.enabled);
// $('.clock_inputs, .render_clock').toggleClass('hidden', !window.static_data.clock.enabled);
//
// $('.do_render_clock :input, .do_render_clock :button').prop('disabled', !window.static_data.clock.render);
// $('.do_render_clock').toggleClass('hidden', !window.static_data.clock.render);
//
// $('.hour_input').each(function() {
// $(this).prop('min', 0).prop('max', window.static_data.clock.hours).not('[clocktype]').prop('disabled', !window.static_data.clock.enabled).toggleClass('hidden', !window.static_data.clock.enabled);
// });
// $('.minute_input').each(function() {
// $(this).prop('min', 1).prop('max', window.static_data.clock.minutes - 1).not('[clocktype]').prop('disabled', !window.static_data.clock.enabled).toggleClass('hidden', !window.static_data.clock.enabled);
// });
//
// $('input[clocktype="timezone_hour"]').each(function() {
// $(this).prop('min', window.static_data.clock.hours * -0.5).prop('max', window.static_data.clock.hours * 0.5).prop('disabled', !window.static_data.clock.enabled).toggleClass('hidden', !window.static_data.clock.enabled);
// });
// $('input[clocktype="timezone_minute"]').each(function() {
// $(this).prop('min', window.static_data.clock.minutes * -0.5).prop('max', window.static_data.clock.minutes * 0.5).prop('disabled', !window.static_data.clock.enabled).toggleClass('hidden', !window.static_data.clock.enabled);
// });
//
// $('#create_season_events').prop('disabled', window.static_data.seasons.data.length == 0 && !window.static_data.clock.enabled);
// }

var block_inputs = false;

Expand Down Expand Up @@ -5627,11 +5627,11 @@ export function set_up_edit_values() {
}
}

if ($('#collapsible_clock').is(':checked')) {
$('#clock').appendTo($('#collapsible_clock').parent().children('.collapsible-content'));
} else {
$('#clock').prependTo($('#collapsible_date').parent().children('.collapsible-content'));
}
// if ($('#collapsible_clock').is(':checked')) {
// $('#clock').appendTo($('#collapsible_clock').parent().children('.collapsible-content'));
// } else {
// $('#clock').prependTo($('#collapsible_date').parent().children('.collapsible-content'));
// }

if (window.static_data.year_data.leap_days) {

Expand Down
3 changes: 1 addition & 2 deletions resources/js/calendar/calendar_inputs_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
do_error_check,
evaluate_season_daylength_warning,
evaluate_save_button,
evaluate_clock_inputs,
} from "./calendar_inputs_edit";
import { pre_rebuild_calendar } from "./calendar_manager";

Expand Down Expand Up @@ -523,7 +522,7 @@ export function set_up_view_values() {

repopulate_location_select_list();

evaluate_clock_inputs();
// evaluate_clock_inputs();

window.dynamic_data.epoch = window.dynamic_date_manager.epoch;
}
Loading

0 comments on commit 4b13e30

Please sign in to comment.