summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/ConfiguratorModuleConfig.vue
diff options
context:
space:
mode:
authorUdo Walter2018-09-18 10:33:04 +0200
committerUdo Walter2018-09-18 10:33:04 +0200
commit1d07a975a2562b800fe183c6560f4a3b84ee307a (patch)
tree07f886f07047016af3d9a7565e4abedf497c4c2f /webapp/src/components/ConfiguratorModuleConfig.vue
parent[groups] small bugfixes (diff)
downloadbas-1d07a975a2562b800fe183c6560f4a3b84ee307a.tar.gz
bas-1d07a975a2562b800fe183c6560f4a3b84ee307a.tar.xz
bas-1d07a975a2562b800fe183c6560f4a3b84ee307a.zip
[configurator] add ipxe configurator
Diffstat (limited to 'webapp/src/components/ConfiguratorModuleConfig.vue')
-rw-r--r--webapp/src/components/ConfiguratorModuleConfig.vue193
1 files changed, 193 insertions, 0 deletions
diff --git a/webapp/src/components/ConfiguratorModuleConfig.vue b/webapp/src/components/ConfiguratorModuleConfig.vue
new file mode 100644
index 0000000..7413a90
--- /dev/null
+++ b/webapp/src/components/ConfiguratorModuleConfig.vue
@@ -0,0 +1,193 @@
+<i18n>
+{
+ "en": {
+ "name": "Name",
+ "description": "Description",
+ "timeout": "Timeout",
+ "expertMode": "Expert Mode",
+ "script": "iPXE Script",
+ "titleNew": "Create config",
+ "titleExisting": "Edit config",
+ "entries": "Entries",
+ "customName": "Custom Name",
+ "keyBind": "Key Bind",
+ "defaultEntry": "Mark this entry as default",
+ "entry": "Entry",
+ "spacer": "[Spacer]"
+ },
+ "de": {
+ "name": "Name",
+ "description": "Beschreibung",
+ "timeout": "Timeout",
+ "expertMode": "Expertenmodus",
+ "script": "iPXE Script",
+ "titleNew": "Konfiguration erstellen",
+ "titleExisting": "Konfiguration bearbeiten",
+ "entries": "Einträge",
+ "customName": "Alternativer Name",
+ "keyBind": "Tastenbelegung",
+ "defaultEntry": "Diesen Eintrag als Standard markieren",
+ "entry": "Eintrag",
+ "spacer": "[Abstandshalter]"
+ }
+}
+</i18n>
+
+<template>
+ <v-card>
+ <v-card-title primary-title class="dialog-title elevation-3">
+ <div class="headline">{{ dialog.info.id ? $t('titleExisting') : $t('titleNew') }}</div>
+ </v-card-title>
+ <v-card-text>
+ <v-layout wrap>
+ <v-flex>
+ <v-text-field prepend-icon="label" :label="$t('name')" color="primary" v-model="name"></v-text-field>
+ </v-flex>
+ <v-flex class="text-xs-center">
+ <div style="display: inline-block; max-width: 180px">
+ <v-text-field prepend-icon="timer" :label="$t('timeout')" color="primary" v-model="timeout" mask="######" suffix="ms"></v-text-field>
+ </div>
+ </v-flex>
+ <v-flex class="text-xs-center">
+ <div style="display: inline-block"><v-switch v-model="expertMode" color="primary" :label="$t('expertMode')"></v-switch></div>
+ </v-flex>
+ </v-layout>
+ <v-textarea prepend-icon="description" rows="1" :label="$t('description')" color="primary" v-model="description"></v-textarea>
+ <v-textarea v-if="expertMode" prepend-icon="code" rows="20" :label="$t('script')" color="primary" v-model="script"></v-textarea>
+ <div v-else class="text-xs-right">
+ <v-subheader>{{ $t('entries') }}</v-subheader>
+ <v-list>
+ <draggable v-model="items" :options="{handle:'.handle'}">
+ <v-list-tile v-for="item in items" :key="item.entry.id" @click.stop>
+ <v-list-tile-action class="handle">
+ <v-icon>drag_handle</v-icon>
+ </v-list-tile-action>
+ <v-list-tile-action>
+ <v-tooltip top open-delay="800">
+ <v-radio-group slot="activator" v-model="defaultEntry">
+ <v-radio v-if="item.entry.id" color="primary" :value="item.entry.id"></v-radio>
+ </v-radio-group>
+ <span>{{ $t('defaultEntry') }}</span></v-tooltip>
+ </v-list-tile-action>
+ <v-list-tile-content class="item-content">
+ <v-select return-object style="max-width: 280px" item-text="name" offset-y :label="$t('entry')" color="primary" v-model="item.entry"
+ :items="item.entry.id ? [item.entry, ...availableEntries] : availableEntries"></v-select>
+ <v-text-field v-if="item.entry.id" class="custom-name-input" :label="$t('customName')" color="primary" v-model="item.customName"></v-text-field>
+ <v-text-field v-if="item.entry.id" style="max-width: 60px" prepend-inner-icon="keyboard" color="primary" v-model="item.keyBind" maxlength="1"></v-text-field>
+ </v-list-tile-content>
+ <v-list-tile-action>
+ <v-btn @click="removeItem(item)" icon><v-icon>clear</v-icon></v-btn>
+ </v-list-tile-action>
+ </v-list-tile>
+ </draggable>
+ </v-list>
+ <v-btn @click="addItem" color="success" fab small><v-icon dark>add</v-icon></v-btn>
+ </div>
+ </v-card-text>
+ <v-divider></v-divider>
+ <v-card-actions>
+ <v-spacer></v-spacer>
+ <v-btn flat="flat" @click="setDialog({ show: false })">{{ $t('cancel') }}</v-btn>
+ <v-btn :color="dialog.info.id ? 'primary' : 'success'" @click="saveConfig">{{ dialog.info.id ? $t('save') : $t('create') }}</v-btn>
+ </v-card-actions>
+ </v-card>
+</template>
+
+<script>
+import axios from 'axios'
+import draggable from 'vuedraggable'
+import ComponentSearchTable from '@/components/ComponentSearchTable'
+import { mapState } from 'vuex'
+
+export default {
+ name: 'ConfiguratorModuleConfig',
+ components: {
+ draggable,
+ ComponentSearchTable
+ },
+ data () {
+ return {
+ name: '',
+ description: '',
+ defaultEntry: null,
+ timeout: '',
+ script: '',
+ expertMode: false,
+ items: []
+ }
+ },
+ computed: {
+ ...mapState('configurator', ['dialog', 'entries']),
+ availableEntries () {
+ var selectedEntryIds = this.items.map(x => x.entry.id)
+ return [...this.entries.filter(x => !selectedEntryIds.includes(x.id)), {id: 0, name: this.$t('spacer')}]
+ }
+ },
+ watch: {
+ dialog: {
+ immediate: true,
+ deep: true,
+ async handler (value) {
+ if (value.type === 'config' && value.show) {
+ this.name = value.info.name
+ this.description = value.info.description
+ this.defaultEntry = value.info.defaultEntry
+ this.timeout = value.info.timeout
+ this.script = value.info.script
+ if (this.script) this.expertMode = true
+ this.items = []
+ var result = await axios.get('/api/configurator/configs/' + value.info.id + '/entries')
+ this.items = result.data.map(x => ({
+ entry: { id: x.id, name: x.name, script: x.script },
+ customName: x.config_x_entry.customName,
+ keyBind: x.config_x_entry.keyBind
+ }))
+ }
+ }
+ }
+ },
+ methods: {
+ setDialog (data) {
+ this.$store.commit('configurator/setDialog', data)
+ },
+ addItem () {
+ this.items.push({ entry: {} })
+ },
+ removeItem (item) {
+ this.items.splice(this.items.indexOf(item), 1)
+ },
+ async saveConfig () {
+ await axios.post('/api/configurator/configs/' + this.dialog.info.id, {
+ name: this.name,
+ description: this.description,
+ defaultEntry: this.defaultEntry,
+ timeout: this.timeout,
+ script: this.script,
+ entries: this.items.map(x => ({
+ id: x.entry.id,
+ customName: x.customName,
+ keyBind: x.keyBind
+ }))
+ })
+ this.$store.dispatch('configurator/loadData')
+ this.setDialog({ show: false })
+ }
+ }
+}
+</script>
+
+<!-- Add "scoped" attribute to limit CSS to this component only -->
+<style scoped>
+.dialog-title {
+ z-index: 1;
+}
+.item-content {
+ display: flex;
+ flex-direction: row;
+ justify-content: flex-start;
+}
+.custom-name-input {
+ margin-left: 20px;
+ margin-right: 20px;
+}
+</style>