Untangling folder structure.

This commit is contained in:
2025-07-03 10:11:06 +10:00
parent 5c77dbc2a3
commit 21862771c1
11 changed files with 0 additions and 0 deletions

103
adm/index.js Executable file
View File

@@ -0,0 +1,103 @@
Vue.createApp({
data: function() {
return { 'events': null
, 'frm': { 'e': null, 'modal': null }
, 'faults': null
, 'fields': { 'coordinates': { 'patterns': [ '^$', '^-?\\d{1,3}(?:\\.\\d+)?,-?\\d{1,3}(?:\\.\\d+)?$' ], 'default': '-27.38621539644283,153.0351689206467' }
, 'start': { 'patterns': [ '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$' ], 'default': '' }
, 'end': { 'patterns': [ '^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$' ], 'default': '' }
, 'title': { 'patterns': [ '^.{20,50}$' ], 'default': 'Event Title' }
, 'description': { 'patterns': [ '^.{20,}$' ], 'default': 'Event Description' }
, 'location': { 'patterns': [ '^.{5,100}$' ], 'default': 'Event Location' }
}
}
},
methods: { formatDate: function(dt) {
var fmt = 'DD MMM YYYY';
var m = moment(dt);
var t = m.hour() * 3600 + m.minute() * 60 + m.second();
if ( t > 0 ) {
fmt = 'DD MMM YYYY, HH:mm:ss';
}
var ret = moment(dt).format(fmt);
return ret;
},
createEvent: function() {
var event = {};
for ( var k in this.fields ) {
event[k] = this.fields[k].default;
}
const now = moment();
let next7pm = moment().hour(19).minute(0).second(0);
if (now.isSameOrAfter(next7pm)) {
next7pm.add(1, 'day');
}
const twoHoursLater = moment(next7pm).add(2, 'hours');
event.start = next7pm.format('YYYY-MM-DDTHH:mm:ss');
event.end = twoHoursLater.format('YYYY-MM-DDTHH:mm:ss');
this.events.unshift(event);
this.frm.e = 0;
},
saveEvents: function() {
console.log(this.events);
var app = this;
jQuery.post( 'api.php'
, { 'cmd': 'put'
, 'payload': btoa(JSON.stringify(this.events))
}
, function(data) {
app.events = data;
app.validateEvents();
}
);
},
deleteEvent: function() {
this.events.splice(this.frm.e, 1);
this.frm.e = null;
this.validateEvents();
},
validateEvents: function() {
var faults = [];
for ( var e in this.events ) {
for ( var k in this.fields ) {
var value = this.events[e][k];
value = ( value == undefined ? '' : value );
var patterns = this.fields[k].patterns;
var match = false;
for ( var p in patterns ) {
var pattern = new RegExp(patterns[p]);
match = match || pattern.test(value);
}
if ( ! match ) {
var fault = {};
fault.e = e;
fault.k = k;
fault.v = value;
faults.push(fault);
}
}
}
this.faults = ( faults.length == 0 ? null : faults );
},
load: function() {
var app = this;
jQuery.get( 'api.php'
, { 'cmd': 'get' }
, function(data) {
app.events = data;
app.validateEvents();
$('body').fadeIn();
}
);
},
modal: function(property) {
var d = {};
d.property = property;
d.value = this.events[this.frm.e][property];
this.frm.modal = d;
}
},
mounted: function() {
this.load();
}
}).mount('#app')