2020-08-21 12:51:20 +00:00
|
|
|
import Vue from 'vue'
|
2020-08-24 02:56:33 +00:00
|
|
|
import { mapActions } from 'vuex'
|
|
|
|
import FtLoader from '../../components/ft-loader/ft-loader.vue'
|
2020-08-21 12:51:20 +00:00
|
|
|
import FtCard from '../../components/ft-card/ft-card.vue'
|
2020-08-31 21:35:22 +00:00
|
|
|
import FtPrompt from '../../components/ft-prompt/ft-prompt.vue'
|
2020-08-21 12:51:20 +00:00
|
|
|
import FtFlexBox from '../../components/ft-flex-box/ft-flex-box.vue'
|
2020-08-24 02:56:33 +00:00
|
|
|
import FtInput from '../../components/ft-input/ft-input.vue'
|
|
|
|
import FtButton from '../../components/ft-button/ft-button.vue'
|
2020-08-21 12:51:20 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'ProfileEdit',
|
|
|
|
components: {
|
2020-08-24 02:56:33 +00:00
|
|
|
'ft-loader': FtLoader,
|
2020-08-21 12:51:20 +00:00
|
|
|
'ft-card': FtCard,
|
2020-08-31 21:35:22 +00:00
|
|
|
'ft-prompt': FtPrompt,
|
2020-08-21 12:51:20 +00:00
|
|
|
'ft-flex-box': FtFlexBox,
|
2020-08-24 02:56:33 +00:00
|
|
|
'ft-input': FtInput,
|
|
|
|
'ft-button': FtButton
|
|
|
|
},
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
isLoading: false,
|
2020-08-31 21:35:22 +00:00
|
|
|
showDeletePrompt: false,
|
|
|
|
deletePromptLabel: '',
|
2020-08-24 02:56:33 +00:00
|
|
|
isNew: false,
|
|
|
|
profileId: '',
|
|
|
|
profileName: '',
|
|
|
|
profileBgColor: '',
|
|
|
|
profileTextColor: '',
|
2020-08-31 21:35:22 +00:00
|
|
|
profileSubscriptions: [],
|
|
|
|
deletePromptValues: [
|
|
|
|
'yes',
|
|
|
|
'no'
|
|
|
|
]
|
2020-08-24 02:56:33 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
colorValues: function () {
|
|
|
|
return this.$store.getters.getColorValues
|
|
|
|
},
|
|
|
|
profileInitial: function () {
|
|
|
|
return this.profileName.slice(0, 1).toUpperCase()
|
2020-08-31 21:35:22 +00:00
|
|
|
},
|
|
|
|
activeProfile: function () {
|
|
|
|
return this.$store.getters.getActiveProfile
|
|
|
|
},
|
|
|
|
defaultProfile: function () {
|
|
|
|
return this.$store.getters.getDefaultProfile
|
|
|
|
},
|
|
|
|
deletePromptNames: function () {
|
|
|
|
return [
|
|
|
|
this.$t('Yes'),
|
|
|
|
this.$t('No')
|
|
|
|
]
|
2020-08-24 02:56:33 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
profileBgColor: async function (val) {
|
|
|
|
this.profileTextColor = await this.calculateColorLuminance(val)
|
|
|
|
}
|
2020-08-21 12:51:20 +00:00
|
|
|
},
|
2020-08-31 21:35:22 +00:00
|
|
|
mounted: async function () {
|
2020-08-24 02:56:33 +00:00
|
|
|
this.isLoading = true
|
|
|
|
const profileType = this.$route.name
|
|
|
|
|
2020-08-31 21:35:22 +00:00
|
|
|
this.deletePromptLabel = 'Are you sure you want to delete this profile? All subscriptions in this profile will also be deleted.'
|
|
|
|
|
2020-08-24 02:56:33 +00:00
|
|
|
if (profileType === 'newProfile') {
|
|
|
|
this.isNew = true
|
2020-08-31 21:35:22 +00:00
|
|
|
this.profileBgColor = await this.getRandomColor()
|
|
|
|
this.isLoading = false
|
2020-08-24 02:56:33 +00:00
|
|
|
} else {
|
|
|
|
this.isNew = false
|
|
|
|
this.profileId = this.$route.params.id
|
|
|
|
console.log(this.profileId)
|
|
|
|
console.log(this.$route.name)
|
|
|
|
|
|
|
|
this.grabProfileInfo(this.profileId).then((profile) => {
|
2020-08-31 21:35:22 +00:00
|
|
|
if (profile === null) {
|
|
|
|
this.showToast({
|
|
|
|
message: 'Profile could not be found'
|
|
|
|
})
|
|
|
|
this.$router.push({
|
|
|
|
path: '/settings/profile/'
|
|
|
|
})
|
|
|
|
}
|
2020-08-24 02:56:33 +00:00
|
|
|
this.profileName = profile.name
|
|
|
|
this.profileBgColor = profile.bgColor
|
|
|
|
this.profileTextColor = profile.textColor
|
|
|
|
this.profileSubscriptions = profile.subscriptions
|
|
|
|
this.isLoading = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-08-31 21:35:22 +00:00
|
|
|
openDeletePrompt: function () {
|
|
|
|
this.showDeletePrompt = true
|
|
|
|
},
|
|
|
|
|
|
|
|
handleDeletePrompt: function (response) {
|
|
|
|
if (response === 'yes') {
|
|
|
|
this.deleteProfile()
|
|
|
|
} else {
|
|
|
|
this.showDeletePrompt = false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-08-24 02:56:33 +00:00
|
|
|
saveProfile: function () {
|
2020-08-31 21:35:22 +00:00
|
|
|
if (this.profileName === '') {
|
|
|
|
this.showToast({
|
|
|
|
message: 'Your profile name cannot be empty'
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2020-08-24 02:56:33 +00:00
|
|
|
const profile = {
|
|
|
|
name: this.profileName,
|
|
|
|
bgColor: this.profileBgColor,
|
|
|
|
textColor: this.profileTextColor,
|
|
|
|
subscriptions: this.profileSubscriptions
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.isNew) {
|
|
|
|
profile._id = this.profileId
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(profile)
|
|
|
|
|
|
|
|
this.updateProfile(profile)
|
2020-08-31 21:35:22 +00:00
|
|
|
|
|
|
|
if (this.isNew) {
|
|
|
|
this.showToast({
|
|
|
|
message: 'Profile has been created'
|
|
|
|
})
|
|
|
|
this.$router.push({
|
|
|
|
path: '/settings/profile/'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.showToast({
|
|
|
|
message: 'Profile has been updated'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setDefaultProfile: function () {
|
|
|
|
this.updateDefaultProfile(this.profileId)
|
|
|
|
this.showToast({
|
|
|
|
message: `Your default profile has been set to ${this.profileName}`
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteProfile: function () {
|
|
|
|
this.removeProfile(this.profileId)
|
2020-08-24 02:56:33 +00:00
|
|
|
this.showToast({
|
2020-08-31 21:35:22 +00:00
|
|
|
message: `Removed ${this.profileName} from your profiles`
|
|
|
|
})
|
|
|
|
if (this.defaultProfile === this.profileId) {
|
|
|
|
this.updateDefaultProfile('allChannels')
|
|
|
|
this.showToast({
|
|
|
|
message: 'Your default profile has been set your Primary profile'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (this.activeProfile._id === this.profileId) {
|
|
|
|
this.updateActiveProfile('allChannels')
|
|
|
|
}
|
|
|
|
this.$router.push({
|
|
|
|
path: '/settings/profile/'
|
2020-08-24 02:56:33 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
...mapActions([
|
|
|
|
'showToast',
|
|
|
|
'grabProfileInfo',
|
|
|
|
'updateProfile',
|
2020-08-31 21:35:22 +00:00
|
|
|
'removeProfile',
|
|
|
|
'updateDefaultProfile',
|
|
|
|
'updateActiveProfile',
|
|
|
|
'calculateColorLuminance',
|
|
|
|
'getRandomColor'
|
2020-08-24 02:56:33 +00:00
|
|
|
])
|
2020-08-21 12:51:20 +00:00
|
|
|
}
|
|
|
|
})
|