Browse Source

add published date to weight page

main
Aaron Parecki 7 months ago
parent
commit
01f99ab940
2 changed files with 19 additions and 3 deletions
  1. +7
    -2
      controllers/controllers.php
  2. +12
    -1
      views/new-weight.php

+ 7
- 2
controllers/controllers.php View File

@ -1039,7 +1039,7 @@ $app->get('/map-img', function() use($app) {
});
function create_weight(&$user, $weight_num, $weight_unit) {
function create_weight(&$user, $weight_num, $weight_unit, $published) {
$micropub_request = array(
'type' => ['h-entry'],
'properties' => [
@ -1052,6 +1052,11 @@ function create_weight(&$user, $weight_num, $weight_unit) {
]]
]
);
try {
$date = new DateTime($published);
$micropub_request['properties']['published'] = [$date->format('c')];
} catch(Exception $e) {
}
$r = micropub_post_for_user($user, $micropub_request, null, true);
return $r;
@ -1070,7 +1075,7 @@ $app->post('/weight', function() use($app) {
if($user=require_login($app)) {
$params = $app->request()->params();
$r = create_weight($user, $params['weight_num'], $user->weight_unit);
$r = create_weight($user, $params['weight_num'], $user->weight_unit, $params['published']);
$location = $r['location'];
$app->response()['Content-type'] = 'application/json';

+ 12
- 1
views/new-weight.php View File

@ -13,6 +13,11 @@
<input type="number" id="weight_num" class="form-control">
</div>
<div class="form-group">
<label for="date">Date and Time</label>
<input type="text" id="date" class="form-control" value="<?= date('Y-m-d H:i:s') ?>">
</div>
<div style="float: right; margin-top: 6px;">
<button class="btn btn-success" id="btn_post">Post</button>
</div>
@ -23,11 +28,17 @@
</div>
<script>
$(function(){
var d = new Date();
var tzOffset = tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1);
$("#date").val( $("#date").val() + " " + tzOffset);
$("#btn_post").click(function(){
$("#btn_post").addClass("loading disabled");
$.post("/weight", {
weight_num: $("#weight_num").val()
weight_num: $("#weight_num").val(),
published: $("#date").val()
}, function(response){
if(response.location != false) {

Loading…
Cancel
Save