From a82221d2a5a086493ffe3e5948bbb502bdbc93a2 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Tue, 12 Feb 2019 13:20:47 -0800 Subject: [PATCH] Case 21118 - descending sorts don't work in new (qml) marketplace --- .../hifi/commerce/marketplace/Marketplace.qml | 40 ++++++---- .../hifi/commerce/marketplace/SortButton.qml | 76 ++++++++++--------- interface/src/commerce/QmlMarketplace.cpp | 8 +- interface/src/commerce/QmlMarketplace.h | 7 +- 4 files changed, 72 insertions(+), 59 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/marketplace/Marketplace.qml b/interface/resources/qml/hifi/commerce/marketplace/Marketplace.qml index 65fe35d4ee..cdb8368296 100644 --- a/interface/resources/qml/hifi/commerce/marketplace/Marketplace.qml +++ b/interface/resources/qml/hifi/commerce/marketplace/Marketplace.qml @@ -31,8 +31,9 @@ Rectangle { id: root property string activeView: "initialize" - property int currentSortIndex: 0 + property int currentSortIndex: 1 property string sortString: "recent" + property bool isAscending: false property string categoryString: "" property string searchString: "" property bool keyboardEnabled: HMD.active @@ -503,6 +504,7 @@ Rectangle { "", "", root.sortString, + root.isAscending, WalletScriptingInterface.limitedCommerce, marketBrowseModel.currentPageToRetrieve, marketBrowseModel.itemsPerPage @@ -731,7 +733,7 @@ Rectangle { top: parent.top leftMargin: 20 } - width: root.isLoggedIn ? 322 : 242 + width: root.isLoggedIn ? 342 : 262 height: 36 radius: 4 @@ -742,27 +744,27 @@ Rectangle { id: sortModel ListElement { - name: "Name"; - glyph: ";" + name: "Name" sortString: "alpha" + ascending: true } ListElement { - name: "Date"; - glyph: ";"; - sortString: "recent"; + name: "Date" + sortString: "recent" + ascending: false } ListElement { - name: "Popular"; - glyph: ";"; - sortString: "likes"; + name: "Popular" + sortString: "likes" + ascending: false } ListElement { - name: "My Likes"; - glyph: ";"; - sortString: "my_likes"; + name: "My Likes" + sortString: "my_likes" + ascending: false } } @@ -788,10 +790,10 @@ Rectangle { currentIndex: 1; delegate: SortButton { - width: 80 + width: 85 height: parent.height - glyph: model.glyph + ascending: model.ascending text: model.name visible: root.isLoggedIn || model.sortString != "my_likes" @@ -799,6 +801,12 @@ Rectangle { checked: ListView.isCurrentItem onClicked: { + if(root.currentSortIndex == index) { + ascending = !ascending; + } else { + ascending = model.ascending; + } + root.isAscending = ascending; root.currentSortIndex = index; sortListView.positionViewAtIndex(index, ListView.Beginning); sortListView.currentIndex = index; @@ -807,7 +815,7 @@ Rectangle { } } highlight: Rectangle { - width: 80 + width: 85 height: parent.height color: hifi.colors.faintGray diff --git a/interface/resources/qml/hifi/commerce/marketplace/SortButton.qml b/interface/resources/qml/hifi/commerce/marketplace/SortButton.qml index 37ad2735ce..e876842d89 100644 --- a/interface/resources/qml/hifi/commerce/marketplace/SortButton.qml +++ b/interface/resources/qml/hifi/commerce/marketplace/SortButton.qml @@ -28,58 +28,60 @@ Item { id: root; + property string ascGlyph: "\u2191" + property string descGlyph: "\u2193" + property string text: "" + property bool ascending: false + property bool checked: false + signal clicked() - property string glyph: ""; - property string text: ""; - property bool checked: false; - signal clicked(); - - width: childrenRect.width; - height: parent.height; + width: childrenRect.width + height: parent.height Rectangle { - anchors.top: parent.top; - anchors.left: parent.left; - height: parent.height; - width: 2; - color: hifi.colors.faintGray; - visible: index > 0; + anchors.top: parent.top + anchors.left: parent.left + height: parent.height + width: 2 + color: hifi.colors.faintGray + visible: index > 0 } - HiFiGlyphs { - id: buttonGlyph; - text: root.glyph; + RalewayRegular { + id: buttonGlyph + text: root.ascending ? root.ascGlyph : root.descGlyph // Size - size: 14; + size: 14 // Anchors - anchors.left: parent.left; - anchors.leftMargin: 0; - anchors.top: parent.top; - anchors.verticalCenter: parent.verticalCenter; - height: parent.height; - horizontalAlignment: Text.AlignHCenter; + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: parent.top + anchors.topMargin: 6 + anchors.bottom: parent.bottom + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignTop // Style - color: hifi.colors.lightGray; + color: hifi.colors.lightGray } RalewayRegular { - id: buttonText; - text: root.text; + id: buttonText + text: root.text // Text size - size: 14; + size: 14 // Style - color: hifi.colors.lightGray; - elide: Text.ElideRight; - horizontalAlignment: Text.AlignHCenter; - verticalAlignment: Text.AlignVCenter; + color: hifi.colors.lightGray + elide: Text.ElideRight + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter // Anchors - anchors.left: parent.left; - anchors.leftMargin: 20; - anchors.top: parent.top; - height: parent.height; + anchors.left: buttonGlyph.right + anchors.leftMargin: 5 + anchors.top: parent.top + height: parent.height } MouseArea { - anchors.fill: parent; - hoverEnabled: enabled; + anchors.fill: parent + hoverEnabled: enabled onClicked: { root.clicked(); } diff --git a/interface/src/commerce/QmlMarketplace.cpp b/interface/src/commerce/QmlMarketplace.cpp index 23ba418a2d..8197b20275 100644 --- a/interface/src/commerce/QmlMarketplace.cpp +++ b/interface/src/commerce/QmlMarketplace.cpp @@ -50,9 +50,10 @@ void QmlMarketplace::getMarketplaceItems( const QString& adminFilter, const QString& adminFilterCost, const QString& sort, - const bool isFree, - const int& page, - const int& perPage) { + bool isAscending, + bool isFree, + int page, + int perPage) { QString endpoint = "items"; QUrlQuery request; @@ -62,6 +63,7 @@ void QmlMarketplace::getMarketplaceItems( request.addQueryItem("adminFilter", adminFilter); request.addQueryItem("adminFilterCost", adminFilterCost); request.addQueryItem("sort", sort); + request.addQueryItem("sort_dir", isAscending ? "asc" : "desc"); if (isFree) { request.addQueryItem("isFree", "true"); } diff --git a/interface/src/commerce/QmlMarketplace.h b/interface/src/commerce/QmlMarketplace.h index 5794d4f53c..76b3d41449 100644 --- a/interface/src/commerce/QmlMarketplace.h +++ b/interface/src/commerce/QmlMarketplace.h @@ -46,9 +46,10 @@ protected: const QString& adminFilter = QString("published"), const QString& adminFilterCost = QString(), const QString& sort = QString(), - const bool isFree = false, - const int& page = 1, - const int& perPage = 20); + bool isAscending = false, + bool isFree = false, + int page = 1, + int perPage = 20); Q_INVOKABLE void getMarketplaceItem(const QString& marketplaceItemId); Q_INVOKABLE void marketplaceItemLike(const QString& marketplaceItemId, const bool like = true); Q_INVOKABLE void getMarketplaceCategories();