summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/IpxeBuilderModuleConfig.vue
blob: 709a04b7f9c1ad0cde3782fbbcbb780db4f2c31b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<i18n>
{
  "en": {
    "efi": "EFI",
    "bios": "BIOS",
    "general": "general.h",
    "console": "console.h",
    "script": "Embedded script (EMBED=)",
    "trust": "Embedded certificate (TRUST=)",
    "ipxe": "iPXE",
    "buildIpxe": "Build iPXE",
    "scriptSaved": "Embedded script saved successfully",
    "certificateSaved": "Certificate saved successfully",
    "generalSaved": "general.h saved successfully",
    "consoleSaved": "console.h saved successfully",
    "buildingIpxe": "Building iPXE ...",
    "cleanIpxe": "Clean iPXE",
    "cleaningIpxe": "Cleaning iPXE ...",
    "alreadyBuiling": "The iPXE building process not finished",
    "cancelIpxe": "Cancel iPXE"
  },
  "de": {
    "efi": "EFI",
    "bios": "BIOS",
    "general": "general.h",
    "console": "console.h",
    "script": "Eingebettetes Skript (EMBED=)",
    "trust": "Eingebettetes Zertifikat (TRUST=)",
    "ipxe": "iPXE",
    "buildIpxe": "iPXE bauen",
    "scriptSaved": "Eingebettetes Skript wurde erfolgreich gespeichert",
    "certificateSaved": "Zertifikat wurde erfolgreich gespeichert",
    "generalSaved": "general.h wurde erfolgreich gespeichert",
    "consoleSaved": "console.h wurde erfolgreich gespeichert",
    "buildingIpxe": "iPXE wird gebaut ...",
    "cleanIpxe": "iPXE aufräumen",
    "cleaningIpxe": "iPXE wird aufgeräumt ..",
    "alreadyBuiling": "Der iPXE build-Prozess ist noch nicht abgeschlossen",
    "cancelIpxe": "iPXE stoppen"
  }
}
</i18n>

<template>
  <div>

    <v-subheader>{{ $t('ipxe') }}</v-subheader>
    <v-card style="height: 588px;" ref="log">
      <RecycleScroller :items="log" :item-size="21" style="height: 100%;">
        <div slot-scope="{ item }" style="height: 21px;">
          <pre :class="item.status + '--text'" style="margin-bottom: 0px"><span>{{ item.date }} {{ item.msg }}</span></pre>
        </div>
      </RecycleScroller>

      <!--
      <v-card style="padding-left: 24px;padding-right: 24px; padding-top: 12px; padding-bottom: 12px; height: 50vh; overflow: auto;" ref="log">
      <template v-for="(entry, index) in log">
      <pre :class="entry.status + '--text'" style="margin-bottom: 0px" :key="index"><span>{{ entry.date }} {{ entry.msg }}</span></pre>
      </template>-->
    </v-card>
    <div class="text-xs-right">
      <v-btn flat color="error" @click="cleanIpxe" :disabled=disableButtons><v-icon left>delete</v-icon>{{ $t('cleanIpxe') }}</v-btn>
      <v-btn flat color="warning" @click="cancelIpxe" :disabled=!disableButtons><v-icon left>cancel</v-icon>{{ $t('cancelIpxe') }}</v-btn>
      <v-btn flat color="primary" @click="buildIpxe" :disabled=disableButtons><v-icon left>gavel</v-icon>{{ $t('buildIpxe') }}</v-btn>
    </div>
    <v-subheader></v-subheader>
    <v-expansion-panel v-model="scriptExpanded" class="non-selectable">
       <v-expansion-panel-content>
        <div slot="header">{{ $t('script') }}</div>
        <v-card>
          <codemirror class="script-editor" ref="script" v-model="script"></codemirror>
        </v-card>
        <!--<v-divider></v-divider>-->
        <div class="text-xs-right">
          <v-btn flat color="error" @click="undo('script')"><v-icon left>undo</v-icon>{{ $t('undo') }}</v-btn>
          <v-btn flat color="success" @click="redo('script')"><v-icon left>redo</v-icon>{{ $t('redo') }}</v-btn>
          <v-btn color="primary" @click="save('script')"><v-icon left>save</v-icon>{{ $t('save') }}</v-btn>
        </div>
      </v-expansion-panel-content>
    </v-expansion-panel>

    <v-subheader></v-subheader>
    <v-expansion-panel v-model="certificateExpanded">
       <v-expansion-panel-content class="non-selectable">
        <div slot="header">{{ $t('trust') }}</div>
        <v-card>
          <codemirror class="script-editor" ref="certificate" v-model="certificate"></codemirror>
        </v-card>
        <!--<v-divider></v-divider>-->
        <div class="text-xs-right">
          <v-btn flat color="error" @click="undo('certificate')"><v-icon left>undo</v-icon>{{ $t('undo') }}</v-btn>
          <v-btn flat color="success" @click="redo('certificate')"><v-icon left>redo</v-icon>{{ $t('redo') }}</v-btn>
          <v-btn color="primary" @click="save('certificate')"><v-icon left>save</v-icon>{{ $t('save') }}</v-btn>
        </div>
      </v-expansion-panel-content>
    </v-expansion-panel>

    <v-subheader></v-subheader>
    <v-expansion-panel v-model="generalExpanded">
       <v-expansion-panel-content class="non-selectable">
        <div slot="header">{{ $t('general') }}</div>
        <v-card>
          <codemirror class="script-editor" ref="general" v-model="general"></codemirror>
        </v-card>
        <!--<v-divider></v-divider>-->
        <div class="text-xs-right">
          <v-btn flat color="error" @click="undo('general')"><v-icon left>undo</v-icon>{{ $t('undo') }}</v-btn>
          <v-btn flat color="success" @click="redo('general')"><v-icon left>redo</v-icon>{{ $t('redo') }}</v-btn>
          <v-btn color="primary" @click="save('general')"><v-icon left>save</v-icon>{{ $t('save') }}</v-btn>
        </div>
      </v-expansion-panel-content>
    </v-expansion-panel>

    <v-subheader></v-subheader>
    <v-expansion-panel v-model="consoleExpanded">
       <v-expansion-panel-content class="non-selectable">
        <div slot="header">{{ $t('console') }}</div>
        <v-card>
          <codemirror class="script-editor" ref="console" v-model="console"></codemirror>
        </v-card>
        <!--<v-divider></v-divider>-->
        <div class="text-xs-right">
          <v-btn flat color="error" @click="undo('console')"><v-icon left>undo</v-icon>{{ $t('undo') }}</v-btn>
          <v-btn flat color="success" @click="redo('console')"><v-icon left>redo</v-icon>{{ $t('redo') }}</v-btn>
          <v-btn color="primary" @click="save('console')"><v-icon left>save</v-icon>{{ $t('save') }}</v-btn>
        </div>
      </v-expansion-panel-content>
    </v-expansion-panel>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import axios from 'axios'

