Fix collection functionality

This commit is contained in:
Timothy Warren 2015-12-08 14:52:59 -05:00
parent 52397bbd61
commit f386766841
12 changed files with 47 additions and 31 deletions

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* Bootstrap / Dependency Injection * Bootstrap / Dependency Injection
*/ */
namespace Aviat\AnimeClient; namespace Aviat\AnimeClient;
use Aura\Html\HelperLocatorFactory; use Aura\Html\HelperLocatorFactory;
@ -69,7 +69,7 @@ return function(array $config_array = []) {
$container->set('url-generator', new UrlGenerator($container)); $container->set('url-generator', new UrlGenerator($container));
$container->set('auth', new HummingbirdAuth($container)); $container->set('auth', new HummingbirdAuth($container));
// Miscellaneous helper methods // Miscellaneous helper methods
$anime_client = new AnimeClient(); $anime_client = new AnimeClient();
$anime_client->setContainer($container); $anime_client->setContainer($container);

View File

@ -30,7 +30,7 @@ $config = [
'show_anime_collection' => TRUE, 'show_anime_collection' => TRUE,
// do you wish to show the manga collection? // do you wish to show the manga collection?
'show_manga_collection' => TRUE, 'show_manga_collection' => FALSE,
// path to public directory on the server // path to public directory on the server
'asset_dir' => realpath(__DIR__ . '/../../public'), 'asset_dir' => realpath(__DIR__ . '/../../public'),

View File

@ -20,7 +20,6 @@ return [
'on_hold' => '/on_hold', 'on_hold' => '/on_hold',
'dropped' => '/dropped', 'dropped' => '/dropped',
'completed' => '/completed', 'completed' => '/completed',
//'collection' => '/collection/view',
'all' => '/all' 'all' => '/all'
] ]
], ],
@ -34,12 +33,5 @@ return [
'completed' => '/completed', 'completed' => '/completed',
'all' => '/all' 'all' => '/all'
] ]
],
'collection' => [
'route_prefix' => '/collection',
'items' => [
'anime' => '/anime',
'manga' => '/manga',
]
] ]
]; ];

View File

@ -36,11 +36,17 @@ return [
'anime_edit.js', 'anime_edit.js',
'manga_edit.js' 'manga_edit.js'
], ],
'collection' => [ 'anime_collection' => [
'lib/jquery.min.js', 'lib/jquery.min.js',
'lib/jquery.throttle-debounce.js', 'lib/jquery.throttle-debounce.js',
'lib/jsrender.js', 'lib/jsrender.js',
'collection.js' 'anime_collection.js'
],
'manga_collection' => [
'lib/jquery.min.js',
'lib/jquery.throttle-debounce.js',
'lib/jsrender.js',
'manga_collection.js'
] ]
]; ];

View File

