Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
7 changed files with 99 additions and 19 deletions
Showing only changes of commit bc8822e725 - Show all commits

View File

@ -82,8 +82,10 @@ class Anime extends BaseController {
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL) public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL)
{ {
$title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE)) $title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE))
? $this->config->get('whose_list') . ? $this->formatTitle(
"'s Anime List · " . AnimeWatchingStatus::ROUTE_TO_TITLE[$type] $this->config->get('whose_list') . "'s Anime List",
AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
)
: ''; : '';
$viewMap = [ $viewMap = [
@ -110,8 +112,10 @@ class Anime extends BaseController {
{ {
$this->setSessionRedirect(); $this->setSessionRedirect();
$this->outputHTML('anime/add', [ $this->outputHTML('anime/add', [
'title' => $this->config->get('whose_list') . 'title' => $this->formatTitle(
"'s Anime List · Add", $this->config->get('whose_list') . "'s Anime List",
'Add'
),
'action_url' => $this->urlGenerator->url('anime/add'), 'action_url' => $this->urlGenerator->url('anime/add'),
'status_list' => AnimeWatchingStatus::KITSU_TO_TITLE 'status_list' => AnimeWatchingStatus::KITSU_TO_TITLE
]); ]);
@ -158,8 +162,10 @@ class Anime extends BaseController {
$this->setSessionRedirect(); $this->setSessionRedirect();
$this->outputHTML('anime/edit', [ $this->outputHTML('anime/edit', [
'title' => $this->config->get('whose_list') . 'title' => $this->formatTitle(
"'s Anime List · Edit", $this->config->get('whose_list') . "'s Anime List",
'Edit'
),
'item' => $item, 'item' => $item,
'statuses' => AnimeWatchingStatus::KITSU_TO_TITLE, 'statuses' => AnimeWatchingStatus::KITSU_TO_TITLE,
'action' => $this->container->get('url-generator') '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'])) if (( ! array_key_exists('data', $data)) || empty($data['data']))
{ {
return $this->notFound( return $this->notFound(
$this->config->get('whose_list') . $this->formatTitle(
"'s Anime List · Characters · " . $this->config->get('whose_list') . "'s Anime List",
'Character not found', 'Characters',
'Character not found'
),
'Character Not Found' 'Character Not Found'
); );
} }
// $this->outputJSON($data);
$this->outputHTML('character', [ $this->outputHTML('character', [
'title' => $this->config->get('whose_list') . 'title' => $this->formatTitle(
"'s Anime List · Characters · " . $data['data'][0]['attributes']['name'], $this->config->get('whose_list') . "'s Anime List",
'Characters',
$data['data'][0]['attributes']['name']
),
'data' => $data['data'][0]['attributes'] 'data' => $data['data'][0]['attributes']
]); ]);
} }

View File

@ -122,7 +122,10 @@ class Collection extends BaseController {
$this->outputHTML('collection/' . strtolower($action), [ $this->outputHTML('collection/' . strtolower($action), [
'action' => $action, 'action' => $action,
'action_url' => $this->urlGenerator->fullUrl('collection/' . strtolower($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(), 'media_items' => $this->animeCollectionModel->getMediaTypeList(),
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : [] 'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
]); ]);

View File

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

View File

@ -301,6 +301,17 @@ trait ControllerTrait {
], NULL, 200); ], 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 * Add a message box to the page
* *

View File

@ -21,6 +21,7 @@ use Aura\Web\WebFactory;
use Aviat\AnimeClient\Controller; use Aviat\AnimeClient\Controller;
use Aviat\AnimeClient\Controller\{ use Aviat\AnimeClient\Controller\{
Anime as AnimeController, Anime as AnimeController,
Character as CharacterController,
Collection as CollectionController, Collection as CollectionController,
Manga as MangaController Manga as MangaController
}; };
@ -64,6 +65,10 @@ class ControllerTest extends AnimeClientTestCase {
'Aviat\AnimeClient\Controller', 'Aviat\AnimeClient\Controller',
new MangaController($this->container) new MangaController($this->container)
); );
$this->assertInstanceOf(
'Aviat\AnimeClient\Controller',
new CharacterController($this->container)
);
$this->assertInstanceOf( $this->assertInstanceOf(
'Aviat\AnimeClient\Controller', 'Aviat\AnimeClient\Controller',
new CollectionController($this->container) 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'
);
}
}