Browse Source

feat(www): add sort clients by name

pull/1227/head
Hoang Nè 2 years ago
parent
commit
09b593eac9
  1. 6
      src/www/index.html
  2. 19
      src/www/js/app.js
  3. 10
      src/www/js/i18n.js

6
src/www/index.html

@ -111,6 +111,12 @@
</svg> </svg>
<span class="max-md:hidden text-sm">{{$t("backup")}}</span> <span class="max-md:hidden text-sm">{{$t("backup")}}</span>
</a> </a>
<!-- Sort client -->
<button @click="sortClient = !sortClient;"
class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 max-md:border-l-0 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded-r-full md:rounded inline-flex items-center transition">
<span v-if="sortClient === false" class="max-md:hidden text-sm">{{$t("sort")}} ↑</span>
<span v-if="sortClient === true" class="max-md:hidden text-sm">{{$t("sort")}} ↓</span>
</button>
<!-- New client --> <!-- New client -->
<button @click="clientCreate = true; clientCreateName = '';" <button @click="clientCreate = true; clientCreateName = '';"
class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 max-md:border-l-0 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded-r-full md:rounded inline-flex items-center transition"> class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 dark:text-neutral-200 max-md:border-l-0 border-2 border-gray-100 dark:border-neutral-600 py-2 px-4 rounded-r-full md:rounded inline-flex items-center transition">

19
src/www/js/app.js

@ -23,6 +23,22 @@ function bytes(bytes, decimals, kib, maxunit) {
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`; return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
} }
/**
* Sorts an array of objects by a specified property in ascending or descending order.
*
* @param {Array} array - The array of objects to be sorted.
* @param {string} property - The property to sort the array by.
* @param {boolean} [sort=true] - Whether to sort the array in descending (default) or ascending order.
* @return {Array} - The sorted array of objects.
*/
function sortByProperty(array, property, sort = true) {
if (sort) {
return array.sort((a, b) => typeof a[property] === "string" ? a[property].localeCompare(b[property]) : a[property] - b[property]);
} else {
return array.sort((a, b) => typeof a[property] === "string" ? b[property].localeCompare(a[property]) : b[property] - a[property]);
}
}
const i18n = new VueI18n({ const i18n = new VueI18n({
locale: localStorage.getItem('lang') || 'en', locale: localStorage.getItem('lang') || 'en',
fallbackLocale: 'en', fallbackLocale: 'en',
@ -155,6 +171,8 @@ new Vue({
}, },
}, },
}, },
sortClient: true // Sort clients by name, true = desc, false = asc
}, },
methods: { methods: {
dateTime: (value) => { dateTime: (value) => {
@ -229,6 +247,7 @@ new Vue({
return client; return client;
}); });
this.clients = sortByProperty(this.clients, 'name', this.sortClient);
}, },
login(e) { login(e) {
e.preventDefault(); e.preventDefault();

10
src/www/js/i18n.js

@ -34,6 +34,7 @@ const messages = { // eslint-disable-line no-unused-vars
backup: 'Backup', backup: 'Backup',
titleRestoreConfig: 'Restore your configuration', titleRestoreConfig: 'Restore your configuration',
titleBackupConfig: 'Backup your configuration', titleBackupConfig: 'Backup your configuration',
sort: 'Sort',
}, },
ua: { ua: {
name: 'Ім`я', name: 'Ім`я',
@ -328,7 +329,7 @@ const messages = { // eslint-disable-line no-unused-vars
madeBy: '만든 사람', madeBy: '만든 사람',
donate: '기부', donate: '기부',
}, },
vi: { vi: { // https://github.com/hoangneeee
name: 'Tên', name: 'Tên',
password: 'Mật khẩu', password: 'Mật khẩu',
signIn: 'Đăng nhập', signIn: 'Đăng nhập',
@ -354,6 +355,13 @@ const messages = { // eslint-disable-line no-unused-vars
downloadConfig: 'Tải xuống cấu hình', downloadConfig: 'Tải xuống cấu hình',
madeBy: 'Được tạo bởi', madeBy: 'Được tạo bởi',
donate: 'Ủng hộ', donate: 'Ủng hộ',
toggleCharts: 'Mở/Ẩn Biểu đồ',
theme: { dark: 'Dark theme', light: 'Light theme', auto: 'Auto theme' },
restore: 'Khôi phục',
backup: 'Sao lưu',
titleRestoreConfig: 'Khôi phục cấu hình của bạn',
titleBackupConfig: 'Sao lưu cấu hình của bạn',
sort: 'Sắp xếp'
}, },
nl: { nl: {
name: 'Naam', name: 'Naam',

Loading…
Cancel
Save