diff --git a/lootalot_front/src/App.vue b/lootalot_front/src/App.vue
index 396b84b..35dfeb6 100644
--- a/lootalot_front/src/App.vue
+++ b/lootalot_front/src/App.vue
@@ -1,11 +1,11 @@
-
+
{{ player.name }}
@@ -19,7 +19,7 @@
Changer
-
{{ p.name }}
@@ -57,14 +57,14 @@
pending_loot.push(item)"
@confirmAction="addNewLoot"
>
{ switchView('player'); actions.buyItems(data); }">
@@ -72,7 +72,7 @@
{
+ this.playerList = players.value;
+ this.groupLoot = loot.value;
+ this.itemsInventory = items.value;
+ })
+ .catch(r => alert("Error ! \n" + r))
+ .then(() => this.initiated = true);
},
methods: {
setActivePlayer (idx) {
if (idx == 0) this.switchView('group');
- AppStorage.setActivePlayer(idx);
+ this.player_id = Number(idx)
+ document.cookie = `player_id=${idx};`;
},
switchView (viewId) {
if (!['group', 'player', 'adding'].includes(viewId)) {
@@ -151,21 +160,19 @@ export default {
}
this.activeView = viewId;
},
- switchPlayerChestVisibility () {
- AppStorage.switchPlayerChestVisibility();
- },
addNewLoot () {
- Api.newLoot(this.pending_loot)
- .then(_ => {
+ api.fetch("admin/add-loot", "POST", this.pending_loot)
+ .then(() => {
this.pending_loot = []
this.switchView('group');
- });
+ })
+ .catch(r => alert("Error: " + r));
}
},
computed: {
showPlayerChest () { return this.activeView == 'player' },
isAdding () { return this.activeView == 'adding' },
- playerIsGroup () { return this.state.player_id == 0 },
+ playerIsGroup () { return this.player_id == 0 },
}
}
diff --git a/lootalot_front/src/AppStorage.js b/lootalot_front/src/AppStorage.js
deleted file mode 100644
index 4a7c9e9..0000000
--- a/lootalot_front/src/AppStorage.js
+++ /dev/null
@@ -1,149 +0,0 @@
-import Vue from 'vue'
-
-const API_BASEURL = "http://localhost:8088/api/"
-const API_ENDPOINT = function (tailString) {
- return API_BASEURL + tailString;
-}
-
-export const Api = {
- __doFetch (endpoint, method, payload) {
- return fetch(API_ENDPOINT(endpoint),
- {
- method,
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(payload)
- })
- .then(r => r.json())
- },
- fetchPlayerList () {
- return fetch(API_ENDPOINT("players/"))
- .then(r => r.json())
- },
- fetchInventory () {
- return fetch(API_ENDPOINT("items"))
- .then(r => r.json())
- },
- fetchClaims () {
- return fetch(API_ENDPOINT("claims"))
- .then(r => r.json())
- },
- fetchLoot (playerId) {
- return fetch(API_ENDPOINT("players/" + playerId + "/loot"))
- .then(r => r.json())
- },
- putClaim (player_id, item_id) {
- const payload = item_id;
- return this.__doFetch("players/" + player_id + "/claims", 'PUT', payload);
- },
- unClaim (player_id, item_id) {
- const payload = item_id;
- return this.__doFetch("players/" + player_id + "/claims", 'DELETE', payload);
- },
- updateWealth (player_id, value_in_gp) {
- const payload = Number(value_in_gp);
- return this.__doFetch("players/" + player_id + "/wealth", 'PUT', payload);
- },
- buyItems (player_id, items) {
- const payload = items;
- return this.__doFetch("players/" + player_id + "/loot", 'PUT', payload);
- },
- sellItems (player_id, items) {
- const payload = items;
- return this.__doFetch("players/" + player_id + "/loot", 'DELETE', payload);
- },
- newLoot (items) {
- return this.__doFetch("admin/add-loot", 'POST', items);
- },
-};
-
-
-export const AppStorage = {
- debug: true,
- state: {
- player_id: 0,
- player_list: {},
- group_loot: [],
- player_claims: {},
- inventory: [],
- initiated: false,
- show_player_chest: false,
- },
- // Initiate the state
- initStorage (playerId) {
- if (this.debug) console.log('Initiates with player : ', playerId)
- this.state.player_id = playerId;
- // Fetch initial data
- return Promise
- .all([
- Api.fetchPlayerList(),
- Api.fetchClaims(),
- Api.fetchInventory(),
- Api.fetchLoot(0)
- ])
- .then(data => {
- const [players, claims, inventory, group_loot] = data;
- this.__initPlayerList(players.value);
- this.__initClaimsStore(claims.value);
- Vue.set(this.state, 'group_loot', group_loot.value);
- Vue.set(this.state, 'inventory', inventory.value);
- })
- .then(_ => this.state.initiated = true)
- .catch(e => { alert(e); this.state.initiated = false });
- },
- __initClaimsStore(data) {
- for (var idx in data) {
- var claimDesc = data[idx];
- this.state.player_claims[claimDesc.player_id].push(claimDesc.loot_id);
- }
- },
- __initPlayerList(data) {
- for (var idx in data) {
- var playerDesc = data[idx];
- const playerId = Number(playerDesc.id);
- if (this.debug) console.log("Creates", playerId, playerDesc.name)
- // Initiate data for a single Player.
- Vue.set(this.state.player_list, playerId, playerDesc);
- Vue.set(this.state.player_claims, playerId, []);
- }
- },
- // User actions
- // Sets a new active player by id
- setActivePlayer (newPlayerId) {
- if (this.debug) console.log('setActivePlayer to ', newPlayerId)
- this.state.player_id = Number(newPlayerId)
- document.cookie = `player_id=${newPlayerId};`;
- },
- // Show/Hide player's chest
- switchPlayerChestVisibility () {
- if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest)
- this.state.show_player_chest = !this.state.show_player_chest
- },
- // Put a claim on an item from group chest.
- putRequest (itemId) {
- const playerId = this.state.player_id
- return Api.putClaim(playerId, itemId)
- .then(done => {
- // Update cliend-side state
- this.state.player_claims[playerId].push(itemId);
- });
- },
- // Withdraws a claim.
- cancelRequest(itemId) {
- const playerId = this.state.player_id
- return Api.unClaim(playerId, itemId)
- .then(_ => {
- var idx = this.state.player_claims[playerId].indexOf(itemId);
- if (idx > -1) {
- this.state.player_claims[playerId].splice(idx, 1);
- } else {
- if (this.debug) console.log("cancel a non-existent request")
- }
- });
- },
- addNewLoot (items) {
- return Api.newLoot(items);
- },
-}
-
diff --git a/lootalot_front/src/components/HeaderBar.vue b/lootalot_front/src/components/HeaderBar.vue
index edee958..1a3884e 100644
--- a/lootalot_front/src/components/HeaderBar.vue
+++ b/lootalot_front/src/components/HeaderBar.vue
@@ -4,10 +4,10 @@
...
-
-
-
-
+
+
+
+
diff --git a/lootalot_front/src/components/Request.vue b/lootalot_front/src/components/Request.vue
index b1fe6c8..0238e96 100644
--- a/lootalot_front/src/components/Request.vue
+++ b/lootalot_front/src/components/Request.vue
@@ -25,7 +25,6 @@