gancio/components/admin/Federation.vue

124 lines
4.4 KiB
Vue
Raw Normal View History

<template lang="pug">
2020-02-21 17:33:20 +01:00
el-main
el-switch.d-block(v-model='enable_federation' :active-text="$t('admin.enable_federation')")
small.text-secondary {{$t('admin.enable_federation_help')}}
2019-11-03 00:54:23 +01:00
2020-02-21 17:33:20 +01:00
template(v-if='enable_federation')
2019-11-03 00:54:23 +01:00
2020-02-21 17:33:20 +01:00
el-switch.d-block.mt-4(v-model='enable_resources' :active-text="$t('admin.enable_resources')")
small.text-secondary {{$t('admin.enable_resources_help')}}
2019-11-03 00:54:23 +01:00
2020-02-21 17:33:20 +01:00
el-switch.d-block.mt-4(v-model='hide_boosts' :active-text="$t('admin.hide_boost_bookmark')")
small.text-secondary {{$t('admin.hide_boost_bookmark_help')}}
div.mt-4 {{$t('admin.instance_name')}}
2020-03-18 10:11:24 +01:00
el-input(v-model='instance_name' placeholder='Instance name' @blur='save("instance_name", instance_name)')
2020-02-21 17:33:20 +01:00
small.d-block.text-secondary {{$t('admin.instance_name_help')}} (<u>@{{instance_name}}@{{settings.baseurl|url2host}}</u>)
2019-10-30 15:01:15 +01:00
2020-03-18 10:11:24 +01:00
el-switch.d-block.mt-4(v-model='enable_trusted_instances' :active-text="$t('admin.enable_trusted_instances')")
small.text-secondary {{$t('admin.trusted_instances_help')}}
template(v-if='enable_trusted_instances')
div.mt-4 {{$t('admin.instance_place')}}
el-input(v-model='instance_place' @blur='save("instance_place", instance_place)')
small.d-block.text-secondary {{$t('admin.instance_place_help')}}
div.mt-4 {{$t('admin.add_trusted_instance')}}
el-input(v-model='instance_url' :placeholder="$t('common.url')")
el-button(slot='append' @click='createTrustedInstance') {{$t('common.send')}}
2020-03-14 18:45:20 +01:00
el-table(:data='settings.trusted_instances')
el-table-column(:label="$t('common.name')")
template(slot-scope='data')
span {{data.row.name}}
el-table-column(:label="$t('common.url')")
template(slot-scope='data')
span {{data.row.url}}
2020-03-18 10:11:24 +01:00
el-table-column(:label="$t('common.place')")
template(slot-scope='data')
span {{data.row.label}}
el-table-column(:label="$t('common.actions')")
2020-03-14 18:45:20 +01:00
template(slot-scope='data')
el-button(size='mini'
type='danger'
2020-03-18 10:11:24 +01:00
@click='deleteInstance(data.row)') {{$t('admin.delete_user')}}
2020-03-14 18:45:20 +01:00
</template>
<script>
2020-02-05 00:41:23 +01:00
import { mapActions, mapState } from 'vuex'
2020-05-22 00:30:29 +02:00
import { Message, MessageBox } from 'element-ui'
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-03-18 10:11:24 +01:00
data ({ $store }) {
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,
instance_place: $store.state.settings.instance_place
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 }) }
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 () {
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) {
Message({
showClose: true,
type: 'error',
message: e
})
}
},
2020-05-22 00:30:29 +02:00
deleteInstance (instance) {
MessageBox.confirm(this.$t('admin.delete_trusted_instance_confirm'),
this.$t('common.confirm'), {
confirmButtonText: this.$t('common.ok'),
cancelButtonText: this.$t('common.cancel'),
type: 'error'
}
).then(() => {
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>