adds a working inventory
This commit is contained in:
2255
lootalot_db/res/items.csv
Normal file
2255
lootalot_db/res/items.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -66,8 +66,10 @@ impl<'q> DbApi<'q> {
|
|||||||
Ok(schema::players::table.load::<models::Player>(self.0)?)
|
Ok(schema::players::table.load::<models::Player>(self.0)?)
|
||||||
}
|
}
|
||||||
/// Fetch the inventory of items
|
/// Fetch the inventory of items
|
||||||
|
///
|
||||||
|
/// TODO: remove limit used for debug
|
||||||
pub fn fetch_inventory(self) -> QueryResult<Vec<models::Item>> {
|
pub fn fetch_inventory(self) -> QueryResult<Vec<models::Item>> {
|
||||||
Ok(schema::items::table.load::<models::Item>(self.0)?)
|
Ok(schema::items::table.limit(100).load::<models::Item>(self.0)?)
|
||||||
}
|
}
|
||||||
/// Fetch all existing claims
|
/// Fetch all existing claims
|
||||||
pub fn fetch_claims(self) -> QueryResult<Vec<models::Claim>> {
|
pub fn fetch_claims(self) -> QueryResult<Vec<models::Claim>> {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
<template v-if="isAdding">
|
<template v-if="isAdding">
|
||||||
<h2 v-show="playerIsGroup">ItemInput</h2>
|
<h2 v-show="playerIsGroup">ItemInput</h2>
|
||||||
<AddingChest
|
<AddingChest
|
||||||
:items="playerIsGroup ? [] : shopInventory"
|
:items="playerIsGroup ? [] : state.inventory"
|
||||||
:perms="playerIsGroup ? {} : { canBuy: true }"
|
:perms="playerIsGroup ? {} : { canBuy: true }"
|
||||||
@buy="(data) => { switchView('player'); actions.buyItems(data); }">
|
@buy="(data) => { switchView('player'); actions.buyItems(data); }">
|
||||||
</AddingChest>
|
</AddingChest>
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ export const Api = {
|
|||||||
return fetch(API_ENDPOINT("players/all"))
|
return fetch(API_ENDPOINT("players/all"))
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
},
|
},
|
||||||
|
fetchInventory () {
|
||||||
|
return fetch(API_ENDPOINT("items"))
|
||||||
|
.then(r => r.json())
|
||||||
|
},
|
||||||
fetchClaims () {
|
fetchClaims () {
|
||||||
return fetch(API_ENDPOINT("claims"))
|
return fetch(API_ENDPOINT("claims"))
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
@@ -51,6 +55,7 @@ export const AppStorage = {
|
|||||||
player_list: {},
|
player_list: {},
|
||||||
group_loot: [],
|
group_loot: [],
|
||||||
player_claims: {},
|
player_claims: {},
|
||||||
|
inventory: [],
|
||||||
initiated: false,
|
initiated: false,
|
||||||
show_player_chest: false,
|
show_player_chest: false,
|
||||||
},
|
},
|
||||||
@@ -63,13 +68,15 @@ export const AppStorage = {
|
|||||||
.all([
|
.all([
|
||||||
Api.fetchPlayerList(),
|
Api.fetchPlayerList(),
|
||||||
Api.fetchClaims(),
|
Api.fetchClaims(),
|
||||||
|
Api.fetchInventory(),
|
||||||
Api.fetchLoot(0)
|
Api.fetchLoot(0)
|
||||||
])
|
])
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const [players, claims, group_loot] = data;
|
const [players, claims, inventory, group_loot] = data;
|
||||||
this.__initPlayerList(players);
|
this.__initPlayerList(players);
|
||||||
this.__initClaimsStore(claims);
|
this.__initClaimsStore(claims);
|
||||||
Vue.set(this.state, 'group_loot', group_loot);
|
Vue.set(this.state, 'group_loot', group_loot);
|
||||||
|
Vue.set(this.state, 'inventory', inventory);
|
||||||
})
|
})
|
||||||
.then(_ => this.state.initiated = true)
|
.then(_ => this.state.initiated = true)
|
||||||
.catch(e => { alert(e); this.state.initiated = false });
|
.catch(e => { alert(e); this.state.initiated = false });
|
||||||
|
|||||||
@@ -15,7 +15,9 @@
|
|||||||
<PercentInput v-show="is_selling"></PercentInput>
|
<PercentInput v-show="is_selling"></PercentInput>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="perms.canBuy">
|
<div v-else-if="perms.canBuy">
|
||||||
<button class="button is-danger is-fullwidth" @click="buySelectedItems">Acheter</button>
|
<button class="button is-danger is-fullwidth"
|
||||||
|
:disabled="selected_items.length == 0"
|
||||||
|
@click="buySelectedItems">Acheter</button>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="perms.canGrab">
|
<div v-else-if="perms.canGrab">
|
||||||
<button class="button is-static is-fullwidth">Demander</button>
|
<button class="button is-static is-fullwidth">Demander</button>
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
|||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::scope("/api")
|
web::scope("/api")
|
||||||
|
.route("/items", web::get().to_async(move |pool: AppPool| {
|
||||||
|
db_call(pool, move |api| api.fetch_inventory())
|
||||||
|
}))
|
||||||
.service(
|
.service(
|
||||||
web::scope("/players")
|
web::scope("/players")
|
||||||
.route(
|
.route(
|
||||||
|
|||||||
Reference in New Issue
Block a user