Add product edit page
This commit is contained in:
parent
ce83385596
commit
ac056cd511
9 changed files with 251 additions and 68 deletions
|
@ -24,11 +24,11 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
WHERE `id` = ' . $_GET['wish_id'] . ';')
|
||||
->fetch();
|
||||
|
||||
$wish = new wish($columns);
|
||||
$wish = new wish($columns, true);
|
||||
|
||||
$response = array(
|
||||
'info' => $wish,
|
||||
'html' => $wish->getCard($_GET['wishlist_user'], true)
|
||||
'html' => $wish->getCard($_GET['wishlist_user'])
|
||||
);
|
||||
} elseif (isset($_GET['wish_url'])) {
|
||||
$cache = new EmbedCache($_GET['wish_url']);
|
||||
|
@ -42,10 +42,18 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
break;
|
||||
|
||||
case 'POST':
|
||||
if (isset($_POST['wishlist_id'], $_POST['wish_url'])) {
|
||||
if (isset($_POST['wishlist_id'])) {
|
||||
/**
|
||||
* Insert New Wish
|
||||
*/
|
||||
if (
|
||||
empty($_POST['wish_title'])
|
||||
&& empty($_POST['wish_description'])
|
||||
&& empty($_POST['wish_url'])
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
$database->query('INSERT INTO `wishes`
|
||||
(
|
||||
`wishlist`,
|
||||
|
@ -54,9 +62,9 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
`url`
|
||||
) VALUES ('
|
||||
. $_POST['wishlist_id'] . ',
|
||||
"' . $_POST['wish_title'] . '",
|
||||
"' . $_POST['wish_description'] . '",
|
||||
"' . $_POST['wish_url'] . '"
|
||||
"' . trim($_POST['wish_title']) . '",
|
||||
"' . trim($_POST['wish_description']) . '",
|
||||
"' . trim($_POST['wish_url']) . '"
|
||||
)
|
||||
;');
|
||||
|
||||
|
|
|
@ -45,17 +45,20 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
$user = isset($_GET['userid']) ? new User($_GET['userid']) : new User();
|
||||
|
||||
$wishlists = $user->getWishlists();
|
||||
$wishlists = array_map(function ($dataWishlist) {
|
||||
$wishlists = array_map(
|
||||
function ($dataWishlist) {
|
||||
$data = $dataWishlist;
|
||||
// $newFormat['name'] = $wishlist['name'];
|
||||
$data['value'] = $dataWishlist['id'];
|
||||
$data['text'] = $dataWishlist['name'];
|
||||
|
||||
$wishlist = new Wishlist(intval($dataWishlist['id']));
|
||||
$wishlist = new Wishlist($dataWishlist['id']);
|
||||
$data['cards'] = $wishlist->getCards();
|
||||
|
||||
return $data;
|
||||
}, $wishlists);
|
||||
},
|
||||
$wishlists
|
||||
);
|
||||
|
||||
$response['results'] = $wishlists;
|
||||
$response['success'] = true;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
:root {
|
||||
--lineHeight: 1.4285;
|
||||
--wishPreviewHeight: 25vh;
|
||||
}
|
||||
|
||||
img {
|
||||
|
@ -33,16 +34,16 @@ img {
|
|||
/**
|
||||
* Card
|
||||
*/
|
||||
.ui.card {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.ui.fluid.card.stretch {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/** Overlay */
|
||||
@media (hover: hover) {
|
||||
.ui.card:hover {
|
||||
z-index: 102;
|
||||
}
|
||||
|
||||
.ui.card .overlay {
|
||||
transition: 0.4s ease opacity;
|
||||
|
||||
|
@ -64,8 +65,9 @@ img {
|
|||
|
||||
/** Image */
|
||||
.ui.card > .image > img.preview{
|
||||
height: 25vh;
|
||||
height: var(--wishPreviewHeight);
|
||||
object-fit: cover;
|
||||
object-position: 50%;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
|
@ -197,6 +199,19 @@ img {
|
|||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
.ui.card .ui.menu {
|
||||
flex: 1 1 auto;
|
||||
|
||||
margin: 0;
|
||||
|
||||
box-shadow: none;
|
||||
}
|
||||
.ui.card .ui.menu .ui.button {
|
||||
margin: 0;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/**
|
||||
* Label
|
||||
*/
|
||||
|
|
6
src/assets/css/wish.css
Normal file
6
src/assets/css/wish.css
Normal file
|
@ -0,0 +1,6 @@
|
|||
.ui.fluid.image {
|
||||
height: var(--wishPreviewHeight);
|
||||
|
||||
object-fit: cover;
|
||||
object-position: 50%;
|
||||
}
|
|
@ -24,6 +24,8 @@ $(function () {
|
|||
element.dropdown('set selected', wishlists[0].value);
|
||||
}
|
||||
}
|
||||
|
||||
$('.ui.dropdown').dropdown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -146,6 +148,8 @@ $(function () {
|
|||
.finally(function() {
|
||||
card.attr('data-cache', 'true');
|
||||
card.removeClass('loading');
|
||||
|
||||
$('.ui.dropdown').dropdown();
|
||||
});
|
||||
|
||||
refresh.removeClass('working');
|
||||
|
@ -234,9 +238,9 @@ $(function () {
|
|||
/**
|
||||
* Delete Wish
|
||||
*/
|
||||
$(document).on('click', '.ui.button.delete', function () {
|
||||
var button = $(this);
|
||||
var card = button.closest('.ui.card');
|
||||
$(document).on('click', '.menu.options .item.delete', function () {
|
||||
var buttonDelete = $(this);
|
||||
var card = buttonDelete.closest('.ui.card');
|
||||
var column = card.closest('.column');
|
||||
var modalDefault = $('.ui.modal.default');
|
||||
|
||||
|
@ -260,7 +264,7 @@ $(function () {
|
|||
/**
|
||||
* Delete wish
|
||||
*/
|
||||
button.api({
|
||||
buttonDelete.api({
|
||||
action: 'delete wish',
|
||||
method: 'DELETE',
|
||||
data: {
|
||||
|
|
|
@ -35,7 +35,7 @@ class EmbedCache
|
|||
{
|
||||
}
|
||||
|
||||
public function get(bool $generateCache = false): mixed
|
||||
public function get(bool $generateCache = false): \stdClass
|
||||
{
|
||||
$info = null;
|
||||
$maxAge = 2592000; // 30 days
|
||||
|
|
|
@ -10,6 +10,8 @@ namespace wishthis;
|
|||
|
||||
class Wish
|
||||
{
|
||||
private EmbedCache $cache;
|
||||
|
||||
public int $id;
|
||||
public int $wishlist;
|
||||
public ?string $title;
|
||||
|
@ -17,13 +19,15 @@ class Wish
|
|||
public ?string $url;
|
||||
public ?string $status;
|
||||
|
||||
public function __construct(int|array $wish)
|
||||
public \stdClass $info;
|
||||
|
||||
public function __construct(int|array $wish, bool $generateCache = false)
|
||||
{
|
||||
global $database;
|
||||
|
||||
$columns = array();
|
||||
|
||||
if (is_int($wish)) {
|
||||
if (is_numeric($wish)) {
|
||||
$wish = $database
|
||||
->query('SELECT *
|
||||
FROM `wishes`
|
||||
|
@ -40,9 +44,26 @@ class Wish
|
|||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$this->info = new \stdClass();
|
||||
|
||||
if ($this->url) {
|
||||
$this->cache = new EmbedCache($this->url);
|
||||
$this->info = $this->cache->get($generateCache);
|
||||
}
|
||||
|
||||
public function getCard(int $ofUser, bool $generateCache = false): string
|
||||
if (empty($this->info->image)) {
|
||||
$this->info->image = '/src/assets/img/no-image.svg';
|
||||
}
|
||||
|
||||
foreach ($columns as $key => $value) {
|
||||
if (empty($value) && isset($this->info->$key)) {
|
||||
$this->$key = $this->info->$key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getCard(int $ofUser): string
|
||||
{
|
||||
ob_start();
|
||||
|
||||
|
@ -52,40 +73,29 @@ class Wish
|
|||
$userIsCurrent = isset($_SESSION['user']['id']) && intval($_SESSION['user']['id']) === $ofUser;
|
||||
|
||||
if ($this->url) {
|
||||
$cache = new EmbedCache($this->url);
|
||||
$info = $cache->get($generateCache);
|
||||
$exists = $cache->exists() || !$this->url ? 'true' : 'false';
|
||||
$exists = $this->cache->exists() || !$this->url ? 'true' : 'false';
|
||||
} else {
|
||||
$exists = 'true';
|
||||
}
|
||||
|
||||
$title = $this->title ?? $info->title ?? null;
|
||||
$description = $this->description ?? $info->description ?? null;
|
||||
$url = $this->url ?? $info->url ?? null;
|
||||
|
||||
$image = $info->image ? $info->image : '/src/assets/img/no-image.svg';
|
||||
$favicon = $info->favicon ?? null;
|
||||
$providerName = $info->providerName ?? null;
|
||||
$keywords = $info->keywords ?? null;
|
||||
?>
|
||||
|
||||
<div class="ui fluid card stretch" data-id="<?= $this->id ?>" data-cache="<?= $exists ?>">
|
||||
<div class="overlay"></div>
|
||||
|
||||
<div class="image">
|
||||
<?php if ($image) { ?>
|
||||
<img class="preview" src="<?= $image ?>" loading="lazy" />
|
||||
<?php if (isset($this->info->image)) { ?>
|
||||
<img class="preview" src="<?= $this->info->image ?>" loading="lazy" />
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($favicon) { ?>
|
||||
<img class="favicon" src="<?= $favicon ?>" loading="lazy" />
|
||||
<?php if (isset($this->info->favicon)) { ?>
|
||||
<img class="favicon" src="<?= $this->info->favicon ?>" loading="lazy" />
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($providerName) { ?>
|
||||
<span class="provider"><?= $providerName ?></span>
|
||||
<?php if (isset($this->info->providerName)) { ?>
|
||||
<span class="provider"><?= $this->info->providerName ?></span>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($userIsCurrent && $url) { ?>
|
||||
<?php if ($userIsCurrent && isset($this->url)) { ?>
|
||||
<button class="ui icon button refresh">
|
||||
<i class="refresh icon"></i>
|
||||
</button>
|
||||
|
@ -93,25 +103,25 @@ class Wish
|
|||
</div>
|
||||
|
||||
<div class="content">
|
||||
<?php if ($title) { ?>
|
||||
<?php if ($this->title) { ?>
|
||||
<div class="header">
|
||||
<?php if ($url) { ?>
|
||||
<a href="<?= $url ?>" target="_blank"><?= $title ?></a>
|
||||
<?php if ($this->url) { ?>
|
||||
<a href="<?= $this->url ?>" target="_blank"><?= $this->title ?></a>
|
||||
<?php } else { ?>
|
||||
<?= $title ?>
|
||||
<?= $this->title ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($keywords) { ?>
|
||||
<?php if (isset($this->info->keywords)) { ?>
|
||||
<div class="meta">
|
||||
<?= implode(', ', $keywords) ?>
|
||||
<?= implode(', ', $this->info->keywords) ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($description) { ?>
|
||||
<?php if ($this->description) { ?>
|
||||
<div class="description">
|
||||
<?= $description ?>
|
||||
<?= $this->description ?>
|
||||
</div>
|
||||
<div class="description-fade"></div>
|
||||
<?php } ?>
|
||||
|
@ -119,25 +129,40 @@ class Wish
|
|||
|
||||
<div class="extra content buttons">
|
||||
<?php if (!$userIsCurrent) { ?>
|
||||
<a class="ui small primary labeled icon button commit">
|
||||
<a class="ui primary labeled icon button commit">
|
||||
<i class="shopping cart icon"></i>
|
||||
Commit
|
||||
</a>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($url) { ?>
|
||||
<a class="ui small labeled icon button" href="<?= $url ?>" target="_blank">
|
||||
<?php if ($this->url) { ?>
|
||||
<a class="ui labeled icon button" href="<?= $this->url ?>" target="_blank">
|
||||
<i class="external icon"></i>
|
||||
Visit
|
||||
</a>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($userIsCurrent) { ?>
|
||||
<a class="ui small labeled red icon button delete">
|
||||
<div class="ui menu">
|
||||
<div class="ui fluid floating dropdown labeled icon button">
|
||||
<i class="cog icon"></i>
|
||||
Options
|
||||
|
||||
<div class="bottom menu options">
|
||||
<a class="item" href="/?page=wish&id=<?= $this->id ?>">
|
||||
<i class="pen icon"></i>
|
||||
Edit
|
||||
</a>
|
||||
|
||||
<a class="item delete">
|
||||
<i class="trash icon"></i>
|
||||
Delete
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
|
|
@ -24,10 +24,9 @@ class Wishlist
|
|||
|
||||
$column;
|
||||
|
||||
if (is_int($id_or_hash)) {
|
||||
if (is_numeric($id_or_hash)) {
|
||||
$column = 'id';
|
||||
}
|
||||
if (is_string($id_or_hash)) {
|
||||
} elseif (is_string($id_or_hash)) {
|
||||
$column = 'hash';
|
||||
$id_or_hash = '"' . $id_or_hash . '"';
|
||||
}
|
||||
|
@ -61,7 +60,7 @@ class Wishlist
|
|||
->fetchAll();
|
||||
|
||||
foreach ($this->wishes as &$wish) {
|
||||
$wish = new Wish($wish);
|
||||
$wish = new Wish($wish, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +88,7 @@ class Wishlist
|
|||
<div class="ui three column doubling stackable grid">
|
||||
<?php foreach ($wishes as $wish) { ?>
|
||||
<div class="column">
|
||||
<?= $wish->getCard($this->data['user'], false) ?>
|
||||
<?= $wish->getCard($this->data['user']) ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
|
123
src/pages/wish.php
Normal file
123
src/pages/wish.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Template for viewing a wish.
|
||||
*
|
||||
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
||||
*/
|
||||
|
||||
use wishthis\{Page, Wish};
|
||||
|
||||
$messages = array();
|
||||
|
||||
if ('POST' === $_SERVER['REQUEST_METHOD'] && count($_POST) >= 0) {
|
||||
$database
|
||||
->query('UPDATE `wishes`
|
||||
SET `title` = "' . trim($_POST['wish_title']) . '",
|
||||
`description` = "' . trim($_POST['wish_description']) . '",
|
||||
`url` = "' . trim($_POST['wish_url']) . '"
|
||||
WHERE `id` = ' . trim($_POST['wish_id']) . ';');
|
||||
|
||||
$messages[] = Page::success('Wish successfully updated.', 'Success');
|
||||
}
|
||||
|
||||
$wish = new Wish($_GET['id'], false);
|
||||
|
||||
/*
|
||||
if (!$wish->exists()) {
|
||||
http_response_code(404);
|
||||
?>
|
||||
<h1>Not found</h1>
|
||||
<p>The requested Wish was not found.</p>
|
||||
<?php
|
||||
die();
|
||||
}
|
||||
*/
|
||||
|
||||
$page = new page(__FILE__, $wish->title);
|
||||
$page->header();
|
||||
$page->navigation();
|
||||
|
||||
$referer = '/?page=wishlists&wishlist=' . $wish->wishlist;
|
||||
?>
|
||||
|
||||
<main>
|
||||
<div class="ui container">
|
||||
<h1 class="ui header"><?= $page->title ?></h1>
|
||||
|
||||
<?= $page->messages($messages) ?>
|
||||
|
||||
<div class="ui segment">
|
||||
<form class="ui form" method="POST">
|
||||
<input type="hidden" name="wish_id" value="<?= $_GET['id'] ?>">
|
||||
|
||||
<div class="ui two column grid">
|
||||
|
||||
<div class="stackable row">
|
||||
<div class="column">
|
||||
<?php if ($wish->info->image) { ?>
|
||||
<img class="ui fluid rounded image" src="<?= $wish->info->image ?>" />
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="column">
|
||||
<div class="ui header">Options</div>
|
||||
|
||||
<a class="ui labeled icon button" href="<?= $wish->url ?>" target="_blank">
|
||||
<i class="external icon"></i>
|
||||
Visit
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="one column row">
|
||||
<div class="column">
|
||||
|
||||
<div class="field">
|
||||
<label>Title</label>
|
||||
|
||||
<div class="ui input">
|
||||
<input type="text"
|
||||
name="wish_title"
|
||||
placeholder="<?= $wish->title ?>"
|
||||
value="<?= $wish->title ?>"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label>Description</label>
|
||||
<textarea name="wish_description"
|
||||
placeholder="<?= $wish->description ?>"
|
||||
><?= $wish->description ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label>URL</label>
|
||||
|
||||
<div class="ui input">
|
||||
<input type="url"
|
||||
name="wish_url"
|
||||
placeholder="<?= $wish->url ?>"
|
||||
value="<?= $wish->url ?>"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input class="ui primary button" type="submit" value="Save" />
|
||||
<input class="ui button" type="reset" value="Reset" />
|
||||
<a class="ui secondary button" href="<?= $referer ?>">Cancel</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
$page->footer();
|
||||
?>
|
Loading…
Reference in a new issue