stash
This commit is contained in:
parent
297ad7bd99
commit
905452cdf3
6 changed files with 109 additions and 43 deletions
|
@ -32,8 +32,8 @@ export default {
|
|||
}
|
||||
},
|
||||
mounted() {
|
||||
console.log(this.$route)
|
||||
console.log(this.$route.params.query)
|
||||
//console.log(this.$route)
|
||||
//console.log(this.$route.params.query)
|
||||
this.query = decodeURIComponent(this.$route.params.query || encodeURIComponent(""));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ class FallBackResolver {
|
|||
endpoints: this._servers,
|
||||
}
|
||||
)
|
||||
if(result.answers.length === 0) throw new Error('No answer');
|
||||
const first = result.answers[0];
|
||||
this._cache[key] = {time: Date.now(), ...first}; // TODO hadle multiple answers
|
||||
localStorage.setItem('dns-cache', JSON.stringify(this._cache));
|
||||
|
|
|
@ -67,6 +67,11 @@ export default createStore({
|
|||
} else {
|
||||
}
|
||||
router.push('/');
|
||||
/*if (this.$route.query.redirect) {
|
||||
router.push({path: this.$route.query.redirect});
|
||||
} else {
|
||||
router.push({path: '/'});
|
||||
}*/
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -112,7 +117,7 @@ export default createStore({
|
|||
if (!state.user || !state.keypair) {
|
||||
throw new Error('no user or keypair')
|
||||
}
|
||||
const url = host + target
|
||||
const url = "http://" + host + target // TODO https
|
||||
const signature = nacl.crypto_sign_detached(nacl.encode_utf8(url), state.keypair.signSk)
|
||||
const auth = 'Signature ' + state.user + ':' + nacl.to_hex(signature)
|
||||
return await fetch(url, {
|
||||
|
@ -124,13 +129,14 @@ export default createStore({
|
|||
).then(response => response.json())
|
||||
},
|
||||
async apiFederatedPost({state}, {host, target, data}) {
|
||||
console.log('apiFederatedPost', host, target, data)
|
||||
if (state.unreachable_neighbors.queryUnreachable(host)) {
|
||||
throw new Error('unreachable neighbor')
|
||||
}
|
||||
if (!state.user || !state.keypair) {
|
||||
throw new Error('no user or keypair')
|
||||
}
|
||||
const url = host + target
|
||||
const url = "http://" + host + target // TODO https
|
||||
const json = JSON.stringify(data)
|
||||
const signature = nacl.crypto_sign_detached(nacl.encode_utf8(url + json), state.keypair.signSk)
|
||||
const auth = 'Signature ' + state.user + ':' + nacl.to_hex(signature)
|
||||
|
@ -163,6 +169,20 @@ export default createStore({
|
|||
credentials: 'omit',
|
||||
body: JSON.stringify(data)
|
||||
}).then(response => response.json())
|
||||
},
|
||||
async requestFriend({state, dispatch}, {username}) {
|
||||
console.log('requesting friend ' + username)
|
||||
if(username in state.friends) {
|
||||
return true;
|
||||
}
|
||||
const server = await dispatch('getFriendServer', {username})
|
||||
const data = await dispatch('apiFederatedPost', {
|
||||
host: server[0],
|
||||
target: '/api/friendrequests/',
|
||||
data: {befriender: state.user, befriendee: username, befriender_key: nacl.to_hex(state.keypair.signPk)}
|
||||
})
|
||||
console.log(data)
|
||||
return true;
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
|
|
|
@ -15,29 +15,45 @@
|
|||
<tr>
|
||||
<th style="width:40%;">Name</th>
|
||||
<th class="d-none d-md-table-cell" style="width:25%">Server</th>
|
||||
<th>Actions</th>
|
||||
<th>
|
||||
<a @click="fetchFriends" class="align-middle">
|
||||
<b-icon-arrow-clockwise></b-icon-arrow-clockwise>
|
||||
Refresh
|
||||
</a>
|
||||
<a @click="showNewFriend" class="align-middle">
|
||||
<b-icon-plus></b-icon-plus>
|
||||
Add Friend
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="show_newfriend">
|
||||
<td colspan="2">
|
||||
<input type="text" class="form-control" placeholder="user@domain"
|
||||
v-model="newfriend">
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-primary" @click="tryRequestFriend">Send Request</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-for="friend in friendslist" :key="friend.name">
|
||||
<td>{{ friend.name }}</td>
|
||||
<td class="d-none d-md-table-cell">{{ friend.server.join(', ') }}</td>
|
||||
<td class="table-action">
|
||||
<a href="#">
|
||||
<a href="#" class="align-middle">
|
||||
<b-icon-pencil-square></b-icon-pencil-square>
|
||||
Edit
|
||||
</a>
|
||||
<a href="#">
|
||||
<a href="#" class="align-middle">
|
||||
<b-icon-trash></b-icon-trash>
|
||||
Delete
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card">
|
||||
<button class="btn" @click="fetchFriends">Refresh</button>
|
||||
<router-link to="/inventory/new" class="btn btn-primary">Add</router-link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -59,6 +75,8 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
friends: {},
|
||||
show_newfriend: false,
|
||||
newfriend: ""
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -75,7 +93,7 @@ export default {
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['getFriends', "getFriendServer"]),
|
||||
...mapActions(['getFriends', "getFriendServer", "requestFriend"]),
|
||||
fetchFriends() {
|
||||
this.getFriends().then((friends) => {
|
||||
friends.map((friend) => {
|
||||
|
@ -84,6 +102,18 @@ export default {
|
|||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
showNewFriend() {
|
||||
this.show_newfriend = true
|
||||
},
|
||||
tryRequestFriend() {
|
||||
this.requestFriend({username: this.newfriend}).then((ok) => {
|
||||
if (ok) {
|
||||
this.show_newfriend = false
|
||||
this.newfriend = ""
|
||||
this.fetchFriends()
|
||||
}
|
||||
}).catch(() => {})
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
|
|
@ -73,7 +73,7 @@ export default {
|
|||
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: `http://${s}`, target: "/api/inventory_items/"}
|
||||
return {host: s, target: "/api/inventory_items/"}
|
||||
}))
|
||||
urls.map(url => url.then(u => this.apiFederatedGet(u).then(items => {
|
||||
this.setInventoryItems({url: u.domain, items})
|
||||
|
|
|
@ -4,37 +4,36 @@
|
|||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">Inventory</div>
|
||||
<div class="card-header">Create New Item</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Item</th>
|
||||
<th>Quantity</th>
|
||||
<th>Owner</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in inventory_items" :key="item.id">
|
||||
<td>{{ item.name }}</td>
|
||||
<td>{{ item.quantity }}</td>
|
||||
<td>{{ item.owner }}</td>
|
||||
<td>
|
||||
<a href="#">
|
||||
<b-icon-pencil-square></b-icon-pencil-square>
|
||||
</a>
|
||||
<a href="#">
|
||||
<b-icon-trash></b-icon-trash>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name"
|
||||
placeholder="Enter item name" v-model="item.name">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="description" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="description" name="description"
|
||||
placeholder="Enter description" v-model="item.description"></textarea>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="quantity" class="form-label">Quantity</label>
|
||||
<input type="number" class="form-control" id="quantity" name="quantity"
|
||||
placeholder="Enter quantity" v-model="item.quantity">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="price" class="form-label">Price</label>
|
||||
<input type="number" class="form-control" id="price" name="price"
|
||||
placeholder="Enter price" v-model="item.price">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="image" class="form-label">Image</label>
|
||||
<input type="text" class="form-control" id="image" name="image"
|
||||
placeholder="Enter image" v-model="item.image">
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<button class="btn" @click="getInventoryItems">Refresh</button>
|
||||
<router-link to="/inventory/new" class="btn btn-primary">Add</router-link>
|
||||
<button type="submit" class="btn btn-primary" @click="createInventoryItem(item)">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -46,13 +45,29 @@
|
|||
<script>
|
||||
import * as BIcons from "bootstrap-icons-vue";
|
||||
import BaseLayout from "@/components/BaseLayout.vue";
|
||||
import {createApp} from "vue";
|
||||
import {mapActions} from "vuex";
|
||||
|
||||
export default {
|
||||
name: "InventoryNew",
|
||||
data() {
|
||||
return {
|
||||
item: {
|
||||
name: "",
|
||||
description: "",
|
||||
quantity: 0,
|
||||
price: 0,
|
||||
image: ""
|
||||
}
|
||||
}
|
||||
},
|
||||
components: {
|
||||
BaseLayout,
|
||||
...BIcons
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['createInventoryItem']),
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in a new issue