forked from AkkomaGang/admin-fe
Add validation and installation of an unknown frontend
This commit is contained in:
parent
d7ef98e68b
commit
56c20277a4
5 changed files with 57 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
import { getToken } from '@/utils/auth'
|
import { getToken } from '@/utils/auth'
|
||||||
import { baseName } from './utils'
|
import { baseName } from './utils'
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
export async function deleteInstanceDocument(name, authHost, token) {
|
export async function deleteInstanceDocument(name, authHost, token) {
|
||||||
return await request({
|
return await request({
|
||||||
|
@ -78,12 +79,13 @@ export async function fetchFrontends(authHost, token) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installFrontend(data, authHost, token) {
|
export async function installFrontend(data, authHost, token) {
|
||||||
|
const filteredData = _.pickBy(data)
|
||||||
return await request({
|
return await request({
|
||||||
baseURL: baseName(authHost),
|
baseURL: baseName(authHost),
|
||||||
url: `/api/pleroma/admin/frontends/install`,
|
url: `/api/pleroma/admin/frontends/install`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
headers: authHeaders(token),
|
headers: authHeaders(token),
|
||||||
data
|
data: filteredData
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -473,8 +473,9 @@ export default {
|
||||||
ref: 'Ref',
|
ref: 'Ref',
|
||||||
file: 'File',
|
file: 'File',
|
||||||
buildUrl: 'Build URL',
|
buildUrl: 'Build URL',
|
||||||
buildDir: 'Build Directory'
|
buildDir: 'Build Directory',
|
||||||
|
frontendSuccess: 'Frontend installed successfully!',
|
||||||
|
frontendStartedInstallation: 'Installation started'
|
||||||
},
|
},
|
||||||
invites: {
|
invites: {
|
||||||
inviteTokens: 'Invite tokens',
|
inviteTokens: 'Invite tokens',
|
||||||
|
|
|
@ -10,6 +10,8 @@ import {
|
||||||
updateSettings } from '@/api/settings'
|
updateSettings } from '@/api/settings'
|
||||||
import { formSearchObject, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers'
|
import { formSearchObject, parseNonTuples, parseTuples, valueHasTuples, wrapUpdatedSettings } from './normalizers'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
import { Message } from 'element-ui'
|
||||||
|
import i18n from '@/lang'
|
||||||
|
|
||||||
const settings = {
|
const settings = {
|
||||||
state: {
|
state: {
|
||||||
|
@ -122,11 +124,18 @@ const settings = {
|
||||||
commit('TOGGLE_TABS', false)
|
commit('TOGGLE_TABS', false)
|
||||||
commit('SET_LOADING', false)
|
commit('SET_LOADING', false)
|
||||||
},
|
},
|
||||||
async InstallFrontend({ commit, getters }, { name, _ref, _file, _buildUrl, _buildDir }) {
|
async InstallFrontend({ commit, getters }, { name, ref, file, buildUrl, buildDir }) {
|
||||||
const { data } = _ref
|
try {
|
||||||
? await installFrontend({ name, ref: _ref, file: _file, build_url: _buildUrl, build_dir: _buildDir }, getters.authHost, getters.token)
|
const { data } = await installFrontend({ name, ref, file, build_url: buildUrl, build_dir: buildDir }, getters.authHost, getters.token)
|
||||||
: await installFrontend({ name }, getters.authHost, getters.token)
|
|
||||||
commit('SET_FRONTENDS', data)
|
commit('SET_FRONTENDS', data)
|
||||||
|
} catch (_e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Message({
|
||||||
|
message: i18n.t('settings.frontendSuccess'),
|
||||||
|
type: 'success',
|
||||||
|
duration: 5 * 1000
|
||||||
|
})
|
||||||
},
|
},
|
||||||
async RemoveInstanceDocument({ dispatch, getters }, name) {
|
async RemoveInstanceDocument({ dispatch, getters }, name) {
|
||||||
await deleteInstanceDocument(name, getters.authHost, getters.token)
|
await deleteInstanceDocument(name, getters.authHost, getters.token)
|
||||||
|
|
|
@ -45,8 +45,8 @@
|
||||||
@click="toggleFrontendInput"/>
|
@click="toggleFrontendInput"/>
|
||||||
<span class="icons-button-desc">{{ $t('settings.installAnotherFrontend') }}</span>
|
<span class="icons-button-desc">{{ $t('settings.installAnotherFrontend') }}</span>
|
||||||
</div>
|
</div>
|
||||||
<el-form v-if="frontendInputOpen" :model="frontendFormData" label-width="120px">
|
<el-form v-if="frontendInputOpen" ref="frontendFormData" :rules="rules" :model="frontendFormData" label-width="130px">
|
||||||
<el-form-item :label="$t('settings.name')" class="frontend-form-input">
|
<el-form-item :label="$t('settings.name')" class="frontend-form-input" prop="name">
|
||||||
<el-input v-model="frontendFormData.name"/>
|
<el-input v-model="frontendFormData.name"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('settings.ref')" class="frontend-form-input">
|
<el-form-item :label="$t('settings.ref')" class="frontend-form-input">
|
||||||
|
@ -123,6 +123,9 @@ export default {
|
||||||
file: '',
|
file: '',
|
||||||
buildUrl: '',
|
buildUrl: '',
|
||||||
buildDir: ''
|
buildDir: ''
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
name: { required: true, message: 'Please input Name', trigger: 'blur' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -214,10 +217,39 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
installFrontend({ name }) {
|
installFrontend({ name }) {
|
||||||
|
try {
|
||||||
this.$store.dispatch('InstallFrontend', { name })
|
this.$store.dispatch('InstallFrontend', { name })
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: i18n.t('settings.frontendStartedInstallation')
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
},
|
},
|
||||||
installNewFrontend() {
|
installNewFrontend() {
|
||||||
|
try {
|
||||||
|
this.$refs['frontendFormData'].validate((valid) => {
|
||||||
|
if (valid) {
|
||||||
|
this.$store.dispatch('InstallFrontend', this.frontendFormData)
|
||||||
|
this.frontendFormData = {
|
||||||
|
name: '',
|
||||||
|
ref: '',
|
||||||
|
file: '',
|
||||||
|
buildUrl: '',
|
||||||
|
buildDir: ''
|
||||||
|
}
|
||||||
|
this.$message({
|
||||||
|
type: 'success',
|
||||||
|
message: i18n.t('settings.frontendStartedInstallation')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async onSubmit() {
|
async onSubmit() {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -79,7 +79,7 @@
|
||||||
margin-right: 30px;
|
margin-right: 30px;
|
||||||
}
|
}
|
||||||
.frontend-form-input {
|
.frontend-form-input {
|
||||||
margin-top: 15px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
.frontends-button-container {
|
.frontends-button-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
Loading…
Reference in a new issue