@ -29,8 +29,12 @@ return [
] ]
], ],
], ],
// Routes on collection controller // Routes on anime collection controller
'collection' => [ 'collection' => [
'collection_search' => [
'path' => '/collection/search',
'action' => 'search'
],
'collection_add_form' => [ 'collection_add_form' => [
'path' => '/collection/add', 'path' => '/collection/add',
'action' => 'form', 'action' => 'form',

View File

@ -1,4 +1,4 @@
<?php if (is_logged_in()): ?> <?php if ($auth->is_authenticated()): ?>
<main> <main>
<form action="<?= $action_url ?>" method="post"> <form action="<?= $action_url ?>" method="post">
<dl> <dl>
@ -34,5 +34,5 @@
<img src="{{:cover_image}}" alt="{{:title}}" /> <img src="{{:cover_image}}" alt="{{:title}}" />
</article> </article>
</template> </template>
<script src="<?= $config->asset_url('js.php?g=collection&debug=1') ?>"></script> <script src="<?= $urlGenerator->asset_url('js.php?g=anime_collection') ?>"></script>
<?php endif ?> <?php endif ?>

View File

@ -1,7 +1,7 @@
<main> <main>
<?php /*if (is_logged_in()): ?> <?php if ($auth->is_authenticated()): ?>
[<a href="<?= $config->full_url('collection/add', 'anime') ?>">Add Item</a>] [<a href="<?= $urlGenerator->url('collection/add', 'anime') ?>">Add Item</a>]
<?php endif*/ ?> <?php endif ?>
<?php if (empty($sections)): ?> <?php if (empty($sections)): ?>
<h3>There's nothing here!</h3> <h3>There's nothing here!</h3>
<?php else: ?> <?php else: ?>
@ -27,9 +27,9 @@
</div> </div>
</article> </article>
<?php /*if (is_logged_in()): ?> <?php if ($auth->is_authenticated()): ?>
<span>[<a href="<?= $urlGenerator->full_url("collection/edit/{$item['hummingbird_id']}", "anime") ?>">Edit</a>]</span> <span>[<a href="<?= $urlGenerator->url("collection/edit/{$item['hummingbird_id']}", "anime") ?>">Edit</a>]</span>
<?php endif*/ ?> <?php endif ?>
<?php endforeach ?> <?php endforeach ?>
</section> </section>
</section> </section>

View File

@ -1,4 +1,4 @@
<?php if (is_logged_in()): ?> <?php if ($auth->is_authenticated()): ?>
<main> <main>
<form action="<?= $action_url ?>" method="post"> <form action="<?= $action_url ?>" method="post">
<dl> <dl>
@ -33,5 +33,5 @@
<img src="{{:cover_image}}" alt="{{:title}}" /> <img src="{{:cover_image}}" alt="{{:title}}" />
</article> </article>
</template> </template>
<script src="<?= $config->asset_url('js.php?g=collection&debug=1') ?>"></script> <script src="<?= $urlGenerator->asset_url('js.php?g=anime_collection') ?>"></script>
<?php endif ?> <?php endif ?>

View File

@ -13,9 +13,21 @@
<body class="<?= $escape->attr($url_type) ?> list"> <body class="<?= $escape->attr($url_type) ?> list">
<h1 class="flex flex-align-end flex-wrap"> <h1 class="flex flex-align-end flex-wrap">
<span class="flex-no-wrap grow-1"> <span class="flex-no-wrap grow-1">
<a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>"> <?php if(strpos($route_path, 'collection') === FALSE): ?>
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> <?= (strpos($route_path, 'collection') !== FALSE) ? 'Collection' : 'List' ?> <a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>">
</a> [<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>] <?= $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 ?>
</span> </span>
<span class="flex-no-wrap small-font"> <span class="flex-no-wrap small-font">
<?php if ($auth->is_authenticated()): ?> <?php if ($auth->is_authenticated()): ?>

View File

@ -2,6 +2,7 @@
$animeclient_file_patterns = [ $animeclient_file_patterns = [
'app/config/*.php', 'app/config/*.php',
'app/booststrap.php',
'src/functions.php', 'src/functions.php',
'src/Aviat/AnimeClient/*.php' 'src/Aviat/AnimeClient/*.php'
]; ];

View File

@ -2,10 +2,10 @@
function search(query, callback) function search(query, callback)
{ {
$.get(BASE_URL + 'search', {'query':query}, callback); $.get(BASE_URL + 'collection/search', {'query':query}, callback);
} }
$("#search").on('keypress', $.throttle(250, function(e) { $("#search").on('keypress', $.throttle(750, function(e) {
var query = encodeURIComponent($(this).val()); var query = encodeURIComponent($(this).val());
search(query, function(res) { search(query, function(res) {
var template = $.templates("#show_list"); var template = $.templates("#show_list");

View File

@ -53,6 +53,7 @@ class Collection extends BaseController {
parent::__construct($container); parent::__construct($container);
$this->urlGenerator = $container->get('url-generator'); $this->urlGenerator = $container->get('url-generator');
$this->anime_model = new AnimeModel($container);
$this->anime_collection_model = new AnimeCollectionModel($container); $this->anime_collection_model = new AnimeCollectionModel($container);
$this->base_data = array_merge($this->base_data, [ $this->base_data = array_merge($this->base_data, [
'menu_name' => 'collection', 'menu_name' => 'collection',
@ -71,7 +72,7 @@ class Collection extends BaseController {
public function search() public function search()
{ {
$query = $this->request->query->get('query'); $query = $this->request->query->get('query');
$this->outputJSON($this->model->search($query)); $this->outputJSON($this->anime_model->search($query));
} }
/** /**
@ -109,7 +110,7 @@ class Collection extends BaseController {
$this->outputHTML('collection/' . strtolower($action), [ $this->outputHTML('collection/' . strtolower($action), [
'action' => $action, 'action' => $action,
'action_url' => $this->urlGenerator->full_url("collection/" . strtolower($action)), 'action_url' => $this->urlGenerator->full_url("collection/" . strtolower($action)),
'title' => $this->config->whose_list . " Anime Collection &middot; {$action}", 'title' => $this->config->get('whose_list') . " Anime Collection &middot; {$action}",
'media_items' => $this->anime_collection_model->get_media_type_list(), 'media_items' => $this->anime_collection_model->get_media_type_list(),
'item' => ($action === "Edit") ? $this->anime_collection_model->get($id) : [] 'item' => ($action === "Edit") ? $this->anime_collection_model->get($id) : []
]); ]);