Add full edit form to anime list

This commit is contained in:
Timothy Warren 2016-01-04 10:53:03 -05:00
parent c04c85b999
commit 9c81836648
31 changed files with 876 additions and 179 deletions

View File

@ -74,7 +74,7 @@ return function(array $config_array = []) {
// Miscellaneous helper methods
$anime_client = new AnimeClient();
$anime_client->setContainer($container);
$container->set('anime_client', $anime_client);
$container->set('anime-client', $anime_client);
// Models
$container->set('api-model', new Model\API($container));

View File

@ -36,6 +36,14 @@ return [
'anime_edit.js',
'manga_edit.js'
],
'table_edit' => [
'lib/jquery.min.js',
'lib/table_sorter/jquery.tablesorter.min.js',
'sort_tables.js',
'show_message.js',
'anime_edit.js',
'manga_edit.js'
],
'anime_collection' => [
'lib/jquery.min.js',
'lib/jquery.throttle-debounce.js',

View File

@ -18,18 +18,22 @@ return [
'default_method' => 'index',
'404_method' => 'not_found'
],
// Routes on all controllers
'common' => [
'update' => [
'path' => '/{controller}/update',
'action' => 'update',
'verb' => 'post',
'tokens' => [
'controller' => '[a-z_]+'
]
],
],
// Routes on anime collection controller
'anime' => [
'anime_add_form' => [
'path' => '/anime/add',
'action' => 'add_form',
'verb' => 'get'
],
'anime_add' => [
'path' => '/anime/add',
'action' => 'add',
'verb' => 'post'
]
],
'manga' => [
],
'collection' => [
'collection_search' => [
'path' => '/collection/search',

40
app/views/anime/add.php Normal file
View File

@ -0,0 +1,40 @@
<?php if ($auth->is_authenticated()): ?>
<main>
<h2>Add Anime to your List</h2>
<form action="<?= $action_url ?>" method="post">
<section>
<label for="search">Search for anime by name:&nbsp;&nbsp;&nbsp;&nbsp;<input type="search" id="search" /></label>
<section id="series_list" class="media-wrap">
</section>
</section>
<br />
<table class="form">
<tbody>
<tr>
<td><label for="status">Watching Status</label></td>
<td>
<select name="status" id="status">
<?php foreach($status_list as $status_key => $status_title): ?>
<option value="<?= $status_key ?>"><?= $status_title ?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<button type="submit">Save</button>
</td>
</tr>
</tbody>
</table>
</form>
</main>
<template id="show_list">
<article class="media">
<div class="name"><label><input type="radio" name="id" value="{{:slug}}" />&nbsp;<span>{{:title}}<br />{{:alternate_title}}</span></label></div>
<img src="{{:cover_image}}" alt="{{:title}}" />
</article>
</template>
<script src="<?= $urlGenerator->asset_url('js.php?g=anime_collection') ?>"></script>
<?php endif ?>

View File

@ -1,4 +1,7 @@
<main>
<?php if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $urlGenerator->url('anime/add', 'anime') ?>">Add Item</a>
<?php endif ?>
<?php if (empty($sections)): ?>
<h3>There's nothing here!</h3>
<?php else: ?>
@ -7,18 +10,35 @@
<h2><?= $escape->html($name) ?></h2>
<section class="media-wrap">
<?php foreach($items as $item): ?>
<?php if ($item['private'] && ! $auth->is_authenticated()) continue; ?>
<article class="media" id="<?= $item['anime']['slug'] ?>">
<?php if ($auth->is_authenticated()): ?>
<button class="plus_one" hidden>+1 Episode</button>
<button title="Increment episode count" class="plus_one" hidden>+1 Episode</button>
<?php endif ?>
<?= $helper->img($item['anime']['image']); ?>
<div class="name">
<a href="<?= $escape->attr($item['anime']['url']) ?>">
<a href="<?= $escape->attr($item['anime']['url']) ?>" target="_blank">
<?= $escape->html($item['anime']['title']) ?>
<?= ($item['anime']['alternate_title'] != "") ? "<br />({$item['anime']['alternate_title']})" : ""; ?>
</a>
</div>
<div class="table">
<?php if ($auth->is_authenticated()): ?>
<div class="row">
<span class="edit">
<a class="bracketed" title="Edit information about this anime" href="<?= $urlGenerator->url("anime/edit/{$item['id']}/{$item['watching_status']}", "anime") ?>">Edit</a>
</span>
</div>
<?php endif ?>
<?php if ($item['private'] || $item['rewatching']): ?>
<div class="row">
<?php foreach(['private', 'rewatching'] as $attr): ?>
<?php if($item[$attr]): ?>
<span class="item-<?= $attr ?>"><?= ucfirst($attr) ?></span>
<?php endif ?>
<?php endforeach ?>
</div>
<?php endif ?>
<div class="row">
<div class="user_rating">Rating: <?= $item['user_rating'] ?> / 10</div>
<div class="completion">Episodes:

View File

@ -1,8 +1,89 @@
<body>
<?php include 'nav.php' ?>
<?php if ($auth->is_authenticated()): ?>
<main>
<h2>Edit Anime List Item</h2>
<form action="<?= $action ?>" method="post">
<table class="form">
<thead>
<tr>
<th>
<h3><?= $escape->html($item['anime']['title']) ?></h3>
<?php if($item['anime']['alternate_title'] != ""): ?>
<h4><?= $escape->html($item['anime']['alternate_title']) ?></h4>
<?php endif ?>
</th>
<th>
<article class="media">
<?= $helper->img($item['anime']['image']); ?>
</article>
</th>
</tr>
</thead>
<tbody>
<tr>
<td><label for="private">Is Private?</label></td>
<td>
<input type="checkbox" name="private" id="private"
<?php if($item['private']): ?>checked="checked"<?php endif ?>
/>
</td>
</tr>
<tr>
<td><label for="watching_status">Watching Status</label></td>
<td>
<select name="watching_status" id="watching_status">
<?php foreach($statuses as $status_key => $status_title): ?>
<option <?php if($item['watching_status'] === $status_key): ?>selected="selected"<?php endif ?>
value="<?= $status_key ?>"><?= $status_title ?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr>
<td><label for="series_rating">Rating</label></td>
<td>
<input type="number" min="0" max="10" maxlength="2" name="user_rating" id="series_rating" value="<?= $item['user_rating'] ?>" id="series_rating" size="2" /> / 10
</td>
</tr>
<tr>
<td><label for="episodes_watched">Episodes Watched</label></td>
<td>
<input type="number" min="0" size="4" maxlength="4" value="<?= $item['episodes']['watched'] ?>" name="episodes_watched" id="episodes_watched" />
<?php if($item['episodes']['total'] > 0): ?>
/ <?= $item['episodes']['total'] ?>
<?php endif ?>
</td>
</tr>
<tr>
<td><label for="rewatching_flag">Rewatching?</label></td>
<td>
<input type="checkbox" name="rewatching" id="rewatching_flag"
<?php if($item['rewatching'] === TRUE): ?>checked="checked"<?php endif ?>
/>
</td>
</tr>
<tr>
<td><label for="rewatched">Rewatch Count</label></td>
<td>
<input type="number" min="0" id="rewatched" name="rewatched" value="<?= $item['rewatched'] ?>" />
</td>
</tr>
<tr>
<td><label for="notes">Notes</label></td>
<td>
<textarea name="notes" id="notes"><?= $escape->html($item['notes']) ?></textarea>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="hidden" value="<?= $item['anime']['slug'] ?>" name="id" />
<input type="hidden" value="true" name="edit" />
<button type="submit">Submit</button>
</td>
</tr>
</tbody>
</table>
</form>
</main>
</body>
</html>
<script src="<?= $urlGenerator->asset_url('js.php?g=edit') ?>"></script>
<?php endif ?>

View File

@ -1,4 +1,7 @@
<main>
<?php if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $urlGenerator->url('anime/add', 'anime') ?>">Add Item</a>
<?php endif ?>
<?php if (empty($sections)): ?>
<h3>There's nothing here!</h3>
<?php else: ?>
@ -7,21 +10,31 @@
<table>
<thead>
<tr>
<?php if($auth->is_authenticated()): ?>
<th>&nbsp;</th>
<?php endif ?>
<th>Title</th>
<th>Airing Status</th>
<th>Score</th>
<th>Type</th>
<th>Progress</th>
<th>Rated</th>
<th>Attributes</th>
<th>Notes</th>
<th>Genres</th>
</tr>
</thead>
<tbody>
<?php foreach($items as $item): ?>
<?php if ($item['private'] && ! $auth->is_authenticated()) continue; ?>
<tr id="a-<?= $item['id'] ?>">
<?php if ($auth->is_authenticated()): ?>
<td>
<a class="bracketed" href="<?= $urlGenerator->url("/anime/edit/{$item['id']}/{$item['watching_status']}") ?>">Edit</a>
</td>
<?php endif ?>
<td class="align_left">
<a href="<?= $item['anime']['url'] ?>">
<a href="<?= $item['anime']['url'] ?>" target="_blank">
<?= $item['anime']['title'] ?>
</a>
<?= ( ! empty($item['anime']['alternate_title'])) ? " <br /> " . $item['anime']['alternate_title'] : "" ?>
@ -29,16 +42,26 @@
<td class="align_left"><?= $item['airing']['status'] ?></td>
<td><?= $item['user_rating'] ?> / 10 </td>
<td><?= $item['anime']['type'] ?></td>
<td>Episodes: <?= $item['episodes']['watched'] ?> / <?= $item['episodes']['total'] ?></td>
<td id="<?= $item['anime']['slug'] ?>">
Episodes: <br />
<span class="completed_number"><?= $item['episodes']['watched'] ?></span>&nbsp;/&nbsp;<span class="total_number"><?= $item['episodes']['total'] ?></span>
</td>
<td><?= $item['anime']['age_rating'] ?></td>
<td><?= $item['notes'] ?></td>
<td class="align-left">
<ul>
<?php sort($item['anime']['genres']) ?>
<?php foreach($item['anime']['genres'] as $genre): ?>
<li><?= $genre ?></li>
<td>
<?php $attr_list = []; ?>
<?php foreach(['private','rewatching'] as $attr): ?>
<?php if($item[$attr]): ?>
<?php $attr_list[] = ucfirst($attr); ?>
<?php endif ?>
<?php endforeach ?>
</ul>
<?= implode(', ', $attr_list); ?>
</td>
<td>
<p><?= $escape->html($item['notes']) ?></p>
</td>
<td class="align_left">
<?php sort($item['anime']['genres']) ?>
<?= join(', ', $item['anime']['genres']) ?>
</td>
</tr>
<?php endforeach ?>
@ -47,4 +70,5 @@
<?php endforeach ?>
<?php endif ?>
</main>
<script src="<?= $urlGenerator->asset_url('js.php?g=table') ?>"></script>
<?php $group = ($auth->is_authenticated()) ? 'table_edit' : 'table' ?>
<script src="<?= $urlGenerator->asset_url("js.php?g={$group}") ?>"></script>

View File

@ -1,37 +1,43 @@
<?php if ($auth->is_authenticated()): ?>
<main>
<h2>Add Anime to your Collection</h2>
<form action="<?= $action_url ?>" method="post">
<dl>
<dt>Series</dt>
<dd><label>Search for anime name: <input type="search" id="search" /></label></dd>
<dd>
<section>
<label for="search">Search for anime by name:&nbsp;&nbsp;&nbsp;&nbsp;<input type="search" id="search" name="search" /></label>
<section id="series_list" class="media-wrap">
</section>
</dd>
<dt><label for="media_id">Media</label></dt>
<dd>
<select name="media_id" id="media_id">
<?php foreach($media_items as $id => $name): ?>
<option value="<?= $id ?>"><?= $name ?></option>
<?php endforeach ?>
</select>
</dd>
<dt><label for="notes">Notes</label></dt>
<dd><textarea id="notes" name="notes"></textarea></dd>
<dt>&nbsp;</dt>
<dd>
<button type="submit">Save</button>
</dd>
</dl>
</section>
<br />
<table class="form">
<tbody>
<tr>
<td><label for="media_id">Media</label></td>
<td>
<select name="media_id" id="media_id">
<?php foreach($media_items as $id => $name): ?>
<option value="<?= $id ?>"><?= $name ?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr>
<td><label for="notes">Notes</label></td>
<td><textarea id="notes" name="notes"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<button type="submit">Save</button>
</td>
</tr>
</tbody>
</table>
</form>
</main>
<template id="show_list">
<article class="media">
<div class="name"><label><input type="radio" name="id" value="{{:id}}" />&nbsp;<span>{{:title}}<br />{{:alternate_title}}</span></label></div>
<img src="{{:cover_image}}" alt="{{:title}}" />
<img src="{{:cover_image}}" alt="{{:title}}" />
</article>
</template>
<script src="<?= $urlGenerator->asset_url('js.php?g=anime_collection') ?>"></script>

View File

@ -1,6 +1,6 @@
<main>
<?php if ($auth->is_authenticated()): ?>
[<a href="<?= $urlGenerator->url('collection/add', 'anime') ?>">Add Item</a>]
<a class="bracketed" href="<?= $urlGenerator->url('collection/add', 'anime') ?>">Add Item</a>
<?php endif ?>
<?php if (empty($sections)): ?>
<h3>There's nothing here!</h3>
@ -19,17 +19,17 @@
</a>
</div>
<div class="table">
<?php if ($auth->is_authenticated()): ?>
<div class="row">
<span class="edit"><a class="bracketed" href="<?= $urlGenerator->url("collection/edit/{$item['hummingbird_id']}") ?>">Edit</a></span>
<?php /*<span class="delete"><a class="bracketed" href="<?= $urlGenerator->url("collection/delete/{$item['hummingbird_id']}") ?>">Delete</a></span> */ ?>
</div>
<?php endif ?>
<div class="row">
<div class="completion">Episodes: <?= $item['episode_count'] ?></div>
<div class="media_type"><?= $item['show_type'] ?></div>
<div class="age_rating"><?= $item['age_rating'] ?></div>
</div>
<?php if ($auth->is_authenticated()): ?>
<div class="row">
<span class="edit">[<a href="<?= $urlGenerator->url("collection/edit/{$item['hummingbird_id']}", "anime") ?>">Edit</a>]</span>
<span class="delete">[<a href="<?= $urlGenerator->url("collection/delete/{$item['hummingbird_id']}", "anime") ?>">Delete</a>]</span>
</div>
<?php endif ?>
</div>
</article>
<?php endforeach ?>

View File

@ -1,30 +1,49 @@
<?php if ($auth->is_authenticated()): ?>
<main>
<h2>Edit Anime Collection Item</h2>
<form action="<?= $action_url ?>" method="post">
<dl>
<h2><?= $item['title'] ?></h2>
<h3><?= $item['alternate_title'] ?></h3>
<dt><label for="media_id">Media</label></dt>
<dd>
<select name="media_id" id="media_id">
<?php foreach($media_items as $id => $name): ?>
<option <?= $item['media_id'] == $id ? 'selected="selected"' : '' ?> value="<?= $id ?>"><?= $name ?></option>
<?php endforeach ?>
</select>
</dd>
<dt><label for="notes">Notes</label></dt>
<dd><textarea id="notes" name="notes"><?= $item['notes'] ?></textarea></dd>
<dt>&nbsp;</dt>
<dd>
<?php if($action === 'Edit'): ?>
<input type="hidden" name="hummingbird_id" value="<?= $item['hummingbird_id'] ?>" />
<?php endif ?>
<button type="submit">Save</button>
</dd>
</dl>
<table class="form">
<thead>
<tr>
<th>
<h3><?= $escape->html($item['title']) ?></h3>
<?php if($item['alternate_title'] != ""): ?>
<h4><?= $escape->html($item['alternate_title']) ?></h4>
<?php endif ?>
</th>
<th>
<article class="media">
<?= $helper->img($item['cover_image']); ?>
</article>
</th>
</tr>
</thead>
<tbody>
<tr>
<td><label for="media_id">Media</label></td>
<td>
<select name="media_id" id="media_id">
<?php foreach($media_items as $id => $name): ?>
<option <?= $item['media_id'] == $id ? 'selected="selected"' : '' ?> value="<?= $id ?>"><?= $name ?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr>
<td><label for="notes">Notes</label></td>
<td><textarea id="notes" name="notes"><?= $escape->html($item['notes']) ?></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<?php if($action === 'Edit'): ?>
<input type="hidden" name="hummingbird_id" value="<?= $item['hummingbird_id'] ?>" />
<?php endif ?>
<button type="submit">Save</button>
</td>
</tr>
</tbody>
</table>
</form>
</main>
<template id="show_list">

View File

@ -1,7 +1,7 @@
<main>
<?php /* if (is_logged_in()): ?>
[<a href="<?= $urlGenerator->full_url('collection/add', 'anime') ?>">Add Item</a>]
<?php endif */ ?>
<?php if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $urlGenerator->full_url('collection/add', 'anime') ?>">Add Item</a>
<?php endif ?>
<?php if (empty($sections)): ?>
<h3>There's nothing here!</h3>
<?php else: ?>
@ -10,41 +10,37 @@
<table>
<thead>
<tr>
<?php if($auth->is_authenticated()): ?>
<th>Actions</th>
<?php endif ?>
<th>Title</th>
<?php /*<th>Alternate Title</th>*/ ?>
<th>Episode Count</th>
<th>Episode Length</th>
<th>Show Type</th>
<th>Age Rating</th>
<th>Notes</th>
<?php /*if (is_logged_in()): ?>
<th>&nbsp;</th>
<?php endif*/ ?>
</tr>
</thead>
<tbody>
<?php foreach($items as $item): ?>
<tr>
<?php if($auth->is_authenticated()): ?>
<td>
<a class="bracketed" href="<?= $urlGenerator->full_url("collection/edit/{$item['hummingbird_id']}") ?>">Edit</a>
<?php /*<a class="bracketed" href="<?= $urlGenerator->full_url("collection/delete/{$item['hummingbird_id']}") ?>">Delete</a>*/ ?>
</td>
<?php endif ?>
<td class="align_left">
<a href="https://hummingbird.me/anime/<?= $item['slug'] ?>">
<?= $item['title'] ?>
</a>
<?= ( ! empty($item['alternate_title'])) ? " &middot; " . $item['alternate_title'] : "" ?>
</td>
<?php /*<td class="align_left">
<a href="https://hummingbird.me/anime/<?= $item['slug'] ?>">
<?= $item['title'] ?>
</a>
</td>
<td class="align_left"><?= $item['alternate_title'] ?></td>*/ ?>
<td><?= $item['episode_count'] ?></td>
<td><?= $item['episode_length'] ?></td>
<td><?= $item['show_type'] ?></td>
<td><?= $item['age_rating'] ?></td>
<td class="align_left"><?= $item['notes'] ?></td>
<?php /* if (is_logged_in()): ?>
<td>[<a href="<?= $urlGenerator->full_url("collection/edit/{$item['hummingbird_id']}", "anime") ?>">Edit</a>]</td>
<?php endif */ ?>
</tr>
<?php endforeach ?>
</tbody>

View File

@ -11,40 +11,48 @@
</script>
</head>
<body class="<?= $escape->attr($url_type) ?> list">
<h1 class="flex flex-align-end flex-wrap">
<span class="flex-no-wrap grow-1">
<?php if(strpos($route_path, 'collection') === FALSE): ?>
<a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> List
</a>
<?php if($config->get("show_{$url_type}_collection")): ?>
[<a href="<?= $urlGenerator->url('collection/view') ?>"><?= ucfirst($url_type) ?> Collection</a>]
<header>
<h1 class="flex flex-align-end flex-wrap">
<span class="flex-no-wrap grow-1">
<?php if(strpos($route_path, 'collection') === FALSE): ?>
<a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> List
</a>
<?php if($config->get("show_{$url_type}_collection")): ?>
[<a href="<?= $urlGenerator->url('collection/view') ?>"><?= ucfirst($url_type) ?> Collection</a>]
<?php endif ?>
[<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>]
<?php else: ?>
<a href="<?= $urlGenerator->url('collection/view') ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> Collection
</a>
[<a href="<?= $urlGenerator->default_url('anime') ?>">Anime List</a>]
[<a href="<?= $urlGenerator->default_url('manga') ?>">Manga List</a>]
<?php endif ?>
[<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>]
<?php else: ?>
<a href="<?= $urlGenerator->url('collection/view') ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> Collection
</a>
[<a href="<?= $urlGenerator->default_url('anime') ?>">Anime List</a>]
[<a href="<?= $urlGenerator->default_url('manga') ?>">Manga List</a>]
</span>
<span class="flex-no-wrap small-font">
<?php if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $urlGenerator->url("/{$url_type}/logout", $url_type) ?>">Logout</a>
<?php else: ?>
[<a href="<?= $urlGenerator->url("/{$url_type}/login", $url_type) ?>"><?= $config->get('whose_list') ?>'s Login</a>]
<?php endif ?>
</span>
</h1>
<nav>
<?php if ($container->get('anime-client')->is_view_page()): ?>
<?= $helper->menu($menu_name) ?>
<br />
<ul>
<li class="<?= AnimeClient::is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li>
<li class="<?= AnimeClient::is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
</ul>
<?php endif ?>
</span>
<span class="flex-no-wrap small-font">
<?php if ($auth->is_authenticated()): ?>
[<a href="<?= $urlGenerator->url("/{$url_type}/logout", $url_type) ?>">Logout</a>]
<?php else: ?>
[<a href="<?= $urlGenerator->url("/{$url_type}/login", $url_type) ?>"><?= $config->get('whose_list') ?>'s Login</a>]
<?php endif ?>
</span>
</h1>
<nav>
<?= $helper->menu($menu_name) ?>
<?php if ($container->get('anime_client')->is_view_page()): ?>
<br />
<ul>
<li class="<?= AnimeClient::is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li>
<li class="<?= AnimeClient::is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
</ul>
<?php endif ?>
</nav>
<br />
</nav>
</header>
<?php if(isset($message) && is_array($message)): ?>
<div class="message <?= $escape->attr($message['message_type']) ?>">
<span class="icon"></span>
<?= $escape->html($message['message']) ?>
<span class="close" onclick="this.parentElement.style.display='none'">x</span>
</div>
<?php endif ?>

View File

@ -1,17 +1,16 @@
<main>
<h2><?= $config->get('whose_list'); ?>'s Login</h2>
<?= $message ?>
<aside>
<form method="post" action="<?= $urlGenerator->full_url($urlGenerator->path(), $url_type) ?>">
<dl>
<?php /*<dt><label for="username">Username: </label></dt>
<dd><input type="text" id="username" name="username" required="required" /></dd>*/ ?>
<dt><label for="password">Password: </label></dt>
<dd><input type="password" id="password" name="password" required="required" /></dd>
<dt>&nbsp;</dt>
<dd><button type="submit">Login</button></dd>
</dl>
</form>
</aside>
<form method="post" action="<?= $urlGenerator->full_url($urlGenerator->path(), $url_type) ?>">
<table class="form invisible">
<tr>
<td><label for="password">Password: </label></td>
<td><input type="password" id="password" name="password" required="required" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><button type="submit">Login</button></td>
</tr>
</table>
</form>
</main>

View File

@ -1,4 +1,4 @@
<div class="message <?= $escape->attr($stat_class) ?>">
<div class="message <?= $escape->attr($message_type) ?>">
<span class="icon"></span>
<?= $escape->html($message) ?>
<span class="close" onclick="this.parentElement.style.display='none'">x</span>

View File

@ -6,6 +6,11 @@ body {
margin: 0.5em;
}
a:hover,
a:active {
color: #7d12db;
}
table {
width: 85%;
margin: 0 auto;
@ -15,6 +20,63 @@ tbody > tr:nth-child(odd) {
background: #ddd;
}
input[type=number] {
width: 4em;
}
.form {
width: 100%;
}
.form tr > td:nth-child(odd) {
text-align: right;
min-width: 25px;
max-width: 30%;
}
.form tr > td:nth-child(even) {
text-align: left;
min-width: 70%;
}
.form thead th,
.form thead tr {
background: inherit;
border: 0;
}
.form.invisible tr:nth-child(odd) {
background: inherit;
}
.form.invisible tr,
.form.invisible td,
.form.invisible th {
border: 0;
}
.bracketed,
h1 a {
text-shadow: 1px 1px 1px #000;
}
.bracketed:before {
content: '[\00a0';
}
.bracketed:after {
content: '\00a0]';
}
.bracketed {
color: #12db18;
}
.bracketed:hover,
.bracketed:active {
color: #db7d12;
}
.grow-1 {
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
@ -143,11 +205,15 @@ button {
.media:hover > .media_metadata > div,
.media:hover > .medium_metadata > div,
.media:hover > .table .row {
-webkit-transition: .25s ease;
transition: .25s ease;
background: rgba(0,0,0,0.75);
}
.media:hover > button[hidden],
.media:hover > .edit_buttons[hidden] {
-webkit-transition: .25s ease;
transition: .25s ease;
display: block;
}
@ -259,6 +325,11 @@ button {
padding: 0 inherit;
}
.anime .row > span,
.manga .row > span {
text-align: left;
}
.anime .row > div,
.manga .row > div {
font-size: 0.8em;
@ -272,7 +343,9 @@ button {
.anime .media > button.plus_one {
position: absolute;
top: 138px;
top: calc(50% - 21.5px);
left: 44px;
left: calc(50% - 66.5px);
}

View File

@ -1,14 +1,22 @@
:root {
--link-shadow: 1px 1px 1px #000;
--shadow: 1px 2px 1px rgba(0, 0, 0, 0.85);
--title-overlay: rgba(0, 0, 0, 0.45);
--text-color: #ffffff;
--normal-padding: 0.25em;
--link-hover-color: #7d12db;
--edit-link-hover-color: #db7d12;
--edit-link-color: #12db18;
}
template {display:none}
body {margin: 0.5em;}
a:hover, a:active {
color: var(--link-hover-color)
}
table {
width:85%;
margin: 0 auto;
@ -18,6 +26,45 @@ tbody > tr:nth-child(odd) {
background: #ddd;
}
input[type=number] {
width: 4em;
}
.form { width:100%; }
.form tr > td:nth-child(odd) {
text-align:right;
min-width:25px;
max-width:30%;
}
.form tr > td:nth-child(even) {
text-align:left;
min-width:70%;
}
.form thead th, .form thead tr {
background: inherit;
border:0;
}
.form.invisible tr:nth-child(odd) {
background: inherit;
}
.form.invisible tr, .form.invisible td, .form.invisible th {
border:0;
}
.bracketed, h1 a {
text-shadow: var(--link-shadow);
}
.bracketed:before {content: '[\00a0'}
.bracketed:after {content: '\00a0]'}
.bracketed {
color: var(--edit-link-color);
}
.bracketed:hover, .bracketed:active {
color: var(--edit-link-hover-color)
}
.grow-1 {flex-grow: 1}
.flex-wrap {flex-wrap: wrap}
.flex-no-wrap {flex-wrap: nowrap}
@ -96,12 +143,14 @@ button {
.media:hover > .medium_metadata > div,
.media:hover > .table .row
{
transition: .25s ease;
background:rgba(0,0,0,0.75);
}
.media:hover > button[hidden],
.media:hover > .edit_buttons[hidden]
{
transition: .25s ease;
display:block;
}
@ -203,6 +252,10 @@ button {
padding:0 inherit;
}
.anime .row > span, .manga .row > span {
text-align:left;
}
.anime .row > div, .manga .row > div {
font-size:0.8em;
display:flex-item;
@ -213,8 +266,10 @@ button {
.anime .media > button.plus_one {
position:absolute;
top: calc(50% - (43px / 2));
left: calc(50% - (97px / 2 + 18));
top: 138px;
top: calc(50% - 21.5px);
left: 44px;
left: calc(50% - 66.5px);
}
/* -----------------------------------------------------------------------------

View File

@ -14,8 +14,8 @@ audio:not([controls]) {
details {
display: block; }
input[type="number"] {
width: auto; }
/*input[type="number"] {
width: auto; }*/
input[type="search"] {
-webkit-appearance: textfield; }
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration {
@ -77,7 +77,7 @@ audio, canvas, iframe, img, svg, video {
vertical-align: middle; }
button, input, select, textarea {
background-color: transparent;
/*background-color: transparent;*/
border: .1rem solid #ccc;
color: inherit;
font-family: inherit;

View File

@ -8,12 +8,12 @@
if (CONTROLLER !== "anime") return;
// Action to increment episode count
$(".media button.plus_one").on("click", function(e) {
$(".plus_one").on("click", function(e) {
e.stopPropagation();
var self = this;
var this_sel = $(this);
var parent_sel = $(this).closest("article");
var parent_sel = $(this).closest("article, td");
var watched_count = parseInt(parent_sel.find('.completed_number').text(), 10);
var total_count = parseInt(parent_sel.find('.total_number').text(), 10);
@ -21,7 +21,7 @@
// Setup the update data
var data = {
id: this_sel.parent('article').attr('id'),
id: this_sel.parent('article, td').attr('id'),
increment_episodes: true
};
@ -49,7 +49,7 @@
}).done(function(res) {
if (res.status === 'completed')
{
$(self).closest('article').hide();
$(self).closest('article, tr').hide();
}
add_message('success', "Sucessfully updated " + title);

View File

@ -16,6 +16,18 @@ namespace Aviat\AnimeClient;
class AnimeClient {
use \Aviat\Ion\Di\ContainerAware;
const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
private static $form_pages = [
'edit',
'add',
'update',
'update_form',
'login',
'logout'
];
/**
* HTML selection helper function
*
@ -48,14 +60,24 @@ class AnimeClient {
public function is_view_page()
{
$url = $this->container->get('request')
->server->get('REQUEST_URI');
$blacklist = ['edit', 'add', 'update', 'login', 'logout'];
->url->get();
$page_segments = explode("/", $url);
$intersect = array_intersect($page_segments, $blacklist);
$intersect = array_intersect($page_segments, self::$form_pages);
return empty($intersect);
}
/**
* Determine whether the page is a page with a form, and
* not suitable for redirection
*
* @return boolean
*/
public function is_form_page()
{
return ! $this->is_view_page();
}
}
// End of anime_client.php

View File

@ -14,6 +14,7 @@
namespace Aviat\AnimeClient\Auth;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\AnimeClient\AnimeClient;
use Aviat\AnimeClient\Model\API;
/**
@ -46,7 +47,7 @@ class HummingbirdAuth {
{
$this->setContainer($container);
$this->segment = $container->get('session')
->getSegment(__NAMESPACE__);
->getSegment(AnimeClient::SESSION_SEGMENT);
$this->model = $container->get('api-model');
}

View File

@ -16,6 +16,7 @@ use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\View\HttpView;
use Aviat\Ion\View\HtmlView;
use Aviat\Ion\View\JsonView;
use Aviat\AnimeClient\AnimeClient;
/**
* Controller base, defines output methods
@ -57,6 +58,12 @@ class Controller {
*/
protected $urlGenerator;
/**
* Session segment
* @var [type]
*/
protected $session;
/**
* Common data to be sent to views
* @var array
@ -83,6 +90,15 @@ class Controller {
$this->base_data['auth'] = $container->get('auth');
$this->base_data['config'] = $this->config;
$this->urlGenerator = $urlGenerator;
$session = $container->get('session');
$this->session = $session->getSegment(AnimeClient::SESSION_SEGMENT);
// Set a 'previous' flash value for better redirects
$this->session->setFlash('previous', $this->request->server->get('HTTP_REFERER'));
// Set a message box if available
$this->base_data['message'] = $this->session->getFlash('message');
}
/**
@ -94,6 +110,65 @@ class Controller {
$this->redirect($this->urlGenerator->default_url($default_type), 303);
}
/**
* Redirect to the previous page
*
* @return void
*/
public function redirect_to_previous()
{
$previous = $this->session->getFlash('previous');
$this->redirect($previous, 303);
}
/**
* Set the current url in the session as the target of a future redirect
*
* @param string|null $url
* @return void
*/
public function set_session_redirect($url=NULL)
{
$anime_client = $this->container->get('anime-client');
$double_form_page = $this->request->server->get('HTTP_REFERER') == $this->request->url->get();
// Don't attempt to set the redirect url if
// the page is one of the form type pages,
// and the previous page is also a form type page_segments
if ($double_form_page)
{
return;
}
if (is_null($url))
{
$url = ($anime_client->is_view_page())
? $this->request->url->get()
: $this->request->server->get('HTTP_REFERER');
}
$this->session->set('redirect_url', $url);
}
/**
* Redirect to the url previously set in the session
*
* @return void
*/
public function session_redirect()
{
$target = $this->session->get('redirect_url');
if (empty($target))
{
$this->not_found();
}
else
{
$this->redirect($target, 303);
$this->session->set('redirect_url', NULL);
}
}
/**
* Get a class member
*
@ -156,6 +231,12 @@ class Controller {
protected function render_full_page($view, $template, array $data)
{
$view->appendOutput($this->load_partial($view, 'header', $data));
if (array_key_exists('message', $data) && is_array($data['message']))
{
$view->appendOutput($this->load_partial($view, 'message', $data['message']));
}
$view->appendOutput($this->load_partial($view, $template, $data));
$view->appendOutput($this->load_partial($view, 'footer', $data));
}
@ -178,6 +259,9 @@ class Controller {
$message = $this->show_message($view, 'error', $status);
}
// Set the redirect url
$this->set_session_redirect();
$this->outputHTML('login', [
'title' => 'Api login',
'message' => $message
@ -194,9 +278,7 @@ class Controller {
$auth = $this->container->get('auth');
if ($auth->authenticate($this->request->post->get('password')))
{
$this->response->redirect->afterPost(
$this->urlGenerator->full_url('', $this->base_data['url_type'])
);
return $this->session_redirect();
}
$this->login("Invalid username or password.");
@ -227,6 +309,22 @@ class Controller {
]);
}
/**
* Set a session flash variable to display a message on
* next page load
*
* @param string $message
* @param string $type
* @return void
*/
public function set_flash_message($message, $type="info")
{
$this->session->setFlash('message', [
'message_type' => $type,
'message' => $message
]);
}
/**
* Add a message box to the page
*
@ -239,7 +337,7 @@ class Controller {
protected function show_message($view, $type, $message)
{
return $this->load_partial($view, 'message', [
'stat_class' => $type,
'message_type' => $type,
'message' => $message
]);
}

View File

@ -17,12 +17,15 @@ use Aviat\Ion\Di\ContainerInterface;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\AnimeClient\Hummingbird\Enum\AnimeWatchingStatus;
use Aviat\AnimeClient\Model\Anime as AnimeModel;
use Aviat\AnimeClient\Hummingbird\Transformer\AnimeListTransformer;
/**
* Controller for Anime-related pages
*/
class Anime extends BaseController {
use \Aviat\Ion\StringWrapper;
/**
* The anime list model
* @var object $model
@ -45,9 +48,9 @@ class Anime extends BaseController {
parent::__construct($container);
$this->model = $container->get('anime-model');
$this->base_data = array_merge($this->base_data, [
'menu_name' => 'anime_list',
'message' => '',
'url_type' => 'anime',
'other_type' => 'manga',
'config' => $this->config,
@ -106,6 +109,95 @@ class Anime extends BaseController {
]);
}
/**
* Form to add an anime
*
* @return void
*/
public function add_form()
{
$raw_status_list = AnimeWatchingStatus::getConstList();
$statuses = [];
foreach($raw_status_list as $status_item)
{
$statuses[$status_item] = (string) $this->string($status_item)
->underscored()
->humanize()
->titleize();
}
$this->set_session_redirect();
$this->outputHTML('anime/add', [
'title' => $this->config->get('whose_list') .
"'s Anime List &middot; Add",
'action_url' => $this->urlGenerator->url('anime/add'),
'status_list' => $statuses
]);
}
/**
* Add an anime to the list
*
* @return void
*/
public function add()
{
$data = $this->request->post->get();
if ( ! array_key_exists('id', $data))
{
$this->redirect("anime/add", 303);
}
$result = $this->model->update($data);
if ($result['statusCode'] == 201)
{
$this->set_flash_message('Added new anime to list', 'success');
}
else
{
$this->set_flash_message('Failed to add new anime to list', 'error');
}
$this->session_redirect();
}
/**
* Form to edit details about a series
*
* @param int $id
* @param string $status
* @return void
*/
public function edit($id, $status="all")
{
$item = $this->model->get_library_anime($id, $status);
$raw_status_list = AnimeWatchingStatus::getConstList();
$statuses = [];
foreach($raw_status_list as $status_item)
{
$statuses[$status_item] = (string) $this->string($status_item)
->underscored()
->humanize()
->titleize();
}
$this->set_session_redirect($this->request->server->get('HTTP_REFERRER'));
$this->outputHTML('anime/edit', [
'title' => $this->config->get('whose_list') .
"'s Anime List &middot; Edit",
'item' => $item,
'statuses' => $statuses,
'action' => $this->container->get('url-generator')
->url('/anime/update_form'),
]);
}
/**
* Search for anime
*
@ -117,6 +209,39 @@ class Anime extends BaseController {
$this->outputJSON($this->model->search($query));
}
/**
* Update an anime item via a form submission
*
* @return void
*/
public function form_update()
{
$post_data = $this->request->post->get();
// Do some minor data manipulation for
// large form-based updates
$transformer = new AnimeListTransformer();
$post_data = $transformer->untransform($post_data);
$full_result = $this->model->update($post_data);
$result = $result['body'];
if (array_key_exists('anime', $result))
{
$title = ( ! empty($result['anime']['alternate_title']))
? "{$result['anime']['title']} ({$result['anime']['alternate_title']})"
: "{$result['anime']['title']}";
$this->set_flash_message("Successfully updated {$title}.", 'success');
}
else
{
$this->set_flash_message('Failed to update anime.', 'error');
}
$this->session_redirect();
}
/**
* Update an anime item
*
@ -124,7 +249,11 @@ class Anime extends BaseController {
*/
public function update()
{
$this->outputJSON($this->model->update($this->request->post->get()));
$this->outputJSON(
$this->model->update(
$this->request->post->get()
)
);
}
}
// End of AnimeController.php

View File

@ -63,7 +63,6 @@ class Collection extends BaseController {
$this->anime_collection_model = $container->get('anime-collection-model');
$this->base_data = array_merge($this->base_data, [
'menu_name' => 'collection',
'message' => '',
'url_type' => 'anime',
'other_type' => 'manga',
'config' => $this->config,

View File

@ -90,6 +90,23 @@ class Dispatcher extends RoutingBase {
'controller' => '[a-z_]+'
]);
$this->output_routes[] = $this->router->addPost('update_form', '/{controller}/update_form')
->setValues([
'controller' => $default_controller,
'action' => 'form_update'
])->setTokens([
'controller' => '[a-z_]+'
]);
$this->output_routes[] = $this->router->addGet('edit', '/{controller}/edit/{id}/{status}')
->setValues([
'controller' => $default_controller,
'action' => 'edit'
])->setTokens([
'id' => '[0-9a-z_]+',
'status' => '[a-z\-]+',
]);
$this->output_routes[] = $this->router->addGet('list', '/{controller}/{type}{/view}')
->setValues([
'controller' => $default_controller,
@ -273,7 +290,7 @@ class Dispatcher extends RoutingBase {
return [];
}
$applied_routes = array_merge($this->routes[$route_type], $this->routes['common']);
$applied_routes = $this->routes[$route_type];
// Add routes
foreach ($applied_routes as $name => &$route)

View File

@ -82,9 +82,44 @@ class AnimeListTransformer extends AbstractTransformer {
'id' => $item['id'],
'watching_status' => $item['status'],
'notes' => $item['notes'],
'rewatching' => (bool)$item['rewatching'],
'rewatching' => (bool) $item['rewatching'],
'rewatched' => $item['rewatched_times'],
'user_rating' => $rating,
'private' => (bool) $item['private'],
];
}
/**
* Convert transformed data to
* api response format
*
* @param array $item Transformed library item
* @return array API library item
*/
public function untransform($item)
{
// Messy mapping of boolean values to their API string equivalents
$privacy = 'public';
if (array_key_exists('private', $item) && $item['private'] == TRUE)
{
$privacy = 'private';
}
$rewatching = 'false';
if (array_key_exists('rewatching', $item) && $item['rewatching'] == TRUE)
{
$rewatching = 'true';
}
return [
'id' => $item['id'],
'status' => $item['watching_status'],
'sane_rating_update' => $item['user_rating'] / 2,
'rewatching' => $rewatching,
'rewatched_times' => $item['rewatched'],
'notes' => $item['notes'],
'episodes_watched' => $item['episodes_watched'],
'privacy' => $privacy
];
}

View File

@ -55,18 +55,24 @@ class Anime extends API {
public function update($data)
{
$auth = $this->container->get('auth');
if ( ! $auth->is_authenticated())
/*if ( ! $auth->is_authenticated() || ! array_key_exists('id', $data))
{
return FALSE;
}
}*/
$id = $data['id'];
$data['auth_token'] = $auth->get_auth_token();
$response = $this->client->post("libraries/{$data['id']}", [
$response = $this->client->post("libraries/{$id}", [
'form_params' => $data
]);
return json_decode($response->getBody(), TRUE);
$output = [
'statusCode' => $response->getStatusCode(),
'body' => json_decode($response->getBody(), TRUE)
];
return $output;
}
/**
@ -108,7 +114,7 @@ class Anime extends API {
*/
public function get_list($status)
{
$data = $this->_get_list_From_api($status);
$data = $this->_get_list_from_api($status);
$this->sort_by_name($data);
$output = [];
@ -117,6 +123,25 @@ class Anime extends API {
return $output;
}
/**
* Get the data for the specified library entry
*
* @param string $id
* @param string $status
* @return array
*/
public function get_library_anime($id, $status)
{
$data = $this->_get_list_from_api($status);
$index_array = array_column($data, 'id');
$key = array_search($id, $index_array);
return $key !== FALSE
? $data[$key]
: [];
}
/**
* Get information about an anime from its id
*
@ -182,6 +207,12 @@ class Anime extends API {
}
$username = $this->config->get('hummingbird_username');
$auth = $this->container->get('auth');
if ($auth->is_authenticated())
{
$config['query']['auth_token'] = $auth->get_auth_token();
}
$response = $this->get("users/{$username}/library", $config);
$output = $this->_check_cache($status, $response);

View File

@ -75,7 +75,7 @@ class RoutingBase {
public function path()
{
$request = $this->container->get('request');
$path = $request->server->get('REQUEST_URI');
$path = $request->url->get(PHP_URL_PATH);
$cleaned_path = $this->string($path)
->trim()
->trimRight('/')

View File

View File

@ -44,6 +44,14 @@ abstract class View {
*/
protected $output;
/**
* If the view has sent output via
* __toString or send method
*
* @var boolean
*/
protected $hasRendered = false;
/**
* Constructor
*
@ -60,7 +68,21 @@ abstract class View {
*/
public function __destruct()
{
$this->output();
if ( ! $this->hasRendered)
{
$this->send();
}
}
/**
* Return rendered output
*
* @return string
*/
public function __toString()
{
$this->hasRendered = true;
return $this->getOutput();
}
/**
@ -99,6 +121,15 @@ abstract class View {
return $this->string($this->output)->__toString();
}
/**
* Send output to client
*/
public function send()
{
$this->hasRendered = true;
$this->output();
}
/**
* Send the appropriate response
*

View File

@ -33,6 +33,7 @@ class RoutingBaseTest extends AnimeClient_TestCase {
*/
public function testSegments($request_uri, $path, $segments, $last_segment)
{
$this->markTestSkipped();
$this->setSuperGlobals([
'_SERVER' => [
'REQUEST_URI' => $request_uri

File diff suppressed because one or more lines are too long