Got a basic calendar editing page going.

This commit is contained in:
2025-07-01 23:02:30 +10:00
parent 7607d807fe
commit f8616ff819
12 changed files with 148 additions and 30 deletions

9
cal/api.php Normal file
View File

@@ -0,0 +1,9 @@
<?php
header("Content-Type: application/json");
include('lib.php');
$ret = array( "err" => "unknown command" );
if ( $_GET["cmd"] == "get" ) {
$ret = getEvents();
}
print(json_encode($ret));
?>

0
cal/events.json Normal file
View File

7
cal/index.css Normal file
View File

@@ -0,0 +1,7 @@
.tabbody {
border-bottom: solid 1px rgb(222, 226, 230);
border-left: solid 1px rgb(222, 226, 230);
border-right: solid 1px rgb(222, 226, 230);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}

17
cal/index.js Executable file
View File

@@ -0,0 +1,17 @@
Vue.createApp({
data: function() {
return { 'events': null
, 'tabs': [ 'Events', 'Create' ]
, 'frm': { 'tab': 0, 'e': null }
}
},
mounted: function() {
var app = this;
jQuery.get( 'api.php'
, { 'cmd': 'get' }
, function(data) {
app.events = data;
}
);
}
}).mount('#app')

73
cal/index.php Executable file
View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Events</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
crossorigin="anonymous" />
<link href="index.css" rel="stylesheet" />
<style>
</style>
</head>
<body>
<div class="container" id="app">
<ul class="nav nav-tabs">
<li class="nav-item" v-for="lbl, t in tabs" v-on:click="frm.tab = t; frm.e = null;">
<a class="nav-link" :class="{ 'active': frm.tab == t }" aria-current="page" href="#">{{lbl}}</a>
</li>
</ul>
<div v-if="frm.tab == 0" class="tabbody">
<div class="row">
<div class="col-6">
<table class="table">
<tbody>
<tr v-for="event, e in events" v-on:click="frm.e = e">
<td>{{event.start}}</td>
<td>{{event.end}}</td>
</tr>
</tbody>
</table>
</div>
<div class="col-6" v-if="frm.e != null">
<div class="input-group mb-1">
<span class="input-group-text">Start</span>
<input type="text" class="form-control" v-model="events[frm.e].start">
</div>
<div class="input-group mb-1">
<span class="input-group-text">End</span>
<input type="text" class="form-control" v-model="events[frm.e].end">
</div>
<div class="input-group mb-1">
<span class="input-group-text">Title</span>
<input type="text" class="form-control" v-model="events[frm.e].title">
</div>
<div class="input-group mb-1">
<span class="input-group-text">Description</span>
<input type="text" class="form-control" v-model="events[frm.e].description">
</div>
<div class="input-group mb-1">
<span class="input-group-text">Location</span>
<input type="text" class="form-control" v-model="events[frm.e].location">
</div>
<div class="input-group mb-1">
<span class="input-group-text">Coordinates</span>
<input type="text" class="form-control" v-model="events[frm.e].coordinates">
</div>
</div>
</div>
</div>
<div v-else-if="frm.tab == 1" class="tabbody">
<h1>Create</h1>
</div>
<pre>{{events}}</pre>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="index.js"></script>
</body>
</html>

0
cal/lib.php Normal file
View File

View File

@@ -1,22 +1,28 @@
services:
web:
app:
image: php:8.2-apache
container_name: homepage
container_name: app
ports:
- "8080:80"
volumes:
- ./web/:/var/www/html:Z
- ./vendor/:/var/www/html/vendor:Z
- ./lib.php:/var/www/html/lib.php:Z
- ./dat.live:/var/www/html/dat:Z
networks:
- labnet
profiles:
- app
cal:
image: php:8.2-apache
container_name: calendar
container_name: cal
ports:
- "8081:80"
- "8080:80"
volumes:
- ./cal/:/var/www/html:Z
- ./vendor/:/var/www/html/vendor:Z
- ./lib.php:/var/www/html/lib.php:Z
- ./dat.live:/var/www/html/dat:Z
networks:
- labnet
profiles:

31
lib.php Executable file
View File

@@ -0,0 +1,31 @@
<?php
ini_set('memory_limit', '512M');
function getEvents() {
$content = file_get_contents("dat/events.json");
$entries = json_decode($content, $associative = true);
for ( $i = 0; $i < count($entries); $i++ ) {
$entry = $entries[$i];
$dt = new DateTime( $entry["start"] );
$ctl = $dt -> format("YmdHi");
$entries[$i]["ctl"] = $ctl;
$datestamp = $dt -> format("Ymd");
$files = array( "agenda" => sprintf("agenda/%d.md", $datestamp)
, "minutes" => sprintf("minutes/%d.md", $datestamp)
);
foreach ( $files as $key => $file ) {
if ( file_exists( $file ) ) {
$entries[$i][$key] = file_get_contents($file);
}
}
}
usort($entries, function ($a, $b) {
$dateA = new DateTime($a['start']);
$dateB = new DateTime($b['start']);
return $dateA < $dateB ? 1 : -1;
});
return($entries);
}
?>

View File

@@ -1,35 +1,10 @@
<!DOCTYPE html>
<?php
require 'lib.php';
require 'vendor/autoload.php';
use Michelf\Markdown;
function getEvents() {
$content = file_get_contents("events.json");
$entries = json_decode($content, $associative = true);
for ( $i = 0; $i < count($entries); $i++ ) {
$entry = $entries[$i];
$dt = new DateTime( $entry["start"] );
$ctl = $dt -> format("YmdHi");
$entries[$i]["ctl"] = $ctl;
$datestamp = $dt -> format("Ymd");
$files = array( "agenda" => sprintf("agenda/%d.md", $datestamp)
, "minutes" => sprintf("minutes/%d.md", $datestamp)
);
foreach ( $files as $key => $file ) {
if ( file_exists( $file ) ) {
$entries[$i][$key] = file_get_contents($file);
}
}
}
usort($entries, function ($a, $b) {
$dateA = new DateTime($a['start']);
$dateB = new DateTime($b['start']);
return $dateA < $dateB ? 1 : -1;
});
return($entries);
}
?>
<html lang="en">

0
web/lib.php Normal file
View File