Fix various edge cases

This commit is contained in:
Timothy Warren 2017-04-10 15:31:35 -04:00
parent d157f097d1
commit 679560e185
6 changed files with 24 additions and 7 deletions

View File

@ -8,7 +8,7 @@
// Action to increment episode count // Action to increment episode count
_.on('body.anime.list', 'click', '.plus_one', (e) => { _.on('body.anime.list', 'click', '.plus_one', (e) => {
let parentSel = _.closestParent(e.target, 'article'); let parentSel = _.closestParent(e.target, 'article');
let watchedCount = parseInt(_.$('.completed_number', parentSel)[0].textContent, 10); let watchedCount = parseInt(_.$('.completed_number', parentSel)[0].textContent, 10) || 0;
let totalCount = parseInt(_.$('.total_number', parentSel)[0].textContent, 10); let totalCount = parseInt(_.$('.total_number', parentSel)[0].textContent, 10);
let title = _.$('.name a', parentSel)[0].textContent; let title = _.$('.name a', parentSel)[0].textContent;

View File

@ -9,7 +9,7 @@
let thisSel = e.target; let thisSel = e.target;
let parentSel = _.closestParent(e.target, 'article'); let parentSel = _.closestParent(e.target, 'article');
let type = thisSel.classList.contains('plus_one_chapter') ? 'chapter' : 'volume'; let type = thisSel.classList.contains('plus_one_chapter') ? 'chapter' : 'volume';
let completed = parseInt(_.$(`.${type}s_read`, parentSel)[0].textContent, 10); let completed = parseInt(_.$(`.${type}s_read`, parentSel)[0].textContent, 10) || 0;
let total = parseInt(_.$(`.${type}_count`, parentSel)[0].textContent, 10); let total = parseInt(_.$(`.${type}_count`, parentSel)[0].textContent, 10);
let mangaName = _.$('.name', parentSel)[0].textContent; let mangaName = _.$('.name', parentSel)[0].textContent;

View File

@ -238,9 +238,9 @@ class Model {
* *
* @param string $malId * @param string $malId
* @param string $type "anime" or "manga" * @param string $type "anime" or "manga"
* @return string * @return string|NULL
*/ */
public function getKitsuIdFromMALId(string $malId, string $type="anime"): string public function getKitsuIdFromMALId(string $malId, string $type="anime")
{ {
$options = [ $options = [
'query' => [ 'query' => [
@ -257,6 +257,11 @@ class Model {
$raw = $this->getRequest('mappings', $options); $raw = $this->getRequest('mappings', $options);
if ( ! array_key_exists('included', $raw))
{
return NULL;
}
return $raw['included'][0]['id']; return $raw['included'][0]['id'];
} }

View File

@ -120,11 +120,15 @@ class AnimeListTransformer extends AbstractTransformer {
'reconsuming' => $rewatching, 'reconsuming' => $rewatching,
'reconsumeCount' => $item['rewatched'], 'reconsumeCount' => $item['rewatched'],
'notes' => $item['notes'], 'notes' => $item['notes'],
'progress' => $item['episodes_watched'],
'private' => $privacy 'private' => $privacy
] ]
]; ];
if (is_numeric($item['episodes_watched']) && $item['episodes_watched'] > 0)
{
$untransformed['data']['progress'] = (int) $item['episodes_watched'];
}
if (is_numeric($item['user_rating']) && $item['user_rating'] > 0) if (is_numeric($item['user_rating']) && $item['user_rating'] > 0)
{ {
$untransformed['data']['rating'] = $item['user_rating'] / 2; $untransformed['data']['rating'] = $item['user_rating'] / 2;

View File

@ -117,14 +117,18 @@ class MangaListTransformer extends AbstractTransformer {
'mal_id' => $item['mal_id'], 'mal_id' => $item['mal_id'],
'data' => [ 'data' => [
'status' => $item['status'], 'status' => $item['status'],
'progress' => (int)$item['chapters_read'],
'reconsuming' => $rereading, 'reconsuming' => $rereading,
'reconsumeCount' => (int)$item['reread_count'], 'reconsumeCount' => (int)$item['reread_count'],
'notes' => $item['notes'], 'notes' => $item['notes'],
], ],
]; ];
if (is_numeric($item['new_rating'])) if (is_numeric($item['chapters_read']) && $item['chapters_read'] > 0)
{
$map['data']['progress'] = (int)$item['chapters_read'];
}
if (is_numeric($item['new_rating']) && $item['new_rating'] > 0)
{ {
$map['data']['rating'] = $item['new_rating'] / 2; $map['data']['rating'] = $item['new_rating'] / 2;
} }

View File

@ -118,6 +118,10 @@ class Index extends BaseController {
// return $rawfavorites; // return $rawfavorites;
$output = []; $output = [];
unset($rawfavorites['data']);
// dump($rawfavorites);
foreach($rawfavorites as $item) foreach($rawfavorites as $item)
{ {
$rank = $item['attributes']['favRank']; $rank = $item['attributes']['favRank'];