-
Notifications
You must be signed in to change notification settings - Fork 1
/
Node.vue
116 lines (108 loc) · 3.65 KB
/
Node.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<div>
<nodes></nodes>
<hr>
<h1>Node {{id}}: {{name}}</h1>
<input v-model="newName">
<button @click="putNodeName">change name</button>
<br><br>
<button @click="deleteNode">delete</button>
<h2>Relatives</h2>
<node-relatives v-for="(relativesInOneDirection, i) in relativesInBothDirections"
:relatives="relativesInOneDirection"
:downInt="i"
:currentNodeDebug="id"
></node-relatives>
</div>
</template>
<script>
import Nodes from '../components/Nodes.vue'
import NodeRelatives from '../components/NodeRelatives.vue'
import axios from 'axios'
import { mapActions } from 'vuex'
export default {
data() { return {
id: this.$route.params.id,
name: '',
newName: '',
relativesInBothDirections: [],
backUrlBase: this.$store.state.backUrlBase,
backUrlNodes: this.$store.getters.backUrlNodes,
auth: this.$store.state.auth
}},
computed: {
nodesUrl() {
return this.backUrlNodes + this.id + '/'
},
detailUrl() {
return this.backUrlBase + 'node-details/' + this.id + '/'
},
deleteUrl() {
return this.backUrlBase + 'node-delete/' + this.id + '/'
}
},
watch: {
'$route'(to, from) {
console.log(from.params.id + ' ----> ' + to.params.id)
this.id = to.params.id
this.name = to.params.name
this.newName = to.params.name
this.getNodeRelatives()
}
},
methods: {
...mapActions(['updateNodes']),
getNode() {
axios.get(this.nodesUrl, {auth: this.auth})
.then(response => {
this.name = response.data.name
this.newName = response.data.name
})
.catch(e => {
console.log(e)
})
},
getNodeRelatives() {
axios.get(this.detailUrl, {auth: this.auth})
.then(response => {
this.relativesInBothDirections = response.data
})
.catch(e => {
console.log(e)
})
},
deleteNode() {
axios.delete(this.deleteUrl, {auth: this.auth})
.then(response => {
if (response.data == 'node deleted') {
this.$store.dispatch('updateNodes')
this.$router.push({name: 'nodes'}) // redirect
} else {
alert('node was not deleted')
}
})
.catch(e => {
console.log(e)
})
},
putNodeName() {
axios.put(this.url, {name: this.newName}, {auth: this.auth})
.then(response => {
this.$store.dispatch('updateNodes')
})
.catch(e => {
console.log(e)
})
this.name = this.newName
}
},
created() {
this.getNode()
this.getNodeRelatives()
},
components: {
nodes: Nodes,
nodeRelatives: NodeRelatives
}
}
</script>