Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

feat: add filter and sort dashboard by subscription state

Miguel Ribeiroafff99287828
diff --git a/endpoints/subscriptions/get.php b/endpoints/subscriptions/get.php
index c721fd7..b6240fe 100644
--- a/endpoints/subscriptions/get.php
+++ b/endpoints/subscriptions/get.php
@@ -24,7 +24,7 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
$sql = "SELECT * FROM subscriptions ORDER BY next_payment ASC, inactive ASC";
if (isset($_COOKIE['sortOrder']) && $_COOKIE['sortOrder'] != "") {
$sort = $_COOKIE['sortOrder'];
- $allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id'];
+ $allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id', 'inactive'];
if ($sort == "price" || $sort == "id") {
$order = "DESC";
}
@@ -51,7 +51,18 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
$params[':member'] = $_GET['member'];
}
- $sql .= " ORDER BY $sort $order, inactive ASC";
+ if (isset($_GET['state']) && $_GET['state'] != "") {
+ $sql .= " AND inactive = :inactive";
+ $params[':inactive'] = $_GET['state'];
+ }
+
+ $sql .= " ORDER BY $sort $order";
+ if ($sort != "next_payment") {
+ $sql .= ", next_payment ASC";
+ }
+ if ($sort != "state") {
+ $sql .= ", inactive ASC";
+ }
$stmt = $db->prepare($sql);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
diff --git a/includes/i18n/de.php b/includes/i18n/de.php
index 3c8c8a5..36d7da9 100644
--- a/includes/i18n/de.php
+++ b/includes/i18n/de.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Erstes Abonnement hinzufügen",
'new_subscription' => "Neues Abonnement",
'search' => "Suche",
+ 'state' => "Status",
'sort' => "Sortieren",
'name' => "Bezeichnung",
'last_added' => "Zuletzt hinzugefügt",
diff --git a/includes/i18n/el.php b/includes/i18n/el.php
index 12e277a..622c7fa 100644
--- a/includes/i18n/el.php
+++ b/includes/i18n/el.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Προσθήκη πρώτης συνδρομής",
'new_subscription' => "Νέα συνδρομή",
'search' => "Αναζήτηση",
+ 'state' => "Κατάσταση",
'sort' => "Ταξινόμηση",
'name' => "Όνομα",
'last_added' => "Τελευταία προσθήκη",
diff --git a/includes/i18n/en.php b/includes/i18n/en.php
index a085be2..2f07022 100644
--- a/includes/i18n/en.php
+++ b/includes/i18n/en.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Add first subscription",
'new_subscription' => "New Subscription",
'search' => "Search",
+ 'state' => "State",
'sort' => "Sort",
'name' => "Name",
'last_added' => "Last Added",
diff --git a/includes/i18n/es.php b/includes/i18n/es.php
index bbd8828..06ac85f 100644
--- a/includes/i18n/es.php
+++ b/includes/i18n/es.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Añadir primera suscripción",
'new_subscription' => "Nueva Suscripción",
'search' => "Buscar",
+ 'state' => "Estado",
'sort' => "Ordenar",
'name' => "Nombre",
'last_added' => "Última Añadida",
diff --git a/includes/i18n/fr.php b/includes/i18n/fr.php
index 8d47de3..8b22561 100644
--- a/includes/i18n/fr.php
+++ b/includes/i18n/fr.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Ajoutez le premier abonnement",
'new_subscription' => "Nouvel abonnement",
'search' => "Rechercher",
+ 'state' => "État",
'sort' => "Trier",
'name' => "Nom",
'last_added' => "Dernier ajouté",
diff --git a/includes/i18n/it.php b/includes/i18n/it.php
index 42d00ff..127729f 100644
--- a/includes/i18n/it.php
+++ b/includes/i18n/it.php
@@ -44,6 +44,7 @@ $i18n = [
'add_first_subscription' => 'Aggiungo il tuo primo abbonamento',
'new_subscription' => 'Nuovo abbonamento',
'search' => 'Cerca',
+ 'state' => "Stato",
'sort' => 'Ordina',
'name' => 'Nome',
'last_added' => 'Ultimo aggiunto',
diff --git a/includes/i18n/jp.php b/includes/i18n/jp.php
index 88441f1..02afc4a 100644
--- a/includes/i18n/jp.php
+++ b/includes/i18n/jp.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "最初の定期購入を追加する",
'new_subscription' => "新しい定期購入",
'search' => "検索",
+ 'state' => "状態",
'sort' => "並べ替え",
'name' => "名前",
'last_added' => "最終追加日",
diff --git a/includes/i18n/ko.php b/includes/i18n/ko.php
index c58b2cb..d92deef 100644
--- a/includes/i18n/ko.php
+++ b/includes/i18n/ko.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "첫번째 구독을 추가하세요.",
'new_subscription' => "새 구독",
'search' => "검색",
+ 'state' => "상태",
'sort' => "정렬",
'name' => "이름",
'last_added' => "최근 등록",
diff --git a/includes/i18n/pl.php b/includes/i18n/pl.php
index 01c6aaf..e154eec 100644
--- a/includes/i18n/pl.php
+++ b/includes/i18n/pl.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Dodaj pierwszą subskrypcję",
'new_subscription' => "Nowa subskrypcja",
'search' => "Szukaj",
+ 'state' => "Stan",
'sort' => "Sortuj",
'name' => "Nazwa",
'last_added' => "Ostatnio dodane",
diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php
index 2072f3b..4268c10 100644
--- a/includes/i18n/pt.php
+++ b/includes/i18n/pt.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Adicionar primeira subscrição",
'new_subscription' => "Nova Subscrição",
'search' => "Pesquisar",
+ 'state' => "Estado",
'sort' => "Ordenar",
'name' => "Nome",
'last_added' => "Última Adicionada",
diff --git a/includes/i18n/pt_br.php b/includes/i18n/pt_br.php
index bf57bf7..a5e7feb 100644
--- a/includes/i18n/pt_br.php
+++ b/includes/i18n/pt_br.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Adicionar a primeira assinatura",
'new_subscription' => "Nova assinatura",
'search' => "Pesquisar",
+ 'state' => "Estado",
'sort' => "Ordenar",
'name' => "Nome",
'last_added' => "Última adicionada",
diff --git a/includes/i18n/ru.php b/includes/i18n/ru.php
index 0187f1a..73ce6a6 100644
--- a/includes/i18n/ru.php
+++ b/includes/i18n/ru.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Добавить первую подписку",
'new_subscription' => "Новая подписка",
'search' => "Поиск",
+ 'state' => "Состояние",
'sort' => "Сортировка",
'name' => "Имя",
'last_added' => "Дата создания",
diff --git a/includes/i18n/sl.php b/includes/i18n/sl.php
index 3bdaf27..5a63a6d 100644
--- a/includes/i18n/sl.php
+++ b/includes/i18n/sl.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Dodaj prvo naročnino",
'new_subscription' => "Nova naročnina",
'search' => "Iskanje",
+ 'state' => "Stanje",
'sort' => "Razvrsti",
'name' => "Ime",
'last_added' => "Zadnje dodano",
diff --git a/includes/i18n/sr.php b/includes/i18n/sr.php
index 34ee487..1166039 100644
--- a/includes/i18n/sr.php
+++ b/includes/i18n/sr.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Додајте прву претплату",
'new_subscription' => "Нова претплата",
'search' => "Претрага",
+ 'state' => "Статус",
'sort' => "Сортирај",
'name' => "Назив",
'last_added' => "Последње додато",
diff --git a/includes/i18n/sr_lat.php b/includes/i18n/sr_lat.php
index 601ffed..6eef424 100644
--- a/includes/i18n/sr_lat.php
+++ b/includes/i18n/sr_lat.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "Dodajte prvu pretplatu",
'new_subscription' => "Nova pretplata",
'search' => "Pretraga",
+ 'state' => "Stanje",
'sort' => "Sortiraj",
'name' => "Naziv",
'last_added' => "Poslednje dodato",
diff --git a/includes/i18n/tr.php b/includes/i18n/tr.php
index ddb1f48..f1d3f3c 100644
--- a/includes/i18n/tr.php
+++ b/includes/i18n/tr.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "İlk aboneliği ekle",
'new_subscription' => "Yeni Abonelik",
'search' => "Ara",
+ 'state' => "Durum",
'sort' => "Sırala",
'name' => "İsim",
'last_added' => "Son Eklenen",
diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php
index 5c398f0..abb4aaa 100644
--- a/includes/i18n/zh_cn.php
+++ b/includes/i18n/zh_cn.php
@@ -44,6 +44,7 @@ $i18n = [
"add_first_subscription" => "添加首个订阅",
'new_subscription' => "新订阅",
'search' => "搜索",
+ 'state' => "状态",
'sort' => "排序",
'name' => "名称",
'last_added' => "创建时间",
diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.php
index a40829d..3c7cee7 100644
--- a/includes/i18n/zh_tw.php
+++ b/includes/i18n/zh_tw.php
@@ -40,6 +40,7 @@ $i18n = [
"add_first_subscription" => "新增第一個訂閱",
'new_subscription' => "新訂閱",
'search' => "搜尋",
+ 'state' => "狀態",
'sort' => "排序",
'name' => "名稱",
'last_added' => "建立時間",
diff --git a/index.php b/index.php
index f9d5aec..2428fc5 100644
--- a/index.php
+++ b/index.php
@@ -8,13 +8,22 @@ $sort = "next_payment";
$sql = "SELECT * FROM subscriptions WHERE user_id = :userId ORDER BY next_payment ASC, inactive ASC";
if (isset($_COOKIE['sortOrder']) && $_COOKIE['sortOrder'] != "") {
$sort = $_COOKIE['sortOrder'];
- $allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id'];
+ $allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id', 'inactive'];
$order = "ASC";
if ($sort == "price" || $sort == "id") {
$order = "DESC";
}
- if (in_array($sort, $allowedSortCriteria)) {
- $sql = "SELECT * FROM subscriptions WHERE user_id = :userId ORDER BY $sort $order, inactive ASC";
+ if (!in_array($sort, $allowedSortCriteria)) {
+ $sort = "next_payment";
+ }
+
+ $sql = "SELECT * FROM subscriptions WHERE user_id = :userId";
+ $sql .= " ORDER BY $sort $order";
+ if ($sort != "next_payment") {
+ $sql .= ", next_payment ASC";
+ }
+ if ($sort != "inactive") {
+ $sql .= ", inactive ASC";
}
}
@@ -127,6 +136,13 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden
<?php
}
?>
+ <div class="filtermenu-submenu">
+ <div class="filter-title" onClick="toggleSubMenu('state')"><?= translate("state", $i18n) ?></div>
+ <div class="filtermenu-submenu-content" id="filter-state">
+ <div class="filter-item capitalize" data-state="0"><?= translate("enabled", $i18n) ?></div>
+ <div class="filter-item capitalize" data-state="1"><?= translate("disabled", $i18n) ?></div>
+ </div>
+ </div>
<div class="filtermenu-submenu hide" id="clear-filters">
<div class="filter-title filter-clear" onClick="clearFilters()">
<i class="fa-solid fa-times-circle"></i> <?= translate("clear", $i18n) ?>
@@ -159,6 +175,8 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden
id="sort-category_id"><?= translate('category', $i18n) ?></li>
<li <?= $sort == "payment_method_id" ? 'class="selected"' : "" ?> onClick="setSortOption('payment_method_id')"
id="sort-payment_method_id"><?= translate('payment_method', $i18n) ?></li>
+ <li <?= $sort == "inactive" ? 'class="selected"' : "" ?> onClick="setSortOption('inactive')"
+ id="sort-inactive"><?= translate('state', $i18n) ?></li>
</ul>
</div>
</div>
diff --git a/scripts/dashboard.js b/scripts/dashboard.js
index d5a98b0..828cfd9 100644
--- a/scripts/dashboard.js
+++ b/scripts/dashboard.js
@@ -301,6 +301,9 @@ function fetchSubscriptions() {
if (activeFilters['payment'] !== "") {
getSubscriptions += getSubscriptions.includes("?") ? `&payment=${activeFilters['payment']}` : `?payment=${activeFilters['payment']}`;
}
+ if (activeFilters['state'] !== "") {
+ getSubscriptions += getSubscriptions.includes("?") ? `&state=${activeFilters['state']}` : `?state=${activeFilters['state']}`;
+ }
fetch(getSubscriptions)
.then(response => response.text())
@@ -459,6 +462,7 @@ const activeFilters = [];
activeFilters['category'] = "";
activeFilters['member'] = "";
activeFilters['payment'] = "";
+activeFilters['state'] = "";
document.addEventListener("DOMContentLoaded", function () {
var filtermenu = document.querySelector('#filtermenu-button');
@@ -532,6 +536,18 @@ document.querySelectorAll('.filter-item').forEach(function (item) {
});
this.classList.add('selected');
}
+ } else if (this.hasAttribute('data-state')) {
+ const state = this.getAttribute('data-state');
+ if (activeFilters['state'] === state) {
+ activeFilters['state'] = "";
+ this.classList.remove('selected');
+ } else {
+ activeFilters['state'] = state;
+ Array.from(this.parentNode.children).forEach(sibling => {
+ sibling.classList.remove('selected');
+ });
+ this.classList.add('selected');
+ }
}
if (activeFilters['category'] !== "" || activeFilters['member'] !== "" || activeFilters['payment'] !== "") {