mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-04 21:26:08 +08:00
Add pkg/harvester components + shell portings - 1
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<script>
|
||||
import Tabbed from '@shell/components/Tabbed';
|
||||
import Tab from '@shell/components/Tabbed/Tab';
|
||||
import CruResource from '@shell/components/CruResource';
|
||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import NameNsDescription from '@shell/components/form/NameNsDescription';
|
||||
import FileSelector, { createOnSelected } from '@shell/components/form/FileSelector';
|
||||
|
||||
import { randomStr } from '@shell/utils/string';
|
||||
import CreateEditView from '@shell/mixins/create-edit-view';
|
||||
|
||||
export default {
|
||||
name: 'HarvesterEditKeypair',
|
||||
|
||||
components: {
|
||||
Tab,
|
||||
Tabbed,
|
||||
CruResource,
|
||||
LabeledInput,
|
||||
FileSelector,
|
||||
NameNsDescription
|
||||
},
|
||||
|
||||
mixins: [CreateEditView],
|
||||
|
||||
props: {
|
||||
value: {
|
||||
type: Object,
|
||||
required: true,
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
if ( !this.value.spec ) {
|
||||
this.value.spec = {};
|
||||
this.value.metadata = { name: '' };
|
||||
}
|
||||
|
||||
return {
|
||||
publicKey: this.value.spec.publicKey || '',
|
||||
randomString: '',
|
||||
};
|
||||
},
|
||||
|
||||
watch: {
|
||||
publicKey(neu) {
|
||||
const trimNeu = neu.trim();
|
||||
|
||||
this.value.spec.publicKey = trimNeu;
|
||||
|
||||
const splitSSH = trimNeu.split(/\s+/);
|
||||
|
||||
if (splitSSH.length === 3 && !this.value.metadata.name) {
|
||||
const keyComment = splitSSH[2];
|
||||
|
||||
this.randomString = randomStr(10).toLowerCase();
|
||||
this.value.metadata.name = keyComment.includes('@') ? keyComment.split('@')[0] : keyComment;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: { onKeySelected: createOnSelected('publicKey') },
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<CruResource
|
||||
:done-route="doneRoute"
|
||||
:resource="value"
|
||||
:mode="mode"
|
||||
:errors="errors"
|
||||
:apply-hooks="applyHooks"
|
||||
@finish="save"
|
||||
>
|
||||
<div class="header mb-20">
|
||||
<FileSelector
|
||||
v-if="isCreate"
|
||||
class="btn btn-sm bg-primary mt-10"
|
||||
:label="t('generic.readFromFile')"
|
||||
accept=".pub"
|
||||
@selected="onKeySelected"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<NameNsDescription
|
||||
ref="nd"
|
||||
:key="randomString"
|
||||
v-model="value"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Tabbed v-bind="$attrs" class="mt-15" :side-tabs="true">
|
||||
<Tab name="basic" :label="t('harvester.sshKey.tabs.basics')" :weight="1" class="bordered-table">
|
||||
<LabeledInput
|
||||
v-model="publicKey"
|
||||
type="multiline"
|
||||
:mode="mode"
|
||||
:min-height="160"
|
||||
:label="t('harvester.sshKey.keypair')"
|
||||
required
|
||||
/>
|
||||
</Tab>
|
||||
</Tabbed>
|
||||
</CruResource>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user