Rename products to wishes

This commit is contained in:
grandeljay 2022-02-26 21:36:50 +01:00
parent 9cbab6c929
commit 63d936acaf
14 changed files with 98 additions and 98 deletions

View file

@ -1,7 +1,7 @@
<?php
/**
* Generate cache for product
* Generate cache for wish
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
@ -17,7 +17,7 @@ require '../../index.php';
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$cache = new EmbedCache($_GET['product_url']);
$cache = new EmbedCache($_GET['wish_url']);
$info = $cache->get(true);
$response['success'] = true;

View file

@ -18,7 +18,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
if (isset($_GET['table'])) {
if ('all' === $_GET['table']) {
$tables = array(
'products',
'wishes',
'wishlists',
'users',
);

View file

@ -1,7 +1,7 @@
<?php
/**
* products.php
* wishes.php
*
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
@ -17,17 +17,17 @@ require '../../index.php';
switch ($_SERVER['REQUEST_METHOD']) {
case 'POST':
if (isset($_POST['wishlist_id'], $_POST['product_url'])) {
if (isset($_POST['wishlist_id'], $_POST['wish_url'])) {
/**
* Insert New Product
* Insert New Wish
*/
$database->query('INSERT INTO `products`
$database->query('INSERT INTO `wishes`
(
`wishlist`,
`url`
) VALUES ('
. $_POST['wishlist_id'] . ',
"' . $_POST['product_url'] . '"
"' . $_POST['wish_url'] . '"
)
;');
@ -41,23 +41,23 @@ switch ($_SERVER['REQUEST_METHOD']) {
case 'PUT':
parse_str(file_get_contents("php://input"), $_PUT);
if (isset($_PUT['productID'], $_PUT['productStatus'])) {
if (isset($_PUT['wish_id'], $_PUT['wish_status'])) {
/**
* Update Product Status
* Update Wish Status
*/
$database->query('UPDATE `products`
SET `status` = "' . $_PUT['productStatus'] . '"
WHERE `id` = ' . $_PUT['productID'] . '
$database->query('UPDATE `wishes`
SET `status` = "' . $_PUT['wish_status'] . '"
WHERE `id` = ' . $_PUT['wish_id'] . '
;');
$response['success'] = true;
} elseif (isset($_PUT['product_url_current'], $_PUT['product_url_proposed'])) {
} elseif (isset($_PUT['wish_url_current'], $_PUT['wish_url_proposed'])) {
/**
* Update Product URL
* Update Wish URL
*/
$database->query('UPDATE `products`
SET `url` = "' . $_PUT['product_url_proposed'] . '"
WHERE `url` = "' . $_PUT['product_url_current'] . '"
$database->query('UPDATE `wishes`
SET `url` = "' . $_PUT['wish_url_proposed'] . '"
WHERE `url` = "' . $_PUT['wish_url_current'] . '"
;');
$response['success'] = true;
@ -67,9 +67,9 @@ switch ($_SERVER['REQUEST_METHOD']) {
case 'DELETE':
parse_str(file_get_contents("php://input"), $_DELETE);
if (isset($_DELETE['productID'])) {
$database->query('DELETE FROM `products`
WHERE `id` = ' . $_DELETE['productID'] . '
if (isset($_DELETE['wish_id'])) {
$database->query('DELETE FROM `wishes`
WHERE `id` = ' . $_DELETE['wish_id'] . '
;');
$response['success'] = true;

View file

@ -20,8 +20,8 @@ $(function() {
$.fn.api.settings.api = {
'get wishlists' : '/src/api/wishlists.php',
'delete wishlist' : '/src/api/wishlists.php',
'update product status': '/src/api/products.php',
'delete product' : '/src/api/products.php',
'update wish status': '/src/api/wishes.php',
'delete wish' : '/src/api/wishes.php',
};
/** Default callbacks */

View file

@ -11,8 +11,8 @@ $(function() {
if (response.success) {
showStatistic(
$('#products .value'),
response.data.products.count,
$('#wishes .value'),
response.data.wishes.count,
0
);
showStatistic(

View file

@ -31,7 +31,7 @@ $(function() {
}
/**
* Commit to Product
* Commit to Wish
*/
$(document).on('click', '.ui.button.commit', function() {
var button = $(this);
@ -55,14 +55,14 @@ $(function() {
],
onApprove: function() {
/**
* Update product status
* Update wish status
*/
button.api({
action: 'update product status',
action: 'update wish status',
method: 'PUT',
data: {
productID: card.data('id'),
productStatus: 'unavailable'
wish_id: card.data('id'),
wish_status: 'unavailable'
},
on: 'now',
onSuccess: function(response, element, xhr) {

View file

@ -49,7 +49,7 @@ $(function () {
$('.wishlist-share').attr('href', '/?wishlist=' + wishlists[wishlistIndex].hash);
$('.button.wishlist-product-add').removeClass('disabled');
$('.button.wishlist-wish-add').removeClass('disabled');
$('.button.wishlist-share').removeClass('disabled');
$('.wishlist-delete button').removeClass('disabled');
@ -66,7 +66,7 @@ $(function () {
}
});
} else {
$('.button.wishlist-product-add').addClass('disabled');
$('.button.wishlist-wish-add').addClass('disabled');
$('.button.wishlist-share').addClass('disabled');
$('.wishlist-delete button').addClass('disabled');
}
@ -119,14 +119,14 @@ $(function () {
function generateCacheCard(card) {
card = $(card);
var href = card.find('.content [href]').prop('href');
var product_id = card.data('id');
var refresh = card.find('button.refresh');
var href = card.find('.content [href]').prop('href');
var wish_id = card.data('id');
var refresh = card.find('button.refresh');
card.addClass('loading');
card.attr('data-cache', true);
fetch('/src/api/cache.php?product_id=' + product_id + '&product_url=' + href, {
fetch('/src/api/cache.php?wish_id=' + wish_id + '&wish_url=' + href, {
method: 'GET'
})
.then(response => response.json())
@ -311,7 +311,7 @@ $(function () {
});
/**
* Delete Product
* Delete Wish
*/
$(document).on('click', '.ui.button.delete', function () {
var button = $(this);
@ -322,7 +322,7 @@ $(function () {
modalDefault
.modal({
title: 'Really delete?',
content: '<p>Would you really like to delete to this product? It will be gone forever.</p>',
content: '<p>Would you really like to delete to this wish? It will be gone forever.</p>',
class: 'tiny',
actions: [
{
@ -337,13 +337,13 @@ $(function () {
buttonApprove.addClass('loading');
/**
* Delete product
* Delete wish
*/
button.api({
action: 'delete product',
action: 'delete wish',
method: 'DELETE',
data: {
productID: card.data('id'),
wish_id: card.data('id'),
},
on: 'now',
onSuccess: function () {
@ -352,7 +352,7 @@ $(function () {
$('body').toast({
class: 'success',
showIcon: 'check',
message: 'Product successfully deleted.'
message: 'Wish successfully deleted.'
});
wishlistsRefresh();
@ -374,25 +374,25 @@ $(function () {
});
/**
* Add product
* Add wish
*/
$(document).on('click', '.button.wishlist-product-add', function () {
var modalWishlistProductAdd = $('.ui.modal.wishlist-product-add');
$(document).on('click', '.button.wishlist-wish-add', function () {
var modalWishlistWishAdd = $('.ui.modal.wishlist-wish-add');
modalWishlistProductAdd.find('[name="wishlist_id"]').val($('.ui.dropdown.wishlists').dropdown('get value'));
modalWishlistProductAdd.find('.primary.approve.button').addClass('disabled');
modalWishlistWishAdd.find('[name="wishlist_id"]').val($('.ui.dropdown.wishlists').dropdown('get value'));
modalWishlistWishAdd.find('.primary.approve.button').addClass('disabled');
modalWishlistProductAdd
modalWishlistWishAdd
.modal({
onApprove: function (button) {
button.addClass('loading');
var form = $('.ui.form.wishlist-product-fetch');
var form = $('.ui.form.wishlist-wish-fetch');
var formData = new URLSearchParams();
formData.append('wishlist_id', form.find('input[name="wishlist_id"]').val());
formData.append('product_url', form.find('input[name="product_url"]').val());
formData.append('wish_url', form.find('input[name="wish_url"]').val());
fetch('/src/api/products.php', {
fetch('/src/api/wishes.php', {
method: 'POST',
body: formData
})
@ -402,12 +402,12 @@ $(function () {
$('body').toast({
class: 'success',
showIcon: 'check',
message: 'Product successfully added.'
message: 'Wish successfully added.'
});
wishlistsRefresh();
modalWishlistProductAdd.modal('hide');
modalWishlistWishAdd.modal('hide');
}
button.removeClass('loading');
@ -420,20 +420,20 @@ $(function () {
});
/** Fetch */
$(document).on('submit', '.wishlist-product-fetch', function (event) {
$(document).on('submit', '.wishlist-wish-fetch', function (event) {
event.preventDefault();
var form = $(event.currentTarget);
var href = form.find('[name="product_url"]').val();
var href = form.find('[name="wish_url"]').val();
var elementModalAdd = $('.ui.modal.wishlist-product-add');
var elementModalAdd = $('.ui.modal.wishlist-wish-add');
var elementButtons = elementModalAdd.find('.actions .button');
var elementImage = elementModalAdd.find('.image img');
form.addClass('loading');
elementButtons.addClass('disabled');
fetch('/src/api/cache.php?product_url=' + href, {
fetch('/src/api/cache.php?wish_url=' + href, {
method: 'GET'
})
.then(response => response.json())
@ -452,7 +452,7 @@ $(function () {
* URL
*/
if (info.url && info.url !== href) {
var elementModalFetch = $('.ui.modal.wishlist-product-fetch');
var elementModalFetch = $('.ui.modal.wishlist-wish-fetch');
elementModalFetch.find('input.current').val(href);
elementModalFetch.find('input.proposed').val(info.url);
@ -465,12 +465,12 @@ $(function () {
closable: false,
onApprove: function (buttonFetch) {
var formData = new URLSearchParams();
formData.append('product_url_current', href);
formData.append('product_url_proposed', info.url);
formData.append('wish_url_current', href);
formData.append('wish_url_proposed', info.url);
buttonFetch.addClass('loading');
fetch('/src/api/products.php', {
fetch('/src/api/wishes.php', {
method: 'PUT',
body: formData
})

View file

@ -69,22 +69,22 @@ class User
}
/**
* Returns a list of products for a given wishlist.
* Returns a list of wishes for a given wishlist.
*
* @param int $wishlist
*
* @return array
*/
public function getProducts(int $wishlist): array
public function getWishes(int $wishlist): array
{
global $database;
$products = $database->query(
$wishes = $database->query(
'SELECT *
FROM products
FROM wishes
WHERE wishlist = ' . $wishlist . ';'
)->fetchAll();
return $products;
return $wishes;
}
}

View file

@ -14,7 +14,7 @@ class Wishlist
private string $hash;
public array $data;
public array $products = array();
public array $wishes = array();
public bool $exists = false;
@ -52,10 +52,10 @@ class Wishlist
}
/**
* Get Products
* Get Wishes
*/
$this->products = $database->query('SELECT *
FROM `products`
$this->wishes = $database->query('SELECT *
FROM `wishes`
WHERE `wishlist` = ' . $this->id . ';')
->fetchAll();
}
@ -70,11 +70,11 @@ class Wishlist
$exclude = isset($options['exclude']) ? $options['exclude'] : array();
if ($exclude) {
$products = array_filter($this->products, function ($product) use ($exclude) {
return !in_array($product['status'], $exclude);
$wishes = array_filter($this->wishes, function ($wish) use ($exclude) {
return !in_array($wish['status'], $exclude);
});
} else {
$products = $this->products;
$wishes = $this->wishes;
}
/**
@ -83,15 +83,15 @@ class Wishlist
$userIsCurrent = isset($_SESSION['user']) && $this->data['user'] === $_SESSION['user']['id'];
$cardIndex = 0;
if (!empty($products)) { ?>
if (!empty($wishes)) { ?>
<div class="ui three column doubling stackable grid">
<?php foreach ($products as $product) {
$cache = new EmbedCache($product['url']);
<?php foreach ($wishes as $wish) {
$cache = new EmbedCache($wish['url']);
$info = $cache->get(false);
$exists = $cache->exists() ? 'true' : 'false';
?>
<div class="column">
<div class="ui fluid card stretch" data-id="<?= $product['id'] ?>" data-index="<?= $cardIndex ?>" data-cache="<?= $exists ?>">
<div class="ui fluid card stretch" data-id="<?= $wish['id'] ?>" data-index="<?= $cardIndex ?>" data-cache="<?= $exists ?>">
<div class="overlay"></div>
<div class="image">

View file

@ -51,9 +51,9 @@ $page->navigation();
<div class="ui stackable statistics">
<div class="statistic" id="products">
<div class="statistic" id="wishes">
<div class="value">N. A.</div>
<div class="label">Products</div>
<div class="label">Wishes</div>
</div>
<div class="statistic" id="wishlists">

View file

@ -135,9 +135,9 @@ switch ($step) {
$database->query('CREATE INDEX `idx_hash` ON `wishlists` (`hash`);');
/**
* Products
* Wishes
*/
$database->query('CREATE TABLE `products` (
$database->query('CREATE TABLE `wishes` (
`id` int NOT NULL PRIMARY KEY AUTO_INCREMENT,
`wishlist` int NOT NULL,
`url` VARCHAR(255) NOT NULL,

View file

@ -80,7 +80,7 @@ if ('POST' === $_SERVER['REQUEST_METHOD']) {
/** Current version is below 0.3.0 */
if (-1 === version_compare($options->version, '0.3.0')) {
$database->query('ALTER TABLE `products`
$database->query('ALTER TABLE `wishes`
ADD `status` VARCHAR(32) NOT NULL AFTER `url`
;');
}

View file

@ -32,7 +32,7 @@ $page->navigation();
/**
* Warn the wishlist creator
*/
if (isset($user->id) && $user->id === intval($wishlist->data['user']) && !empty($wishlist->products)) { ?>
if (isset($user->id) && $user->id === intval($wishlist->data['user']) && !empty($wishlist->wishes)) { ?>
<div class="ui icon warning message wishlist-own">
<i class="exclamation triangle icon"></i>
<div class="content">
@ -42,7 +42,7 @@ $page->navigation();
<div class="text">
<p>
You are viewing your own wishlist!
You will be able to see which products have already been bought for you.
You will be able to see which wishes have already been bought for you.
Don't you want to be surprised?
</p>
<p>
@ -69,7 +69,7 @@ $page->navigation();
</div>
<div class="ui container">
<h2 class="ui header">Products</h2>
<h2 class="ui header">Wishes</h2>
<div class="wishlist-cards">
<?php

View file

@ -36,9 +36,9 @@ $page->navigation();
<div class="ui divider"></div>
<div class="flex">
<a class="ui small labeled icon button wishlist-product-add disabled">
<a class="ui small labeled icon button wishlist-wish-add disabled">
<i class="add icon"></i>
Add a product
Add a wish
</a>
<a class="ui small labeled icon button wishlist-share disabled" target="_blank">
@ -68,7 +68,7 @@ $page->navigation();
</div>
<h2 class="ui header">Products</h2>
<h2 class="ui header">Wishes</h2>
<div class="ui primary progress">
<div class="bar">
@ -122,25 +122,25 @@ $page->navigation();
</div>
</div>
<!-- Wishlist: Add a product -->
<div class="ui modal wishlist-product-add">
<!-- Wishlist: Add a wish -->
<div class="ui modal wishlist-wish-add">
<div class="header">
Add a product
Add a wish
</div>
<div class="image content">
<div class="ui medium image">
<img src="/src/assets/img/no-image.svg" loading="lazy" />
</div>
<div class="description">
<div class="ui header">Product</div>
<p>Fill out the below fields to add your new product.</p>
<div class="ui header">Wish</div>
<p>Fill out the below fields to add your new wish.</p>
<form class="ui form wishlist-product-fetch" method="post">
<form class="ui form wishlist-wish-fetch" method="post">
<input type="hidden" name="wishlist_id" />
<div class="field">
<label>URL</label>
<input type="url" name="product_url" />
<input type="url" name="wish_url" />
</div>
<input class="ui button" type="submit" value="Fetch" />
@ -157,14 +157,14 @@ $page->navigation();
</div>
</div>
<!-- Wishlist: Add a product (fetch) -->
<div class="ui small modal wishlist-product-fetch">
<!-- Wishlist: Add a wish (fetch) -->
<div class="ui small modal wishlist-wish-fetch">
<div class="header">
Incorrect URL
</div>
<div class="content">
<div class="description">
<div class="ui header">Product URLs</div>
<div class="ui header">Wish URLs</div>
<p>The URL you have entered does not seem quite right. Would you like to update it with the one I found?</p>
<div class="ui form urls">