mirror of
https://github.com/laurent22/joplin.git
synced 2025-04-14 11:18:47 +02:00
Improved debug client
This commit is contained in:
parent
fe277e0cac
commit
359ed44729
@ -84,8 +84,11 @@ function execRequest($method, $path, $query = array(), $data = null) {
|
|||||||
|
|
||||||
$output = json_decode($response, true);
|
$output = json_decode($response, true);
|
||||||
if ($output === null) {
|
if ($output === null) {
|
||||||
$msg = 'Cannot decode JSON: ' . $response . "\n\n" . $curlCmd;
|
throw new Exception('Cannot decode JSON: ' . $response . "\n" . $curlCmd);
|
||||||
die($msg);
|
}
|
||||||
|
|
||||||
|
if (isset($output['error'])) {
|
||||||
|
throw new Exception('API error: ' . $response . "\n" . $curlCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
@ -133,21 +136,31 @@ function redirect($path) {
|
|||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
|
try {
|
||||||
$session = execRequest('POST', 'sessions', null, array(
|
$session = execRequest('POST', 'sessions', null, array(
|
||||||
'email' => config('email'),
|
'email' => config('email'),
|
||||||
'password' => config('password'),
|
'password' => config('password'),
|
||||||
'client_id' => config('clientId'),
|
'client_id' => config('clientId'),
|
||||||
));
|
));
|
||||||
|
} catch (Exception $e) {
|
||||||
if (isset($session['error'])) throw new Exception('Could not login. Please check credentials. ' . json_encode($session));
|
die('Could not login. Please check credentials. ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$_SESSION['sessionId'] = $session['id'];
|
$_SESSION['sessionId'] = $session['id'];
|
||||||
|
|
||||||
$action = isset($_GET['action']) ? $_GET['action'] : 'folders';
|
if (!isset($_GET['action'])) {
|
||||||
|
$action = 'items';
|
||||||
|
$_GET['type'] = 'folder';
|
||||||
|
} else {
|
||||||
|
$action = $_GET['action'];
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_POST['create_folder'])) $action = 'create_folder';
|
if (isset($_POST['create_item'])) $action = 'create_item';
|
||||||
if (isset($_POST['delete_folder'])) $action = 'delete_folder';
|
if (isset($_POST['delete_folder'])) $action = 'delete_folder';
|
||||||
|
if (isset($_POST['delete_item'])) $action = 'delete_item';
|
||||||
if (isset($_POST['update_folder'])) $action = 'update_folder';
|
if (isset($_POST['update_folder'])) $action = 'update_folder';
|
||||||
|
if (isset($_POST['update_note'])) $action = 'update_note';
|
||||||
|
if (isset($_POST['update_item'])) $action = 'update_item';
|
||||||
|
|
||||||
$pageParams = array(
|
$pageParams = array(
|
||||||
'pageTitle' => parse_url(config('baseUrl'), PHP_URL_HOST) . ' - ' . ucfirst($action),
|
'pageTitle' => parse_url(config('baseUrl'), PHP_URL_HOST) . ' - ' . ucfirst($action),
|
||||||
@ -158,17 +171,30 @@ $pageParams = array(
|
|||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
|
|
||||||
case 'folders':
|
case 'items':
|
||||||
|
|
||||||
$folders = execRequest('GET', 'folders');
|
$type = $_GET['type'];
|
||||||
usort($folders, function($a, $b) { return strnatcmp($a['title'], $b['title']); });
|
$parentId = isset($_GET['parent_id']) ? $_GET['parent_id'] : null;
|
||||||
$pageParams['contentHtml'] = renderView('folders', array('folders' => $folders));
|
|
||||||
|
if ($type == 'folder') {
|
||||||
|
$path = 'folders';
|
||||||
|
$pageParams['headerTitle'] = 'Folders';
|
||||||
|
} else if ($type == 'note') {
|
||||||
|
$path = 'folders/' . $_GET['parent_id'] . '/notes';
|
||||||
|
$folder = execRequest('GET', 'folders/' . $parentId);
|
||||||
|
$pageParams['headerTitle'] = 'Notes in ' . $folder['title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = execRequest('GET', $path);
|
||||||
|
usort($items, function($a, $b) { return strnatcmp($a['title'], $b['title']); });
|
||||||
|
$pageParams['contentHtml'] = renderView('items', array('items' => $items, 'type' => $type, 'parentId' => $parentId));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'folder':
|
case 'item':
|
||||||
|
|
||||||
$folder = execRequest('GET', 'folders/' . $_GET['folder_id']);
|
$path = $_GET['type'] . 's';
|
||||||
$pageParams['contentHtml'] = renderView('folder', array('folder' => $folder));
|
$item = execRequest('GET', $path . '/' . $_GET['item_id']);
|
||||||
|
$pageParams['contentHtml'] = renderView('item', array('item' => $item, 'type' => $_GET['type']));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'changes':
|
case 'changes':
|
||||||
@ -185,32 +211,40 @@ switch ($action) {
|
|||||||
$pageParams['contentHtml'] = renderView('changes', array('changes' => $changes));
|
$pageParams['contentHtml'] = renderView('changes', array('changes' => $changes));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'notes':
|
case 'create_item':
|
||||||
|
|
||||||
$notes = execRequest('GET', 'folders/' . $_GET['folder_id'] . '/notes');
|
$parentId = !empty($_POST['parent_id']) ? $_POST['parent_id'] : null;
|
||||||
$pageParams['contentHtml'] = renderView('notes', array('notes' => $notes));
|
$path = $_POST['type'] . 's';
|
||||||
|
$data = array(
|
||||||
|
'title' => $_POST['item_title']
|
||||||
|
);
|
||||||
|
if ($parentId) $data['parent_id'] = $parentId;
|
||||||
|
$item = execRequest('POST', $path, null, $data);
|
||||||
|
|
||||||
|
$query = array(
|
||||||
|
'action' => 'items',
|
||||||
|
'type' => $_POST['type'],
|
||||||
|
'parent_id' => $parentId,
|
||||||
|
);
|
||||||
|
|
||||||
|
redirect('/?' . http_build_query($query));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'create_folder':
|
case 'delete_item':
|
||||||
|
|
||||||
$data = array('title' => $_POST['folder_title']);
|
$path = $_POST['type'] . 's';
|
||||||
$folder = execRequest('POST', 'folders', null, $data);
|
$item = execRequest('DELETE', $path . '/' . $_POST['item_id']);
|
||||||
redirect('/');
|
redirect('/');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'delete_folder':
|
case 'update_item':
|
||||||
|
|
||||||
$folder = execRequest('DELETE', 'folders/' . $_POST['folder_id']);
|
$oldItem = json_decode($_POST['original_item'], true);
|
||||||
redirect('/');
|
$newItem = removePrefix($_POST, 'item_');
|
||||||
break;
|
$diff = differentProperties($oldItem, $newItem);
|
||||||
|
$path = $_POST['type'] . 's';
|
||||||
case 'update_folder':
|
|
||||||
|
|
||||||
$oldFolder = json_decode($_POST['original_folder'], true);
|
|
||||||
$newFolder = removePrefix($_POST, 'folder_');
|
|
||||||
$diff = differentProperties($oldFolder, $newFolder);
|
|
||||||
if (count($diff)) {
|
if (count($diff)) {
|
||||||
execRequest('PATCH', 'folders/' . $_POST['folder_id'], null, $diff);
|
execRequest('PATCH', $path . '/' . $_POST['item_id'], null, $diff);
|
||||||
}
|
}
|
||||||
redirect('/');
|
redirect('/');
|
||||||
break;
|
break;
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<form method="post">
|
|
||||||
<?php foreach ($folder as $k => $v): ?>
|
|
||||||
<div class="form-group">
|
|
||||||
<label><?php echo htmlentities($k); ?></label>
|
|
||||||
<input type="text" class="form-control" name="folder_<?php echo htmlentities($k); ?>" value="<?php echo htmlentities($v); ?>" >
|
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
<input type="hidden" value="<?php echo htmlentities(json_encode($folder)); ?>" name="original_folder" />
|
|
||||||
<input type="submit" value="Save" name="update_folder" />
|
|
||||||
</form>
|
|
@ -1,32 +0,0 @@
|
|||||||
<table>
|
|
||||||
<tr><th>ID</th><th>Title</th><th></th><th></th></tr>
|
|
||||||
<?php foreach ($folders as $folder): ?>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<a href="/?action=folder&folder_id=<?php echo $folder['id']; ?>"><?php echo htmlentities($folder['id']); ?></a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<?php echo htmlentities($folder['title']); ?>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="/?action=notes&folder_id=<?php echo $folder['id']; ?>">View notes</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" value="<?php echo htmlentities($folder['id']); ?>" name="folder_id">
|
|
||||||
<input type="submit" value="Delete" name="delete_folder" />
|
|
||||||
</form>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<hr/>
|
|
||||||
|
|
||||||
<form method="post">
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="folder_title">Folder title</label>
|
|
||||||
<input type="text" class="form-control" name="folder_title" >
|
|
||||||
</div>
|
|
||||||
<input type="submit" value="Create" name="create_folder" />
|
|
||||||
</form>
|
|
11
debug_client/views/item.php
Normal file
11
debug_client/views/item.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<form method="post">
|
||||||
|
<?php foreach ($item as $k => $v): ?>
|
||||||
|
<div class="form-group">
|
||||||
|
<label><?php echo htmlentities($k); ?></label>
|
||||||
|
<input type="text" class="form-control" name="item_<?php echo htmlentities($k); ?>" value="<?php echo htmlentities($v); ?>" >
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<input type="hidden" value="<?php echo htmlentities(json_encode($item)); ?>" name="original_item" />
|
||||||
|
<input type="hidden" value="<?php echo $type; ?>" name="type" />
|
||||||
|
<input type="submit" value="Save" name="update_item" />
|
||||||
|
</form>
|
37
debug_client/views/items.php
Normal file
37
debug_client/views/items.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<table>
|
||||||
|
<tr><th>ID</th><th>Title</th><th></th><th></th></tr>
|
||||||
|
<?php foreach ($items as $item): ?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="/?action=item&type=<?php echo $type; ?>&item_id=<?php echo $item['id']; ?>"><?php echo htmlentities($item['id']); ?></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo htmlentities($item['title']); ?>
|
||||||
|
</td>
|
||||||
|
<?php if ($type == 'folder'): ?>
|
||||||
|
<td>
|
||||||
|
<a href="/?action=items&type=note&parent_id=<?php echo $item['id']; ?>">View notes</a>
|
||||||
|
</td>
|
||||||
|
<?php endif; ?>
|
||||||
|
<td>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" value="<?php echo $type; ?>" name="type">
|
||||||
|
<input type="hidden" value="<?php echo htmlentities($item['id']); ?>" name="item_id">
|
||||||
|
<input type="submit" value="Delete" name="delete_item" />
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="item_title">Title</label>
|
||||||
|
<input type="hidden" class="form-control" name="type" value="<?php echo $type; ?>" >
|
||||||
|
<input type="hidden" class="form-control" name="parent_id" value="<?php echo $parentId; ?>" >
|
||||||
|
<input type="text" class="form-control" name="item_title" >
|
||||||
|
</div>
|
||||||
|
<input type="submit" value="Create" name="create_item" />
|
||||||
|
</form>
|
@ -1,6 +0,0 @@
|
|||||||
<table>
|
|
||||||
<tr><th>Title</th></tr>
|
|
||||||
<?php foreach ($notes as $note): ?>
|
|
||||||
<tr><td><a href="/?action=notes¬e_id=<?php echo $note['id']; ?>"><?php echo htmlentities($note['title']); ?></a></td></tr>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</table>
|
|
Loading…
x
Reference in New Issue
Block a user