Skip to content

Commit

Permalink
Add full edit form to anime list
Browse files Browse the repository at this point in the history
  • Loading branch information
timw4mail committed Jan 4, 2016
1 parent 1251486 commit 6e4e8ed
Show file tree
Hide file tree
Showing 31 changed files with 875 additions and 178 deletions.
2 changes: 1 addition & 1 deletion app/bootstrap.php
Expand Up @@ -74,7 +74,7 @@
// 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));
Expand Down
8 changes: 8 additions & 0 deletions app/config/minify_js_groups.php
Expand Up @@ -36,6 +36,14 @@
'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',
Expand Down
24 changes: 14 additions & 10 deletions app/config/routes.php
Expand Up @@ -18,18 +18,22 @@
'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' => [

],
// Routes on anime collection controller
'collection' => [
'collection_search' => [
'path' => '/collection/search',
Expand Down
40 changes: 40 additions & 0 deletions app/views/anime/add.php
@@ -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 ?>
24 changes: 22 additions & 2 deletions app/views/anime/cover.php
@@ -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: ?>
Expand All @@ -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:
Expand Down
89 changes: 85 additions & 4 deletions app/views/anime/edit.php
@@ -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 ?>
44 changes: 34 additions & 10 deletions app/views/anime/list.php
@@ -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: ?>
Expand All @@ -7,38 +10,58 @@
<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'] : "" ?>
</td>
<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 ?>
Expand All @@ -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>
54 changes: 30 additions & 24 deletions app/views/collection/add.php
@@ -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>
Expand Down

0 comments on commit 6e4e8ed

Please sign in to comment.