Update all the page titles

This commit is contained in:
Timothy Warren 2017-03-24 09:58:27 -04:00
parent da336876b6
commit bc8822e725
7 changed files with 99 additions and 19 deletions

View File

@ -82,8 +82,10 @@ class Anime extends BaseController {
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL)
{
$title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE))
? $this->config->get('whose_list') .
"'s Anime List · " . AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
? $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
)
: '';
$viewMap = [
@ -110,8 +112,10 @@ class Anime extends BaseController {
{
$this->setSessionRedirect();
$this->outputHTML('anime/add', [
'title' => $this->config->get('whose_list') .
"'s Anime List · Add",
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Add'
),
'action_url' => $this->urlGenerator->url('anime/add'),
'status_list' => AnimeWatchingStatus::KITSU_TO_TITLE
]);
@ -158,8 +162,10 @@ class Anime extends BaseController {
$this->setSessionRedirect();
$this->outputHTML('anime/edit', [
'title' => $this->config->get('whose_list') .
"'s Anime List · Edit",
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Edit'
),
'item' => $item,
'statuses' => AnimeWatchingStatus::KITSU_TO_TITLE,
'action' => $this->container->get('url-generator')

View File

@ -29,17 +29,21 @@ class Character extends BaseController {
if (( ! array_key_exists('data', $data)) || empty($data['data']))
{
return $this->notFound(
$this->config->get('whose_list') .
"'s Anime List · Characters · " .
'Character not found',
$this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Characters',
'Character not found'
),
'Character Not Found'
);
}
// $this->outputJSON($data);
$this->outputHTML('character', [
'title' => $this->config->get('whose_list') .
"'s Anime List · Characters · " . $data['data'][0]['attributes']['name'],
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Characters',
$data['data'][0]['attributes']['name']
),
'data' => $data['data'][0]['attributes']
]);
}

View File

@ -122,7 +122,10 @@ class Collection extends BaseController {
$this->outputHTML('collection/' . strtolower($action), [
'action' => $action,
'action_url' => $this->urlGenerator->fullUrl('collection/' . strtolower($action)),
'title' => $this->config->get('whose_list') . " Anime Collection · {$action}",
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime Collection",
$action
),
'media_items' => $this->animeCollectionModel->getMediaTypeList(),
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
]);

View File

@ -71,7 +71,10 @@ class Manga extends Controller {
{
$statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status];
$title = $this->config->get('whose_list') . "'s Manga List · {$statusTitle}";
$title = $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List",
$statusTitle
);
$view_map = [
'' => 'cover',
@ -109,8 +112,10 @@ class Manga extends Controller {
$this->setSessionRedirect();
$this->outputHTML('manga/add', [
'title' => $this->config->get('whose_list') .
"'s Manga List · Add",
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List",
'Add'
),
'action_url' => $this->urlGenerator->url('manga/add'),
'status_list' => $statuses
]);
@ -155,7 +160,10 @@ class Manga extends Controller {
{
$this->setSessionRedirect();
$item = $this->model->getLibraryItem($id);
$title = $this->config->get('whose_list') . "'s Manga List · Edit";
$title = $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List",
'Edit'
);
$this->outputHTML('manga/edit', [
'title' => $title,
@ -263,7 +271,11 @@ class Manga extends Controller {
$data = $this->model->getManga($manga_id);
$this->outputHTML('manga/details', [
'title' => 'Manga · ' . $data['title'],
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Manga List",
'Manga',
$data['title']
),
'data' => $data,
]);
}

View File

@ -301,6 +301,17 @@ trait ControllerTrait {
], NULL, 200);
}
/**
* Helper for consistent page titles
*
* @param string ...$parts Title segements
* @return string
*/
public function formatTitle(string ...$parts) : string
{
return implode(' · ', $parts);
}
/**
* Add a message box to the page
*

View File

@ -21,12 +21,13 @@ use Aura\Web\WebFactory;
use Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\Controller\{
Anime as AnimeController,
Character as CharacterController,
Collection as CollectionController,
Manga as MangaController
};
class ControllerTest extends AnimeClientTestCase {
protected $BaseController;
public function setUp()
@ -64,6 +65,10 @@ class ControllerTest extends AnimeClientTestCase {
'Aviat\AnimeClient\Controller',
new MangaController($this->container)
);
$this->assertInstanceOf(
'Aviat\AnimeClient\Controller',
new CharacterController($this->container)
);
$this->assertInstanceOf(
'Aviat\AnimeClient\Controller',
new CollectionController($this->container)

View File

@ -0,0 +1,39 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
*
* PHP version 7
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2017 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 4.0
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Tests;
use Aviat\AnimeClient\ControllerTrait;
class ControllerTraitTest extends AnimeClientTestCase {
public function setUp()
{
parent::setUp();
$this->controller = new class {
use ControllerTrait;
};
}
public function testFormatTitle()
{
$this->assertEquals(
$this->controller->formatTitle('foo', 'bar', 'baz'),
'foo &middot; bar &middot; baz'
);
}
}