gancio/components/admin/Federation.vue

147 lines
5.1 KiB
Vue
Raw Normal View History

<template lang="pug">
2020-07-25 21:41:22 +02:00
v-container
2020-08-05 17:29:15 +02:00
v-card-title {{$t('common.federation')}}
v-card-text
v-switch(v-model='enable_federation'
:label="$t('admin.enable_federation')"
persistent-hint
inset
:hint="$t('admin.enable_federation_help')")
2019-11-03 00:54:23 +01:00
2020-08-05 17:29:15 +02:00
template(v-if='enable_federation')
2019-11-03 00:54:23 +01:00
2020-08-05 17:29:15 +02:00
v-switch.mt-4(v-model='enable_resources'
:label="$t('admin.enable_resources')"
:hint="$t('admin.enable_resources_help')"
persistent-hint inset)
2019-11-03 00:54:23 +01:00
2020-08-05 17:29:15 +02:00
v-switch.mt-4(v-model='hide_boosts'
:label="$t('admin.hide_boost_bookmark')"
:hint="$t('admin.hide_boost_bookmark_help')"
persistent-hint inset)
2020-02-21 17:33:20 +01:00
2020-08-05 17:29:15 +02:00
//- div.mt-4 {{$t('admin.instance_name')}}
v-text-field.mt-5(v-model='instance_name'
:label="$t('admin.instance_name')"
2020-09-05 01:21:47 +02:00
:hint="`${$t('admin.instance_name_help')} ${instance_ap_url}`"
2020-08-05 17:29:15 +02:00
placeholder='Instance name' persistent-hint
@blur='save("instance_name", instance_name)')
2019-10-30 15:01:15 +01:00
2020-08-05 17:29:15 +02:00
v-switch.mt-4(v-model='enable_trusted_instances'
:label="$t('admin.enable_trusted_instances')"
persistent-hint inset
:hint="$t('admin.trusted_instances_help')")
2020-03-18 10:11:24 +01:00
2020-08-05 17:29:15 +02:00
template(v-if='enable_trusted_instances')
v-text-field.mt-4(v-model='instance_place'
:label="$t('admin.instance_place')"
persistent-hint
:hint="$t('admin.instance_place_help')"
@blur='save("instance_place", instance_place)'
)
2020-03-18 10:11:24 +01:00
2020-08-05 17:29:15 +02:00
v-dialog(v-model='dialogAddInstance' width="500px")
2020-10-09 00:40:36 +02:00
v-card(color='secondary')
2020-08-05 17:29:15 +02:00
v-card-title {{$t('admin.add_trusted_instance')}}
v-card-text
2020-10-09 00:40:36 +02:00
v-form(v-model='valid' ref='form' lazy-validation)
v-text-field.mt-4(v-model='instance_url'
persistent-hint
:rules="[$validators.required('common.url')]"
:hint="$t('admin.add_trusted_instance')"
:label="$t('common.url')")
2020-08-05 17:29:15 +02:00
v-card-actions
v-spacer
v-btn(color='error' @click='dialogAddInstance=false') {{$t('common.cancel')}}
2020-10-09 00:40:36 +02:00
v-btn(color='primary' :disabled='!valid' @click='createTrustedInstance') {{$t('common.ok')}}
2020-03-14 18:45:20 +01:00
2020-10-07 10:06:49 +02:00
v-btn.mt-4(@click='dialogAddInstance = true' color='primary' text) <v-icon>mdi-plus</v-icon> Add instance
2020-08-05 17:29:15 +02:00
v-data-table(
:headers='headers'
:items='settings.trusted_instances')
template(v-slot:item.actions="{item}")
v-btn(icon @click='deleteInstance(item)' color='error')
v-icon mdi-delete-forever
2020-03-14 18:45:20 +01:00
</template>
<script>
2020-02-05 00:41:23 +01:00
import { mapActions, mapState } from 'vuex'
2020-03-18 10:11:24 +01:00
import axios from 'axios'
2019-12-04 01:20:31 +01:00
export default {
name: 'Federation',
2020-07-25 21:41:22 +02:00
data ({ $store, $options }) {
2020-03-14 18:45:20 +01:00
return {
2020-03-18 10:11:24 +01:00
instance_url: '',
instance_name: $store.state.settings.instance_name,
2020-07-25 21:41:22 +02:00
instance_place: $store.state.settings.instance_place,
2020-07-28 12:24:39 +02:00
url2host: $options.filters.url2host,
dialogAddInstance: false,
2020-08-05 17:29:15 +02:00
valid: false,
2020-07-28 12:24:39 +02:00
headers: [
{ value: 'name', text: 'Name' },
{ value: 'url', text: 'URL' },
{ value: 'label', text: 'Place' },
{ value: 'actions', text: 'Actions', align: 'right' }
]
2020-03-14 18:45:20 +01:00
}
},
computed: {
...mapState(['settings']),
enable_federation: {
get () { return this.settings.enable_federation },
set (value) { this.setSetting({ key: 'enable_federation', value }) }
},
2019-12-04 01:20:31 +01:00
enable_resources: {
get () { return this.settings.enable_resources },
set (value) { this.setSetting({ key: 'enable_resources', value }) }
},
2019-12-04 01:20:31 +01:00
hide_boosts: {
get () { return this.settings.hide_boosts },
set (value) { this.setSetting({ key: 'hide_boosts', value }) }
2020-03-18 10:11:24 +01:00
},
enable_trusted_instances: {
get () { return this.settings.enable_trusted_instances },
set (value) { this.setSetting({ key: 'enable_trusted_instances', value }) }
2020-09-05 01:21:47 +02:00
},
instance_ap_url () {
const instance_url = this.settings.baseurl.match(/^https?:\/\/(.[^/:]+)/i)[1]
return `(@${this.instance_name}@${instance_url})`
2019-10-28 17:33:20 +01:00
}
2020-02-05 00:41:23 +01:00
},
2020-02-21 17:33:20 +01:00
methods: {
...mapActions(['setSetting']),
2020-03-18 10:11:24 +01:00
async createTrustedInstance () {
2020-10-09 00:40:36 +02:00
if (!this.$refs.form.validate()) return
2020-03-18 10:11:24 +01:00
try {
2020-05-22 00:30:29 +02:00
const instance = await axios.get(`${this.instance_url}/.well-known/nodeinfo/2.1`)
2020-03-18 10:11:24 +01:00
this.setSetting({
key: 'trusted_instances',
value: this.settings.trusted_instances.concat({
url: this.instance_url,
name: instance.data.metadata.nodeName,
label: instance.data.metadata.nodeLabel
})
})
this.instance_url = ''
} catch (e) {
2020-10-07 11:12:13 +02:00
this.$root.$message(e, { color: 'error' })
2020-03-18 10:11:24 +01:00
}
},
2020-07-28 12:24:39 +02:00
async deleteInstance (instance) {
2020-10-07 11:12:13 +02:00
const ret = await this.$root.$confirm('admin.delete_trusted_instance_confirm')
2020-07-28 12:24:39 +02:00
if (!ret) { return }
this.setSetting({
key: 'trusted_instances',
value: this.settings.trusted_instances.filter(i => i.url !== instance.url)
2020-03-18 10:11:24 +01:00
})
},
2020-02-21 17:33:20 +01:00
save (key, value) {
if (this.settings[key] !== value) {
this.setSetting({ key, value })
}
2020-03-02 15:36:11 +01:00
}
2020-02-21 17:33:20 +01:00
}
}
2019-10-28 17:33:20 +01:00
</script>