CouchDb.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <main class="flex flex-col">
  3. <h1 class="w-full text-4xl text-center font-bold mt-5 p-3 border-b-4 border-gray-500">
  4. CouchDB Lab
  5. </h1>
  6. <!-- Page Section -->
  7. <section class="w-full h-full flex">
  8. <div class="w-1/2 bg-rose-500">
  9. code window
  10. <select @change="selectQuery" v-model="selected">
  11. <option value="default">Default</option>
  12. </select>
  13. <textarea class="w-full h-96" v-model="userQuery" />
  14. <button @click="query" class="ml-5 mt-3 p-3 text-center text-lg font-medium bg-pink-300 border-4 border-pink-500 rounded-xl">
  15. Send Query
  16. </button>
  17. </div>
  18. <div class="w-1/2 bg-yellow-300 overflow-x-scroll overflow-y-scroll">
  19. instructions &amp; output
  20. <pre v-html="output" />
  21. </div>
  22. </section>
  23. </main>
  24. </template>
  25. <script>
  26. /* Import modules. */
  27. // import Nito from 'nitojs'
  28. /* Import components. */
  29. // import UnderConstruction from '@/components/UnderConstruction'
  30. export default {
  31. components: {
  32. // UnderConstruction,
  33. },
  34. data: () => {
  35. return {
  36. requests: null,
  37. selected: null,
  38. output: null,
  39. userQuery: null,
  40. }
  41. },
  42. computed: {
  43. //
  44. },
  45. methods: {
  46. async query() {
  47. console.log('SEND QUERY')
  48. /* Clear output. */
  49. this.output = ''
  50. let request
  51. if (this.userQuery) {
  52. try {
  53. // NOTE: We remove "helpful" comment.
  54. const pos = this.userQuery.indexOf('{')
  55. let userQuery
  56. if (pos) {
  57. userQuery = this.userQuery.slice(pos)
  58. } else {
  59. userQuery = this.userQuery
  60. }
  61. request = JSON.parse(userQuery)
  62. } catch (err) {
  63. console.error(err)
  64. }
  65. } else {
  66. request = this.requests[0]
  67. }
  68. console.log('REQUEST', request)
  69. // const response = await fetch()
  70. const response = await Nito.Blockchain.Query.request(request)
  71. .catch(err => console.error(err))
  72. console.log('RESPONSE (body):', response)
  73. this.output = JSON.stringify(response, null, 2)
  74. },
  75. selectQuery() {
  76. console.log('SELECTED', this.selected)
  77. switch(this.selected) {
  78. case 'latest-block':
  79. return this.loadLatestBlock()
  80. default:
  81. return this.loadDefault()
  82. }
  83. },
  84. loadDefault() {
  85. this.userQuery = `/* Customize your query below. */
  86. n/a
  87. `
  88. },
  89. },
  90. created: async function () {
  91. this.requests = []
  92. let request
  93. request = {
  94. v: 3,
  95. q: {
  96. find: {},
  97. limit: 10
  98. }
  99. }
  100. this.requests.push(request)
  101. },
  102. mounted: function () {
  103. //
  104. },
  105. }
  106. </script>