Add and remove functionality enabled.

This commit is contained in:
Kasen IO 2020-04-04 00:03:03 -04:00
parent d8693d4d43
commit c89f07d508
2 changed files with 151 additions and 21 deletions

View file

@ -124,7 +124,7 @@
</v-list-item-action>
</v-list-item>
<v-list-item
@click="removeDialog.show = true;"
@click="removeDialog.show = true; removeDialog.url = item.url;"
color="red darken-1"
>
<v-list-item-title>Remove</v-list-item-title>
@ -135,10 +135,8 @@
</v-list>
</v-menu>
</v-list-item>
</v-card>
</v-col>
</v-row>
@ -172,7 +170,7 @@
<v-btn
color="red"
class="px-3"
@click="removeDialog.show = false"
@click="removeDialog.show = false; removeItem(removeDialog.url);"
>
Yes
</v-btn>
@ -188,6 +186,17 @@
>
<v-card>
<v-card-title class="headline">Add Item</v-card-title>
<v-card-text>
Enter the name of the item.
</v-card-text>
<v-text-field
class="px-2"
label="Name"
v-model="addDialog.data.name"
required
></v-text-field>
<v-card-text>
Enter the URL of the item.
@ -196,6 +205,8 @@
<v-text-field
class="px-2"
label="URL"
v-model="addDialog.data.url"
required
></v-text-field>
<v-card-actions>
@ -213,7 +224,7 @@
<v-btn
color="blue"
class="px-3"
@click="addDialog.show = false"
@click="addDialog.show = false; addItem(addDialog.data.name, addDialog.data.url)"
>
Add
</v-btn>
@ -285,42 +296,42 @@ new Vue({
{
"type": "script",
"name": "VRGrabScale",
"url": "https://google.com/vr.js",
"url": "https://gooawefaweawfgle.com/vr.js",
},
{
"type": "script",
"name": "VRGrabScale",
"url": "https://google.com/vr.js",
"url": "https://googfdafsgaergale.com/vr.js",
},
{
"type": "script",
"name": "TEST",
"url": "https://google.com/vr.js",
"url": "https://gooadfdagle.com/vr.js",
},
{
"type": "script",
"name": "TESTLONGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"url": "https://google.com/vrLONGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG.js",
"url": "https://googfdaffle.com/vrLONGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG.js",
},
{
"type": "avatar",
"name": "AVI",
"url": "https://google.com/vr.fst",
"url": "https://googlfadfe.com/vr.fst",
},
{
"type": "avatar",
"name": "AVI",
"url": "https://google.com/vr.fst",
"url": "https://googlefdaf.com/vr.fst",
},
{
"type": "model",
"name": "3D MODEL",
"url": "https://google.com/vr.fbx",
"url": "https://googlee.com/vr.fbx",
},
{
"type": "model",
"name": "3D MODEL",
"url": "https://google.com/vr.fbx",
"url": "https://googleee.com/vr.fbx",
},
],
iconType: {
@ -336,13 +347,21 @@ new Vue({
"icon": "mdi-account-convert",
"color": "purple",
},
"unknown": {
"icon": "mdi-help",
"color": "grey",
}
},
removeDialog: {
show: false,
item: null,
url: null, // This is the item to remove since URL is the key.
},
addDialog: {
show: false,
data: {
"name": null,
"url": null,
},
},
receiveDialog: {
show: false,
@ -358,13 +377,57 @@ new Vue({
created: function () {
vue_this = this;
this.$vuetify.theme.dark = this.darkTheme;
this.sendAppMessage("ready", "");
},
methods: {
addItem: function(url) {
addItem: function(name, url) {
var extensionRegex = /\.[0-9a-z]+$/i; // to detect the file type based on extension in the URL.
var detectedFileType = url.match(extensionRegex);
var itemType;
if (detectedFileType == null || detectedFileType[0] == null) {
itemType = "unknown";
} else {
switch (detectedFileType[0]) {
// Model Cases
case ".fbx":
itemType = "model";
break;
case ".gltf":
itemType = "model";
break;
// Script Cases
case ".js":
itemType = "script";
break;
// Avatar Cases
case ".fst":
itemType = "avatar";
break;
}
}
if (itemType == null) {
// This is not a known item...
itemType = "unknown";
}
var itemToPush =
{
"type": itemType,
"name": name,
"url": url,
};
this.items.push(itemToPush);
},
removeItem: function(url) {
for (i = 0; i < this.items.length; i++) {
if (this.items[i].url == url) {
this.items.splice(i, 1);
}
}
},
renameItem: function(url) {
@ -381,6 +444,12 @@ new Vue({
useItem: function(url) {
alert(url);
this.sendAppMessage("test", "testData");
},
sendInventory: function() {
},
receiveInventory: function() {
},
sendAppMessage: function(command, data) {
var JSONtoSend = {
@ -388,6 +457,7 @@ new Vue({
"command": command,
"data": data
};
EventBridge.emitWebEvent(JSON.stringify(JSONtoSend));
},
displayIcon: function(itemType) {

View file

@ -13,25 +13,72 @@ var AppUi = Script.require('appUi');
var ui;
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
// APP EVENT ROUTING
var inventoryDataSettingString = "inventoryApp.data";
var inventoryData;
// APP EVENT AND MESSAGING ROUTING
function onWebAppEventReceived(event) {
var eventJSON = JSON.parse(event);
if (eventJSON.app == "inventory") { // This is our web app!
print("gemstoneApp.js received a web event: " + event);
print("inventory.js received a web event: " + event);
if (eventJSON.command == "ready") {
initializeInventoryApp();
}
if (eventJSON.command == "web-to-script-inventory") {
receiveInventory(eventJSON.data);
}
}
}
tablet.webEventReceived.connect(onWebAppEventReceived);
// END APP EVENT ROUTING
function sendToWeb(command, data) {
var dataToSend = {
"app": "inventory",
"command": command,
"data": data
}
tablet.emitScriptEvent(dataToSend);
}
// var inventoryMessagesChannel = "com.vircadia.inventory";
// function onMessageReceived(channel, message, sender, localOnly) {
// if (channel == inventoryMessagesChannel) {
// var messageJSON = JSON.parse(message);
// }
// print("Message received:");
// print("- channel: " + channel);
// print("- message: " + message);
// print("- sender: " + sender);
// print("- localOnly: " + localOnly);
// }
// END APP EVENT AND MESSAGING ROUTING
// SEND AND RECEIVE INVENTORY STATE
function receiveInventory(receivedInventoryData) {
inventoryData = receivedInventoryData;
saveInventory();
}
function sendInventory() {
sendToWeb("script-to-web-inventory", inventoryData);
}
// END SEND AND RECEIVE INVENTORY STATE
function saveInventory() {
Settings.setValue(inventoryDataSettingString, inventoryData);
}
function loadInventory() {
inventoryData = Settings.getValue(inventoryDataSettingString);
}
function receivingItem() {
@ -42,6 +89,10 @@ function shareItem() {
}
function initializeInventoryApp() {
sendInventory();
}
function onOpened() {
console.log("hello world!");
}
@ -51,6 +102,9 @@ function onClosed() {
}
function startup() {
loadInventory();
ui = new AppUi({
buttonName: "INVENTORY",
home: Script.resolvePath("inventory.html"),
@ -60,4 +114,10 @@ function startup() {
});
}
startup();
Script.scriptEnding.connect(function () {
// Messages.messageReceived.disconnect(onMessageReceived);
// Messages.unsubscribe(inventoryMessagesChannel);
});
}()); // END LOCAL_SCOPE