stash
This commit is contained in:
parent
34942cedda
commit
df70a347e3
2 changed files with 6 additions and 21 deletions
|
@ -52,6 +52,7 @@ export default createStore({
|
||||||
localStorage.setItem('remember', remember);
|
localStorage.setItem('remember', remember);
|
||||||
},
|
},
|
||||||
setInventoryItems(state, {url, items}) {
|
setInventoryItems(state, {url, items}) {
|
||||||
|
console.log('setInventoryItems', url, items)
|
||||||
state.item_map[url] = items;
|
state.item_map[url] = items;
|
||||||
},
|
},
|
||||||
setFriends(state, friends) {
|
setFriends(state, friends) {
|
||||||
|
@ -109,13 +110,12 @@ export default createStore({
|
||||||
actions: {
|
actions: {
|
||||||
async login({commit, dispatch, state, getters}, {username, password, remember}) {
|
async login({commit, dispatch, state, getters}, {username, password, remember}) {
|
||||||
commit('setRemember', remember);
|
commit('setRemember', remember);
|
||||||
const data = await dispatch('lookupServer', {username}).then(servers => new ServerSet(servers, state.unreachable_neighbors))
|
const s = await dispatch('lookupServer', {username}).then(servers => new ServerSet(servers, state.unreachable_neighbors))
|
||||||
.then(set => set.post(getters.nullAuth, '/auth/token/', {username, password}))
|
const data = await s.post(getters.nullAuth, '/auth/token/', {username, password})
|
||||||
if (data.token && data.key) {
|
if (data.token && data.key) {
|
||||||
commit('setToken', data.token);
|
commit('setToken', data.token);
|
||||||
commit('setUser', username);
|
commit('setUser', username);
|
||||||
commit('setKey', data.key);
|
commit('setKey', data.key);
|
||||||
const s = await dispatch('lookupServer', {username}).then(servers => new ServerSet(servers, state.unreachable_neighbors))
|
|
||||||
commit('setHomeServers', s)
|
commit('setHomeServers', s)
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -77,7 +77,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<button class="btn" @click="getInventoryItems">Refresh</button>
|
<button class="btn" @click="fetchInventoryItems">Refresh</button>
|
||||||
<router-link to="/inventory/new" class="btn btn-primary">Add</router-link>
|
<router-link to="/inventory/new" class="btn btn-primary">Add</router-link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -110,25 +110,10 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(["apiFederatedGet", "getFriends", "getFriendServer"]),
|
...mapActions(["fetchInventoryItems"]),
|
||||||
...mapMutations(["setInventoryItems"]),
|
|
||||||
async getInventoryItems() {
|
|
||||||
try {
|
|
||||||
const servers = await this.getFriends().then(friends => friends.map(friend => this.getFriendServer({username: friend})))
|
|
||||||
const urls = servers.map(server => server.then(s => {
|
|
||||||
return {host: s, target: "/api/inventory_items/"}
|
|
||||||
}))
|
|
||||||
urls.map(url => url.then(u => this.apiFederatedGet(u).then(items => {
|
|
||||||
this.setInventoryItems({url: u.domain, items})
|
|
||||||
}).catch(e => {
|
|
||||||
}))) // TODO: handle error
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
await this.getInventoryItems()
|
await this.fetchInventoryItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue