Schemas.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <main>
  3. <h1>Schemas</h1>
  4. <hr/>
  5. <br/>
  6. <select v-model="importAccountSchemaName">
  7. <option v-for="schema in schemasInDirectory" :value="schema">{{ schema }}</option>
  8. </select>
  9. <button @click="importAccountSchema()" class="button">Import account schema</button>
  10. <br/>
  11. <br/>
  12. <data-table ref="datatable"
  13. :fields="fields"
  14. :sort-order="sortOrder"
  15. :data="localData"
  16. >
  17. <div slot="actions-slot" slot-scope="props">
  18. <router-link
  19. :to="`/schemas/${props.data.schemaId}`"
  20. class="button"
  21. >
  22. View schema
  23. </router-link>
  24. </div>
  25. </data-table>
  26. </main>
  27. </template>
  28. <script>
  29. import io from "../../io.js";
  30. import DataTable from '../components/DataTable.vue';
  31. export default {
  32. components: { DataTable },
  33. data: () => {
  34. return {
  35. importAccountSchemaName: "",
  36. schemasInDirectory: [],
  37. schemas: [],
  38. fields: [
  39. {
  40. name: "name",
  41. displayName: "Name"
  42. },
  43. {
  44. name: "version",
  45. displayName: "Version"
  46. },
  47. {
  48. name: "actions-slot",
  49. displayName: "Actions"
  50. }
  51. ],
  52. sortOrder: [
  53. {
  54. field: "version",
  55. order: "desc"
  56. }
  57. ]
  58. }
  59. },
  60. computed: {
  61. localData: function() {
  62. return this.schemas.map(schema => {
  63. return {
  64. name: schema.name,
  65. version: schema.version,
  66. schemaId: schema._id
  67. };
  68. });
  69. }
  70. },
  71. methods: {
  72. importAccountSchema() {
  73. this.socket.emit("accountSchema.import", this.importAccountSchemaName, (res) => {
  74. console.log(res);
  75. alert(res.status);
  76. });
  77. }
  78. },
  79. mounted() {
  80. io.getSocket(socket => {
  81. this.socket = socket;
  82. this.socket.emit("accountSchema.getAll", res => {
  83. this.schemas = res.schemas;
  84. });
  85. socket.emit("accountSchema.listSchemasInDirectory", res => {
  86. this.schemasInDirectory = res.schemasInDirectory;
  87. });
  88. });
  89. }
  90. };
  91. </script>
  92. <style lang="scss" scoped>
  93. .schema-item {
  94. display: block;
  95. }
  96. </style>