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;
property string activeView: "initialize";
property bool inventoryReceived: false;
property bool purchasesReceived: false;
property bool balanceReceived: false;
property string itemId: "";
property string itemHref: "";
@ -76,10 +76,10 @@ Rectangle {
onInventoryResult: {
if (result.status !== 'success') {
console.log("Failed to get inventory", result.data.message);
console.log("Failed to get purchases", result.data.message);
} else {
root.inventoryReceived = true;
if (inventoryContains(result.data.assets, itemId)) {
root.purchasesReceived = true;
if (purchasesContains(result.data.assets, itemId)) {
root.alreadyOwned = true;
} else {
root.alreadyOwned = false;
@ -638,7 +638,7 @@ Rectangle {
// "Buy" button
HifiControlsUit.Button {
id: buyButton;
enabled: balanceAfterPurchase >= 0 && inventoryReceived && balanceReceived;
enabled: balanceAfterPurchase >= 0 && purchasesReceived && balanceReceived;
color: hifi.buttons.blue;
colorScheme: hifi.colorSchemes.dark;
anchors.top: parent.top;
@ -647,16 +647,16 @@ Rectangle {
anchors.right: parent.right;
anchors.rightMargin: 20;
width: parent.width/2 - anchors.rightMargin*2;
text: (inventoryReceived && balanceReceived) ? (root.alreadyOwned ? "Buy Again" : "Buy"): "--";
text: (purchasesReceived && balanceReceived) ? (root.alreadyOwned ? "Buy Again" : "Buy"): "--";
onClicked: {
buyButton.enabled = false;
commerce.buy(itemId, itemPriceFull);
}
}
// "Inventory" button
// "Purchases" button
HifiControlsUit.Button {
id: goToInventoryButton;
id: goToPurchasesButton;
color: hifi.buttons.black;
colorScheme: hifi.colorSchemes.dark;
anchors.top: buyButton.bottom;
@ -666,9 +666,9 @@ Rectangle {
anchors.left: parent.left;
anchors.leftMargin: 20;
width: parent.width - anchors.leftMargin*2;
text: "View Inventory"
text: "View Purchases"
onClicked: {
sendToScript({method: 'checkout_goToInventory'});
sendToScript({method: 'checkout_goToPurchases'});
}
}
@ -741,9 +741,9 @@ Rectangle {
anchors.left: parent.left;
anchors.right: parent.right;
// "Inventory" button
// "Purchases" button
HifiControlsUit.Button {
id: inventoryButton;
id: purchasesButton;
color: hifi.buttons.black;
colorScheme: hifi.colorSchemes.dark;
anchors.top: parent.top;
@ -753,9 +753,9 @@ Rectangle {
anchors.left: parent.left;
anchors.leftMargin: 20;
width: parent.width/2 - anchors.leftMargin*2;
text: "View Inventory";
text: "View Purchases";
onClicked: {
sendToScript({method: 'checkout_goToInventory'});
sendToScript({method: 'checkout_goToPurchases'});
}
}
@ -825,7 +825,7 @@ Rectangle {
RalewayRegular {
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
size: 24;
// Anchors
@ -925,9 +925,9 @@ Rectangle {
}
signal sendToScript(var message);
function inventoryContains(inventoryJson, id) {
for (var idx = 0; idx < inventoryJson.length; idx++) {
if(inventoryJson[idx].id === id) {
function purchasesContains(purchasesJson, id) {
for (var idx = 0; idx < purchasesJson.length; idx++) {
if(purchasesJson[idx].id === id) {
return true;
}
}
@ -935,10 +935,10 @@ Rectangle {
}
function setBuyText() {
if (root.inventoryReceived && root.balanceReceived) {
if (root.purchasesReceived && root.balanceReceived) {
if (root.balanceAfterPurchase < 0) {
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 {
buyText.text = "You do not have enough HFC to purchase this item.";
}
@ -946,7 +946,7 @@ Rectangle {
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.";
} 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 {

View file

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

View file

@ -1,8 +1,8 @@
//
// Inventory.qml
// qml/hifi/commerce/inventory
// Purchases.qml
// qml/hifi/commerce/purchases
//
// Inventory
// Purchases
//
// Created by Zach Fox on 2017-08-25
// Copyright 2017 High Fidelity, Inc.
@ -35,25 +35,25 @@ Rectangle {
onSecurityImageResult: {
if (!exists && root.activeView !== "notSetUp") { // "If security image is not set up"
root.activeView = "notSetUp";
} else if (exists && root.activeView !== "inventoryMain") {
root.activeView = "inventoryMain";
} else if (exists && root.activeView !== "purchasesMain") {
root.activeView = "purchasesMain";
}
}
onKeyFilePathIfExistsResult: {
if (path === "" && root.activeView !== "notSetUp") {
root.activeView = "notSetUp";
} else if (path !== "" && root.activeView !== "inventoryMain") {
root.activeView = "inventoryMain";
} else if (path !== "" && root.activeView !== "purchasesMain") {
root.activeView = "purchasesMain";
}
}
onInventoryResult: {
if (result.status !== 'success') {
console.log("Failed to get inventory", result.message);
console.log("Failed to get purchases", result.message);
} else {
inventoryModel.append(result.data.assets);
filteredInventoryModel.append(result.data.assets);
purchasesModel.append(result.data.assets);
filteredPurchasesModel.append(result.data.assets);
}
}
}
@ -73,7 +73,7 @@ Rectangle {
// Title Bar text
RalewaySemiBold {
id: titleBarText;
text: "INVENTORY";
text: "PURCHASES";
// Text size
size: hifi.fontSizes.overlayTitle;
// Anchors
@ -116,11 +116,11 @@ Rectangle {
}
//
// INVENTORY CONTENTS START
// PURCHASES CONTENTS START
//
Item {
id: inventoryContentsContainer;
visible: root.activeView === "inventoryMain";
id: purchasesContentsContainer;
visible: root.activeView === "purchasesMain";
// Anchors
anchors.left: parent.left;
anchors.leftMargin: 4;
@ -152,16 +152,16 @@ Rectangle {
onTextChanged: {
if (filterBar.text.length < previousLength) {
filteredInventoryModel.clear();
filteredPurchasesModel.clear();
for (var i = 0; i < inventoryModel.count; i++) {
filteredInventoryModel.append(inventoryModel.get(i));
for (var i = 0; i < purchasesModel.count; i++) {
filteredPurchasesModel.append(purchasesModel.get(i));
}
}
for (var i = 0; i < filteredInventoryModel.count; i++) {
if (filteredInventoryModel.get(i).title.toLowerCase().indexOf(filterBar.text.toLowerCase()) === -1) {
filteredInventoryModel.remove(i);
for (var i = 0; i < filteredPurchasesModel.count; i++) {
if (filteredPurchasesModel.get(i).title.toLowerCase().indexOf(filterBar.text.toLowerCase()) === -1) {
filteredPurchasesModel.remove(i);
i--;
}
}
@ -174,23 +174,23 @@ Rectangle {
//
ListModel {
id: inventoryModel;
id: purchasesModel;
}
ListModel {
id: filteredInventoryModel;
id: filteredPurchasesModel;
}
ListView {
id: inventoryContentsList;
id: purchasesContentsList;
clip: true;
model: filteredInventoryModel;
model: filteredPurchasesModel;
// Anchors
anchors.top: filterBarContainer.bottom;
anchors.topMargin: 12;
anchors.left: parent.left;
anchors.bottom: parent.bottom;
width: parent.width;
delegate: InventoryItem {
delegate: PurchasedItem {
itemName: title;
itemId: id;
itemPreviewImageUrl: preview;
@ -199,9 +199,9 @@ Rectangle {
Connections {
target: parent;
onSendToInventory: {
if (msg.method === 'inventory_itemInfoClicked') {
sendToScript({method: 'inventory_itemInfoClicked', itemId: itemId});
onSendToPurchases: {
if (msg.method === 'purchases_itemInfoClicked') {
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;
text: "Back"
onClicked: {
sendToScript({method: 'inventory_backClicked', referrerURL: referrerURL});
sendToScript({method: 'purchases_backClicked', referrerURL: referrerURL});
}
}
}
@ -265,7 +265,7 @@ Rectangle {
//
function fromScript(message) {
switch (message.method) {
case 'updateInventory':
case 'updatePurchases':
referrerURL = message.referrerURL;
commerce.balance();
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.
var navbarBrandElement = document.getElementsByClassName('navbar-brand')[0];
var inventoryElement = document.createElement('a');
inventoryElement.classList.add("btn");
inventoryElement.classList.add("btn-default");
inventoryElement.id = "inventoryButton";
inventoryElement.setAttribute('href', "#");
inventoryElement.innerHTML = "INVENTORY";
inventoryElement.style = "height:100%;margin-top:0;padding:15px 15px;";
navbarBrandElement.parentNode.insertAdjacentElement('beforeend', inventoryElement);
$('#inventoryButton').on('click', function () {
var purchasesElement = document.createElement('a');
purchasesElement.classList.add("btn");
purchasesElement.classList.add("btn-default");
purchasesElement.id = "purchasesButton";
purchasesElement.setAttribute('href', "#");
purchasesElement.innerHTML = "PURCHASES";
purchasesElement.style = "height:100%;margin-top:0;padding:15px 15px;";
navbarBrandElement.parentNode.insertAdjacentElement('beforeend', purchasesElement);
$('#purchasesButton').on('click', function () {
EventBridge.emitWebEvent(JSON.stringify({
type: "INVENTORY",
type: "PURCHASES",
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,
// since that doesn't trigger another AJAX request.
injectBuyButtonOnMainPage;
addInventoryButton();
addPurchasesButton();
}
}
@ -183,7 +183,7 @@
cost,
href);
});
addInventoryButton();
addPurchasesButton();
}
}

View file

@ -20,7 +20,7 @@
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
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_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 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) {
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.
marketplaceButton.editProperties({ isActive: onMarketplaceScreen });
if (type === "Web" && url.indexOf(MARKETPLACE_URL) !== -1) {
@ -141,10 +141,10 @@
action: "inspectionModeSetting",
data: Settings.getValue("inspectionMode", false)
}));
} else if (parsedJsonMessage.type === "INVENTORY") {
tablet.pushOntoStack(MARKETPLACE_INVENTORY_QML_PATH);
} else if (parsedJsonMessage.type === "PURCHASES") {
tablet.pushOntoStack(MARKETPLACE_PURCHASES_QML_PATH);
tablet.sendToQml({
method: 'updateInventory',
method: 'updatePurchases',
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.
//tablet.popFromStack();
break;
case 'checkout_goToInventory':
tablet.pushOntoStack(MARKETPLACE_INVENTORY_QML_PATH);
case 'checkout_goToPurchases':
tablet.pushOntoStack(MARKETPLACE_PURCHASES_QML_PATH);
tablet.sendToQml({
method: 'updateInventory',
method: 'updatePurchases',
referrerURL: MARKETPLACE_URL_INITIAL
});
break;
@ -219,17 +219,17 @@
tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + message.itemId, MARKETPLACES_INJECT_SCRIPT_URL);
//tablet.popFromStack();
break;
case 'inventory_itemInfoClicked':
case 'purchases_itemInfoClicked':
var itemId = message.itemId;
if (itemId && itemId !== "") {
tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + itemId, MARKETPLACES_INJECT_SCRIPT_URL);
}
break;
case 'inventory_backClicked':
case 'purchases_backClicked':
tablet.gotoWebScreen(message.referrerURL, MARKETPLACES_INJECT_SCRIPT_URL);
break;
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));
}
}