Add wish priority

This commit is contained in:
Jay Trees 2022-03-07 11:36:51 +01:00
parent bce1eb9d6b
commit e57f0e239b
6 changed files with 113 additions and 32 deletions

View file

@ -57,12 +57,14 @@ switch ($_SERVER['REQUEST_METHOD']) {
`wishlist`,
`title`,
`description`,
`url`
`url`,
`priority`
) VALUES ('
. $_POST['wishlist_id'] . ',
"' . trim($_POST['wish_title']) . '",
"' . trim($_POST['wish_description']) . '",
"' . trim($_POST['wish_url']) . '"
"' . trim($_POST['wish_url']) . '",
' . trim($_POST['wish_priority']) . '
)
;');

View file

@ -267,3 +267,10 @@ p .ui.horizontal.label {
.ui.dropdown .menu > a.item:hover {
color: rgba(0,0,0,.95);
}
/**
* Ribbon
*/
.ui.ribbon.label {
z-index: 2;
}

View file

@ -147,4 +147,9 @@ $(function () {
.modal('show');
});
/**
* Priority
*/
$('.dropdown.priority').dropdown();
});

View file

@ -10,6 +10,27 @@ namespace wishthis;
class Wish
{
/**
* Static
*/
public static array $priorities = array(
'' => array(
'name' => 'Default',
'color' => '',
),
'1' => array(
'name' => 'Nice to have',
'color' => 'black',
),
'3' => array(
'name' => 'Must have',
'color' => 'orange',
),
);
/**
* Non-Static
*/
private EmbedCache $cache;
public int $id;
@ -18,6 +39,7 @@ class Wish
public ?string $description;
public ?string $image;
public ?string $url;
public ?int $priority;
public ?string $status;
public \stdClass $info;
@ -82,6 +104,12 @@ class Wish
<div class="ui fluid card stretch" data-id="<?= $this->id ?>" data-cache="<?= $exists ?>">
<div class="image">
<?php if ($this->priority && isset(Wish::$priorities[$this->priority])) { ?>
<div class="ui small <?= Wish::$priorities[$this->priority]['color'] ?> right ribbon label">
<?= Wish::$priorities[$this->priority]['name'] ?>
</div>
<?php } ?>
<?php if ($this->image) { ?>
<img class="preview" src="<?= $this->image ?>" loading="lazy" />
<?php } ?>

View file

@ -149,6 +149,7 @@ switch ($step) {
`description` TEXT NULL DEFAULT NULL,
`image` VARCHAR(255) NULL DEFAULT NULL,
`url` VARCHAR(255) NULL DEFAULT NULL,
`priority` TINEINT(1) NULL DEFAULT NULL,
`status` VARCHAR(32) NULL DEFAULT NULL,
FOREIGN KEY (`wishlist`)
REFERENCES `wishlists` (`id`)

View file

@ -14,12 +14,19 @@ $wish = new Wish($_GET['id'], false);
$page = new Page(__FILE__, $wish->title);
if ('POST' === $_SERVER['REQUEST_METHOD'] && count($_POST) >= 0) {
$wish_id = $_POST['wish_id'];
$wish_title = trim($_POST['wish_title']);
$wish_description = trim($_POST['wish_description']);
$wish_url = trim($_POST['wish_url']);
$wish_priority = $_POST['wish_priority'] ?: 'NULL';
$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']) . ';');
SET `title` = "' . $wish_title . '",
`description` = "' . $wish_description . '",
`url` = "' . $wish_url . '",
`priority` = ' . $wish_priority . '
WHERE `id` = ' . $wish_id . ';');
$wish = new Wish($_GET['id'], false);
$page = new Page(__FILE__, $wish->title);
@ -57,6 +64,36 @@ $referer = '/?page=wishlists&wishlist=' . $wish->wishlist;
<?= $page->messages() ?>
<div class="ui grid">
<div class="row">
<div class="sixteen wide column">
<?php if ($wish->image) { ?>
<img class="ui fluid rounded image preview" src="<?= $wish->image ?>" />
<?php } ?>
</div>
</div>
<div class="row">
<div class="sixteen wide column">
<a class="ui labeled icon button" href="<?= $wish->url ?>" target="_blank">
<i class="external icon"></i>
Visit
</a>
<button class="ui labeled icon button auto-fill disabled"
type="button"
>
<i class="redo icon"></i>
Auto-fill
</button>
</div>
</div>
</div>
<div class="ui segment">
<form class="ui form wish" method="POST">
<input type="hidden" name="wish_id" value="<?= $_GET['id'] ?>">
@ -64,32 +101,6 @@ $referer = '/?page=wishlists&wishlist=' . $wish->wishlist;
<div class="ui two column grid">
<div class="stackable row">
<div class="column">
<?php if ($wish->image) { ?>
<img class="ui fluid rounded image preview" src="<?= $wish->image ?>" />
<?php } ?>
</div>
<div class="column">
<div class="ui header">Options</div>
<div class="flex">
<a class="ui labeled icon button" href="<?= $wish->url ?>" target="_blank">
<i class="external icon"></i>
Visit
</a>
<button class="ui labeled icon button auto-fill disabled"
type="button"
>
<i class="redo icon"></i>
Auto-fill
</button>
</div>
</div>
</div>
<div class="one column row">
<div class="column">
<div class="field">
@ -107,11 +118,16 @@ $referer = '/?page=wishlists&wishlist=' . $wish->wishlist;
<div class="field">
<label>Description</label>
<textarea name="wish_description"
placeholder="<?= $wish->description ?>"
><?= $wish->description ?></textarea>
</div>
</div>
<div class="column">
<div class="field">
<label>URL</label>
@ -123,6 +139,28 @@ $referer = '/?page=wishlists&wishlist=' . $wish->wishlist;
/>
</div>
<div class="field">
<label>Priority</label>
<select class="ui selection clearable dropdown priority"
name="wish_priority"
>
<?php foreach (Wish::$priorities as $priority => $item) { ?>
<?php if ($wish->priority === $priority) { ?>
<option value="<?= $priority ?>" selected><?= $item['name'] ?></option>
<?php } else { ?>
<option value="<?= $priority ?>"><?= $item['name'] ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="stackable row">
<div class="sixteen wide column">
<input class="ui primary button" type="submit" value="Save" />
<input class="ui button" type="reset" value="Reset" />
<a class="ui secondary button" href="<?= $referer ?>">Back</a>