Skip to content

Commit

Permalink
Move modify:save to VxgBasicEntityEditPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zackatbrightbeam committed Aug 2, 2024
1 parent a749efc commit 388b3f9
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 124 deletions.
2 changes: 2 additions & 0 deletions dist/VxgBasicEntityEditPlugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ declare function VxgBasicEntityEditPlugin(this: any, options: any): {
};
util: {
dateTimeFromUTC: (utc: number, tz?: string) => any;
localTimeToUTC: (timeString: string, tz?: string) => number;
localDateTimeToUTC: (dateOrDateTimeString: string, tz?: string) => number;
};
};
};
Expand Down
123 changes: 100 additions & 23 deletions dist/voxgig-model-react.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -64878,10 +64878,10 @@ function BasicEntitySliderField(props) {
const { spec } = props;
const basicEntityAutocompleteField = BasicEntitySliderFieldSpecShape(spec);
const { control, field, getValues, errors } = basicEntityAutocompleteField;
const val = getValues(field.name + "_uival$");
const val = getValues(field.name);
const err = errors[field.name];
const { field: controllerField } = useController({
name: field.name + "_uival$",
name: field.name,
control,
defaultValue: val || field.ux.min
});
Expand Down Expand Up @@ -65671,11 +65671,24 @@ function VxgBasicEntityEditPlugin(options) {
const dt = util$1.dateTimeFromUTC(item[field.name]);
item[field.name + "_orig$"] = item[field.name];
item[field.name + "_udm$"] = dt.udm;
item[field.name] = dt.localt;
item[field.name] = dt.locald;
console.log("modify_edit_Date", item[field.name]);
}
return item;
});
}
).add(
"aim:app,on:BasicLed,modify:save",
{ view: spec.name },
function modify_save_Date(msg) {
return __async(this, null, function* () {
const out = yield this.prior(msg);
let item = __spreadValues({}, out);
const dt = util$1.localDateTimeToUTC(item[field.name]);
item[field.name] = dt;
return item;
});
}
);
} else if ("Time" === field.ux.kind) {
seneca.add(
Expand All @@ -65689,18 +65702,30 @@ function VxgBasicEntityEditPlugin(options) {
item[field.name + "_orig$"] = item[field.name];
item[field.name + "_udm$"] = dt.udm;
item[field.name] = dt.localt;
console.log("modify_edit_Time", item[field.name]);
}
return item;
});
}
).add(
"aim:app,on:BasicLed,modify:save",
{ view: spec.name },
function modify_save_Time(msg) {
return __async(this, null, function* () {
const out = yield this.prior(msg);
let item = __spreadValues({}, out);
const dt = util$1.localTimeToUTC(item[field.name]);
item[field.name] = dt;
return item;
});
}
);
} else if ("DateTime" === field.ux.kind) {
seneca.add(
"aim:app,on:BasicLed,modify:edit,view:" + spec.name,
function modify_edit_Datetime(msg) {
return __async(this, null, function* () {
const out = yield this.prior(msg);
console.log("out", out);
let item = __spreadValues({}, out);
if (!item[field.name + "_orig$"]) {
const dt = util$1.dateTimeFromUTC(item[field.name]);
Expand All @@ -65711,6 +65736,18 @@ function VxgBasicEntityEditPlugin(options) {
return item;
});
}
).add(
"aim:app,on:BasicLed,modify:save",
{ view: spec.name },
function modify_save_Datetime(msg) {
return __async(this, null, function* () {
const out = yield this.prior(msg);
let item = __spreadValues({}, out);
const dt = util$1.localDateTimeToUTC(item[field.name]);
item[field.name] = dt;
return item;
});
}
);
} else if ("Slider" === field.ux.kind) {
seneca.add(
Expand All @@ -65720,12 +65757,24 @@ function VxgBasicEntityEditPlugin(options) {
return __async(this, null, function* () {
const out = yield this.prior(msg);
let item = __spreadValues({}, out);
if (!item[field.name + "_uival$"]) {
item[field.name + "_uival$"] = Number(item[field.name]) / 60;
if (!item[field.name + "_orig$"]) {
item[field.name + "_orig$"] = item[field.name];
item[field.name] = Number(item[field.name]) / 60;
}
return item;
});
}
).add(
"aim:app,on:BasicLed,modify:save",
{ view: spec.name },
function modify_save_Slider(msg) {
return __async(this, null, function* () {
const out = yield this.prior(msg);
let item = __spreadValues({}, out);
item[field.name] = Number(item[field.name]) * 60;
return item;
});
}
);
}
}
Expand Down Expand Up @@ -65780,6 +65829,41 @@ const util$1 = {
out.locald = `${year}-${month}-${day}`;
out.localt = `${hour}:${minute}:${second}`;
return out;
},
localTimeToUTC: (timeString, tz) => {
tz = tz || Intl.DateTimeFormat().resolvedOptions().timeZone;
const now = /* @__PURE__ */ new Date();
const [hours, minutes, seconds] = timeString.split(":").map(Number);
const localDate = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
hours,
minutes,
seconds
);
const utcTimestamp = Date.UTC(
localDate.getFullYear(),
localDate.getMonth(),
localDate.getDate(),
localDate.getHours(),
localDate.getMinutes(),
localDate.getSeconds()
);
const tzOffset = new Date(utcTimestamp).getTimezoneOffset() * 6e4;
return utcTimestamp - tzOffset;
},
localDateTimeToUTC: (dateOrDateTimeString, tz) => {
const date = new Date(dateOrDateTimeString);
if (isNaN(date.getTime())) {
throw new Error("Invalid date or datetime string");
}
if (tz) {
const tzDate = new Date(date.toLocaleString("en-GB", { timeZone: tz }));
const offset2 = date.getTime() - tzDate.getTime();
return date.getTime() + offset2;
}
return date.getTime();
}
};
Object.assign(VxgBasicEntityEditPlugin, {
Expand All @@ -65797,7 +65881,6 @@ const makeResolver = (seneca, spec) => useCallback(
const { ent, name } = spec;
const view = name;
let entity = seneca.entity(ent);
console.log("makeResolver", "data", data);
entity = entity.make$().data$(data);
let errors = entity.valid$({ errors: true });
seneca.act("aim:app,on:BasicLed,entity:valid", {
Expand Down Expand Up @@ -65889,18 +65972,21 @@ function BasicEntityEdit(props) {
mode: "onChange",
resolver
});
const onSubmit = (data) => {
const onSubmit = (data) => __async(this, null, function* () {
console.log("BasicEntityEdit", "onSubmit", "data", data);
const modifiedData = seneca.direct("aim:app,on:BasicLed,modify:save", {
view: name,
data,
fields
});
const modifiedData = yield seneca.direct(
"aim:app,on:BasicLed,modify:save",
{
view: name,
data,
fields
}
);
seneca.act("aim:app,on:BasicLed,save:item", {
view: name,
data: modifiedData
});
};
});
return /* @__PURE__ */ jsxRuntimeExports.jsx(Box$2, { className: "vxg-BasicEntityEdit", children: item ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
"form",
{
Expand Down Expand Up @@ -66078,17 +66164,8 @@ function VxgBasicLedPlugin(options) {
return item;
}).add("aim:app,on:BasicLed,modify:save", function modify_save(msg) {
let item = msg.data;
let fields = msg.fields;
if (null == item) return item;
item = __spreadValues({}, item);
for (const field of fields) {
if ("Slider" === field.ux.kind) {
console.log("VxgBasicLedPlugin", "modify:save", "field", field);
console.log("VxgBasicLedPlugin", "modify:save", "item", item);
item[field.name] = Number(item[field.name + "_uival$"]) * 60;
}
}
console.log("modify:save", "item", item);
return item;
}).message(
"aim:app,on:BasicLed,edit:item,redux$:true",
Expand Down
Loading

0 comments on commit 388b3f9

Please sign in to comment.