Inventory to Purchases

This commit is contained in:
Zach Fox 2017-08-25 16:34:48 -07:00
parent b1378816d5
commit a03f9592c1
5 changed files with 83 additions and 83 deletions

View file

@ -26,7 +26,7 @@ Rectangle {
id: root; id: root;
property string activeView: "initialize"; property string activeView: "initialize";
property bool inventoryReceived: false; property bool purchasesReceived: false;
property bool balanceReceived: false; property bool balanceReceived: false;
property string itemId: ""; property string itemId: "";
property string itemHref: ""; property string itemHref: "";
@ -76,10 +76,10 @@ Rectangle {
onInventoryResult: { onInventoryResult: {
if (result.status !== 'success') { if (result.status !== 'success') {
console.log("Failed to get inventory", result.data.message); console.log("Failed to get purchases", result.data.message);
} else { } else {
root.inventoryReceived = true; root.purchasesReceived = true;
if (inventoryContains(result.data.assets, itemId)) { if (purchasesContains(result.data.assets, itemId)) {
root.alreadyOwned = true; root.alreadyOwned = true;
} else { } else {
root.alreadyOwned = false; root.alreadyOwned = false;
@ -638,7 +638,7 @@ Rectangle {
// "Buy" button // "Buy" button
HifiControlsUit.Button { HifiControlsUit.Button {
id: buyButton; id: buyButton;
enabled: balanceAfterPurchase >= 0 && inventoryReceived && balanceReceived; enabled: balanceAfterPurchase >= 0 && purchasesReceived && balanceReceived;
color: hifi.buttons.blue; color: hifi.buttons.blue;
colorScheme: hifi.colorSchemes.dark; colorScheme: hifi.colorSchemes.dark;
anchors.top: parent.top; anchors.top: parent.top;
@ -647,16 +647,16 @@ Rectangle {
anchors.right: parent.right; anchors.right: parent.right;
anchors.rightMargin: 20; anchors.rightMargin: 20;
width: parent.width/2 - anchors.rightMargin*2; width: parent.width/2 - anchors.rightMargin*2;
text: (inventoryReceived && balanceReceived) ? (root.alreadyOwned ? "Buy Again" : "Buy"): "--"; text: (purchasesReceived && balanceReceived) ? (root.alreadyOwned ? "Buy Again" : "Buy"): "--";
onClicked: { onClicked: {
buyButton.enabled = false; buyButton.enabled = false;
commerce.buy(itemId, itemPriceFull); commerce.buy(itemId, itemPriceFull);
} }
} }
// "Inventory" button // "Purchases" button
HifiControlsUit.Button { HifiControlsUit.Button {
id: goToInventoryButton; id: goToPurchasesButton;
color: hifi.buttons.black; color: hifi.buttons.black;
colorScheme: hifi.colorSchemes.dark; colorScheme: hifi.colorSchemes.dark;
anchors.top: buyButton.bottom; anchors.top: buyButton.bottom;
@ -666,9 +666,9 @@ Rectangle {
anchors.left: parent.left; anchors.left: parent.left;
anchors.leftMargin: 20; anchors.leftMargin: 20;
width: parent.width - anchors.leftMargin*2; width: parent.width - anchors.leftMargin*2;
text: "View Inventory" text: "View Purchases"
onClicked: { onClicked: {
sendToScript({method: 'checkout_goToInventory'}); sendToScript({method: 'checkout_goToPurchases'});
} }
} }
@ -741,9 +741,9 @@ Rectangle {
anchors.left: parent.left; anchors.left: parent.left;
anchors.right: parent.right; anchors.right: parent.right;
// "Inventory" button // "Purchases" button
HifiControlsUit.Button { HifiControlsUit.Button {
id: inventoryButton; id: purchasesButton;
color: hifi.buttons.black; color: hifi.buttons.black;
colorScheme: hifi.colorSchemes.dark; colorScheme: hifi.colorSchemes.dark;
anchors.top: parent.top; anchors.top: parent.top;
@ -753,9 +753,9 @@ Rectangle {
anchors.left: parent.left; anchors.left: parent.left;
anchors.leftMargin: 20; anchors.leftMargin: 20;
width: parent.width/2 - anchors.leftMargin*2; width: parent.width/2 - anchors.leftMargin*2;
text: "View Inventory"; text: "View Purchases";
onClicked: { onClicked: {
sendToScript({method: 'checkout_goToInventory'}); sendToScript({method: 'checkout_goToPurchases'});
} }
} }
@ -825,7 +825,7 @@ Rectangle {
RalewayRegular { RalewayRegular {
id: failureHeaderText; id: failureHeaderText;
text: "<b>Purchase Failed.</b><br>Your Inventory and HFC balance haven't changed."; text: "<b>Purchase Failed.</b><br>Your Purchases and HFC balance haven't changed.";
// Text size // Text size
size: 24; size: 24;
// Anchors // Anchors
@ -925,9 +925,9 @@ Rectangle {
} }
signal sendToScript(var message); signal sendToScript(var message);
function inventoryContains(inventoryJson, id) { function purchasesContains(purchasesJson, id) {
for (var idx = 0; idx < inventoryJson.length; idx++) { for (var idx = 0; idx < purchasesJson.length; idx++) {
if(inventoryJson[idx].id === id) { if(purchasesJson[idx].id === id) {
return true; return true;
} }
} }
@ -935,10 +935,10 @@ Rectangle {
} }
function setBuyText() { function setBuyText() {
if (root.inventoryReceived && root.balanceReceived) { if (root.purchasesReceived && root.balanceReceived) {
if (root.balanceAfterPurchase < 0) { if (root.balanceAfterPurchase < 0) {
if (root.alreadyOwned) { if (root.alreadyOwned) {
buyText.text = "You do not have enough HFC to purchase this item again. Go to your Inventory to view the copy you own."; buyText.text = "You do not have enough HFC to purchase this item again. Go to your Purchases to view the copy you own.";
} else { } else {
buyText.text = "You do not have enough HFC to purchase this item."; buyText.text = "You do not have enough HFC to purchase this item.";
} }
@ -946,7 +946,7 @@ Rectangle {
if (root.alreadyOwned) { if (root.alreadyOwned) {
buyText.text = "<b>You already own this item.</b> If you buy it again, you'll be able to use multiple copies of it at once."; buyText.text = "<b>You already own this item.</b> If you buy it again, you'll be able to use multiple copies of it at once.";
} else { } else {
buyText.text = "This item will be added to your <b>Inventory</b>, which can be accessed from <b>Marketplace</b>."; buyText.text = "This item will be added to your <b>Purchases</b>, which can be accessed from <b>Marketplace</b>.";
} }
} }
} else { } else {

View file

@ -1,8 +1,8 @@
// //
// InventoryItem.qml // PurchasedItem.qml
// qml/hifi/commerce/inventory // qml/hifi/commerce/purchases
// //
// InventoryItem // PurchasedItem
// //
// Created by Zach Fox on 2017-08-25 // Created by Zach Fox on 2017-08-25
// Copyright 2017 High Fidelity, Inc. // Copyright 2017 High Fidelity, Inc.
@ -50,7 +50,7 @@ Rectangle {
MouseArea { MouseArea {
anchors.fill: parent; anchors.fill: parent;
onClicked: { onClicked: {
sendToInventory({method: 'inventory_itemInfoClicked', itemId: root.itemId}); sendToPurchases({method: 'purchases_itemInfoClicked', itemId: root.itemId});
} }
} }
} }
@ -78,7 +78,7 @@ Rectangle {
anchors.fill: parent; anchors.fill: parent;
hoverEnabled: enabled; hoverEnabled: enabled;
onClicked: { onClicked: {
sendToInventory({method: 'inventory_itemInfoClicked', itemId: root.itemId}); sendToPurchases({method: 'purchases_itemInfoClicked', itemId: root.itemId});
} }
onEntered: { onEntered: {
itemName.color = hifi.colors.blueHighlight; itemName.color = hifi.colors.blueHighlight;
@ -128,7 +128,7 @@ Rectangle {
height: parent.height/2 - 4; height: parent.height/2 - 4;
text: "More Info" text: "More Info"
onClicked: { onClicked: {
sendToInventory({method: 'inventory_itemInfoClicked', itemId: root.itemId}); sendToPurchases({method: 'purchases_itemInfoClicked', itemId: root.itemId});
} }
} }
} }
@ -136,7 +136,7 @@ Rectangle {
// //
// FUNCTION DEFINITIONS START // FUNCTION DEFINITIONS START
// //
signal sendToInventory(var message); signal sendToPurchases(var message);
// //
// FUNCTION DEFINITIONS END // FUNCTION DEFINITIONS END
// //

View file

@ -1,8 +1,8 @@
// //
// Inventory.qml // Purchases.qml
// qml/hifi/commerce/inventory // qml/hifi/commerce/purchases
// //
// Inventory // Purchases
// //
// Created by Zach Fox on 2017-08-25 // Created by Zach Fox on 2017-08-25
// Copyright 2017 High Fidelity, Inc. // Copyright 2017 High Fidelity, Inc.
@ -35,25 +35,25 @@ Rectangle {
onSecurityImageResult: { onSecurityImageResult: {
if (!exists && root.activeView !== "notSetUp") { // "If security image is not set up" if (!exists && root.activeView !== "notSetUp") { // "If security image is not set up"
root.activeView = "notSetUp"; root.activeView = "notSetUp";
} else if (exists && root.activeView !== "inventoryMain") { } else if (exists && root.activeView !== "purchasesMain") {
root.activeView = "inventoryMain"; root.activeView = "purchasesMain";
} }
} }
onKeyFilePathIfExistsResult: { onKeyFilePathIfExistsResult: {
if (path === "" && root.activeView !== "notSetUp") { if (path === "" && root.activeView !== "notSetUp") {
root.activeView = "notSetUp"; root.activeView = "notSetUp";
} else if (path !== "" && root.activeView !== "inventoryMain") { } else if (path !== "" && root.activeView !== "purchasesMain") {
root.activeView = "inventoryMain"; root.activeView = "purchasesMain";
} }
} }
onInventoryResult: { onInventoryResult: {
if (result.status !== 'success') { if (result.status !== 'success') {
console.log("Failed to get inventory", result.message); console.log("Failed to get purchases", result.message);
} else { } else {
inventoryModel.append(result.data.assets); purchasesModel.append(result.data.assets);
filteredInventoryModel.append(result.data.assets); filteredPurchasesModel.append(result.data.assets);
} }
} }
} }
@ -73,7 +73,7 @@ Rectangle {
// Title Bar text // Title Bar text
RalewaySemiBold { RalewaySemiBold {
id: titleBarText; id: titleBarText;
text: "INVENTORY"; text: "PURCHASES";
// Text size // Text size
size: hifi.fontSizes.overlayTitle; size: hifi.fontSizes.overlayTitle;
// Anchors // Anchors
@ -116,11 +116,11 @@ Rectangle {
} }
// //
// INVENTORY CONTENTS START // PURCHASES CONTENTS START
// //
Item { Item {
id: inventoryContentsContainer; id: purchasesContentsContainer;
visible: root.activeView === "inventoryMain"; visible: root.activeView === "purchasesMain";
// Anchors // Anchors
anchors.left: parent.left; anchors.left: parent.left;
anchors.leftMargin: 4; anchors.leftMargin: 4;
@ -152,16 +152,16 @@ Rectangle {
onTextChanged: { onTextChanged: {
if (filterBar.text.length < previousLength) { if (filterBar.text.length < previousLength) {
filteredInventoryModel.clear(); filteredPurchasesModel.clear();
for (var i = 0; i < inventoryModel.count; i++) { for (var i = 0; i < purchasesModel.count; i++) {
filteredInventoryModel.append(inventoryModel.get(i)); filteredPurchasesModel.append(purchasesModel.get(i));
} }
} }
for (var i = 0; i < filteredInventoryModel.count; i++) { for (var i = 0; i < filteredPurchasesModel.count; i++) {
if (filteredInventoryModel.get(i).title.toLowerCase().indexOf(filterBar.text.toLowerCase()) === -1) { if (filteredPurchasesModel.get(i).title.toLowerCase().indexOf(filterBar.text.toLowerCase()) === -1) {
filteredInventoryModel.remove(i); filteredPurchasesModel.remove(i);
i--; i--;
} }
} }
@ -174,23 +174,23 @@ Rectangle {
// //
ListModel { ListModel {
id: inventoryModel; id: purchasesModel;
} }
ListModel { ListModel {
id: filteredInventoryModel; id: filteredPurchasesModel;
} }
ListView { ListView {
id: inventoryContentsList; id: purchasesContentsList;
clip: true; clip: true;
model: filteredInventoryModel; model: filteredPurchasesModel;
// Anchors // Anchors
anchors.top: filterBarContainer.bottom; anchors.top: filterBarContainer.bottom;
anchors.topMargin: 12; anchors.topMargin: 12;
anchors.left: parent.left; anchors.left: parent.left;
anchors.bottom: parent.bottom; anchors.bottom: parent.bottom;
width: parent.width; width: parent.width;
delegate: InventoryItem { delegate: PurchasedItem {
itemName: title; itemName: title;
itemId: id; itemId: id;
itemPreviewImageUrl: preview; itemPreviewImageUrl: preview;
@ -199,9 +199,9 @@ Rectangle {
Connections { Connections {
target: parent; target: parent;
onSendToInventory: { onSendToPurchases: {
if (msg.method === 'inventory_itemInfoClicked') { if (msg.method === 'purchases_itemInfoClicked') {
sendToScript({method: 'inventory_itemInfoClicked', itemId: itemId}); sendToScript({method: 'purchases_itemInfoClicked', itemId: itemId});
} }
} }
} }
@ -209,7 +209,7 @@ Rectangle {
} }
} }
// //
// INVENTORY CONTENTS END // PURCHASES CONTENTS END
// //
// //
@ -239,7 +239,7 @@ Rectangle {
width: parent.width/2 - anchors.leftMargin*2; width: parent.width/2 - anchors.leftMargin*2;
text: "Back" text: "Back"
onClicked: { onClicked: {
sendToScript({method: 'inventory_backClicked', referrerURL: referrerURL}); sendToScript({method: 'purchases_backClicked', referrerURL: referrerURL});
} }
} }
} }
@ -265,7 +265,7 @@ Rectangle {
// //
function fromScript(message) { function fromScript(message) {
switch (message.method) { switch (message.method) {
case 'updateInventory': case 'updatePurchases':
referrerURL = message.referrerURL; referrerURL = message.referrerURL;
commerce.balance(); commerce.balance();
commerce.inventory(); commerce.inventory();

View file

@ -90,20 +90,20 @@
}); });
} }
function addInventoryButton() { function addPurchasesButton() {
// Why isn't this an id?! This really shouldn't be a class on the website, but it is. // Why isn't this an id?! This really shouldn't be a class on the website, but it is.
var navbarBrandElement = document.getElementsByClassName('navbar-brand')[0]; var navbarBrandElement = document.getElementsByClassName('navbar-brand')[0];
var inventoryElement = document.createElement('a'); var purchasesElement = document.createElement('a');
inventoryElement.classList.add("btn"); purchasesElement.classList.add("btn");
inventoryElement.classList.add("btn-default"); purchasesElement.classList.add("btn-default");
inventoryElement.id = "inventoryButton"; purchasesElement.id = "purchasesButton";
inventoryElement.setAttribute('href', "#"); purchasesElement.setAttribute('href', "#");
inventoryElement.innerHTML = "INVENTORY"; purchasesElement.innerHTML = "PURCHASES";
inventoryElement.style = "height:100%;margin-top:0;padding:15px 15px;"; purchasesElement.style = "height:100%;margin-top:0;padding:15px 15px;";
navbarBrandElement.parentNode.insertAdjacentElement('beforeend', inventoryElement); navbarBrandElement.parentNode.insertAdjacentElement('beforeend', purchasesElement);
$('#inventoryButton').on('click', function () { $('#purchasesButton').on('click', function () {
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: "INVENTORY", type: "PURCHASES",
referrerURL: window.location.href referrerURL: window.location.href
})); }));
}); });
@ -161,7 +161,7 @@
// Try this here in case it works (it will if the user just pressed the "back" button, // Try this here in case it works (it will if the user just pressed the "back" button,
// since that doesn't trigger another AJAX request. // since that doesn't trigger another AJAX request.
injectBuyButtonOnMainPage; injectBuyButtonOnMainPage;
addInventoryButton(); addPurchasesButton();
} }
} }
@ -183,7 +183,7 @@
cost, cost,
href); href);
}); });
addInventoryButton(); addPurchasesButton();
} }
} }

View file

@ -20,7 +20,7 @@
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html"); var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
var MARKETPLACES_INJECT_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesInject.js"); var MARKETPLACES_INJECT_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesInject.js");
var MARKETPLACE_CHECKOUT_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/checkout/Checkout.qml"; var MARKETPLACE_CHECKOUT_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/checkout/Checkout.qml";
var MARKETPLACE_INVENTORY_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/inventory/Inventory.qml"; var MARKETPLACE_PURCHASES_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/purchases/Purchases.qml";
var MARKETPLACE_WALLET_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/wallet/Wallet.qml"; var MARKETPLACE_WALLET_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/wallet/Wallet.qml";
var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png"; var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png";
@ -88,7 +88,7 @@
function onScreenChanged(type, url) { function onScreenChanged(type, url) {
onMarketplaceScreen = type === "Web" && url === MARKETPLACE_URL_INITIAL; onMarketplaceScreen = type === "Web" && url === MARKETPLACE_URL_INITIAL;
wireEventBridge(type === "QML" && (url === MARKETPLACE_CHECKOUT_QML_PATH || url === MARKETPLACE_INVENTORY_QML_PATH)); wireEventBridge(type === "QML" && (url === MARKETPLACE_CHECKOUT_QML_PATH || url === MARKETPLACE_PURCHASES_QML_PATH));
// for toolbar mode: change button to active when window is first openend, false otherwise. // for toolbar mode: change button to active when window is first openend, false otherwise.
marketplaceButton.editProperties({ isActive: onMarketplaceScreen }); marketplaceButton.editProperties({ isActive: onMarketplaceScreen });
if (type === "Web" && url.indexOf(MARKETPLACE_URL) !== -1) { if (type === "Web" && url.indexOf(MARKETPLACE_URL) !== -1) {
@ -141,10 +141,10 @@
action: "inspectionModeSetting", action: "inspectionModeSetting",
data: Settings.getValue("inspectionMode", false) data: Settings.getValue("inspectionMode", false)
})); }));
} else if (parsedJsonMessage.type === "INVENTORY") { } else if (parsedJsonMessage.type === "PURCHASES") {
tablet.pushOntoStack(MARKETPLACE_INVENTORY_QML_PATH); tablet.pushOntoStack(MARKETPLACE_PURCHASES_QML_PATH);
tablet.sendToQml({ tablet.sendToQml({
method: 'updateInventory', method: 'updatePurchases',
referrerURL: parsedJsonMessage.referrerURL referrerURL: parsedJsonMessage.referrerURL
}); });
} }
@ -208,10 +208,10 @@
// I don't think this is trivial to do since we also want to inject some JS into the DOM. // I don't think this is trivial to do since we also want to inject some JS into the DOM.
//tablet.popFromStack(); //tablet.popFromStack();
break; break;
case 'checkout_goToInventory': case 'checkout_goToPurchases':
tablet.pushOntoStack(MARKETPLACE_INVENTORY_QML_PATH); tablet.pushOntoStack(MARKETPLACE_PURCHASES_QML_PATH);
tablet.sendToQml({ tablet.sendToQml({
method: 'updateInventory', method: 'updatePurchases',
referrerURL: MARKETPLACE_URL_INITIAL referrerURL: MARKETPLACE_URL_INITIAL
}); });
break; break;
@ -219,17 +219,17 @@
tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + message.itemId, MARKETPLACES_INJECT_SCRIPT_URL); tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + message.itemId, MARKETPLACES_INJECT_SCRIPT_URL);
//tablet.popFromStack(); //tablet.popFromStack();
break; break;
case 'inventory_itemInfoClicked': case 'purchases_itemInfoClicked':
var itemId = message.itemId; var itemId = message.itemId;
if (itemId && itemId !== "") { if (itemId && itemId !== "") {
tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + itemId, MARKETPLACES_INJECT_SCRIPT_URL); tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + itemId, MARKETPLACES_INJECT_SCRIPT_URL);
} }
break; break;
case 'inventory_backClicked': case 'purchases_backClicked':
tablet.gotoWebScreen(message.referrerURL, MARKETPLACES_INJECT_SCRIPT_URL); tablet.gotoWebScreen(message.referrerURL, MARKETPLACES_INJECT_SCRIPT_URL);
break; break;
default: default:
print('Unrecognized message from Checkout.qml or Inventory.qml: ' + JSON.stringify(message)); print('Unrecognized message from Checkout.qml or Purchases.qml: ' + JSON.stringify(message));
} }
} }