From 9c5d8cd67e9b0f79509a24e3339004d019f3d57d Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Thu, 1 Jun 2023 17:24:49 +0330 Subject: [PATCH 1/4] feat(com-pwa): admin sort --- .../com-pwa/src/ui/page/admin-order-list.ts | 23 +++++++++++++++---- .../src/ui/stuff/user-inc-order-box.ts | 16 ++++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/uniquely/com-pwa/src/ui/page/admin-order-list.ts b/uniquely/com-pwa/src/ui/page/admin-order-list.ts index 808b2ca5f..663da7b4e 100644 --- a/uniquely/com-pwa/src/ui/page/admin-order-list.ts +++ b/uniquely/com-pwa/src/ui/page/admin-order-list.ts @@ -9,7 +9,7 @@ import { state, ScheduleUpdateToFrameMixin, when, - mapObject, + mapIterable, type PropertyValues, } from '@alwatr/element'; import {message} from '@alwatr/i18n'; @@ -153,12 +153,25 @@ export class AlwatrPageAdminOrderList extends ScheduleUpdateToFrameMixin( private _render_usersList(): unknown { const userStorage = userListIncOrderStorageContextConsumer.getResponse(); this._logger.logMethodArgs?.('renderUsersList', {userStorage}); + if (userStorage == null) return; - return mapObject( + const orderStorageList = Object.values(userStorage.data).sort((u1, u2) => { + const lastU1Order = Object.values(u1.orderList).sort((o1, o2) => { + return (o1.meta?.updated || 0) - (o2.meta?.updated || 0); + })[0]; + + const lastU2Order = Object.values(u2.orderList).sort((o1, o2) => { + return (o1.meta?.updated || 0) - (o2.meta?.updated || 0); + })[0]; + + return (lastU2Order?.meta?.updated || 0) - (lastU1Order?.meta?.updated || 0); + }); + + return mapIterable( this, - userStorage?.data, - (user) => { - return html``; + orderStorageList, + (userIncOrder) => { + return html``; }, ); } diff --git a/uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts b/uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts index af7f3fc27..d07b8c748 100644 --- a/uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts +++ b/uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts @@ -5,7 +5,7 @@ import { css, customElement, html, - mapObject, + mapIterable, property, } from '@alwatr/element'; import {date, message} from '@alwatr/i18n'; @@ -103,19 +103,23 @@ export class alwatrUserIncOrderBox extends LocalizeMixin(SignalMixin(AlwatrBaseE } protected _renderOrderBox(): unknown { - let orderList; + let orderListTemplate; if (Object.keys(this.userIncOrder!.orderList).length === 0) { - orderList = html`${message('page_admin_order_list_empty_order_list')}`; + >`; } else { - orderList = mapObject(this, this.userIncOrder!.orderList, (order) => this._renderOrderInfo(order)); + const orderList = Object.values(this.userIncOrder!.orderList).sort((o1, o2) => { + return (o2.meta?.updated || 0) - (o1.meta?.updated || 0); + }); + + orderListTemplate = mapIterable(this, orderList, (order) => this._renderOrderInfo(order)); } return html`

${message('page_admin_order_list_order_list')}:

- ${orderList} + ${orderListTemplate} `; } From 3398aaefcf7200deb46b0b7cb282998dd3fe1c44 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Thu, 1 Jun 2023 17:37:33 +0330 Subject: [PATCH 2/4] fix(com-pwa): set receivePrevious: 'No' for button --- uniquely/com-pwa/src/ui/page/home.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uniquely/com-pwa/src/ui/page/home.ts b/uniquely/com-pwa/src/ui/page/home.ts index 3402c0ae4..288b02a28 100644 --- a/uniquely/com-pwa/src/ui/page/home.ts +++ b/uniquely/com-pwa/src/ui/page/home.ts @@ -62,7 +62,7 @@ export class AlwatrPageHome extends UnresolvedMixin(SignalMixin(AlwatrBaseElemen if (userProfileContextConsumer.getValue()?.permissions === 'root') { redirect({sectionList: ['admin-order-list']}); } - })); + }, {receivePrevious: 'No'})); this._addSignalListeners(homePageContentContextConsumer.subscribe((content) => { this.content = content; From f4050a3c37480a9e78f3e332bc7f4d27956b653e Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Thu, 1 Jun 2023 17:37:51 +0330 Subject: [PATCH 3/4] fix(com-pwa): admin sort --- uniquely/com-pwa/src/ui/page/admin-order-list.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uniquely/com-pwa/src/ui/page/admin-order-list.ts b/uniquely/com-pwa/src/ui/page/admin-order-list.ts index 663da7b4e..0757c1cee 100644 --- a/uniquely/com-pwa/src/ui/page/admin-order-list.ts +++ b/uniquely/com-pwa/src/ui/page/admin-order-list.ts @@ -157,11 +157,11 @@ export class AlwatrPageAdminOrderList extends ScheduleUpdateToFrameMixin( const orderStorageList = Object.values(userStorage.data).sort((u1, u2) => { const lastU1Order = Object.values(u1.orderList).sort((o1, o2) => { - return (o1.meta?.updated || 0) - (o2.meta?.updated || 0); + return (o2.meta?.updated || 0) - (o1.meta?.updated || 0); })[0]; const lastU2Order = Object.values(u2.orderList).sort((o1, o2) => { - return (o1.meta?.updated || 0) - (o2.meta?.updated || 0); + return (o2.meta?.updated || 0) - (o1.meta?.updated || 0); })[0]; return (lastU2Order?.meta?.updated || 0) - (lastU1Order?.meta?.updated || 0); From f68e3340850cf4362e213db490faa1a39031e24d Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Thu, 8 Jun 2023 17:56:22 +0330 Subject: [PATCH 4/4] refactor(com-pwa): use object.values --- uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts b/uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts index d07b8c748..f3802b825 100644 --- a/uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts +++ b/uniquely/com-pwa/src/ui/stuff/user-inc-order-box.ts @@ -104,13 +104,15 @@ export class alwatrUserIncOrderBox extends LocalizeMixin(SignalMixin(AlwatrBaseE protected _renderOrderBox(): unknown { let orderListTemplate; - if (Object.keys(this.userIncOrder!.orderList).length === 0) { - orderListTemplate = html`${message('page_admin_order_list_empty_order_list')}`; + const orderListValues = Object.values(this.userIncOrder?.orderList ?? {}); + if (orderListValues.length === 0) { + orderListTemplate = html` + + ${message('page_admin_order_list_empty_order_list')} + `; } else { - const orderList = Object.values(this.userIncOrder!.orderList).sort((o1, o2) => { + const orderList = orderListValues.sort((o1, o2) => { return (o2.meta?.updated || 0) - (o1.meta?.updated || 0); });