summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjdlugosz963 <jdlugosz963@gmail.com>2021-12-15 15:02:45 +0100
committerjdlugosz963 <jdlugosz963@gmail.com>2021-12-15 15:04:52 +0100
commit1f60c86c538cda423a82554fc15cb95d3ca6a1d8 (patch)
tree9fb8c14f4ac081cbed850058055bfd4a06e7d269
parent49379b11b8dfa179fd81398e8b4b5423c7275038 (diff)
downloadlom_frontend-1f60c86c538cda423a82554fc15cb95d3ca6a1d8.tar.gz
lom_frontend-1f60c86c538cda423a82554fc15cb95d3ca6a1d8.zip
add Groups View and message fetcher
-rw-r--r--src/services/ChatService.js14
-rw-r--r--src/services/CommandsService.js8
-rw-r--r--src/services/NotifyErrorService.js31
-rw-r--r--src/views/Home.vue40
4 files changed, 71 insertions, 22 deletions
diff --git a/src/services/ChatService.js b/src/services/ChatService.js
index 08deba2..d077e9b 100644
--- a/src/services/ChatService.js
+++ b/src/services/ChatService.js
@@ -13,7 +13,7 @@ export default {
13 } 13 }
14 }) 14 })
15 .catch(error => error_notify(error)) 15 .catch(error => error_notify(error))
16 }, 16 },
17 17
18 async get_all_user_groups() { 18 async get_all_user_groups() {
19 return await axios 19 return await axios
@@ -25,5 +25,17 @@ export default {
25 } 25 }
26 }) 26 })
27 .catch(error => error_notify(error)) 27 .catch(error => error_notify(error))
28 },
29
30 async get_group_messages(group_pk) {
31 return await axios
32 .get(url+`groups/detail/${group_pk}/messages/`)
33 .then(res => {
34 return {
35 status: res.status,
36 data: res.data
37 }
38 })
39 .catch(error => error_notify(error))
28 } 40 }
29} 41}
diff --git a/src/services/CommandsService.js b/src/services/CommandsService.js
index cc5bdf2..181d50e 100644
--- a/src/services/CommandsService.js
+++ b/src/services/CommandsService.js
@@ -3,9 +3,9 @@ import ChatService from "./ChatService"
3import store from "@/store/index.js" 3import store from "@/store/index.js"
4import router from '@/router/index.js' 4import router from '@/router/index.js'
5 5
6function set_groups(data) { 6function set_groups(searcher, data) {
7 function group_command(group) { 7 function group_command(group) {
8 console.log(group) 8 searcher.$emit("group_set", group)
9 } 9 }
10 10
11 let groups = {} 11 let groups = {}
@@ -21,11 +21,11 @@ function set_groups(data) {
21export default { 21export default {
22 groups() { 22 groups() {
23 return { 23 return {
24 async send() { 24 async send(searcher) {
25 const {data, status} = await ChatService.get_all_user_groups() 25 const {data, status} = await ChatService.get_all_user_groups()
26 if (status!==200) 26 if (status!==200)
27 return {} 27 return {}
28 const groups = set_groups(data) 28 const groups = set_groups(searcher, data)
29 return groups 29 return groups
30 }, 30 },
31 31
diff --git a/src/services/NotifyErrorService.js b/src/services/NotifyErrorService.js
index b28e664..465b908 100644
--- a/src/services/NotifyErrorService.js
+++ b/src/services/NotifyErrorService.js
@@ -1,16 +1,31 @@
1import Vue from 'vue' 1import Vue from 'vue'
2import router from '@/router/index.js'
3import store from "@/store/index.js"
4
2 5
3const error_notify = (error) => { 6const error_notify = (error) => {
4 for (const [key, values] of Object.entries(error.response.data)) { 7 if(error.response.status === 401) {
5 console.log(values) 8 Vue.notify({
6 values.forEach(value => { 9 type: 'error',
7 Vue.notify({ 10 title: 'Please login again!',
8 type: 'error', 11 text: 'Token expire'
9 title: value,
10 text: (key !== 'non_field_errors') ? key : ''
11 })
12 }) 12 })
13
14 store.dispatch('logout')
15 router.push('/login')
13 } 16 }
17 else
18 for (const [key, values] of Object.entries(error.response.data)) {
19 console.log(values)
20 values.forEach(value => {
21 Vue.notify({
22 type: 'error',
23 title: value,
24 text: (key !== 'non_field_errors') ? key : ''
25 })
26 })
27 }
28
14 return { 29 return {
15 data: error.response.data, 30 data: error.response.data,
16 status: error.response.status 31 status: error.response.status
diff --git a/src/views/Home.vue b/src/views/Home.vue
index 1fbbb7f..7bd99a2 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -1,16 +1,23 @@
1<template> 1<template>
2 <div class="home" v-hotkey="keymap"> 2 <div class="home" v-hotkey="keymap">
3 Hi {{get_username}}! 3 Hi {{get_username}}!
4 <Searcher 4
5 v-if="popups.searcher_show" 5 <div v-for="group in groups" :key="group.name" >
6 @close="hideSearcher" 6 <GroupSender
7 @toogle_group_maker="toogleGroupShow" 7 :group="group"
8 /> 8 />
9 </div>
9 10
10 <GroupMaker 11 <GroupMaker
11 v-if="popups.group_maker_show" 12 v-if="popups.group_maker_show"
12 @close="hideGroup" 13 @close="hideGroup"
14 />
13 15
16 <Searcher
17 v-if="popups.searcher_show"
18 @close="hideSearcher"
19 @toogle_group_maker="toogleGroupShow"
20 @group_set="openGroup"
14 /> 21 />
15 </div> 22 </div>
16</template> 23</template>
@@ -18,6 +25,7 @@
18<script> 25<script>
19import Searcher from '@/components/searcher/Searcher.vue' 26import Searcher from '@/components/searcher/Searcher.vue'
20import GroupMaker from '@/components/group/GroupMaker.vue' 27import GroupMaker from '@/components/group/GroupMaker.vue'
28import GroupSender from '@/components/group/GroupSender.vue'
21 29
22const popups = { 30const popups = {
23 searcher_show: false, 31 searcher_show: false,
@@ -27,7 +35,8 @@ const popups = {
27export default { 35export default {
28 data() { 36 data() {
29 return { 37 return {
30 popups 38 popups,
39 groups: []
31 } 40 }
32 }, 41 },
33 42
@@ -44,7 +53,19 @@ export default {
44 hideSearcher() { this.popups.searcher_show = false }, 53 hideSearcher() { this.popups.searcher_show = false },
45 54
46 toogleGroupShow() { this.popups.group_maker_show = !this.popups.group_maker_show }, 55 toogleGroupShow() { this.popups.group_maker_show = !this.popups.group_maker_show },
47 hideGroup() { this.popups.group_maker_show = false } 56 hideGroup() { this.popups.group_maker_show = false },
57
58 openGroup(group) {
59 let groups = this.groups.slice()
60 let index = groups.findIndex(o => o.name===group.name)
61
62 if(index >= 0)
63 groups.splice(index, 1)
64 else
65 groups.push(group)
66
67 this.groups = groups
68 }
48 }, 69 },
49 70
50 computed: { 71 computed: {
@@ -63,7 +84,8 @@ export default {
63 84
64 components: { 85 components: {
65 Searcher, 86 Searcher,
66 GroupMaker 87 GroupMaker,
88 GroupSender
67 }, 89 },
68 90
69 created() { 91 created() {