|
| 1 | +<template> |
| 2 | + <v-container fluid class="pa-8 canvas fill-canvas"> |
| 3 | + <v-row no-gutters> |
| 4 | + <v-col cols="3"> |
| 5 | + <h3 class="mb-3 text--secondary font-weight-medium">Views</h3> |
| 6 | + <v-list-item-group |
| 7 | + class="themed-border radius-1" |
| 8 | + active-class="token-card-selected" |
| 9 | + :value="selected" |
| 10 | + mandatory |
| 11 | + > |
| 12 | + <template v-for="(item, i) in offChainViews"> |
| 13 | + <v-list-item @click="selected = i" class="token-card" :key="'entrypoint-' + i"> |
| 14 | + <v-list-item-content> |
| 15 | + <v-list-item-title class="d-flex justify-space-between align-center"> |
| 16 | + <span v-if="item.name">{{ item.name }}</span> |
| 17 | + <span v-else class="text--disabled">NO NAME</span> |
| 18 | + <span class="disabled-gray text-small"> |
| 19 | + {{ item.kind }} |
| 20 | + </span> |
| 21 | + </v-list-item-title> |
| 22 | + </v-list-item-content> |
| 23 | + </v-list-item> |
| 24 | + </template> |
| 25 | + </v-list-item-group> |
| 26 | + </v-col> |
| 27 | + <v-col cols="6" class="px-8"> |
| 28 | + <template v-if="selectedItem"> |
| 29 | + <v-card flat outlined> |
| 30 | + <v-card-text class="pa-0 pt-6 data"> |
| 31 | + <SchemaHeader |
| 32 | + title="View" |
| 33 | + :is-storage="true" |
| 34 | + :storage-html="selectedItem.name" |
| 35 | + :storage-name="selectedItem.name" |
| 36 | + /> |
| 37 | + <SchemaForm |
| 38 | + header="Parameters" |
| 39 | + fallback-text="This implementation doesn't have parameters" |
| 40 | + :schema="selectedItem.schema" |
| 41 | + :show="true" |
| 42 | + :is-deploy="true" |
| 43 | + :is-optional-settings="false" |
| 44 | + @executeClick="callOffchainView" |
| 45 | + @modelChange="setModel" |
| 46 | + /> |
| 47 | + </v-card-text> |
| 48 | + </v-card> |
| 49 | + </template> |
| 50 | + <v-dialog |
| 51 | + v-model="showSuccess" |
| 52 | + max-width="525" |
| 53 | + persistent |
| 54 | + dark |
| 55 | + @click:outside="showSuccess = false" |
| 56 | + @keydown.esc="showSuccess = false" |
| 57 | + > |
| 58 | + <v-card flat outlined> |
| 59 | + <v-card-title class="sidebar d-flex justify-center pa-4"> |
| 60 | + <span class="body-1 font-weight-medium text-uppercase text--secondary">View result</span> |
| 61 | + <v-spacer></v-spacer> |
| 62 | + <v-btn icon small @click="showSuccess = false"> |
| 63 | + <v-icon>mdi-close</v-icon> |
| 64 | + </v-btn> |
| 65 | + </v-card-title> |
| 66 | + <v-card-text class="pa-8"> |
| 67 | + <MiguelTreeView :miguel="successResponse" /> |
| 68 | + </v-card-text> |
| 69 | + </v-card> |
| 70 | + </v-dialog> |
| 71 | + </v-col> |
| 72 | + <v-col cols="3"> |
| 73 | + <h3 class="mb-3 text--secondary font-weight-medium">Parameters type</h3> |
| 74 | + <v-card flat outlined style="max-width: 500px;"> |
| 75 | + <v-navigation-drawer floating permanent style="max-height: 80vh; width: 100%;"> |
| 76 | + <div class="pa-3"> |
| 77 | + <TypeDef |
| 78 | + v-if="selectedItem.typedef" |
| 79 | + :typedef="selectedItem.typedef" |
| 80 | + first="parameter" |
| 81 | + class="pt-3 pb-1 px-6" |
| 82 | + style="opacity: 0.8" |
| 83 | + /> |
| 84 | + <p v-else class="mb-0"> |
| 85 | + No parameters for this view. |
| 86 | + </p> |
| 87 | + </div> |
| 88 | + </v-navigation-drawer> |
| 89 | + </v-card> |
| 90 | + </v-col> |
| 91 | + <TreeNodeDetails |
| 92 | + prim="string" |
| 93 | + :data="fullErrorValue" |
| 94 | + :value="isErrorShown" |
| 95 | + is-error-info |
| 96 | + /> |
| 97 | + </v-row> |
| 98 | + </v-container> |
| 99 | +</template> |
| 100 | + |
| 101 | +<script> |
| 102 | +import SchemaHeader from "../../../components/schema/schemaComponents/SchemaHeader"; |
| 103 | +import SchemaForm from "../../../components/schema/schemaForm/SchemaForm"; |
| 104 | +import TreeNodeDetails from "../../../components/Dialogs/TreeNodeDetails"; |
| 105 | +import MiguelTreeView from "../../../components/MiguelTreeView"; |
| 106 | +import TypeDef from "../TypeDef"; |
| 107 | +
|
| 108 | +export default { |
| 109 | + name: "ViewsTab", |
| 110 | + props: { |
| 111 | + address: String, |
| 112 | + network: String, |
| 113 | + offChainViews: Array, |
| 114 | + }, |
| 115 | + components: { |
| 116 | + TypeDef, |
| 117 | + MiguelTreeView, |
| 118 | + TreeNodeDetails, |
| 119 | + SchemaForm, |
| 120 | + SchemaHeader, |
| 121 | + }, |
| 122 | + computed: { |
| 123 | + selectedItem() { |
| 124 | + if (this.selected < 0 || this.offChainViews.length < this.selected) { |
| 125 | + return null; |
| 126 | + } |
| 127 | + if (typeof this.selected === "number") { |
| 128 | + return this.offChainViews[this.selected]; |
| 129 | + } |
| 130 | + return null; |
| 131 | + }, |
| 132 | + }, |
| 133 | + methods: { |
| 134 | + setModel(val) { |
| 135 | + this.model = val; |
| 136 | + }, |
| 137 | + callOffchainView() { |
| 138 | + this.api |
| 139 | + .executeMetadataView(this.network, this.address, { |
| 140 | + name: this.selectedItem.name, |
| 141 | + implementation: this.selectedItem.implementation, |
| 142 | + data: this.model, |
| 143 | + kind: this.selectedItem.kind, |
| 144 | + }) |
| 145 | + .then((res) => { |
| 146 | + if (!res) return; |
| 147 | + this.showSuccess = true; |
| 148 | + this.successResponse = res; |
| 149 | + }) |
| 150 | + .catch((err) => { |
| 151 | + this.isErrorShown = false; |
| 152 | + this.fullErrorValue = { |
| 153 | + name: `${err.response.statusText} — ${err.response.status}`, |
| 154 | + val: err.response.data.message, |
| 155 | + realPrim: 'string', |
| 156 | + label: err.response.data.message, |
| 157 | + }; |
| 158 | + this.$nextTick(() => { |
| 159 | + this.isErrorShown = true; |
| 160 | + }); |
| 161 | + }) |
| 162 | + } |
| 163 | + }, |
| 164 | + data() { |
| 165 | + return { |
| 166 | + model: {}, |
| 167 | + selected: 0, |
| 168 | + isErrorShown: false, |
| 169 | + successText: '', |
| 170 | + showSuccess: false, |
| 171 | + successResponse: null, |
| 172 | + fullErrorValue: null, |
| 173 | + } |
| 174 | + } |
| 175 | +}; |
| 176 | +</script> |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | +<style lang="scss" scoped> |
| 181 | +.entrypoint-panel > .v-expansion-panel-header { |
| 182 | + background-color: var(--v-sidebar-base); |
| 183 | +} |
| 184 | +
|
| 185 | +.v-expansion-panel.entrypoint-selected { |
| 186 | + background-color: var(--v-data-base); |
| 187 | + & > .v-expansion-panel-header { |
| 188 | + background-color: var(--v-data-base); |
| 189 | + } |
| 190 | +} |
| 191 | +</style> |
0 commit comments