mirror of
https://github.com/overte-org/overte.git
synced 2025-06-15 06:46:24 +02:00
checkpoint
This commit is contained in:
parent
2f1ce2a2fc
commit
235971f8bf
7 changed files with 144 additions and 222 deletions
|
@ -44,7 +44,7 @@ Item {
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: avatarImage;
|
id: avatarImage;
|
||||||
visible: profileUrl !== "" && userName !== "";
|
visible: profilePicUrl !== "" && userName !== "";
|
||||||
// Size
|
// Size
|
||||||
anchors.verticalCenter: parent.verticalCenter;
|
anchors.verticalCenter: parent.verticalCenter;
|
||||||
anchors.left: parent.left;
|
anchors.left: parent.left;
|
||||||
|
|
|
@ -19,6 +19,7 @@ import "../../../../styles-uit"
|
||||||
import "../../../../controls-uit" as HifiControlsUit
|
import "../../../../controls-uit" as HifiControlsUit
|
||||||
import "../../../../controls" as HifiControls
|
import "../../../../controls" as HifiControls
|
||||||
import "../" as HifiCommerceCommon
|
import "../" as HifiCommerceCommon
|
||||||
|
import "../../../models" as HifiModels
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
HifiConstants { id: hifi; }
|
HifiConstants { id: hifi; }
|
||||||
|
@ -118,9 +119,7 @@ Item {
|
||||||
|
|
||||||
if (root.currentActiveView === 'chooseRecipientConnection') {
|
if (root.currentActiveView === 'chooseRecipientConnection') {
|
||||||
// Refresh connections model
|
// Refresh connections model
|
||||||
connectionsLoading.visible = false;
|
connectionsModel.getFirstPage();
|
||||||
connectionsLoading.visible = true;
|
|
||||||
sendSignalToParent({method: 'refreshConnections'});
|
|
||||||
} else if (root.currentActiveView === 'sendAssetHome') {
|
} else if (root.currentActiveView === 'sendAssetHome') {
|
||||||
Commerce.balance();
|
Commerce.balance();
|
||||||
} else if (root.currentActiveView === 'chooseRecipientNearby') {
|
} else if (root.currentActiveView === 'chooseRecipientNearby') {
|
||||||
|
@ -392,11 +391,15 @@ Item {
|
||||||
hoverEnabled: true;
|
hoverEnabled: true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
HifiModels.PSFListModel {
|
||||||
id: connectionsModel;
|
id: connectionsModel;
|
||||||
}
|
http: root.parent; // Misuse of "root" in this file!
|
||||||
ListModel {
|
endpoint: "/api/v1/users?per_page=400&filter=connections"; // FIXME per_page
|
||||||
id: filteredConnectionsModel;
|
processPage: function (data) {
|
||||||
|
console.log("HRS FIXME processPage", JSON.stringify(data));
|
||||||
|
return data.users;
|
||||||
|
//buildFilteredConnectionsModel();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
@ -495,6 +498,7 @@ Item {
|
||||||
|
|
||||||
AnimatedImage {
|
AnimatedImage {
|
||||||
id: connectionsLoading;
|
id: connectionsLoading;
|
||||||
|
visible: !connectionsModel.retrievedAtLeastOnePage;
|
||||||
source: "../../../../../icons/profilePicLoading.gif"
|
source: "../../../../../icons/profilePicLoading.gif"
|
||||||
width: 120;
|
width: 120;
|
||||||
height: width;
|
height: width;
|
||||||
|
@ -515,14 +519,14 @@ Item {
|
||||||
}
|
}
|
||||||
visible: !connectionsLoading.visible;
|
visible: !connectionsLoading.visible;
|
||||||
clip: true;
|
clip: true;
|
||||||
model: filteredConnectionsModel;
|
model: connectionsModel.model;
|
||||||
snapMode: ListView.SnapToItem;
|
snapMode: ListView.SnapToItem;
|
||||||
// Anchors
|
// Anchors
|
||||||
anchors.fill: parent;
|
anchors.fill: parent;
|
||||||
delegate: ConnectionItem {
|
delegate: ConnectionItem {
|
||||||
isSelected: connectionsList.currentIndex === index;
|
isSelected: connectionsList.currentIndex === index;
|
||||||
userName: model.userName;
|
userName: model.username;
|
||||||
profilePicUrl: model.profileUrl;
|
profilePicUrl: model.images.thumbnail;
|
||||||
anchors.topMargin: 6;
|
anchors.topMargin: 6;
|
||||||
anchors.bottomMargin: 6;
|
anchors.bottomMargin: 6;
|
||||||
|
|
||||||
|
@ -1806,13 +1810,6 @@ Item {
|
||||||
// FUNCTION DEFINITIONS START
|
// FUNCTION DEFINITIONS START
|
||||||
//
|
//
|
||||||
|
|
||||||
function updateConnections(connections) {
|
|
||||||
connectionsModel.clear();
|
|
||||||
connectionsModel.append(connections);
|
|
||||||
buildFilteredConnectionsModel();
|
|
||||||
connectionsLoading.visible = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildFilteredConnectionsModel() {
|
function buildFilteredConnectionsModel() {
|
||||||
filteredConnectionsModel.clear();
|
filteredConnectionsModel.clear();
|
||||||
for (var i = 0; i < connectionsModel.count; i++) {
|
for (var i = 0; i < connectionsModel.count; i++) {
|
||||||
|
|
|
@ -768,11 +768,32 @@ Rectangle {
|
||||||
case 'updateSelectedRecipientUsername':
|
case 'updateSelectedRecipientUsername':
|
||||||
sendMoney.fromScript(message);
|
sendMoney.fromScript(message);
|
||||||
break;
|
break;
|
||||||
|
case 'http.response':
|
||||||
|
handleHttpResponse(message);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.log('Unrecognized message from wallet.js:', JSON.stringify(message));
|
console.log('Unrecognized message from wallet.js:', JSON.stringify(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
signal sendToScript(var message);
|
signal sendToScript(var message);
|
||||||
|
property var httpCalls: ({});
|
||||||
|
property var httpCounter: 0;
|
||||||
|
function request(options, callback) {
|
||||||
|
console.debug('HRS FIXME Wallet request', JSON.stringify(options));
|
||||||
|
httpCalls[httpCounter] = callback;
|
||||||
|
var message = {method: 'http.request', params: options, id: httpCounter++, jsonrpc: "2.0"};
|
||||||
|
sendToScript(message);
|
||||||
|
}
|
||||||
|
function handleHttpResponse(message) {
|
||||||
|
var callback = httpCalls[message.id]; // FIXME: as different top level tablet apps gets loaded, the id repeats. We should drop old app callbacks without warning.
|
||||||
|
if (!callback) {
|
||||||
|
console.warn('No callback for', JSON.stringify(message));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete httpCalls[message.id];
|
||||||
|
console.log('HRS FIXME QML handling of', JSON.stringify(message));
|
||||||
|
callback(message.error, message.response);
|
||||||
|
}
|
||||||
|
|
||||||
// generateUUID() taken from:
|
// generateUUID() taken from:
|
||||||
// https://stackoverflow.com/a/8809472
|
// https://stackoverflow.com/a/8809472
|
||||||
|
|
|
@ -24,12 +24,9 @@ Item {
|
||||||
HifiConstants { id: hifi; }
|
HifiConstants { id: hifi; }
|
||||||
|
|
||||||
id: root;
|
id: root;
|
||||||
property bool initialResultReceived: false;
|
|
||||||
property int pendingCount: 0;
|
|
||||||
|
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
transactionHistoryModel.clear();
|
|
||||||
Commerce.balance();
|
Commerce.balance();
|
||||||
transactionHistoryModel.getFirstPage();
|
transactionHistoryModel.getFirstPage();
|
||||||
Commerce.getAvailableUpdates();
|
Commerce.getAvailableUpdates();
|
||||||
|
@ -46,7 +43,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
onHistoryResult : {
|
onHistoryResult : {
|
||||||
transactionHistoryModel.pageRetrieved(result);
|
transactionHistoryModel.handlePage(null, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
onAvailableUpdatesResult: {
|
onAvailableUpdatesResult: {
|
||||||
|
@ -61,7 +58,7 @@ Item {
|
||||||
Connections {
|
Connections {
|
||||||
target: GlobalServices
|
target: GlobalServices
|
||||||
onMyUsernameChanged: {
|
onMyUsernameChanged: {
|
||||||
transactionHistoryModel.clear();
|
transactionHistoryModel.resetModel();
|
||||||
usernameText.text = Account.username;
|
usernameText.text = Account.username;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,8 +147,7 @@ Item {
|
||||||
if (transactionHistory.atYBeginning) {
|
if (transactionHistory.atYBeginning) {
|
||||||
console.log("Refreshing 1st Page of Recent Activity...");
|
console.log("Refreshing 1st Page of Recent Activity...");
|
||||||
Commerce.balance();
|
Commerce.balance();
|
||||||
transactionHistoryModel.currentPageToRetrieve = 1;
|
transactionHistoryModel.getFirstPage();
|
||||||
transactionHistoryModel.getPage();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,22 +214,34 @@ Item {
|
||||||
|
|
||||||
listModelName: "transaction history";
|
listModelName: "transaction history";
|
||||||
itemsPerPage: 100;
|
itemsPerPage: 100;
|
||||||
getPage: function() {
|
getPage: function () {
|
||||||
transactionHistoryModel.requestPending = true;
|
console.log('HRS FIXME WalletHome getPage', transactionHistoryModel.currentPageToRetrieve, transactionHistoryModel.itemsPerPage);
|
||||||
Commerce.history(transactionHistoryModel.currentPageToRetrieve, transactionHistoryModel.itemsPerPage);
|
Commerce.history(transactionHistoryModel.currentPageToRetrieve, transactionHistoryModel.itemsPerPage);
|
||||||
}
|
}
|
||||||
pageRetrieved: function(result) {
|
processPage: function (data) {
|
||||||
transactionHistoryModel.processResult(result.status, result.data.history);
|
console.log('HRS FIXME WalletHome processPage', JSON.stringify(data));
|
||||||
|
var result, pending;
|
||||||
if (!transactionHistoryModel.noMoreDataToRetrieve) {
|
if (transactionHistoryModel.currentPageToRetrieve == 1) {
|
||||||
calculatePendingAndInvalidated();
|
pending = {transaction_type: "pendingCount", count: 0};
|
||||||
|
result = [pending];
|
||||||
|
} else {
|
||||||
|
pending = transactionHistoryModel.get(0);
|
||||||
|
result = [];
|
||||||
}
|
}
|
||||||
|
data.history.forEach(function (item) {
|
||||||
|
if (item.status === 'pending') {
|
||||||
|
pending.count++;
|
||||||
|
} else {
|
||||||
|
result = result.concat(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Only auto-refresh if the user hasn't scrolled
|
// Only auto-refresh if the user hasn't scrolled
|
||||||
// and there is more data to grab
|
// and there is more data to grab
|
||||||
if (transactionHistory.atYBeginning && !transactionHistoryModel.noMoreDataToRetrieve) {
|
if (transactionHistory.atYBeginning && data.history.length && transactionHistoryModel.currentPageToRetrieve >= 0) {
|
||||||
refreshTimer.start();
|
refreshTimer.start();
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Item {
|
Item {
|
||||||
|
@ -243,8 +251,8 @@ Item {
|
||||||
anchors.left: parent.left;
|
anchors.left: parent.left;
|
||||||
anchors.right: parent.right;
|
anchors.right: parent.right;
|
||||||
|
|
||||||
Item {
|
Item { // On empty history. We don't want to flash and then replace, so don't show until we know we're zero.
|
||||||
visible: transactionHistoryModel.count === 0 && transactionHistoryModel.initialResultReceived;
|
visible: transactionHistoryModel.count === 0 && transactionHistoryModel.currentPageToRetrieve < 0;
|
||||||
anchors.centerIn: parent;
|
anchors.centerIn: parent;
|
||||||
width: parent.width - 12;
|
width: parent.width - 12;
|
||||||
height: parent.height;
|
height: parent.height;
|
||||||
|
@ -316,10 +324,10 @@ Item {
|
||||||
model: transactionHistoryModel.model;
|
model: transactionHistoryModel.model;
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
width: parent.width;
|
width: parent.width;
|
||||||
height: (model.transaction_type === "pendingCount" && root.pendingCount !== 0) ? 40 : ((model.status === "confirmed" || model.status === "invalidated") ? transactionText.height + 30 : 0);
|
height: (model.transaction_type === "pendingCount" && model.count !== 0) ? 40 : ((model.status === "confirmed" || model.status === "invalidated") ? transactionText.height + 30 : 0);
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
visible: model.transaction_type === "pendingCount" && root.pendingCount !== 0;
|
visible: model.transaction_type === "pendingCount" && model.count !== 0;
|
||||||
anchors.top: parent.top;
|
anchors.top: parent.top;
|
||||||
anchors.left: parent.left;
|
anchors.left: parent.left;
|
||||||
width: parent.width;
|
width: parent.width;
|
||||||
|
@ -328,7 +336,7 @@ Item {
|
||||||
AnonymousProRegular {
|
AnonymousProRegular {
|
||||||
id: pendingCountText;
|
id: pendingCountText;
|
||||||
anchors.fill: parent;
|
anchors.fill: parent;
|
||||||
text: root.pendingCount + ' Transaction' + (root.pendingCount > 1 ? 's' : '') + ' Pending';
|
text: model.count + ' Transaction' + (model.count > 1 ? 's' : '') + ' Pending';
|
||||||
size: 18;
|
size: 18;
|
||||||
color: hifi.colors.blueAccent;
|
color: hifi.colors.blueAccent;
|
||||||
verticalAlignment: Text.AlignVCenter;
|
verticalAlignment: Text.AlignVCenter;
|
||||||
|
@ -432,21 +440,6 @@ Item {
|
||||||
return year + '-' + month + '-' + day + '<br>' + drawnHour + ':' + min + amOrPm;
|
return year + '-' + month + '-' + day + '<br>' + drawnHour + ':' + min + amOrPm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function calculatePendingAndInvalidated(startingPendingCount) {
|
|
||||||
var pendingCount = startingPendingCount ? startingPendingCount : 0;
|
|
||||||
for (var i = 0; i < transactionHistoryModel.count; i++) {
|
|
||||||
if (transactionHistoryModel.get(i).status === "pending") {
|
|
||||||
pendingCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
root.pendingCount = pendingCount;
|
|
||||||
if (pendingCount > 0) {
|
|
||||||
transactionHistoryModel.insert(0, {"transaction_type": "pendingCount"});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Function Name: fromScript()
|
// Function Name: fromScript()
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,102 +18,96 @@
|
||||||
import QtQuick 2.7
|
import QtQuick 2.7
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root;
|
|
||||||
|
|
||||||
// Used when printing debug statements
|
// Used when printing debug statements
|
||||||
property string listModelName: "";
|
property string listModelName: endpoint;
|
||||||
|
|
||||||
// Holds the value of the page that'll be retrieved the next time `getPage()` is called
|
// Parameters. Even if you override getPage, below, please set these for clarity and consistency, when applicable.
|
||||||
property int currentPageToRetrieve: 1;
|
// E.g., your getPage function could refer to this sortKey, etc.
|
||||||
|
|
||||||
// If defined, the endpoint that `getPage()` will hit (as long as there isn't a custom `getPage()`
|
|
||||||
// that does something fancy)
|
|
||||||
property string endpoint;
|
property string endpoint;
|
||||||
// If defined, the sort key used when calling the above endpoint.
|
|
||||||
// (as long as there isn't a custom `getPage()` that does something fancy)
|
|
||||||
property string sortKey;
|
property string sortKey;
|
||||||
// If defined, the search filter used when calling the above endpoint.
|
|
||||||
// (as long as there isn't a custom `getPage()` that does something fancy)
|
|
||||||
property string searchFilter;
|
property string searchFilter;
|
||||||
// If defined, the tags filter used when calling the above endpoint.
|
|
||||||
// (as long as there isn't a custom `getPage()` that does something fancy)
|
|
||||||
property string tagsFilter;
|
property string tagsFilter;
|
||||||
// The number of items that'll be retrieved per page when calling `getPage()`
|
onEndpointChanged: getFirstPage();
|
||||||
// (as long as there isn't a custom `getPage()` that does something fancy)
|
onSortKeyChanged: getFirstPage();
|
||||||
|
onSearchFilterChanged: getFirstPage();
|
||||||
|
onTagsFilterChanged: getFirstPage();
|
||||||
property int itemsPerPage: 100;
|
property int itemsPerPage: 100;
|
||||||
|
|
||||||
// This function, by default, will retrieve data from the above-defined `endpoint` with the
|
// State.
|
||||||
// sort and filter data as set above. It can be custom-defined by this item's Parent.
|
property int currentPageToRetrieve: 0; // 0 = before first page. -1 = we have them all. Otherwise 1-based page number.
|
||||||
property var getPage: function() {
|
property bool retrievedAtLeastOnePage: false;
|
||||||
// Put code here that calls the `endpoint` with the proper `sortKey`, `searchFilter`, and `tagsFilter`.
|
|
||||||
// Whatever code goes here should define the below `pageRetrieved()` as
|
|
||||||
// the callback for after the page is asynchronously retrieved.
|
|
||||||
|
|
||||||
// The parent of this Item can also define custom `getPage()` and `pageRetrieved()` functions.
|
|
||||||
// See `WalletHome.qml` as an example of a file that does this. `WalletHome.qml` must use that method because
|
|
||||||
// it hits an endpoint that must be authenticated via the Wallet.
|
|
||||||
console.log("default getPage()");
|
|
||||||
}
|
|
||||||
// This function, by default, will handle the data retrieved using `getPage()` above.
|
|
||||||
// It can be custom-defined by this item's Parent.
|
|
||||||
property var pageRetrieved: function() {
|
|
||||||
console.log("default pageRetrieved()");
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function, by default, will get the _next_ page of data according to `getPage()` if there
|
|
||||||
// isn't a pending request and if there's more data to retrieve.
|
|
||||||
// It can be custom-defined by this item's Parent.
|
|
||||||
property var getNextPage: function() {
|
|
||||||
if (!root.requestPending && !root.noMoreDataToRetrieve) {
|
|
||||||
root.requestPending = true;
|
|
||||||
root.currentPageToRetrieve++;
|
|
||||||
root.getPage();
|
|
||||||
console.log("Fetching Page " + root.currentPageToRetrieve + " of " + root.listModelName + "...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// A helper function used to get the first page from the server.
|
|
||||||
// It can be custom-defined by this item's Parent.
|
|
||||||
property var getFirstPage: function() {
|
|
||||||
root.initialResultReceived = false;
|
|
||||||
root.currentPageToRetrieve = 1;
|
|
||||||
root.noMoreDataToRetrieve = false;
|
|
||||||
root.getPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resets both internal `ListModel`s and resets the page to retrieve to "1".
|
// Resets both internal `ListModel`s and resets the page to retrieve to "1".
|
||||||
function resetModel() {
|
function resetModel() {
|
||||||
pagesAlreadyAdded = new Array();
|
|
||||||
tempModel.clear();
|
tempModel.clear();
|
||||||
finalModel.clear();
|
finalModel.clear();
|
||||||
root.currentPageToRetrieve = 1;
|
currentPageToRetrieve = 1;
|
||||||
|
retrievedAtLeastOnePage = false
|
||||||
}
|
}
|
||||||
|
|
||||||
onEndpointChanged: {
|
// Processing one page.
|
||||||
|
|
||||||
|
// Override to return one property of data, and/or to transform the elements. Must return an array of model elements.
|
||||||
|
property var processPage: function (data) { return data; }
|
||||||
|
|
||||||
|
// Check consistency and call processPage.
|
||||||
|
function handlePage(error, response) {
|
||||||
|
console.log("HRS FIXME got", endpoint, error, JSON.stringify(response));
|
||||||
|
function fail(message) {
|
||||||
|
console.warn("Warning", listModelName, JSON.stringify(message));
|
||||||
|
current_page_to_retrieve = -1;
|
||||||
|
requestPending = false;
|
||||||
|
}
|
||||||
|
if (error || (response.status !== 'success')) {
|
||||||
|
return fail(error || response.status);
|
||||||
|
}
|
||||||
|
if (!requestPending) {
|
||||||
|
return fail("No request in flight.");
|
||||||
|
}
|
||||||
|
requestPending = false;
|
||||||
|
if (response.current_page && response.current_page !== currentPageToRetrieve) { // Not all endpoints specify this property.
|
||||||
|
return fail("Mismatched page, expected:" + currentPageToRetrieve);
|
||||||
|
}
|
||||||
|
finalModel.append(processPage(response.data || response)); // FIXME keep index steady, and apply any post sort/filter
|
||||||
|
retrievedAtLeastOnePage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override either http or getPage.
|
||||||
|
property var http: null; // An Item that has a request function.
|
||||||
|
property var getPage: function () { // Any override MUST call handlePage(), above, even if results empty.
|
||||||
|
if (!http) { return console.warn("Neither http nor getPage was set in", listModelName); }
|
||||||
|
var url = /^\//.test(endpoint) ? (Account.metaverseServerURL + endpoint) : endpoint;
|
||||||
|
// FIXME: handle sort and search parameters, and per_page and page parameters
|
||||||
|
console.log("HRS FIXME requesting", url);
|
||||||
|
http.request({uri: url}, handlePage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the show by retrieving data according to `getPage()`.
|
||||||
|
// It can be custom-defined by this item's Parent.
|
||||||
|
property var getFirstPage: function () {
|
||||||
resetModel();
|
resetModel();
|
||||||
root.getFirstPage();
|
requestPending = true;
|
||||||
|
getPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSortKeyChanged: {
|
property bool requestPending: false; // For de-bouncing getNextPage.
|
||||||
resetModel();
|
// This function, will get the _next_ page of data according to `getPage()`.
|
||||||
root.getFirstPage();
|
// It can be custom-defined by this item's Parent. Typical usage:
|
||||||
|
// ListView {
|
||||||
|
// id: theList
|
||||||
|
// model: thisPSFListModelId
|
||||||
|
// onAtYEndChanged: if (theList.atYEnd) { thisPSFListModelId.getNextPage(); }
|
||||||
|
// ...}
|
||||||
|
property var getNextPage: function () {
|
||||||
|
if (requestPending || currentPageToRetrieve < 0) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("HRS FIXME Fetching Page " + currentPageToRetrieve + " of " + listModelName + "...");
|
||||||
onSearchFilterChanged: {
|
currentPageToRetrieve++;
|
||||||
resetModel();
|
requestPending = true;
|
||||||
root.getFirstPage();
|
getPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
onTagsFilterChanged: {
|
|
||||||
resetModel();
|
|
||||||
root.getFirstPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
property bool initialResultReceived: false;
|
|
||||||
property bool requestPending: false;
|
|
||||||
property bool noMoreDataToRetrieve: false;
|
|
||||||
property var pagesAlreadyAdded: new Array();
|
|
||||||
|
|
||||||
// Redefining members and methods so that the parent of this Item
|
// Redefining members and methods so that the parent of this Item
|
||||||
// can use PSFListModel as they would a regular ListModel
|
// can use PSFListModel as they would a regular ListModel
|
||||||
property alias model: finalModel;
|
property alias model: finalModel;
|
||||||
|
@ -123,6 +117,8 @@ Item {
|
||||||
function remove(index) { return finalModel.remove(index); }
|
function remove(index) { return finalModel.remove(index); }
|
||||||
function setProperty(index, prop, value) { return finalModel.setProperty(index, prop, value); }
|
function setProperty(index, prop, value) { return finalModel.setProperty(index, prop, value); }
|
||||||
function move(from, to, n) { return finalModel.move(from, to, n); }
|
function move(from, to, n) { return finalModel.move(from, to, n); }
|
||||||
|
function insert(index, newElement) { finalModel.insert(index, newElement); }
|
||||||
|
function append(newElements) { finalModel.append(newElements); }
|
||||||
|
|
||||||
// Used while processing page data and sorting
|
// Used while processing page data and sorting
|
||||||
ListModel {
|
ListModel {
|
||||||
|
@ -134,97 +130,6 @@ Item {
|
||||||
id: finalModel;
|
id: finalModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
function processResult(status, retrievedResult) {
|
|
||||||
root.initialResultReceived = true;
|
|
||||||
root.requestPending = false;
|
|
||||||
|
|
||||||
if (status === 'success') {
|
|
||||||
var currentPage = parseInt(retrievedResult.current_page);
|
|
||||||
|
|
||||||
if (retrievedResult.length === 0) {
|
|
||||||
root.noMoreDataToRetrieve = true;
|
|
||||||
console.log("No more data to retrieve from backend endpoint.")
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
See FIXME below...
|
|
||||||
|
|
||||||
else if (root.currentPageToRetrieve === 1) {
|
|
||||||
var sameItemCount = 0;
|
|
||||||
|
|
||||||
tempModel.clear();
|
|
||||||
tempModel.append(retrievedResult);
|
|
||||||
|
|
||||||
for (var i = 0; i < tempModel.count; i++) {
|
|
||||||
if (!finalModel.get(i)) {
|
|
||||||
sameItemCount = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Gotta think of a generic way to determine if the data we just got is the same
|
|
||||||
// as the data that we already have in the model.
|
|
||||||
else if (tempModel.get(i).transaction_type === finalModel.get(i).transaction_type &&
|
|
||||||
tempModel.get(i).text === finalModel.get(i).text) {
|
|
||||||
sameItemCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sameItemCount !== tempModel.count) {
|
|
||||||
finalModel.clear();
|
|
||||||
for (var i = 0; i < tempModel.count; i++) {
|
|
||||||
finalModel.append(tempModel.get(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
else {
|
|
||||||
// FIXME! Reconsider this logic, because it means that auto-refreshing the first page of results
|
|
||||||
// (like we do in WalletHome for Recent Activity) _won't_ catch brand new data elements!
|
|
||||||
// See the commented code above for how I did this for WalletHome specifically.
|
|
||||||
if (root.pagesAlreadyAdded.indexOf(currentPage) !== -1) {
|
|
||||||
console.log("Page " + currentPage + " of paginated data has already been added to the list.");
|
|
||||||
} else {
|
|
||||||
// First, add the result to a temporary model
|
|
||||||
tempModel.clear();
|
|
||||||
tempModel.append(retrievedResult);
|
|
||||||
|
|
||||||
// Make a note that we've already added this page to the model...
|
|
||||||
root.pagesAlreadyAdded.push(currentPage);
|
|
||||||
|
|
||||||
var insertionIndex = 0;
|
|
||||||
// If there's nothing in the model right now, we don't need to modify insertionIndex.
|
|
||||||
if (finalModel.count !== 0) {
|
|
||||||
var currentIteratorPage;
|
|
||||||
// Search through the whole model and look for the insertion point.
|
|
||||||
// The insertion point is found when the result page from the server is less than
|
|
||||||
// the page that the current item came from, OR when we've reached the end of the whole model.
|
|
||||||
for (var i = 0; i < finalModel.count; i++) {
|
|
||||||
currentIteratorPage = finalModel.get(i).resultIsFromPage;
|
|
||||||
|
|
||||||
if (currentPage < currentIteratorPage) {
|
|
||||||
insertionIndex = i;
|
|
||||||
break;
|
|
||||||
} else if (i === finalModel.count - 1) {
|
|
||||||
insertionIndex = i + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go through the results we just got back from the server, setting the "resultIsFromPage"
|
|
||||||
// property of those results and adding them to the main model.
|
|
||||||
// NOTE that this wouldn't be necessary if we did this step (or a similar step) on the server.
|
|
||||||
for (var i = 0; i < tempModel.count; i++) {
|
|
||||||
tempModel.setProperty(i, "resultIsFromPage", currentPage);
|
|
||||||
finalModel.insert(i + insertionIndex, tempModel.get(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
console.log("Failed to get page result for " + root.listModelName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used when sorting model data on the CLIENT
|
// Used when sorting model data on the CLIENT
|
||||||
// Right now, there is no sorting done on the client for
|
// Right now, there is no sorting done on the client for
|
||||||
|
|
|
@ -511,6 +511,9 @@
|
||||||
case 'wallet_availableUpdatesReceived':
|
case 'wallet_availableUpdatesReceived':
|
||||||
// NOP
|
// NOP
|
||||||
break;
|
break;
|
||||||
|
case 'http.request':
|
||||||
|
// Handled elsewhere, don't log.
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print('Unrecognized message from QML:', JSON.stringify(message));
|
print('Unrecognized message from QML:', JSON.stringify(message));
|
||||||
}
|
}
|
||||||
|
|
|
@ -988,6 +988,9 @@ var selectionDisplay = null; // for gridTool.js to ignore
|
||||||
sendAssetParticleEffectUpdateTimer = Script.setInterval(updateSendAssetParticleEffect, SEND_ASSET_PARTICLE_TIMER_UPDATE);
|
sendAssetParticleEffectUpdateTimer = Script.setInterval(updateSendAssetParticleEffect, SEND_ASSET_PARTICLE_TIMER_UPDATE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'http.request':
|
||||||
|
// Handled elsewhere, don't log.
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print('Unrecognized message from Checkout.qml or Purchases.qml: ' + JSON.stringify(message));
|
print('Unrecognized message from Checkout.qml or Purchases.qml: ' + JSON.stringify(message));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue