|
|
@@ -1,5 +1,5 @@
|
|
1
|
1
|
import { ref } from 'vue'
|
|
2
|
|
-import { fetchResponsesByProfileId } from '../services'
|
|
|
2
|
+import { fetchResponsesByProfileId, Chatter, StonkAlert } from '../services'
|
|
3
|
3
|
import { surveyFactory } from '../utils'
|
|
4
|
4
|
|
|
5
|
5
|
/**
|
|
|
@@ -9,12 +9,15 @@ import { surveyFactory } from '../utils'
|
|
9
|
9
|
class Login {
|
|
10
|
10
|
constructor() {
|
|
11
|
11
|
this._loading = false
|
|
12
|
|
-
|
|
|
12
|
+
|
|
13
|
13
|
// Make reactive with vue observer
|
|
14
|
14
|
this.id = ref(null)
|
|
15
|
15
|
|
|
16
|
16
|
this.responses = []
|
|
17
|
17
|
this.tags = []
|
|
|
18
|
+
|
|
|
19
|
+ this.toaster = null
|
|
|
20
|
+ this.chatter = null
|
|
18
|
21
|
}
|
|
19
|
22
|
get isLoading() {
|
|
20
|
23
|
return this._loading
|
|
|
@@ -30,12 +33,15 @@ class Login {
|
|
30
|
33
|
}
|
|
31
|
34
|
/**
|
|
32
|
35
|
* Combine questions retrieved from the database and
|
|
33
|
|
- * questions defined in out lang file and
|
|
|
36
|
+ * questions defined in out lang file and
|
|
34
|
37
|
* copare to responses stored
|
|
35
|
38
|
* @returns {boolean}
|
|
36
|
39
|
*/
|
|
37
|
40
|
get isComplete() {
|
|
38
|
|
- return this.responses.length == surveyFactory.questionsFromDb.length && surveyFactory.questionsFromDb.length > 0
|
|
|
41
|
+ return (
|
|
|
42
|
+ this.responses.length == surveyFactory.questionsFromDb.length &&
|
|
|
43
|
+ surveyFactory.questionsFromDb.length > 0
|
|
|
44
|
+ )
|
|
39
|
45
|
}
|
|
40
|
46
|
/**
|
|
41
|
47
|
* Check that some responses are set
|
|
|
@@ -43,20 +49,28 @@ class Login {
|
|
43
|
49
|
*/
|
|
44
|
50
|
get hasResponses() {
|
|
45
|
51
|
return this.responses.length && this.responses.length > 0
|
|
46
|
|
- }
|
|
|
52
|
+ }
|
|
47
|
53
|
|
|
48
|
54
|
/**
|
|
49
|
55
|
* Login a profile by id number
|
|
50
|
56
|
* @param {number} profileId
|
|
51
|
57
|
* @returns {number} stored reactive id
|
|
52
|
58
|
*/
|
|
53
|
|
- async login(profileId) {
|
|
|
59
|
+ async login(profileId) {
|
|
54
|
60
|
console.warn('logging in:', profileId)
|
|
55
|
61
|
this.id.value = parseInt(profileId)
|
|
56
|
62
|
return this.id.value
|
|
57
|
63
|
}
|
|
58
|
|
- logout() { this.id.value = null }
|
|
59
|
|
-
|
|
|
64
|
+ logout() {
|
|
|
65
|
+ this.id.value = null
|
|
|
66
|
+ if (this.toaster) {
|
|
|
67
|
+ this.toaster.stop()
|
|
|
68
|
+ }
|
|
|
69
|
+ if (this.chatter) {
|
|
|
70
|
+ this.toaster.stop()
|
|
|
71
|
+ }
|
|
|
72
|
+ }
|
|
|
73
|
+
|
|
60
|
74
|
async getTags() {
|
|
61
|
75
|
try {
|
|
62
|
76
|
const tags = []
|
|
|
@@ -65,7 +79,9 @@ class Login {
|
|
65
|
79
|
console.error(err)
|
|
66
|
80
|
}
|
|
67
|
81
|
}
|
|
68
|
|
- setTags(tags) { this.tags = tags }
|
|
|
82
|
+ setTags(tags) {
|
|
|
83
|
+ this.tags = tags
|
|
|
84
|
+ }
|
|
69
|
85
|
|
|
70
|
86
|
async getResponses() {
|
|
71
|
87
|
try {
|
|
|
@@ -75,7 +91,20 @@ class Login {
|
|
75
|
91
|
console.error(err)
|
|
76
|
92
|
}
|
|
77
|
93
|
}
|
|
78
|
|
- setResponses(responses) { this.responses = responses }
|
|
|
94
|
+ setResponses(responses) {
|
|
|
95
|
+ this.responses = responses
|
|
|
96
|
+ }
|
|
|
97
|
+ /**
|
|
|
98
|
+ * For push notifications and chat
|
|
|
99
|
+ */
|
|
|
100
|
+ setupToaster(waveCb) {
|
|
|
101
|
+ this.toaster = new StonkAlert(this.id.value, waveCb)
|
|
|
102
|
+ }
|
|
|
103
|
+ setupChatter() {
|
|
|
104
|
+ this.chatter = new Chatter()
|
|
|
105
|
+ const testAccountUUID = import.meta.env.VITE_TEST_ACCOUNT_UUID
|
|
|
106
|
+ this.chatter.setup(testAccountUUID)
|
|
|
107
|
+ }
|
|
79
|
108
|
}
|
|
80
|
109
|
|
|
81
|
110
|
const currentProfile = new Login()
|