Skip to content

Commit c4ab55a

Browse files
add parameter save button
1 parent a86d06a commit c4ab55a

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"eslint-loader": "^4.0.2",
3030
"eslint-webpack-plugin": "^3.2.0",
3131
"fast-xml-parser": "^3.21.1",
32+
"file-saver": "^2.0.5",
3233
"git-revision-webpack-plugin": "^3.0.6",
3334
"html-minifier": "^4.0.0",
3435
"https-browserify": "^1.0.0",

src/components/widgets/ParamViewer.vue

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
v-bind:style="{width: width + 'px', height: height + 'px', top: top + 'px', left: left + 'px' }">
44
<div id="paneContent">
55
<input id="filterbox" placeholder="Filter" v-model="filter">
6+
<button @click="saveParametersToFile">save</button>
67
<ul id="params">
78
<li v-for="param in filteredData" v-bind:key="param">
89
{{ param }} : <span style="float: right;">{{state.params.values[param]}}</span>
@@ -15,6 +16,7 @@
1516
<script>
1617
import { store } from '../Globals.js'
1718
import { baseWidget } from './baseWidget'
19+
import { saveAs } from 'file-saver'
1820
1921
export default {
2022
name: 'ParamViewer',
@@ -57,6 +59,40 @@ export default {
5759
}, 2000)
5860
})
5961
},
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+
},
6096
setup () {
6197
}
6298
},
@@ -128,7 +164,6 @@ export default {
128164
}
129165
130166
input#filterbox {
131-
width: 95%;
132167
margin: 23px 0px 0px 10px;
133168
padding: 4px;
134169
background-color: rgba(255, 255, 255, 0.836);

0 commit comments

Comments
 (0)