|
3 | 3 | v-bind:style="{width: width + 'px', height: height + 'px', top: top + 'px', left: left + 'px' }"> |
4 | 4 | <div id="paneContent"> |
5 | 5 | <input id="filterbox" placeholder="Filter" v-model="filter"> |
| 6 | + <button @click="saveParametersToFile">save</button> |
6 | 7 | <ul id="params"> |
7 | 8 | <li v-for="param in filteredData" v-bind:key="param"> |
8 | 9 | {{ param }} : <span style="float: right;">{{state.params.values[param]}}</span> |
|
15 | 16 | <script> |
16 | 17 | import { store } from '../Globals.js' |
17 | 18 | import { baseWidget } from './baseWidget' |
| 19 | +import { saveAs } from 'file-saver' |
18 | 20 |
|
19 | 21 | export default { |
20 | 22 | name: 'ParamViewer', |
@@ -57,6 +59,40 @@ export default { |
57 | 59 | }, 2000) |
58 | 60 | }) |
59 | 61 | }, |
| 62 | + saveParametersToFile () { |
| 63 | + let parameterNameMaxSize = 0 |
| 64 | +
|
| 65 | + // Sort parameters alphabetically |
| 66 | + // We take advantage of sort to also calculate the parameter name maximum size |
| 67 | + const parameters = Object.entries(this.state.params.values).sort((first, second) => { |
| 68 | + parameterNameMaxSize = Math.max(parameterNameMaxSize, first[0].length) |
| 69 | + parameterNameMaxSize = Math.max(parameterNameMaxSize, second[0].length) |
| 70 | +
|
| 71 | + if (first[0] < second[0]) { |
| 72 | + return -1 |
| 73 | + } |
| 74 | + if (first[0] > second[0]) { |
| 75 | + return 1 |
| 76 | + } |
| 77 | + return 0 |
| 78 | + }) |
| 79 | +
|
| 80 | + let content = '' |
| 81 | +
|
| 82 | + content += `# Parameters extracted from file ${this.state.file}\n` |
| 83 | + content += `# Date: ${new Date()}\n` |
| 84 | +
|
| 85 | + const fileName = `${this.state.file}.params` |
| 86 | +
|
| 87 | + for (const param of parameters) { |
| 88 | + // Calculate space between name and value to make it pretty |
| 89 | + const space = Array(parameterNameMaxSize - param[0].length + 2).join(' ') |
| 90 | + content += `${param[0]}${space}${param[1]}\n` |
| 91 | + } |
| 92 | +
|
| 93 | + const file = new File([content], `${fileName}.txt`, { type: 'text/plain' }) |
| 94 | + saveAs(file) |
| 95 | + }, |
60 | 96 | setup () { |
61 | 97 | } |
62 | 98 | }, |
@@ -128,7 +164,6 @@ export default { |
128 | 164 | } |
129 | 165 |
|
130 | 166 | input#filterbox { |
131 | | - width: 95%; |
132 | 167 | margin: 23px 0px 0px 10px; |
133 | 168 | padding: 4px; |
134 | 169 | background-color: rgba(255, 255, 255, 0.836); |
|
0 commit comments