Add wish filter to shared wishlist

This commit is contained in:
Jay Trees 2022-04-07 13:44:14 +02:00
parent a364695dfc
commit 86201964b8
5 changed files with 111 additions and 82 deletions

View file

@ -0,0 +1,52 @@
$(function () {
/**
* Filter wishes
*/
$('.ui.dropdown.filter.priority')
.dropdown({
match : 'text',
fullTextSearch : true,
onChange : function() {
$(this).addClass('disabled loading');
var wishlist_id;
var wistlist_cards_data = $('.wishlist-cards').attr('data-wishlist')
var dropdown_wishlists = $('.dropdown.wishlists');
if (dropdown_wishlists.length) {
wishlist_id = $('.dropdown.wishlists').dropdown('get value');
}
if (typeof wistlist_cards_data !== 'undefined') {
wishlist_id = wistlist_cards_data;
}
if (!Number.isInteger(parseInt(wishlist_id))) {
$(this).removeClass('disabled loading');
return false;
}
var paramater = new URLSearchParams({
wishlist : wishlist_id,
priority : $(this).dropdown('get value'),
});
fetch('/src/api/wishlists.php?' + paramater, {
method : 'GET',
})
.then(handleFetchError)
.then(handleFetchResponse)
.then(function(response) {
var html = response.results ? response.results : '';
$('.wishlist-cards').html(html);
})
.finally(() => {
$(this).removeClass('disabled loading');
});
}
});
});

View file

@ -440,42 +440,4 @@ $(function () {
});
});
/**
* Filter wishes
*/
$('.ui.dropdown.filter.priority')
.dropdown({
match : 'text',
fullTextSearch : true,
onChange : function() {
$(this).addClass('disabled loading');
var wishlist_id = $('.dropdown.wishlists').dropdown('get value');
if (!Number.isInteger(parseInt(wishlist_id))) {
$(this).removeClass('disabled loading');
return false;
}
var paramater = new URLSearchParams({
wishlist : wishlist_id,
priority : $(this).dropdown('get value'),
});
fetch('/src/api/wishlists.php?' + paramater, {
method : 'GET',
})
.then(handleFetchError)
.then(handleFetchResponse)
.then(function(response) {
var html = response.results ? response.results : '';
$('.wishlist-cards').html(html);
})
.finally(() => {
$(this).removeClass('disabled loading');
});
}
});
});

View file

@ -0,0 +1,54 @@
<?php
/**
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
use wishthis\Wish;
$scriptPart = '/src/assets/js/parts/wishlist-filter.js';
?>
<script defer src="/src/assets/js/parts/wishlist-filter.js?m=<?= filemtime(ROOT . $scriptPart) ?>"></script>
<div>
<div class="ui small labeled icon basic white button floating dropdown filter priority">
<input type="hidden" name="filters" />
<i class="filter icon"></i>
<span class="text"><?= __('Filter priorities') ?></span>
<div class="menu">
<div class="ui icon search input">
<i class="search icon"></i>
<input type="text" placeholder="<?= __('Search priorities') ?>" />
</div>
<div class="divider"></div>
<div class="header">
<i class="filter icon"></i>
<?= __('Priorities') ?>
</div>
<div class="scrolling menu">
<div class="item" data-value="-1">
<i class="small circle icon"></i>
<?= __('All priorities') ?>
</div>
<div class="item" data-value="">
<i class="small circle outline icon"></i>
<?= __('No priority') ?>
</div>
<?php foreach (Wish::$priorities as $number => $priority) { ?>
<div class="item" data-value="<?= $number ?>">
<i class="small <?= $priority['color'] ?> circle icon"></i>
<?= $priority['name'] ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
<br />

View file

@ -60,7 +60,9 @@ $page->navigation();
<h2 class="ui header"><?= __('Wishes') ?></h2>
<div class="wishlist-cards">
<?php include 'parts/wishlist-filter.php' ?>
<div class="wishlist-cards" data-wishlist="<?= $wishlist->id ?>">
<?php
echo $wishlist->getCards(
array(

View file

@ -6,7 +6,7 @@
* @author Jay Trees <github.jay@grandel.anonaddy.me>
*/
use wishthis\{Page, User, Wishlist, Wish};
use wishthis\{Page, User, Wishlist};
$page = new Page(__FILE__, __('My lists'));
$page->header();
@ -96,48 +96,7 @@ $page->navigation();
</div>
</div>
<div>
<div class="ui small labeled icon basic white button floating dropdown filter priority">
<input type="hidden" name="filters" />
<i class="filter icon"></i>
<span class="text"><?= __('Filter priorities') ?></span>
<div class="menu">
<div class="ui icon search input">
<i class="search icon"></i>
<input type="text" placeholder="<?= __('Search priorities') ?>" />
</div>
<div class="divider"></div>
<div class="header">
<i class="filter icon"></i>
<?= __('Priorities') ?>
</div>
<div class="scrolling menu">
<div class="item" data-value="-1">
<i class="small circle icon"></i>
<?= __('All priorities') ?>
</div>
<div class="item" data-value="">
<i class="small circle outline icon"></i>
<?= __('No priority') ?>
</div>
<?php foreach (Wish::$priorities as $number => $priority) { ?>
<div class="item" data-value="<?= $number ?>">
<i class="small <?= $priority['color'] ?> circle icon"></i>
<?= $priority['name'] ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
<br />
<?php include 'parts/wishlist-filter.php' ?>
<div class="wishlist-cards"></div>
</div>