Refactor a bit to prepare for manga collection

This commit is contained in:
Timothy Warren 2017-09-14 15:32:53 -04:00
parent 07152cc3be
commit a8e2049d08
8 changed files with 77 additions and 24 deletions

View File

@ -16,6 +16,7 @@
use const Aviat\AnimeClient\{
DEFAULT_CONTROLLER_NAMESPACE,
DEFAULT_CONTROLLER_METHOD,
DEFAULT_CONTROLLER
};
@ -85,48 +86,87 @@ return [
// ---------------------------------------------------------------------
// Anime Collection Routes
// ---------------------------------------------------------------------
'collection.search' => [
'path' => '/collection/search',
'anime.collection.search' => [
'path' => '/anime-collection/search',
'action' => 'search',
],
'collection.add.get' => [
'path' => '/collection/add',
'anime.collection.add.get' => [
'path' => '/anime-collection/add',
'action' => 'form',
'params' => [],
],
'collection.edit.get' => [
'path' => '/collection/edit/{id}',
'anime.collection.edit.get' => [
'path' => '/anime-collection/edit/{id}',
'action' => 'form',
'tokens' => [
'id' => '[0-9]+',
],
],
'collection.add.post' => [
'path' => '/collection/add',
'anime.collection.add.post' => [
'path' => '/anime-collection/add',
'action' => 'add',
'verb' => 'post',
],
'collection.edit.post' => [
'path' => '/collection/edit',
'anime.collection.edit.post' => [
'path' => '/anime-collection/edit',
'action' => 'edit',
'verb' => 'post',
],
'collection.view' => [
'path' => '/collection/view{/view}',
'anime.collection.view' => [
'path' => '/anime-collection/view{/view}',
'action' => 'index',
'params' => [],
'tokens' => [
'view' => '[a-z_]+',
],
],
'collection.delete' => [
'path' => '/collection/delete',
'anime.collection.delete' => [
'path' => '/anime-collection/delete',
'action' => 'delete',
'verb' => 'post',
],
// ---------------------------------------------------------------------
// Manga Collection Routes
// ---------------------------------------------------------------------
'manga.collection.search' => [
'path' => '/manga-collection/search',
'action' => 'search',
],
'manga.collection.add.get' => [
'path' => '/manga-collection/add',
'action' => 'form',
'params' => [],
],
'manga.collection.edit.get' => [
'path' => '/manga-collection/edit/{id}',
'action' => 'form',
'tokens' => [
'id' => '[0-9]+',
],
],
'manga.collection.add.post' => [
'path' => '/manga-collection/add',
'action' => 'add',
'verb' => 'post',
],
'manga.collection.edit.post' => [
'path' => '/manga-collection/edit',
'action' => 'edit',
'verb' => 'post',
],
'manga.collection.view' => [
'path' => '/manga-collection/view{/view}',
'action' => 'index',
'params' => [],
'tokens' => [
'view' => '[a-z_]+',
],
],
'manga.collection.delete' => [
'path' => '/manga-collection/delete',
'action' => 'delete',
'verb' => 'post',
],
// ---------------------------------------------------------------------
// Other Routes
// ---------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
<main>
<?php if ($auth->isAuthenticated()): ?>
<a class="bracketed" href="<?= $url->generate('collection.add.get') ?>">Add Item</a>
<a class="bracketed" href="<?= $url->generate($collection_type . '.collection.add.get') ?>">Add Item</a>
<?php endif ?>
<?php if (empty($sections)): ?>
<h3>There's nothing here!</h3>
@ -23,7 +23,7 @@
<?php if ($auth->isAuthenticated()): ?>
<div class="row">
<span class="edit">
<a class="bracketed" href="<?= $url->generate('collection.edit.get', [
<a class="bracketed" href="<?= $url->generate($collection_type . '.collection.edit.get', [
'id' => $item['hummingbird_id']
]) ?>">Edit</a>
</span>

View File

@ -47,7 +47,7 @@
</form>
<fieldset>
<legend>Danger Zone</legend>
<form class="js-delete" action="<?= $url->generate('collection.delete') ?>" method="post">
<form class="js-delete" action="<?= $url->generate($collection_type . '.collection.delete') ?>" method="post">
<table class="form invisible">
<tbody>
<tr>

View File

@ -1,6 +1,6 @@
<main>
<?php if ($auth->isAuthenticated()): ?>
<a class="bracketed" href="<?= $url->generate('collection.add.get') ?>">Add Item</a>
<a class="bracketed" href="<?= $url->generate($collection_type . '.collection.add.get') ?>">Add Item</a>
<?php endif ?>
<?php if (empty($sections)): ?>
<h3>There's nothing here!</h3>
@ -26,7 +26,7 @@
<tr>
<?php if($auth->isAuthenticated()): ?>
<td>
<a class="bracketed" href="<?= $url->generate('collection.edit.get', ['id' => $item['hummingbird_id']]) ?>">Edit</a>
<a class="bracketed" href="<?= $url->generate($collection_type . '.collection.edit.get', ['id' => $item['hummingbird_id']]) ?>">Edit</a>
</td>
<?php endif ?>
<td class="align_left">

View File

@ -16,10 +16,16 @@ $extraSegment = $lastSegment === 'list' ? '/list' : '';
) ?>
<?php if($config->get("show_{$url_type}_collection")): ?>
[<?= $helper->a(
$url->generate('collection.view') . $extraSegment,
$url->generate("{$url_type}.collection.view") . $extraSegment,
ucfirst($url_type) . ' Collection'
) ?>]
<?php endif ?>
<?php if($config->get("show_{$other_type}_collection")): ?>
[<?= $helper->a(
$url->generate("{$other_type}.collection.view") . $extraSegment,
ucfirst($other_type) . ' Collection'
) ?>]
<?php endif ?>
[<?= $helper->a(
$urlGenerator->defaultUrl($other_type) . $extraSegment,
ucfirst($other_type) . ' List'

View File

@ -21,7 +21,7 @@
"aura/router": "^3.0",
"aura/session": "^2.0",
"aviat/banker": "^1.0.0",
"aviat/ion": "^2.1.0",
"aviat/ion": "^2.2.0",
"monolog/monolog": "^1.0",
"psr/http-message": "~1.0",
"psr/log": "~1.0",

View File

@ -27,7 +27,7 @@ use Aviat\Ion\Di\ContainerInterface;
/**
* Controller for Anime collection pages
*/
class Collection extends BaseController {
class AnimeCollection extends BaseController {
/**
* The anime collection model
@ -53,6 +53,7 @@ class Collection extends BaseController {
$this->animeModel = $container->get('anime-model');
$this->animeCollectionModel = $container->get('anime-collection-model');
$this->baseData = array_merge($this->baseData, [
'collection_type' => 'anime',
'menu_name' => 'collection',
'url_type' => 'anime',
'other_type' => 'manga',
@ -109,7 +110,7 @@ class Collection extends BaseController {
$this->outputHTML('collection/' . $urlAction, [
'action' => $action,
'action_url' => $this->url->generate("collection.{$urlAction}.post"),
'action_url' => $this->url->generate("anime.collection.{$urlAction}.post"),
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime Collection",
$action

View File

@ -29,12 +29,15 @@ use function Aviat\Ion\_dir;
use Aviat\AnimeClient\API\FailedResponseException;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Friend;
use Aviat\Ion\StringWrapper;
/**
* Basic routing/ dispatch
*/
class Dispatcher extends RoutingBase {
use StringWrapper;
/**
* The route-matching object
* @var object $router
@ -208,6 +211,9 @@ class Dispatcher extends RoutingBase {
$segments = explode('/', $path);
$controller = reset($segments);
$logger = $this->container->getLogger('default');
$logger->info('Controller: ' . $controller);
if (empty($controller))
{
$controller = $routeType;
@ -235,7 +241,7 @@ class Dispatcher extends RoutingBase {
foreach ($classFiles as $file)
{
$rawClassName = basename(str_replace(".php", "", $file));
$path = strtolower(basename($rawClassName));
$path = $this->string($rawClassName)->dasherize()->__toString();
$className = trim($defaultNamespace . '\\' . $rawClassName, '\\');
$controllers[$path] = $className;