-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDetails.vue
215 lines (208 loc) · 6.73 KB
/
Details.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<template>
<div>
<!-- Phone and Email can be display inline as icons only (`email.icon_only = true`) or as single line showing text -->
<Contact-Phone
v-if="my_phone && my_phone.number"
:title="my_phone.title"
:country="my_phone.country"
:city="my_phone.city"
:number="my_phone.number"
:icon="my_phone.icon"
:icon_only="phone_as_icon"
:obfuscate="!my_phone_plaintext"
/>
<br v-if="my_phone && my_phone.number && !phone_as_icon" />
<Contact-Phone
v-if="my_mobile && my_mobile.number"
:title="my_mobile.title || 'Mobile'"
:country="my_mobile.country"
:city="my_mobile.city"
:number="my_mobile.number"
:icon="my_mobile.icon || 'mobile-alt'"
:icon_only="mobile_as_icon"
:obfuscate="!my_mobile_plaintext"
/>
<br v-if="my_mobile && my_mobile.number && !mobile_as_icon" />
<Contact-Email
v-if="my_email && (my_email.email || my_email.name)"
:email="my_email.email"
:name="my_email.name"
:domain="my_email.domain"
:title="my_email.title"
:icon_only="email_as_icon"
:obfuscate="!my_email_plaintext"
/>
<br v-if="my_email && (my_email.email || my_email.name) && !email_as_icon" />
<Social-Facebook v-if="my_facebook" :id="my_facebook" />
<Social-LinkedIn v-if="my_linkedin" :id="my_linkedin" />
<Social-XING v-if="my_xing" :id="my_xing" />
<Social-Twitter v-if="my_twitter" :id="my_twitter" />
<Social-Mastodon v-if="my_mastodon" :url="my_mastodon" />
<!-- caution: Mastodon gets an URL passed, not an ID -->
<Social-Telegram v-if="my_telegram" :id="my_telegram" />
<Social-Skype v-if="my_skype" :id="my_skype" />
<Social-Keybase v-if="my_keybase" :id="my_keybase" />
<Social-GitHub v-if="my_github" :id="my_github" />
<Social-StackOverflow v-if="my_stackoverflow" :id="my_stackoverflow" />
<Social-ResearchGate v-if="my_researchgate" :id="my_researchgate" />
<Social-ORCID v-if="my_orcid" :id="my_orcid" />
</div>
</template>
<script>
const attributes = {
phone: ["country", "city", "number", "title"],
mobile: ["country", "city", "number", "title"],
email: ["email", "name", "domain", "title"],
facebook: null,
linkedin: null,
xing: null,
twitter: null,
mastodon: null,
telegram: null,
whatsapp: null,
skype: null,
keybase: null,
github: null,
stackoverflow: null,
researchgate: null,
orcid: null,
}
export default {
name: "Contact-Details",
props: [
"phone",
"phone_as_icon",
"mobile",
"mobile_as_icon",
"email",
"email_as_icon",
"facebook",
"linkedin",
"xing",
"twitter",
"mastodon",
"telegram",
"whatsapp",
"skype",
"keybase",
"github",
"stackoverflow",
"researchgate",
"orcid",
],
data() {
// init the attributes with the component's parameters
return {
my_phone: this.phone,
my_mobile: this.mobile,
my_email: this.email,
my_facebook: this.facebook,
my_linkedin: this.linkedin,
my_xing: this.xing,
my_twitter: this.twitter,
my_telegram: this.telegram,
my_mastodon: this.mastodon,
my_whatsapp: this.whatsapp,
my_skype: this.skype,
my_keybase: this.keybase,
my_github: this.github,
my_stackoverflow: this.stackoverflow,
my_researchgate: this.researchgate,
my_orcid: this.orcid,
}
},
mounted() {
// https://stackoverflow.com/a/57479373/1480587
// this.$route.query.yourProperty
this.checkAllAttributes()
},
methods: {
/**
* iterate over all attributes of all contact elements to check of passed or stored values
*/
checkAllAttributes() {
// first handle some special cases with aliases for URL parameters
this.checkParamAndStorage("email", "email", "email")
this.checkAndParsePhoneNumber("phone", "phone")
this.checkAndParsePhoneNumber("mobile", "mobile")
// then check all other attributes
for (const category in attributes) {
if (attributes.hasOwnProperty(category)) {
const names = attributes[category]
if (names) {
for (const name of names) {
this.checkParamAndStorage(category, name)
}
} else {
// if no array defined, no sub-attributs are available
this.checkParamAndStorage(category, null)
}
}
}
},
/**
* change data value to value from URL query parameter or the one store in local storage
*/
checkParamAndStorage(category, name, url_param_alias) {
// console.debug(this.$route.query)
const key = name ? category + "." + name : category
const paramValue = this.$route.query[url_param_alias || key]
// console.debug(key, " = ", paramValue)
if (paramValue) {
// add to local storage
localStorage.setItem(key, JSON.stringify(paramValue))
}
const storageValue = localStorage.getItem(key)
// console.debug(key, " = ", storageValue)
if (storageValue) {
const value = JSON.parse(storageValue)
// stored or passed value found, use this!
const my_category = "my_" + category
if (!this[my_category]) {
this[my_category] = {}
}
if (name) {
this.$set(this[my_category], name, value)
} else {
this[my_category] = value
}
// and now turn off obfuscation if using value from URL or localStorage
this[my_category + "_plaintext"] = true
}
},
checkAndParsePhoneNumber(url_param_alias, category) {
const paramValue = this.$route.query[url_param_alias]
// console.debug(url_param_alias, " = ", paramValue)
if (paramValue) {
// parse phone number into "country", "city", "number"
// pattern: +country-city-number-ext
let country, city, number
const match = paramValue.match(/^(?:\+(\d+)-)?(?:(\d+)-)?(.*)/)
if (match) {
country = match[1]
city = match[2]
number = match[3]
} else {
// pattern does not match, just set number
number = paramValue
}
// add to local storage
if (!country) country = null
if (!city) city = null
if (!number) number = null
localStorage.setItem(category + ".country", JSON.stringify(country))
localStorage.setItem(category + ".city", JSON.stringify(city))
localStorage.setItem(category + ".number", JSON.stringify(number))
}
},
},
watch: {
// https://router.vuejs.org/guide/essentials/dynamic-matching.html#reacting-to-params-changes
$route(to, from) {
// react to route changes...
// console.info("route changed from ", from, " to ", to)
this.checkAllAttributes()
},
},
}
</script>