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`, `wishlist`,
`title`, `title`,
`description`, `description`,
`url` `url`,
`priority`
) VALUES (' ) VALUES ('
. $_POST['wishlist_id'] . ', . $_POST['wishlist_id'] . ',
"' . trim($_POST['wish_title']) . '", "' . trim($_POST['wish_title']) . '",
"' . trim($_POST['wish_description']) . '", "' . 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 { .ui.dropdown .menu > a.item:hover {
color: rgba(0,0,0,.95); color: rgba(0,0,0,.95);
} }
/**
* Ribbon
*/
.ui.ribbon.label {
z-index: 2;
}

View file

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

View file

@ -10,6 +10,27 @@ namespace wishthis;
class Wish 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; private EmbedCache $cache;
public int $id; public int $id;
@ -18,6 +39,7 @@ class Wish
public ?string $description; public ?string $description;
public ?string $image; public ?string $image;
public ?string $url; public ?string $url;
public ?int $priority;
public ?string $status; public ?string $status;
public \stdClass $info; public \stdClass $info;
@ -82,6 +104,12 @@ class Wish
<div class="ui fluid card stretch" data-id="<?= $this->id ?>" data-cache="<?= $exists ?>"> <div class="ui fluid card stretch" data-id="<?= $this->id ?>" data-cache="<?= $exists ?>">
<div class="image"> <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) { ?> <?php if ($this->image) { ?>
<img class="preview" src="<?= $this->image ?>" loading="lazy" /> <img class="preview" src="<?= $this->image ?>" loading="lazy" />
<?php } ?> <?php } ?>

View file

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

View file

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