From 77a65cd474617694dfb85fb72c372ab99cac4aae Mon Sep 17 00:00:00 2001 From: Jonas Heinrich <onny@project-insanity.org> Date: Fri, 11 Dec 2020 12:29:07 +0100 Subject: [PATCH] table fix display timestamp readable --- lib/Controller/Errors.php | 4 +- lib/Db/Show.php | 9 +-- lib/Db/ShowMapper.php | 6 +- .../Version000000Date20181013124731.php | 64 ------------------- lib/Service/ShowService.php | 8 +-- lib/Service/StationNotFound.php | 27 -------- src/components/Navigation.vue | 6 +- src/components/Table.vue | 10 ++- src/views/Show.vue | 32 ++++++---- 9 files changed, 46 insertions(+), 120 deletions(-) delete mode 100644 lib/Migration/Version000000Date20181013124731.php delete mode 100644 lib/Service/StationNotFound.php diff --git a/lib/Controller/Errors.php b/lib/Controller/Errors.php index e894022..2ba29cd 100644 --- a/lib/Controller/Errors.php +++ b/lib/Controller/Errors.php @@ -28,13 +28,13 @@ use Closure; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; -use OCA\Podcast\Service\StationNotFound; +use OCA\Podcast\Service\ShowNotFound; trait Errors { protected function handleNotFound(Closure $callback): DataResponse { try { return new DataResponse($callback()); - } catch (StationNotFound $e) { + } catch (ShowNotFound $e) { $message = ['message' => $e->getMessage()]; return new DataResponse($message, Http::STATUS_NOT_FOUND); } diff --git a/lib/Db/Show.php b/lib/Db/Show.php index 8c081cc..a43a84f 100644 --- a/lib/Db/Show.php +++ b/lib/Db/Show.php @@ -29,19 +29,20 @@ use OCP\AppFramework\Db\Entity; class Show extends Entity implements JsonSerializable { protected $title; - protected $htmlURL; - protected $smallImageURL; + protected $htmlurl; + protected $smallimageurl; protected $categories; protected $lastpub; protected $description; protected $author; + protected $userId; public function jsonSerialize(): array { return [ 'id' => $this->id, 'title' => $this->title, - 'htmlURL' => $this->htmlURL, - 'smallImageURL' => $this->smallImageURL, + 'htmlurl' => $this->htmlurl, + 'smallimageurl' => $this->smallimageurl, 'categories' => $this->categories, 'lastpub' => $this->lastpub, 'description' => $this->description, diff --git a/lib/Db/ShowMapper.php b/lib/Db/ShowMapper.php index 5a0d7d6..8a11056 100644 --- a/lib/Db/ShowMapper.php +++ b/lib/Db/ShowMapper.php @@ -31,17 +31,17 @@ use OCP\IDBConnection; class ShowMapper extends QBMapper { public function __construct(IDBConnection $db) { - parent::__construct($db, 'shows', Station::class); + parent::__construct($db, 'shows', Show::class); } /** * @param int $id * @param string $userId - * @return Entity|Station + * @return Entity|Show * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws DoesNotExistException */ - public function find(int $id, string $userId): Station { + public function find(int $id, string $userId): Show { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->select('*') diff --git a/lib/Migration/Version000000Date20181013124731.php b/lib/Migration/Version000000Date20181013124731.php deleted file mode 100644 index ad9b84a..0000000 --- a/lib/Migration/Version000000Date20181013124731.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -/** - * Podcast App - * - * @author Jonas Heinrich - * @copyright 2020 Jonas Heinrich <onny@project-insanity.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - -declare(strict_types=1); - -namespace OCA\Podcast\Migration; - -use Closure; -use OCP\DB\ISchemaWrapper; -use OCP\Migration\SimpleMigrationStep; -use OCP\Migration\IOutput; - -class Version000000Date20181013124731 extends SimpleMigrationStep { - - /** - * @param IOutput $output - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - * @return null|ISchemaWrapper - */ - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { - /** @var ISchemaWrapper $schema */ - $schema = $schemaClosure(); - - if (!$schema->hasTable('shows')) { - $table = $schema->createTable('shows'); - $table->addColumn('id', 'integer', [ - 'notnull' => true, - ]); - $table->addColumn('title', 'string'); - $table->addColumn('htmlURL', 'string'); - $table->addColumn('smallImageURL', 'string'); - $table->addColumn('categories', 'text'); - $table->addColumn('lastpub', 'text'); - $table->addColumn('description', 'text'); - $table->addColumn('author', 'text'); - - $table->setPrimaryKey(['id']); - $table->addIndex(['user_id'], 'shows_user_id_index'); - } - - return $schema; - } -} diff --git a/lib/Service/ShowService.php b/lib/Service/ShowService.php index 0185e89..fd6bc29 100644 --- a/lib/Service/ShowService.php +++ b/lib/Service/ShowService.php @@ -47,7 +47,7 @@ class ShowService { private function handleException(Exception $e): void { if ($e instanceof DoesNotExistException || $e instanceof MultipleObjectsReturnedException) { - throw new StationNotFound($e->getMessage()); + throw new ShowNotFound($e->getMessage()); } else { throw $e; } @@ -66,9 +66,8 @@ class ShowService { } } - public function create($id, $title, $htmlURL, $smallImageURL, $categories, $lastpub, $description, $author) { + public function create($title, $htmlURL, $smallImageURL, $categories, $lastpub, $description, $author, $userId) { $show = new Show(); - $show->setId($id); $show->setTitle($title); $show->setHtmlURL($htmlURL); $show->setSmallImageURL($smallImageURL); @@ -80,7 +79,7 @@ class ShowService { return $this->mapper->insert($show); } - public function update($id, $title, $htmlURL, $smallImageURL, $categories, $lastpub, $description, $author) { + public function update($id, $title, $htmlURL, $smallImageURL, $categories, $lastpub, $description, $author, $userId) { try { $show = $this->mapper->find($id, $userId); $show->setTitle($title); @@ -90,7 +89,6 @@ class ShowService { $show->setLastpub($lastpub); $show->setDescription($description); $show->setAuthor($author); - $show->setUserId($userId); return $this->mapper->update($show); } catch (Exception $e) { $this->handleException($e); diff --git a/lib/Service/StationNotFound.php b/lib/Service/StationNotFound.php deleted file mode 100644 index 4ea5df3..0000000 --- a/lib/Service/StationNotFound.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** - * Podcast App - * - * @author Jonas Heinrich - * @copyright 2020 Jonas Heinrich <onny@project-insanity.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\Podcast\Service; - -class StationNotFound extends \Exception { -} diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue index 5b140cd..9a2b541 100644 --- a/src/components/Navigation.vue +++ b/src/components/Navigation.vue @@ -25,15 +25,15 @@ <template id="app-podcast-navigation" #list> <AppNavigationItem :to="{ name: 'LISTENING' }" - icon="icon-category-dashboard" + icon="icon-play" :title="t('podcast', 'Listening')" /> <AppNavigationItem :to="{ name: 'LIBRARY' }" - icon="icon-recent" + icon="icon-files" :title="t('podcast', 'Library')" /> <AppNavigationItem :to="{ name: 'BROWSE' }" - icon="icon-category-monitoring" + icon="icon-link" :title="t('podcast', 'Browse')" /> <AppNavigationItem v-if="isSearch" diff --git a/src/components/Table.vue b/src/components/Table.vue index 152dda4..f3f4d16 100644 --- a/src/components/Table.vue +++ b/src/components/Table.vue @@ -84,7 +84,7 @@ {{ episode.duration_string }} </td> <td> - {{ episode.inserted }} + {{ readableTime(episode.inserted) }} </td> </tr> </tbody> @@ -94,6 +94,11 @@ <script> import Actions from '@nextcloud/vue/dist/Components/Actions' import ActionButton from '@nextcloud/vue/dist/Components/ActionButton' +import TimeAgo from 'javascript-time-ago' +import en from 'javascript-time-ago/locale/en' + +TimeAgo.addDefaultLocale(en) +const timeAgo = new TimeAgo('en-US') export default { name: 'Table', @@ -111,6 +116,9 @@ export default { activeItem: null, }), methods: { + readableTime(datetime) { + return timeAgo.format(Date.parse(datetime)) + }, downloadFile(episodeURL) { window.open(episodeURL, 'download') }, diff --git a/src/views/Show.vue b/src/views/Show.vue index cda01cf..88fa555 100644 --- a/src/views/Show.vue +++ b/src/views/Show.vue @@ -34,13 +34,17 @@ <div class="podcastAuthor"> by <a href="#">{{ podcast.author }}</a> </div> - <div>{{ podcast.description }}</div> - <ul - v-for="(category, idx) in podcast.categories" - :key="idx" - :class="podcastCategory"> - <li>{{ podcast.categories[idx] }}</li> + <div style="height: 40px; overflow: hidden; padding-bottom: 5px;"> + {{ podcast.description }} + </div> + <ul class="podcastCategory"> + <li + v-for="(category, idx) in podcast.categories" + :key="idx"> + {{ podcast.categories[idx] }} + </li> </ul> + <Actions default-icon="icon-add-white" :primary="true" menu-title="Subscribe" /> </div> </div> <Table @@ -67,6 +71,7 @@ import Content from '@nextcloud/vue/dist/Components/Content' import AppContent from '@nextcloud/vue/dist/Components/AppContent' import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent' +import Actions from '@nextcloud/vue/dist/Components/Actions' import Navigation from '../components/Navigation' import Table from '../components/Table' import { Howl, Howler } from 'howler' @@ -84,9 +89,12 @@ export default { AppContent, Table, EmptyContent, + Actions, }, data: () => ({ - podcast: {}, + podcast: { + episodes: [], + }, tableData: [], pageLoading: false, queryParams: {}, @@ -212,7 +220,6 @@ export default { async queryPodcast(podcastId) { const vm = this - podcastId = 1084 const queryURI = 'https://api.fyyd.de/0.2/podcast/episodes?podcast_id=' + podcastId try { @@ -277,7 +284,6 @@ export default { .podcastImage { width: 230px; height: 230px; - background: red; background-size: cover; background-position: center center; } @@ -305,8 +311,12 @@ export default { } ul.podcastCategory li { - padding: 5px; - background: red; + color: var(--color-text-maxcontrast); + display: inline; + border: 1px solid var(--color-text-maxcontrast); + border-radius: var(--border-radius); + padding: 3px 6px; + margin-right: 5px; } } -- GitLab