Skip to content
Permalink
Browse files

Merged collection and wishlist in a tabbed page

  • Loading branch information...
Thoulah committed Mar 3, 2019
1 parent b93c63b commit d5856e0133cd2c43fdd54392a542531aaed7e3be
@@ -4,3 +4,4 @@ A Yii2 web project for personal use
[![Yii2](https://img.shields.io/badge/Powered_by-Yii_Framework-brightgreen.svg)](https://www.yiiframework.com/)
[![Code Climate](https://codeclimate.com/github/Thoulah/mr.42/badges/gpa.svg)](https://codeclimate.com/github/Thoulah/mr.42)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Thoulah/mr.42/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Thoulah/mr.42/?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/41f90b3bc6454ff3a6ffc7f6e2a8a1e1)](https://app.codacy.com/app/Thoulah/mr.42?utm_source=github.com&utm_medium=referral&utm_content=Thoulah/mr.42&utm_campaign=Badge_Grade_Settings)
@@ -79,9 +79,8 @@ public function actionPdf(int $id, string $title): void {
}
public function actionCreate(): string {
if ($this->action->id === 'create') :
$model = new Articles();
else :
$model = new Articles();
if ($this->action->id === 'update') :
$model = Articles::findOne(['id' => $this->request->get('id')]);
$this->belongsToViewer($model);
endif;
@@ -91,7 +90,7 @@ public function actionCreate(): string {
$this->redirect(['article', 'id' => $model->id, 'title' => $model->url])->send();
endif;
$this->layout = '@app/views/layouts/main.php';
$this->layout = 'main';
return $this->render('_formArticle', [
'model' => $model,
]);
@@ -12,7 +12,7 @@ public function behaviors() {
'class' => HttpCache::class,
'enabled' => !YII_DEBUG,
'etagSeed' => function(BaseObject $action) {
return serialize([phpversion(), Yii::$app->user->id, file(Yii::getAlias('@app/views/'.$action->controller->id.'/'.$action->id.'.php'), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)]);
return serialize([phpversion(), Yii::$app->user->id, Yii::$app->view->renderFile("@app/views/{$action->controller->id}/{$action->id}.php")]);
},
'lastModified' => function(BaseObject $action) {
return filemtime(Yii::getAlias('@app/views/'.$action->controller->id.'/'.$action->id.'.php'));
@@ -7,7 +7,7 @@
use yii\web\Response;
class FeedController extends \yii\web\Controller {
public function behaviors() {
public function behaviors(): array {
$lastModified = Articles::getLastModified();
return [
[
@@ -21,11 +21,11 @@ public function behaviors() {
];
}
public function actionIndex() {
$this->redirect(['rss'], 301)->send();
public function actionIndex(): Response {
return $this->redirect(['rss'], 301);
}
public function actionRss() {
public function actionRss(): string {
if (php_sapi_name() !== 'cli' && !StringHelper::startsWith(Yii::$app->request->headers->get('user-agent'), 'FeedBurner') && !ArrayHelper::isIn(Yii::$app->request->userIP, Yii::$app->params['secrets']['params']['specialIPs']))
$this->redirect('http://f.mr42.me/Mr42')->send();
@@ -42,17 +42,17 @@ public function actionRss() {
]);
}
public function actionSitemap() {
public function actionSitemap(): string {
Yii::$app->response->format = Response::FORMAT_RAW;
Yii::$app->response->headers->add('Content-Type', 'application/xml');
return $this->renderPartial(Yii::$app->controller->action->id);
}
public function actionSitemapArticles() {
public function actionSitemapArticles(): string {
return $this->actionSitemap();
}
public function actionSitemapLyrics() {
public function actionSitemapLyrics(): string {
return $this->actionSitemap();
}
}
@@ -53,10 +53,6 @@ public function actionCollection(): string {
]);
}
public function actionWishlist(): string {
return $this->actionCollection();
}
public function actionCollectionCover(int $id): Response {
$album = Collection::find()->where(['id' => $id])->one();
if (!$album || !$album->image) :
@@ -33,12 +33,13 @@ public function behaviors(): array {
'class' => HttpCache::class,
'enabled' => !YII_DEBUG,
'etagSeed' => function(BaseObject $action) {
return serialize([phpversion(), file(Yii::getAlias(($action->id === 'faviconico') ? '@assetsroot/images/favicon.ico' : "@app/views/{$action->controller->id}/{$action->id}.php"), FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)]);
$file = ($action->id === 'faviconico') ? '@assetsroot/images/favicon.ico' : "@app/views/{$action->controller->id}/{$action->id}.php";
return serialize([phpversion(), Yii::$app->user->id, Yii::$app->view->renderFile($file)]);
},
'lastModified' => function(BaseObject $action) {
return filemtime(Yii::getAlias(($action->id === 'faviconico') ? '@assetsroot/images/favicon.ico' : "@app/views/{$action->controller->id}/{$action->id}.php"));
},
'only' => ['browserconfigxml', 'faviconico', 'robotstxt'],
'except' => ['index', 'contact', 'offline'],
],
];
}
@@ -14,7 +14,7 @@ public function behaviors() {
'class' => \yii\filters\HttpCache::class,
'enabled' => !YII_DEBUG,
'etagSeed' => function(BaseObject $action) {
return serialize([phpversion(), Yii::$app->user->id, file(Yii::getAlias('@app/views/'.$action->controller->id.'/'.$action->id.'.php'))]);
return serialize([phpversion(), Yii::$app->user->id, Yii::$app->view->renderFile("@app/views/{$action->controller->id}/{$action->id}.php")]);
},
'lastModified' => function(BaseObject $action) {
return filemtime(Yii::getAlias('@app/views/'.$action->controller->id.'/'.$action->id.'.php'));
@@ -42,13 +42,12 @@
'Buy Music of {artist}' => 'Kaufe Musik von {artist}',
'Buy This Album' => 'Dieses Album kaufen',
'CAPTCHA' => 'CAPTCHA',
'CD Collection' => 'CD Sammlung',
'CD Wishlist' => 'CD Wunschzettel',
'Calculate' => 'Rechnen',
'Calculator' => 'Rechner',
'Change Language' => 'Sprache ändern',
'Changelog' => 'Änderungshistorie',
'Code' => 'Code',
'Collection' => 'Sammlung',
'Comments' => 'Kommentare',
'Contact' => 'Kontakt',
'Content' => 'Inhalt',
@@ -232,6 +231,7 @@
'WiFi' => 'W-lan',
'Wifi Protected Access Pre-Shared Key' => 'Wifi-geschützter Zugang Pre-Shared-Schlüssel',
'Wifi Protected Access Pre-Shared Key (WPA-PSK) Calculator' => 'Wifi-geschützter Zugang Pre-Shared-Schlüssel (WPA-PSK) Rechner',
'Wishlist' => 'Wunschzettel',
'With this calculator you can check the date and time in any timezone around the world.' => 'Mit diesem Rechner können Sie Datum und Uhrzeit in jeder Zeitzone auf der ganzen Welt überprüfen.',
'Work Address' => 'Adresse (arbeit)',
'Work Telephone Number' => 'Telefonnummer (arbeit)',
@@ -42,13 +42,12 @@
'Buy Music of {artist}' => 'Купить музыку {artist}',
'Buy This Album' => 'Купить этот альбом',
'CAPTCHA' => 'Капча',
'CD Collection' => 'Коллекция CD',
'CD Wishlist' => 'Список желаний CD',
'Calculate' => 'Рассчитать',
'Calculator' => 'Калькулятор',
'Change Language' => 'Изменить язык',
'Changelog' => 'Изменения',
'Code' => 'Код',
'Collection' => 'Коллекция',
'Comments' => 'Комментарии',
'Contact' => 'Контакт',
'Content' => 'Содержание',
@@ -232,6 +231,7 @@
'WiFi' => 'Вай-фай',
'Wifi Protected Access Pre-Shared Key' => 'Предустановленный ключ защищенного доступа Wifi',
'Wifi Protected Access Pre-Shared Key (WPA-PSK) Calculator' => 'Калькулятор предварительного ключа с защищенным доступом Wifi (WPA-PSK)',
'Wishlist' => 'Список желаний',
'With this calculator you can check the date and time in any timezone around the world.' => 'С помощью этого калькулятора вы можете проверить дату и время в любом часовом поясе по всему миру.',
'Work Address' => 'Рабочий адрес',
'Work Telephone Number' => 'Рабочий номер телефона',
@@ -71,8 +71,7 @@ private function getData(): array {
],
['label' => Yii::$app->icon->show('music', ['class' => 'mr-1']).Html::tag('span', Yii::t('mr42', 'Music')), 'url' => null,
'items' => [
['label' => Yii::t('mr42', 'CD Collection'), 'url' => ['/music/collection']],
['label' => Yii::t('mr42', 'CD Wishlist'), 'url' => ['/music/wishlist']],
['label' => Yii::t('mr42', 'Collection'), 'url' => ['/music/collection']],
['label' => Yii::t('mr42', 'Lyrics'), 'url' => ['/music/lyrics'], 'visible' => true],
],
],
@@ -2,25 +2,41 @@
use yii\helpers\{Html, Url};
use yii\web\View;
$this->title = (Yii::$app->controller->action->id === 'collection') ? Yii::t('mr42', 'CD Collection') : Yii::t('mr42', 'CD Wishlist');
$this->title = Yii::t('mr42', 'Collection');
$this->params['breadcrumbs'][] = Yii::t('mr42', 'Music');
$this->params['breadcrumbs'][] = $this->title;
$tabs = [
'collection' => Yii::t('mr42', 'Collection'),
'wishlist' => Yii::t('mr42', 'Wishlist'),
];
$this->registerJs(Yii::$app->formatter->jspack('jquery.unveil.js'), View::POS_END);
$this->registerJs('$(\'a[data-toggle="tab"]\').on(\'shown.bs.tab\', function (e) {$(window).trigger("lookup")})', View::POS_END);
$this->registerJs('$("img").unveil();', View::POS_READY);
echo Html::tag('h1', $this->title);
echo Html::beginTag('div', ['class' => 'site-music-collection']);
echo Html::beginTag('div', ['class' => 'card-deck']);
foreach ($model->find()->where(['user_id' => 1, 'status' => Yii::$app->controller->action->id])->orderBy('artist, year')->all() as $album) :
echo Html::beginTag('div', ['class' => 'card mb-3']);
echo Html::a(
Html::img("@assets/images/blank.png", ['alt' => "{$album->artist} - {$album->year} - {$album->title}", 'class' => 'card-img-top rounded', 'data-src' => Url::to(['music/collection-cover', 'id' => $album->id])])
, "https://www.discogs.com/release/{$album->id}");
echo Html::tag('div', Html::tag('small', $album->title, ['class' => 'card-text mt-auto mx-auto font-weight-bold notranslate']), ['class' => 'card-body d-flex text-center p-2']);
echo Html::tag('div', Html::tag('small', $album->artist), ['class' => 'card-footer text-center p-2 notranslate']);
foreach ($tabs as $tab => $tabdesc)
$tabdata[] = Html::a($tabdesc, "#{$tab}", ['aria-controls' => $tab, 'aria-selected' => ($tab === array_key_first($tabs)) ? 'true' : 'false', 'class' => ($tab === array_key_first($tabs)) ? 'nav-link active' : 'nav-link', 'data-toggle' => 'tab', 'id' => "{$tab}-tab", 'role' => 'tab']);
echo Html::ul($tabdata, ['class' => 'nav nav-tabs', 'id' => 'nav-tabs', 'encode' => false, 'itemOptions' => ['class' => 'nav-item'], 'role' => 'tablist']);
echo Html::beginTag('div', ['class' => 'tab-content']);
foreach ($tabs as $tab => $tabdesc) :
echo Html::beginTag('div', ['aria-labelledby' => "{$tab}-tab", 'class' => ($tab === array_key_first($tabs)) ? 'tab-pane fade show active' : 'tab-pane fade', 'id' => $tab, 'role' => 'tabpanel']);
echo Html::beginTag('div', ['class' => 'site-music-collection']);
echo Html::beginTag('div', ['class' => 'card-deck']);
foreach ($model->find()->where(['user_id' => 1, 'status' => $tab])->orderBy(['artist' => SORT_ASC, 'year' => SORT_ASC])->all() as $album) :
echo Html::beginTag('div', ['class' => 'card mb-3']);
echo Html::a(
Html::img("@assets/images/blank.png", ['alt' => "{$album->artist} - {$album->year} - {$album->title}", 'class' => 'card-img-top rounded', 'data-src' => Url::to(['music/collection-cover', 'id' => $album->id])])
, "https://www.discogs.com/release/{$album->id}");
echo Html::tag('div', Html::tag('small', $album->title, ['class' => 'card-text mt-auto mx-auto font-weight-bold notranslate']), ['class' => 'card-body d-flex text-center p-2']);
echo Html::tag('div', Html::tag('small', $album->artist), ['class' => 'card-footer text-center p-2 notranslate']);
echo Html::endTag('div');
endforeach;
echo Html::endTag('div');
echo Html::endTag('div');
endforeach;
echo Html::endTag('div');
echo Html::endTag('div');
endforeach;
echo Html::endTag('div');
@@ -25,7 +25,7 @@
echo Html::tag('h1', $this->title);
foreach ($tabs as $tab => $tabdesc)
$tabdata[] = Html::a(ucfirst($tabdesc['short']), "#{$tab}", ['aria-controls' => $tab, 'aria-selected' => ($tab === array_key_first($tabs)) ? 'true' : 'false', 'class' => ($tab === array_key_first($tabs)) ? 'nav-link active' : 'nav-link', 'data-toggle' => 'tab', 'id' => "{$tab}-tab", 'role' => 'tab']);
$tabdata[] = Html::a($tabdesc['short'], "#{$tab}", ['aria-controls' => $tab, 'aria-selected' => ($tab === array_key_first($tabs)) ? 'true' : 'false', 'class' => ($tab === array_key_first($tabs)) ? 'nav-link active' : 'nav-link', 'data-toggle' => 'tab', 'id' => "{$tab}-tab", 'role' => 'tab']);
echo Html::ul($tabdata, ['class' => 'nav nav-tabs', 'id' => 'nav-tabs', 'encode' => false, 'itemOptions' => ['class' => 'nav-item'], 'role' => 'tablist']);
echo Html::beginTag('div', ['class' => 'tab-content']);

0 comments on commit d5856e0

Please sign in to comment.
You can’t perform that action at this time.