Improve wishlist view
This commit is contained in:
parent
066315fea4
commit
05cc9ee0ce
6 changed files with 107 additions and 109 deletions
|
@ -6,7 +6,7 @@
|
|||
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
||||
*/
|
||||
|
||||
use wishthis\User;
|
||||
use wishthis\{User, Wishlist};
|
||||
|
||||
$api = true;
|
||||
$response = array(
|
||||
|
@ -20,13 +20,16 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
if (isset($_GET['userid']) || isset($_SESSION['user']['id'])) {
|
||||
$user = isset($_GET['userid']) ? new User($_GET['userid']) : new User();
|
||||
$wishlists = $user->getWishlists();
|
||||
$wishlists = array_map(function ($wishlist) {
|
||||
$newFormat = $wishlist;
|
||||
$wishlists = array_map(function ($dataWishlist) {
|
||||
$data = $dataWishlist;
|
||||
// $newFormat['name'] = $wishlist['name'];
|
||||
$newFormat['value'] = $wishlist['id'];
|
||||
$newFormat['text'] = $wishlist['name'];
|
||||
$data['value'] = $dataWishlist['id'];
|
||||
$data['text'] = $dataWishlist['name'];
|
||||
|
||||
return $newFormat;
|
||||
$wishlist = new Wishlist(intval($dataWishlist['id']));
|
||||
$data['cards'] = $wishlist->getCards();
|
||||
|
||||
return $data;
|
||||
}, $wishlists);
|
||||
$response['results'] = $wishlists;
|
||||
$response['success'] = true;
|
||||
|
|
|
@ -40,14 +40,18 @@ $(function() {
|
|||
console.log(element);
|
||||
console.log(xhr);
|
||||
|
||||
if (response.startsWith('<br />')) {
|
||||
response = response.replace('<br />', '');
|
||||
}
|
||||
|
||||
$('body')
|
||||
.modal({
|
||||
title: 'Failure',
|
||||
content: 'The process has failed.',
|
||||
content: response,
|
||||
class: '',
|
||||
actions: [
|
||||
{
|
||||
text: 'Oh well',
|
||||
text: 'Thanks for nothing',
|
||||
class: 'primary'
|
||||
}
|
||||
]
|
||||
|
@ -59,14 +63,18 @@ $(function() {
|
|||
console.log(element);
|
||||
console.log(xhr);
|
||||
|
||||
if (response.startsWith('<br />')) {
|
||||
response = response.replace('<br />', '');
|
||||
}
|
||||
|
||||
$('body')
|
||||
.modal({
|
||||
title: 'Error',
|
||||
content: 'There has been an error.',
|
||||
content: response,
|
||||
class: '',
|
||||
actions: [
|
||||
{
|
||||
text: 'Oh well',
|
||||
text: 'Thanks for nothing',
|
||||
class: 'primary'
|
||||
}
|
||||
]
|
||||
|
@ -85,7 +93,7 @@ $(function() {
|
|||
class: '',
|
||||
actions: [
|
||||
{
|
||||
text: 'Oh well',
|
||||
text: 'Thanks for nothing',
|
||||
class: 'primary'
|
||||
}
|
||||
]
|
||||
|
|
|
@ -10,6 +10,7 @@ $(function() {
|
|||
on: 'now',
|
||||
onSuccess: function(response, element, xhr) {
|
||||
wishlists = response.results;
|
||||
console.log(wishlists);
|
||||
|
||||
element.dropdown({
|
||||
values: wishlists,
|
||||
|
@ -38,8 +39,6 @@ $(function() {
|
|||
$('[name="wishlist_delete_id"]').val(wishlistValue);
|
||||
|
||||
if (wishlistValue) {
|
||||
$('.wishlist-view').removeClass('disabled');
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
urlParams.set('wishlist', wishlistValue);
|
||||
window.history.pushState({}, '', '/?' + urlParams.toString());
|
||||
|
@ -49,11 +48,14 @@ $(function() {
|
|||
$('.wishlist-share').removeClass('disabled');
|
||||
$('.wishlist-delete button').removeClass('disabled');
|
||||
} else {
|
||||
$('.wishlist-view').addClass('disabled');
|
||||
|
||||
$('.wishlist-share').addClass('disabled');
|
||||
$('.wishlist-delete button').addClass('disabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Cards
|
||||
*/
|
||||
$('.wishlist-cards').html(wishlists[wishlistIndex].cards);
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,8 +57,10 @@ class Wishlist
|
|||
->fetchAll();
|
||||
}
|
||||
|
||||
public function getCards($options = array()): void
|
||||
public function getCards($options = array()): string
|
||||
{
|
||||
ob_start();
|
||||
|
||||
/**
|
||||
* Exclude
|
||||
*/
|
||||
|
@ -76,74 +78,70 @@ class Wishlist
|
|||
* Cards
|
||||
*/
|
||||
if (!empty($products)) { ?>
|
||||
<div class="ui three column stackable grid wishlist-cards">
|
||||
<?php foreach ($products as $product) {
|
||||
$cache = new EmbedCache();
|
||||
$info = $cache->get($product['url']);
|
||||
?>
|
||||
<div class="column">
|
||||
<div class="ui fluid card" data-id="<?= $product['id'] ?>">
|
||||
|
||||
<?php foreach ($products as $product) {
|
||||
$cache = new EmbedCache();
|
||||
$info = $cache->get($product['url']);
|
||||
?>
|
||||
<div class="column">
|
||||
<div class="ui fluid card" data-id="<?= $product['id'] ?>">
|
||||
<?php if ($info->image) { ?>
|
||||
<div class="image">
|
||||
<img src="<?= $info->image ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($info->image) { ?>
|
||||
<div class="image">
|
||||
<img src="<?= $info->image ?>" />
|
||||
<div class="content">
|
||||
<?php if ($info->title) { ?>
|
||||
<div class="header">
|
||||
<?php if ($info->favicon) { ?>
|
||||
<img src="<?= $info->favicon ?>" />
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($info->url) { ?>
|
||||
<a href="<?= $info->url ?>" target="_blank"><?= $info->title ?></a>
|
||||
<?php } else { ?>
|
||||
<?= $info->title ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="content">
|
||||
<?php if ($info->title) { ?>
|
||||
<div class="header">
|
||||
<?php if ($info->favicon) { ?>
|
||||
<img src="<?= $info->favicon ?>" />
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($info->url) { ?>
|
||||
<a href="<?= $info->url ?>" target="_blank"><?= $info->title ?></a>
|
||||
<?php } else { ?>
|
||||
<?= $info->title ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($info->keywords) { ?>
|
||||
<div class="meta">
|
||||
<?= $info->keywords ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($info->description) { ?>
|
||||
<div class="description">
|
||||
<?= $info->description ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="extra content">
|
||||
<?php if ($info->publishedTime) { ?>
|
||||
<span class="right floated">
|
||||
<?= $info->publishedTime ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
<?php if ($info->providerName) { ?>
|
||||
<?= $info->providerName ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="extra content">
|
||||
<?php if ($info->url) { ?>
|
||||
<a class="ui tiny button" href="<?= $info->url ?>" target="_blank">View</a>
|
||||
<?php } ?>
|
||||
<?php if ($this->data['user'] === $_SESSION['user']['id']) { ?>
|
||||
<a class="ui tiny red button delete">Delete</a>
|
||||
<?php } else { ?>
|
||||
<a class="ui tiny button commit">Commit</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($info->keywords) { ?>
|
||||
<div class="meta">
|
||||
<?= $info->keywords ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($info->description) { ?>
|
||||
<div class="description">
|
||||
<?= $info->description ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="extra content">
|
||||
<?php if ($info->publishedTime) { ?>
|
||||
<span class="right floated">
|
||||
<?= $info->publishedTime ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
<?php if ($info->providerName) { ?>
|
||||
<?= $info->providerName ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="extra content">
|
||||
<?php if ($info->url) { ?>
|
||||
<a class="ui tiny button" href="<?= $info->url ?>" target="_blank">View</a>
|
||||
<?php } ?>
|
||||
<?php if ($this->data['user'] === $_SESSION['user']['id']) { ?>
|
||||
<a class="ui tiny red button delete">Delete</a>
|
||||
<?php } else { ?>
|
||||
<a class="ui tiny button commit">Commit</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<?php if (isset($_GET['wishlist'])) { ?>
|
||||
<div class="ui icon message">
|
||||
|
@ -157,5 +155,7 @@ class Wishlist
|
|||
</div><?php
|
||||
}
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* wishlist.php
|
||||
* Template for viewing wishlists.
|
||||
*
|
||||
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
||||
*/
|
||||
|
@ -12,13 +12,6 @@ $page = new page(__FILE__, 'View wishlist');
|
|||
$page->header();
|
||||
$page->navigation();
|
||||
|
||||
/**
|
||||
* Get wishlist products
|
||||
*/
|
||||
if (isset($_GET['wishlist'])) {
|
||||
$wishlist = new Wishlist(intval($_GET['wishlist']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete wishlist
|
||||
*/
|
||||
|
@ -37,24 +30,18 @@ if (isset($_POST['wishlist_delete_id'])) {
|
|||
<h2 class="ui header">Wishlists</h2>
|
||||
<p>Please select a wishlist to view.</p>
|
||||
|
||||
<form class="ui form" method="get">
|
||||
<input type="hidden" name="page" value="wishlist-view" />
|
||||
|
||||
<div class="field">
|
||||
<select class="ui search selection dropdown loading wishlists" name="wishlist">
|
||||
<option value="">Loading your wishlists...</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<input class="ui primary button wishlist-view disabled" type="submit" value="View" />
|
||||
</form>
|
||||
<div class="field">
|
||||
<select class="ui search selection dropdown loading wishlists" name="wishlist">
|
||||
<option value="">Loading your wishlists...</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ui segment">
|
||||
<h2 class="ui header">Options</h1>
|
||||
<p>Wishlist related options.</p>
|
||||
|
||||
<a class="ui small labeled icon button wishlist-share <?= !isset($_GET['wishlist']) ? 'disabled' : '' ?>" href="/?wishlist=<?= $wishlist->data['hash'] ?? '' ?>" target="_blank">
|
||||
<a class="ui small labeled icon button wishlist-share disabled" target="_blank">
|
||||
<i class="share icon"></i>
|
||||
Share
|
||||
</a>
|
||||
|
@ -62,7 +49,7 @@ if (isset($_POST['wishlist_delete_id'])) {
|
|||
<form class="ui form wishlist-delete" method="post" style="display: inline-block;">
|
||||
<input type="hidden" name="wishlist_delete_id" />
|
||||
|
||||
<button class="ui small labeled red icon button <?= !isset($_GET['wishlist']) ? 'disabled' : '' ?>" type="submit">
|
||||
<button class="ui small labeled red icon button disabled" type="submit">
|
||||
<i class="trash icon"></i>
|
||||
Delete
|
||||
</button>
|
||||
|
@ -70,11 +57,7 @@ if (isset($_POST['wishlist_delete_id'])) {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (isset($_GET['wishlist'])) {
|
||||
$wishlist->getCards();
|
||||
}
|
||||
?>
|
||||
<div class="ui three column stackable grid wishlist-cards"></div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
|
|
@ -62,13 +62,15 @@ $page->navigation();
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$wishlist->getCards(
|
||||
array(
|
||||
'exclude' => array('unavailable'),
|
||||
)
|
||||
);
|
||||
?>
|
||||
<div class="ui three column stackable grid wishlist-cards">
|
||||
<?php
|
||||
echo $wishlist->getCards(
|
||||
array(
|
||||
'exclude' => array('unavailable'),
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
|
Loading…
Reference in a new issue