export default {
  name: 'IpxeBuilderModuleConfig',
  props: ['ipxeVersion'],
  components: {
  },
  data () {
    return {
      tabs: 0,
      script: '',
      certificate: '',
      general: '',
      console: '',
      scriptExpanded: null,
      certificateExpanded: null,
      generalExpanded: null,
      consoleExpanded: null,
      log: [],
      disableButtons: false
    }
  },
  computed: {
    ...mapGetters(['tabsDark', 'tabsColor', 'tabsSliderColor'])
  },
  watch: {
    scriptExpanded: async function () {
      await this.$nextTick()
      if (this.scriptExpanded === 0) this.$refs.script.refresh()
    },
    certificateExpanded: async function () {
      await this.$nextTick()
      if (this.certificateExpanded === 0) this.$refs.certificate.refresh()
    },
    generalExpanded: async function () {
      await this.$nextTick()
      if (this.generalExpanded === 0) this.$refs.general.refresh()
    },
    consoleExpanded: async function () {
      await this.$nextTick()
      if (this.consoleExpanded === 0) this.$refs.console.refresh()
    }
  },
  methods: {
    save (apiPath) {
      axios.put('/api/ipxe/' + this.ipxeVersion + '/' + apiPath, { data: this[apiPath] }).then(result => {
        const saveMsg = apiPath + 'Saved'
        if (result.data.status === 'SUCCESS') this.$snackbar({ color: 'success', text: this.$tc(saveMsg) })
        else this.$snackbar({ color: 'error', text: result.data.error })
      })
    },
    undo (element) {
      this.$refs[element].codemirror.undo()
    },
    redo (element) {
      this.$refs[element].codemirror.redo()
    },
    buildIpxe () {
      axios.get('/api/ipxe/' + this.ipxeVersion + '/build').then(result => {
        if (result.data.status === 'SUCCESS') this.$snackbar({ color: 'primary', text: this.$tc('buildingIpxe') })
        else if (result.data.status === 'ALREADY_BUILDING') this.$snackbar({ color: 'error', text: this.$tc('alreadyBuiling') })
      })
    },
    cleanIpxe () {
      axios.get('/api/ipxe/' + this.ipxeVersion + '/clean').then(result => {
        if (result.data.status === 'SUCCESS') this.$snackbar({ color: 'primary', text: this.$tc('cleaningIpxe') })
        else if (result.data.status === 'ALREADY_BUILDING') this.$snackbar({ color: 'error', text: this.$tc('alreadyBuiling') })
      })
    },
    cancelIpxe () {
      axios.get('/api/ipxe/' + this.ipxeVersion + '/cancel').then(result => {
        if (result.data.status === 'SUCCESS') this.$snackbar({ color: 'primary', text: this.$tc('cleaningIpxe') }) // TODO:
      })
    }
  },
  created () {
    // Load the data.
    axios.get('/api/ipxe/' + this.ipxeVersion + '/script').then(result => {
      this.script = result.data
    })
    axios.get('/api/ipxe/' + this.ipxeVersion + '/certificate').then(result => {
      this.certificate = result.data
    })
    axios.get('/api/ipxe/' + this.ipxeVersion + '/general').then(result => {
      this.general = result.data
    })
    axios.get('/api/ipxe/' + this.ipxeVersion + '/console').then(result => {
      this.console = result.data
    })

    axios.get('/api/ipxe/' + this.ipxeVersion + '/log').then(result => {
      var lines = result.data.split('\n')
      // Limit the log to 500 lines, to prevent lagging
      lines = lines.slice(-500)
      for (var line in lines) {
        if (lines[line] === '') continue
        var attr = lines[line].split('\t')
        this.log.push({ id: this.log.length, date: attr[0], status: attr[1], msg: attr[2] })
      }
    })

    // Socket io event listeners
    this.$socket.on(this.ipxeVersion + ' log', entry => {
      this.log.push({ id: this.log.length, msg: entry.msg, status: entry.status, date: entry.date })
    })

    // Disable the buttons if a building process is running.
    axios.get('/api/ipxe/' + this.ipxeVersion + '/status').then(result => {
      this.disableButtons = result.data.data
    })

    this.$socket.on(this.ipxeVersion + ' inProgress', inProgress => {
      this.disableButtons = inProgress
    })
  },
  updated () {
    this.$refs.log.$el.firstElementChild.scrollTop = this.$refs.log.$el.firstElementChild.scrollHeight
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>