Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
V13Axel committed Nov 19, 2024
1 parent f8b3848 commit 6152cbb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
29 changes: 13 additions & 16 deletions resources/js/calendar/collapsible_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,25 @@ export default class CollapsibleComponent {
is_valid = true;

load(static_data) {
console.log('Load called on ', this.constructor.prototype.name);
if (!static_data) {
return
}

this.calendar_settings = static_data.settings;

// We want to disable the changeHandlers during loading stages so that we don't get recursive calendar rerender calls
// TODO: Figure out why this doesn't _actually_ work.
this.processWatchers = false;
for (let [localKey, globalKey] of Object.entries(this.inboundProperties)) {
this[localKey] = _.get(static_data, globalKey);
}
this.processWatchers = true;

if (!this.initialized) {
this.setupWatchers();
this.initialized = true;
}
this.processWatchers = true

this.loaded(static_data);
}

setupWatchers() {

init() {
const componentProperties = Array.from(new Set(
Object.keys(this.changeHandlers).concat(Object.keys(this.outboundProperties))
));
Expand All @@ -46,9 +42,8 @@ export default class CollapsibleComponent {

setupWatcher(localKey) {
this.$watch(localKey, (...args) => {
let isValid = this.validate();

if (!isValid) {
if (!this.validate()) {
console.log("Didn't validate", localKey, args);
return this.validationFailed();
}

Expand All @@ -60,10 +55,14 @@ export default class CollapsibleComponent {
return;
}

console.log("Running change handlers for " + localKey, JSON.parse(JSON.stringify(args)));

if (this.changeHandlers[localKey]) {
this.changeHandlers[localKey].bind(this)(...args);
}

console.log("Running outbound properties " + localKey);

if (this.outboundProperties[localKey]) {
this.rerender(this.outboundProperties[localKey], this[localKey]);
}
Expand All @@ -79,13 +78,10 @@ export default class CollapsibleComponent {
}

validate() {
let isValid = true;

for (let [localKey, validator] of Object.entries(this.validators)) {
let { error, message } = validator.bind(this)(localKey);
if (error) {
this.errors[localKey] = message;
isValid = false;
} else if (this.errors?.[localKey]) {
// TODO: Remove error dispatch?
delete this.errors[localKey];
Expand All @@ -94,11 +90,12 @@ export default class CollapsibleComponent {

this.is_valid = !Object.keys(this.errors).length;

return isValid;
return this.is_valid;
}

validationFailed() {
this.$dispatch("calendar-set-errors", {
this.$dispatch("calendar-validation-failed", {
key: this.constructor.prototype.name,
errors: Object.values(this.errors)
})
}
Expand Down
4 changes: 2 additions & 2 deletions resources/js/calendar/leap_days_collapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class LeapDaysCollapsible extends CollapsibleComponent {
}

getLeapDayIntervalText(leapDay) {
if (!this.is_valid) {
return ["Error detected."];
if (!this.validate()) {
return ["Error detected"];
}

let values = leapDay.interval.split(',').reverse();
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/collapsible.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class="wiki">

<div class="collapsible-content card-body"
x-data="{{ Str::snake($contains_clean) }}_collapsible"
@calendar-loaded.window="$nextTick(() => load(window.static_data))"
@calendar-structure-changed.window="$nextTick(() => load(window.static_data))">
@calendar-loaded.window="load(window.static_data)"
@calendar-structure-changed.window="load(window.static_data)">
<x-dynamic-component :calendar="$calendar ?? null" :component="Str::kebab($contains_clean) . '-collapsible'"></x-dynamic-component>
</div>
</div>
2 changes: 1 addition & 1 deletion resources/views/inputs/full.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
return [].concat(...Object.values(this.errors));
}
}"
@calendar-add-errors.window="addErrors"
@calendar-validation-failed.window="addErrors"
@calendar-remove-errors.window="removeErrors"
x-show="getErrors().length"
x-cloak
Expand Down

0 comments on commit 6152cbb

Please sign in to comment.