Skip to content

Commit

Permalink
less keys
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Aug 24, 2023
1 parent b5bd8f6 commit 381337f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 76 deletions.
118 changes: 72 additions & 46 deletions application/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,15 +804,18 @@ const event_check = function (date) {
};

let k = events.filter((event) => {
const eventStartTime = new Date(event.dateStart).getTime();
const eventEndTime = new Date(event.dateEnd).getTime();
const targetTime = new Date(date).getTime();
let targetTime = new Date(date).getTime();

let eventStartTime = dayjs(event.DTSTART).format("YYYY-MM-DD");
eventStartTime = new Date(eventStartTime).getTime();

let eventEndTime = dayjs(event.DTEND).format("YYYY-MM-DD");
eventEndTime = new Date(eventEndTime).getTime();
return (
eventStartTime === targetTime ||
(eventStartTime <= targetTime &&
eventEndTime >= targetTime &&
event.rrule_json.freq === undefined)
event.RRULE.freq === undefined)
);
});

Expand Down Expand Up @@ -914,7 +917,6 @@ let rrule_check = function (date) {
}
return feedback;
};

//////////////////
//event slider
///////////
Expand Down Expand Up @@ -962,7 +964,7 @@ let event_slider = function (date) {
let a = new Date(events[i].dateStart).getTime();
let b = new Date(events[i].dateEnd).getTime();
let c = new Date(date).getTime();
let d = events[i].rrule_json.freq;
let d = events[i].RRULE.freq;

if (d === "none" || d === "" || d === undefined || d === null) {
if (a === c || (a <= c && b >= c)) {
Expand All @@ -973,8 +975,8 @@ let event_slider = function (date) {
//workaround if enddate is not set
//AKA infinity

if (events[i].rrule_json != null) {
if (events[i].rrule_json.until == null) {
if (events[i].RRULE != null) {
if (events[i].RRULE.until == null) {
b = new Date("3000-01-01").getTime();
}
}
Expand Down Expand Up @@ -1233,7 +1235,6 @@ let showCalendar = function (month, year) {
let p = year + "-" + mmonth + "-" + day;

const d = new Date(p);
//cell.setAttribute("data-day", d.getDay());

moon.classList.add("moon-phase-" + getMoonPhase(year, month, date));
cell.appendChild(moon);
Expand Down Expand Up @@ -1512,6 +1513,7 @@ var page_events = {
},
oncreate: function () {
find_closest_date();
sort_array(events, "DTSTART", "date");

bottom_bar(
"<img src='assets/image/pencil.svg'>",
Expand Down Expand Up @@ -1566,7 +1568,8 @@ var page_events = {
class: "item events " + u + " " + a,
tabindex: index + 1,
"data-id": item.UID,
"data-date": item.dateStart,
// "data-date": item.dateStart,
"data-date": dayjs.unix(item.dateStartUnix).format("YYYY-MM-DD"),
"data-category": (item.CATEGORIES || "").toUpperCase(),
"data-summary": (item.SUMMARY || "").toUpperCase(),
},
Expand Down Expand Up @@ -1634,11 +1637,11 @@ var page_events_filtered = {
//date
if (item.dateStart != item.dateEnd && !item.allDay) {
de =
dayjs(item.dateStart).format(settings.dateformat) +
dayjs.unix(item.dateStartUnix).format(settings.dateformat) +
" - " +
dayjs(item.dateEnd).format(settings.dateformat);
dayjs.unix(item.dateEndUnix).format(settings.dateformat);
} else {
de = dayjs(item.dateStart).format(settings.dateformat);
de = dayjs.unix(item.dateStartUnix).format(settings.dateformat);
}

let u = item.isSubscription ? "subscription" : "";
Expand All @@ -1649,7 +1652,9 @@ var page_events_filtered = {
class: "item events " + u + " " + a,
tabindex: tindex,
"data-id": item.UID,
"data-date": item.dateStart,
"data-date": dayjs
.unix(item.dateStartUnix)
.format("YYYY-MM-DD"),
"data-category": (item.CATEGORIES || "").toUpperCase(),
"data-summary": (item.SUMMARY || "").toUpperCase(),
},
Expand Down Expand Up @@ -2784,7 +2789,11 @@ var page_edit_event = {
class: "select-box",

oncreate: function ({ dom }) {
dom.value = update_event_date.dateStart;
dom.value = update_event_date.dateStartUnix;

dom.value = dayjs
.unix(update_event_date.dateStartUnix)
.format("YYYY-MM-DD");
},
}),
]),
Expand All @@ -2798,7 +2807,10 @@ var page_edit_event = {
class: "select-box",

oncreate: function ({ dom }) {
dom.value = update_event_date.dateEnd;
// dom.value = update_event_date.dateEnd;
dom.value = dayjs
.unix(update_event_date.dateEndUnix)
.format("YYYY-MM-DD");
},
}),
]),
Expand Down Expand Up @@ -2862,23 +2874,17 @@ var page_edit_event = {
type: "time",
id: "event-time-start",
class: "select-box",
value:
update_event_date.time_start.length == 8
? update_event_date.time_start.slice(0, -3)
: update_event_date.time_start,
value: dayjs.unix(update_event_date.dateStartUnix).format("HH:mm"),
}),
]),
m("div", { class: "item input-parent time", tabindex: "5" }, [
m("label", { for: "event-time-end" }, "End Time"),
m("input", {
placeholder: "hh:mm",
placeholder: "HH:mm",
type: "time",
id: "event-time-end",
class: "select-box",
value:
update_event_date.time_end.length == 8
? update_event_date.time_end.slice(0, -3)
: update_event_date.time_end,
value: dayjs.unix(update_event_date.dateEndUnix).format("HH:mm"),
}),
]),
m("div", { class: "item input-parent", tabindex: "6" }, [
Expand Down Expand Up @@ -2986,7 +2992,7 @@ var page_edit_event = {
"select",
{
id: "event-recur",
value: update_event_date.rrule_json.freq ?? "none",
value: update_event_date.RRULE.freq ?? "none",
class: "select-box",
},
[
Expand Down Expand Up @@ -3099,7 +3105,7 @@ let callback_getfile = function (result) {
localforage
.setItem("events", only_local_events)
.then(function () {
backup_events();
// backup_events();
side_toaster("<img src='assets/image/E25C.svg'", 2000);
setTimeout(function () {
m.route.set("/page_calendar");
Expand Down Expand Up @@ -3699,34 +3705,54 @@ let remove_alarm = function (id) {
// /////////////
// /////////////

const convert_ics_date = function (t, ful) {
let nn = dayjs(t).format("YYYYMMDDTHHmmss");
let convert_ics_date = function (t, ful, s) {
// Replace hyphens and colons with nothing, and replace space with 'T'
let nn = t.replace(/[-:]/g, "").replace(" ", "T");

// If ful is true, extract the date part and format it
if (ful) {
nn = ";VALUE=DATE:" + dayjs(t).format("YYYYMMDD");
} else {
let w = nn.split("T");
nn = ";VALUE=DATE:" + w[0];
}

// If ful is false, add a colon at the beginning
if (!ful) {
nn = ":" + nn;
}

// If s is true, remove colons
if (s) {
nn = nn.replace(/:/g, "");
}

return nn;
};

const days = ["SU", "MO", "TU", "WE", "TH", "FR", "SA"];

const rrule_convert = function (val, date_end, date_start) {
if (val === "none") {
let rrule_convert = function (val, date_end, date_start) {
let r = "";
let f = days[new Date(date_start).getDay()];

if (val == "none") {
return "";
}
if (val != "none") {
r = "FREQ=" + val + ";UNTIL=" + convert_ics_date(date_end, false, true);

if (val == "WEEKLY") {
r =
"FREQ=" +
val +
";INTERVAL=1;BYDAY=" +
f +
";UNTIL=" +
convert_ics_date(date_end, false, true);
}
console.log(r);

const f = days[new Date(date_start).getDay()];

if (val === "WEEKLY") {
return `FREQ=${val};INTERVAL=1;BYDAY=${f};UNTIL=${convert_ics_date(
date_end
)}`;
return r;
}

return `FREQ=${val};UNTIL=${convert_ics_date(date_end)}`;
};

//todo if is rrule enddate == startdate
Expand Down Expand Up @@ -3911,7 +3937,7 @@ let store_event = function (db_id, cal_name) {
.setItem("events", without_subscription)
.then(function () {
clear_form();
backup_events();
// backup_events();
side_toaster("<img src='assets/image/E25C.svg'", 2000);
setTimeout(function () {
m.route.set("/page_calendar");
Expand All @@ -3925,7 +3951,7 @@ let store_event = function (db_id, cal_name) {
//caldav
//rrule event should end on the same day, but rrule.until should set the end date

if (event.RRULE != "") {
if (event.RRULE && event.RRULE != "") {
event.DTEND =
";TZID=" + settings.timezone + convert_ics_date(rrule_dt_end, allDay);
}
Expand Down Expand Up @@ -4150,7 +4176,7 @@ let update_event = function (etag, url, id, db_id, uid) {
.setItem("events", without_subscription)
.then(function () {
clear_form();
backup_events();
//backup_events();
side_toaster("<img src='assets/image/E25C.svg'", 2000);
setTimeout(function () {
m.route.set("/page_calendar");
Expand All @@ -4171,7 +4197,7 @@ let update_event = function (etag, url, id, db_id, uid) {
//rrule event should end on the same day, but rrule.until should set the end date
const alarm = `\nBEGIN:VALARM\nTRIGGER;VALUE=DATE-TIME:${notification_time}\nACTION:AUDIO\nEND:VALARM`;

if (event.RRULE !== "") {
if (event.RRULE && event.RRULE !== "") {
event.DTEND =
";TZID=" + settings.timezone + convert_ics_date(rrule_dt_end, allDay);
}
Expand Down Expand Up @@ -4230,7 +4256,7 @@ let delete_event = function (etag, url, account_id, uid) {
localforage
.setItem("events", without_subscription)
.then(function (value) {
backup_events();
//backup_events();
side_toaster("event deleted", 2000);
if (events.length != 0) {
m.route.set("/page_events");
Expand Down
45 changes: 17 additions & 28 deletions application/assets/js/eximport.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,12 @@ export const parse_ics = async function (

var comp = new ICAL.Component(jcalData);
var valarm = comp.getAllSubcomponents("VALARM");
valarm.forEach(function (ite) {});

var vevent = comp.getAllSubcomponents("vevent");
let calendar_name = comp.getFirstPropertyValue("x-wr-calname") || "";

vevent.forEach(function (ite) {
let n = "";
let rr_until = "";

if (
typeof ite.getFirstPropertyValue("rrule") == "object" &&
ite.getFirstPropertyValue("rrule") != null &&
ite.getFirstPropertyValue("rrule").freq != null
) {
n = ite.getFirstPropertyValue("rrule");
if (n.until != null) {
rr_until = n.until;
}
}
const rrule = ite.getFirstPropertyValue("rrule") || "";

let dateStart, timeStart, dateStartUnix;

Expand All @@ -221,11 +208,12 @@ export const parse_ics = async function (
timeEnd = dayjs(ite.getFirstPropertyValue("dtend")).format("HH:mm:ss");
dateEndUnix =
new Date(ite.getFirstPropertyValue("dtend")).getTime() / 1000;

if (rr_until != "") {
dateEnd = dayjs(n.until).format("YYYY-MM-DD");
timeEnd = dayjs(n.until).format("HH:mm:ss");
dateEndUnix = new Date(n.until).getTime() / 1000;
if (rrule !== undefined && rrule !== null) {
if (rrule.until && rrule.until !== "") {
dateEnd = dayjs(rrule.until).format("YYYY-MM-DD");
timeEnd = dayjs(rrule.until).format("HH:mm:ss");
dateEndUnix = new Date(rrule.until).getTime() / 1000;
}
}
}

Expand Down Expand Up @@ -254,20 +242,19 @@ export const parse_ics = async function (
dateEndUnix = f.getTime() / 1000;
}

let lastmod = ite.getFirstPropertyValue("last-modified");
let dtstart = ite.getFirstPropertyValue("dtstart");
let dtend = ite.getFirstPropertyValue("dtend");
let dtstart = ite.getFirstPropertyValue("dtstart") || "";
let dtend = ite.getFirstPropertyValue("dtend") || "";

//todo remove more key:values
let imp = {
BEGIN: "VEVENT",
UID: ite.getFirstPropertyValue("uid"),
SUMMARY: ite.getFirstPropertyValue("summary"),
LOCATION: ite.getFirstPropertyValue("location"),
DESCRIPTION: ite.getFirstPropertyValue("description"),
SUMMARY: ite.getFirstPropertyValue("summary") || "",
LOCATION: ite.getFirstPropertyValue("location") || "",
DESCRIPTION: ite.getFirstPropertyValue("description") || "",
CATEGORIES: ite.getFirstPropertyValue("categories") || "",
RRULE: ite.getFirstPropertyValue("rrule") || "",
"LAST-MODIFIED": lastmod,
RRULE: rrule,
"LAST-MODIFIED": ite.getFirstPropertyValue("last-modified") || "",
CLASS: ite.getFirstPropertyValue("class") || "",
DTSTAMP: dtstart,
DTSTART: dtstart,
Expand All @@ -276,19 +263,21 @@ export const parse_ics = async function (
isSubscription: isSubscription,
isCaldav: isCaldav,
allDay: allday,

dateStart: dateStart,
dateStartUnix: dateStartUnix,
dateEndUnix: dateEndUnix,
dateEnd: dateEnd,
time_start: timeStart,
time_end: timeEnd,
alarm: alarm || "none",
rrule_json: n,
etag: etag,
url: url,
calendar_name: calendar_name,
id: account_id,
};

//if (events.RRULE == "") delete events.RRULE;
events.push(imp);
});
};
Expand Down
2 changes: 1 addition & 1 deletion application/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.1.2",
"version": "2.1.4",
"name": "greg",
"id": "greg",
"categories": ["utilities"],
Expand Down
2 changes: 1 addition & 1 deletion application/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],

"b2g_features": {
"version": "3.0.3",
"version": "3.0.4",
"id": "greg",
"subtitle": "easy to use calendar",
"core": true,
Expand Down

0 comments on commit 381337f

Please sign in to comment.