Skip to content

Commit b03f5e0

Browse files
New DataBlockUI displaying every Datablock: Add Comment and XRD block
1 parent ac9730d commit b03f5e0

File tree

3 files changed

+130
-59
lines changed

3 files changed

+130
-59
lines changed

webapp/src/components/DataBlockUI.vue

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<template>
2+
<DataBlockBase :item_id="item_id" :block_id="block_id">
3+
<FileSelectDropdown
4+
v-show="blockInfo.attributes.accepted_file_extensions.length > 0"
5+
v-model="file_id"
6+
:item_id="item_id"
7+
:block_id="block_id"
8+
:extensions="blockInfo.attributes.accepted_file_extensions"
9+
update-block-on-change
10+
/>
11+
<div v-if="file_id && properties.wavelength">
12+
<div class="form-row col-md-6 col-lg-4 mt-2 mb-2 pl-0">
13+
<div class="input-group form-inline">
14+
<label class="mr-2"
15+
><b>{{ properties.wavelength.label }}</b></label
16+
>
17+
<input
18+
v-model="wavelength"
19+
type="text"
20+
class="form-control"
21+
:class="{ 'is-invalid': wavelengthParseError }"
22+
@keydown.enter="
23+
parseWavelength();
24+
updateBlock();
25+
"
26+
@blur="
27+
parseWavelength();
28+
updateBlock();
29+
"
30+
/>
31+
<div v-if="wavelengthParseError" class="alert alert-danger mt-2 mx-auto">
32+
{{ wavelengthParseError }}
33+
</div>
34+
</div>
35+
</div>
36+
37+
<div class="row">
38+
<div id="bokehPlotContainer" class="col-xl-9 col-lg-10 col-md-11 mx-auto">
39+
<BokehPlot :bokeh-plot-data="bokehPlotData" />
40+
</div>
41+
</div>
42+
</div>
43+
</DataBlockBase>
44+
</template>
45+
46+
<script>
47+
import DataBlockBase from "@/components/datablocks/DataBlockBase";
48+
import FileSelectDropdown from "@/components/FileSelectDropdown";
49+
import BokehPlot from "@/components/BokehPlot";
50+
51+
import { blockTypes } from "@/resources.js";
52+
import { createComputedSetterForBlockField } from "@/field_utils.js";
53+
import { updateBlockFromServer } from "@/server_fetch_utils.js";
54+
55+
export default {
56+
components: {
57+
DataBlockBase,
58+
FileSelectDropdown,
59+
BokehPlot,
60+
},
61+
props: {
62+
item_id: {
63+
type: String,
64+
required: true,
65+
},
66+
block_id: {
67+
type: String,
68+
required: true,
69+
},
70+
},
71+
data() {
72+
return {
73+
wavelengthParseError: "",
74+
};
75+
},
76+
computed: {
77+
block() {
78+
return this.$store.state.all_item_data[this.item_id]["blocks_obj"][this.block_id];
79+
},
80+
blockInfo() {
81+
return this.$store.state.blocksInfos[this.block.blocktype];
82+
},
83+
properties() {
84+
return blockTypes[this.block.blocktype].properties;
85+
},
86+
bokehPlotData() {
87+
return this.$store.state.all_item_data[this.item_id]["blocks_obj"][this.block_id]
88+
.bokeh_plot_data;
89+
},
90+
file_id: createComputedSetterForBlockField("file_id"),
91+
wavelength: createComputedSetterForBlockField("wavelength"),
92+
},
93+
methods: {
94+
parseWavelength() {
95+
if (isNaN(this.wavelength) || isNaN(parseFloat(this.wavelength))) {
96+
this.wavelengthParseError = "Please provide a valid number";
97+
} else {
98+
this.wavelengthParseError = "";
99+
}
100+
},
101+
updateBlock() {
102+
updateBlockFromServer(
103+
this.item_id,
104+
this.block_id,
105+
this.$store.state.all_item_data[this.item_id]["blocks_obj"][this.block_id],
106+
);
107+
},
108+
},
109+
};
110+
</script>
111+
112+
<style scoped></style>

webapp/src/components/GenericDataBlock.vue

Lines changed: 0 additions & 48 deletions
This file was deleted.

webapp/src/resources.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// import NMRBlock from "@/components/datablocks/NMRBlock";
1010
// import EISBlock from "@/components/datablocks/EISBlock";
1111
// import MassSpecBlock from "@/components/datablocks/MassSpecBlock";
12-
import GenericDataBlock from "@/components/GenericDataBlock";
12+
import DataBlockUI from "@/components/DataBlockUI";
1313

1414
import SampleInformation from "@/components/SampleInformation";
1515
import StartingMaterialInformation from "@/components/StartingMaterialInformation";
@@ -60,26 +60,33 @@ export const UPPY_MAX_NUMBER_OF_FILES =
6060
export const debounceTime = 250; // time after user stops typing before request is sent
6161

6262
export const blockTypes = {
63-
comment: { description: "Comment", component: GenericDataBlock, name: "Comment" },
64-
media: { description: "Media", component: GenericDataBlock, name: "Media" },
65-
tabular: { description: "Tabular Data", component: GenericDataBlock, name: "Tabular data" },
66-
xrd: { description: "Powder XRD", component: GenericDataBlock, name: "Powder XRD" },
67-
raman: { description: "Raman", component: GenericDataBlock, name: "Raman" },
68-
cycle: { description: "Electrochemistry", component: GenericDataBlock, name: "Electrochemistry" },
63+
comment: { description: "Comment", component: DataBlockUI, name: "Comment" },
64+
media: { description: "Media", component: DataBlockUI, name: "Media" },
65+
tabular: { description: "Tabular Data", component: DataBlockUI, name: "Tabular data" },
66+
xrd: {
67+
description: "Powder XRD",
68+
component: DataBlockUI,
69+
properties: {
70+
wavelength: { label: "Wavelength (Å):" },
71+
},
72+
name: "Powder XRD",
73+
},
74+
raman: { description: "Raman", component: DataBlockUI, name: "Raman" },
75+
cycle: { description: "Electrochemistry", component: DataBlockUI, name: "Electrochemistry" },
6976
eis: {
7077
description: "Electrochemical Impedance Spectroscopy",
71-
component: GenericDataBlock,
78+
component: DataBlockUI,
7279
name: "EIS",
7380
},
7481
nmr: {
7582
description: "Nuclear Magnetic Resonance Spectroscopy",
76-
component: GenericDataBlock,
83+
component: DataBlockUI,
7784
name: "NMR",
7885
},
79-
ms: { description: "Mass Spectrometry", component: GenericDataBlock, name: "Mass Spectrometry" },
86+
ms: { description: "Mass Spectrometry", component: DataBlockUI, name: "Mass Spectrometry" },
8087
chat: {
8188
description: "Virtual assistant",
82-
component: GenericDataBlock,
89+
component: DataBlockUI,
8390
name: "Virtual Assistant",
8491
},
8592
};

0 commit comments

Comments
 (0)