Skip to content

Commit

Permalink
parsing caldav
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Feb 18, 2024
1 parent 0aa1589 commit 5316733
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 250 deletions.
293 changes: 114 additions & 179 deletions application/app.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion application/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ kbd {
#intro kbd {
border: 2px solid pink;
box-shadow: 2px 2px pink;
font-size: 0.85em;
font-size: 0.6em;
line-height: 0.85em;
display: inline-block;
font-weight: 600;
Expand Down Expand Up @@ -313,6 +313,8 @@ div#intro {
z-index: 100000;
min-width: 100%;
height: 100%;
}
.intro-animation {
animation-name: intro;
animation-duration: 2s;
animation-delay: 6s;
Expand All @@ -328,6 +330,9 @@ div#intro #version {
color: white;
text-align: center;
font-size: 1.2rem;
}

.intro-version-animation {
animation-name: intro_img_2;
animation-duration: 2s;
animation-delay: 6s;
Expand All @@ -342,6 +347,9 @@ div#intro img {
top: 50px;
left: 50%;
margin-left: -90px;
}

.intro-img-anmation {
animation-name: intro_img;
animation-duration: 2s;
animation-delay: 6s;
Expand Down
3 changes: 0 additions & 3 deletions application/assets/js/eximport.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,13 @@ export let export_ical_versionChangment = function (filename, event_data) {
result += 'VERSION:2.0' + '\r\n';
result += 'PRODID:GREG' + '\r\n';
result += 'METHOD:PUBLISHED' + '\r\n';
console.log(event_data);
event_data.forEach((e, i) => {
let index = -1;
for (let key in e) {
index++;

//clean data
if (e[key] == null || typeof e[key] == 'object') {
console.log(e.RRULE);

e.RRULE = '';
}

Expand Down
2 changes: 1 addition & 1 deletion application/assets/js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export let autocomplete = function (e, key) {

if (parsed_events.length == 0) return;

let matches = events.filter(function (val, i) {
let matches = parsed_events.filter(function (val, i) {
if (parsed_events[i][key].indexOf(e) >= 0) return parsed_events[i];
});

Expand Down
3 changes: 0 additions & 3 deletions application/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<div id="intro" class="width-100 height-100">
<img src="./assets/icons/intro.svg" />
<div class="width-100" id="version"><kbd>time is relativ</kbd></div>
<div>
<div></div>
</div>
</div>
</div>

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.2.627",
"version": "2.2.6302",
"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.650",
"version": "3.0.651",
"id": "greg",
"subtitle": "easy to use calendar",
"core": true,
Expand Down
127 changes: 66 additions & 61 deletions application/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,65 +65,71 @@ function parse_ics(
callback,
store
) {
let jcalData;
try {
jcalData = ICAL.parse(data);
} catch (e) {
channel.postMessage({ action: 'error', content: 'error' });
}
let comp = new ICAL.Component(ICAL.parse(data), {
parseEvent: true,
});

comp.onerror = function (error) {
console.log('Error occurred:', error);
};

var comp = new ICAL.Component(jcalData);
comp.oncomplete = function () {
console.log('succesfull parsed');
};

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

let imp = null;

vevent.forEach(function (ite) {
let rr_until = '';
let allday = false;
let date_start = ite.getFirstPropertyValue('dtstart');
let date_end = ite.getFirstPropertyValue('dtend');
if (date_end == null) date_end = date_start;
let rrule = ite.getFirstPropertyValue('rrule');
let date_end =
ite.getFirstPropertyValue('dtend') ||
ite.getFirstPropertyValue('dtstart');

if (date_start.isDate && date_end.isDate) allday = true;
//RRULE

if (rrule && typeof rrule === 'object' && rrule.freq) {
//console.log(rrule);
rr_until = new Date('3000-01-01').getTime();
try {
let rrule = ite.getFirstPropertyValue('rrule');

if (rrule && typeof rrule === 'object' && rrule.freq) {
n = rrule;
rr_until = n.until || '';
}

if (ite.getFirstPropertyValue('rrule').isFinite() === false)
rr_until = new Date('3000-01-01').getTime();

if (rrule.until !== null) {
rr_until = rrule.until;
}
if (rrule && typeof rrule === 'object' && rrule.freq) {
n = rrule;
rr_until = n.until || '';
}

if (ite.getFirstPropertyValue('rrule').isFinite() === false)
rr_until = new Date('3000-01-01').getTime();

if (ite.getFirstPropertyValue('rrule').isByCount()) {
let dt = dayjs(date_start);

switch (rrule.freq) {
case 'DAILY':
rr_until = dt.add(rrule.count, 'days').valueOf();
case 'MONTHLY':
rr_until = dt.add(rrule.count, 'months').valueOf();
case 'BIWEEKLY':
rr_until = dt.add(rrule.count * 2, 'weeks').valueOf();
case 'WEEKLY':
rr_until = dt.add(rrule.count, 'weeks').valueOf();
case 'YEARLY':
rr_until = dt.add(rrule.count, 'years').valueOf();
default:
rr_until = new Date('3000-01-01').getTime();
if (rrule.until !== null) {
rr_until = rrule.until;
}

if (ite.getFirstPropertyValue('rrule').isByCount()) {
let dt = dayjs(date_start);

switch (rrule.freq) {
case 'DAILY':
rr_until = dt.add(rrule.count, 'days').valueOf();
case 'MONTHLY':
rr_until = dt.add(rrule.count, 'months').valueOf();
case 'BIWEEKLY':
rr_until = dt.add(rrule.count * 2, 'weeks').valueOf();
case 'WEEKLY':
rr_until = dt.add(rrule.count, 'weeks').valueOf();
case 'YEARLY':
rr_until = dt.add(rrule.count, 'years').valueOf();
default:
rr_until = new Date('3000-01-01').getTime();
}
}
}
} catch (e) {
console.log(e);
}

//date start
Expand All @@ -137,38 +143,34 @@ function parse_ics(

//date end
let dateEnd, timeEnd, dateEndUnix;

if (date_end) {
let a = dayjs(date_end);
dateEnd = a.format('YYYY-MM-DD');
timeEnd = a.format('HH:mm:ss');
dateEndUnix = a.unix();

if (rr_until != '') {
dateEnd = dayjs(rr_until).format('YYYY-MM-DD');
timeEnd = dayjs(rr_until).format('HH:mm:ss');
dateEndUnix = new Date(rr_until).getTime() / 1000;
a = dayjs(rr_until);
}
//allDay

if (allday) {
let f = date_end.toJSDate();
f = new Date(dayjs(f).subtract(1, 'day'));
dateEnd = dayjs(f).format('YYYY-MM-DD');
timeEnd = dayjs(f).format('HH:mm:ss');
dateEndUnix = f.getTime() / 1000;
a = a.subtract(1, 'day');
}

dateEnd = a.format('YYYY-MM-DD');
timeEnd = a.format('HH:mm:ss');
dateEndUnix = a.unix();
}

imp = {
BEGIN: 'VEVENT',
UID: ite.getFirstPropertyValue('uid'),
SUMMARY: ite.getFirstPropertyValue('summary'),
LOCATION: ite.getFirstPropertyValue('location'),
DESCRIPTION: ite.getFirstPropertyValue('description'),
UID: ite.getFirstPropertyValue('uid') || '',
SUMMARY: ite.getFirstPropertyValue('summary') || '',
LOCATION: ite.getFirstPropertyValue('location') || '',
DESCRIPTION: ite.getFirstPropertyValue('description') || '',
CATEGORIES: ite.getFirstPropertyValue('categories') || '',
RRULE: ite.getFirstPropertyValue('rrule') || '',
'LAST-MODIFIED': ite.getFirstPropertyValue('last-modified'),
'LAST-MODIFIED': ite.getFirstPropertyValue('last-modified') || '',
CLASS: ite.getFirstPropertyValue('class') || '',
DTSTAMP: date_start,
DTSTAMP: ite.getFirstPropertyValue('dtstamp') || '',
DTSTART: date_start,
DTEND: date_end,
END: 'VEVENT',
Expand All @@ -184,7 +186,7 @@ function parse_ics(
alarm: alarm || 'none',
etag: etag || '',
url: url,
calendar_name: calendar_name,
calendar_name: comp.getFirstPropertyValue('x-wr-calname') || '',
id: account_id,
modified: ite.getFirstPropertyValue('last-modified').toString(),
};
Expand Down Expand Up @@ -347,13 +349,16 @@ self.addEventListener('message', async (event) => {
// Post the result back to the main thread
channel.postMessage({ action: 'parse', content: ff });
} catch (error) {
console.error('Error parsing:', error);
channel.postMessage({ action: 'error', content: 'error parsing' });
console.log('hello' + error);
channel.postMessage({
action: 'error',
content: 'error parsing ' + error,
});
}
}

if (event.data.type == 'test') {
sync_caldav();
// sync_caldav();
}
});

Expand Down

0 comments on commit 5316733

Please sign in to comment.