Skip to content

Commit

Permalink
Add event data handled
Browse files Browse the repository at this point in the history
Signed-off-by: rovast <rovast@163.com>
  • Loading branch information
rovast committed Sep 1, 2023
1 parent 4f91276 commit 8092d34
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 49 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"js-base64": "^3.7.5",
"leaflet": "^1.9.3",
"loadsh": "^0.0.4",
"lodash": "^4.17.21",
"mitt": "^3.0.0",
"moment": "^2.29.4",
"nft.storage": "^7.0.3",
Expand Down Expand Up @@ -129,4 +130,4 @@
"repository": "https://github.com/rovast/web3-ui.git",
"author": "rovast",
"license": "MIT"
}
}
30 changes: 17 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 54 additions & 35 deletions src/components/IgntCrudCreate.vue
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
<template>
<IgntModal
:visible="true"
:title="`Create ${itemName}`"
:close-icon="true"
:submit-button="true"
:cancel-button="true"
style="text-align: center"
@close="$emit('close')"
@submit="submitItem"
>
<template #body>
<div class="my-4 w-[500px]" />
<div v-for="field in itemFieldsFiltered" :key="'field_' + field">
<label :for="`p${field.name}`" class="sp-label capitalize-first-letter">
{{ field.name }}
</label>
<input
:id="`p${field.name}`"
v-model="formData[field.name]"
:placeholder="`Enter ${field.name}`"
type="text"
:name="`p${field.name}`"
class="sp-input"
/>
<div class="my-4" />
</div>
</template>
</IgntModal>
</template>

<script setup lang="ts">
import { useClient } from "@/composables/useClient";
import { useAddress } from "@/def-composables/useAddress";
import { reactive, computed } from "vue";
import { IgntModal } from "@ignt/vue-library";
import { useRoute } from "vue-router";
import { clone } from "lodash";
const route = useRoute();
const props = defineProps({
storeName: {
Expand Down Expand Up @@ -79,12 +52,28 @@ const itemFields = (
] as any
).structure[props.itemName];
const itemFieldsFiltered = computed(() =>
itemFields.fields.filter((f: any) => f.name !== "id" && f.name !== "creator")
);
const itemFieldsFiltered = computed(() => {
const allFields = itemFields.fields.filter(
(f: any) => f.name !== "id" && f.name !== "creator"
);
// The index field will gen by backend
if (route.name === "iot.device.events") {
const index = allFields.findIndex((f: any) => f.name === "index");
allFields.splice(index, 1);
}
return allFields;
});
const creator = address.value;
const submitItem = async () => {
const cloneFormData = clone(formData);
if (route.name === "iot.device.events") {
cloneFormData["index"] = "";
cloneFormData["payload"] = window.btoa(cloneFormData["payload"]);
}
await (
client[
props.storeName as keyof Omit<
Expand All @@ -100,11 +89,41 @@ const submitItem = async () => {
>
] as any
).tx[props.commandName]({
value: { ...formData, creator }
value: { ...cloneFormData, creator }
});
emit("close");
};
</script>
<template>
<IgntModal
:visible="true"
:title="`Create ${itemName}`"
:close-icon="true"
:submit-button="true"
:cancel-button="true"
style="text-align: center"
@close="$emit('close')"
@submit="submitItem"
>
<template #body>
<div class="my-4 w-[500px]" />
<div v-for="field in itemFieldsFiltered" :key="'field_' + field">
<label :for="`p${field.name}`" class="sp-label capitalize-first-letter">
{{ field.name }}
</label>
<input
:id="`p${field.name}`"
v-model="formData[field.name]"
:placeholder="`Enter ${field.name}`"
type="text"
:name="`p${field.name}`"
class="sp-input"
/>
<div class="my-4" />
</div>
</template>
</IgntModal>
</template>

<style scoped lang="scss">
.page-background {
Expand Down

0 comments on commit 8092d34

Please sign in to comment.