ConvertAccounts.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <main>
  3. <h1>Accounts</h1>
  4. <hr/>
  5. <br/>
  6. <input v-model="importConvertSchemaName"/>
  7. <button @click="importConvertSchema()" class="button">Import convert schema</button>
  8. <br/>
  9. <br/>
  10. <data-table ref="datatable"
  11. :fields="fields"
  12. :sort-order="sortOrder"
  13. :data="localData"
  14. >
  15. <div slot="select-slot" slot-scope="props">
  16. <div tabindex="0" name="name" class="checkbox" @click="toggleCheckbox(props.data.accountId)" v-on:keyup.enter="toggleCheckbox(props.data.accountId)" v-on:keyup.space="toggleCheckbox(props.data.accountId)" :class="{ checked: selectedAccounts.indexOf(props.data.accountId) !== -1 }"></div>
  17. </div>
  18. <div slot="actions-slot" slot-scope="props">
  19. <router-link
  20. :to="`/convert/${props.data.accountId}`"
  21. class="button"
  22. >
  23. Convert account
  24. </router-link>
  25. </div>
  26. </data-table>
  27. <br/>
  28. <br/>
  29. <button @click="convertAccounts()" v-if="!convertingAccounts" class="button">Migrate accounts</button>
  30. </main>
  31. </template>
  32. <script>
  33. import io from "../../io.js";
  34. import DataTable from '../components/DataTable.vue';
  35. export default {
  36. components: { DataTable },
  37. data: () => {
  38. return {
  39. accounts: [],
  40. selectedAccounts: [],
  41. convertingAccounts: false,
  42. fields: [
  43. {
  44. name: "select-slot",
  45. displayName: ""
  46. },
  47. {
  48. name: "name",
  49. displayName: "Name"
  50. },
  51. {
  52. name: "version",
  53. displayName: "Version"
  54. },
  55. {
  56. name: "actions-slot",
  57. displayName: "Actions"
  58. }
  59. ],
  60. sortOrder: [
  61. {
  62. field: "name",
  63. order: "desc"
  64. },
  65. {
  66. field: "version",
  67. order: "asc"
  68. }
  69. ],
  70. importConvertSchemaName: ""
  71. }
  72. },
  73. computed: {
  74. localData: function() {
  75. return this.accounts.map(account => {
  76. return {
  77. name: account.fields.name[0].name,
  78. version: account.version,
  79. accountId: account._id
  80. };
  81. });
  82. }
  83. },
  84. methods: {
  85. importConvertSchema() {
  86. this.socket.emit("convertSchema.import", this.importConvertSchemaName, (res) => {
  87. console.log(res);
  88. alert(res.status);
  89. });
  90. },
  91. convertAccounts() {
  92. this.convertingAccounts = true;
  93. this.socket.emit("account.migrateAccounts", this.selectedAccounts, (res) => {
  94. console.log(res);
  95. alert(`Migrated accounts. Successful: ${res.successful}; failed: ${res.failed}`);
  96. location.reload();
  97. });
  98. },
  99. toggleCheckbox(accountId) {
  100. const selectedAccountIndex = this.selectedAccounts.indexOf(accountId);
  101. if (selectedAccountIndex === -1) this.selectedAccounts.push(accountId);
  102. else this.selectedAccounts.splice(selectedAccountIndex, 1);
  103. }
  104. },
  105. mounted() {
  106. io.getSocket(socket => {
  107. this.socket = socket;
  108. socket.emit("account.getAll", res => {
  109. console.log(res);
  110. this.accounts = res.accounts;
  111. });
  112. });
  113. }
  114. };
  115. </script>
  116. <style lang="scss" scoped>
  117. .checkbox {
  118. height: 32px;
  119. width: 32px;
  120. background-color: white;
  121. border: .5px #464646 solid;
  122. border-radius: 3px;
  123. cursor: pointer;
  124. position: relative;
  125. box-sizing: border-box;
  126. &.disabled {
  127. cursor:auto;
  128. }
  129. }
  130. .checkbox.checked::after {
  131. content: "";
  132. width: 26px;
  133. height: 26px;
  134. left: 2px;
  135. top: 2px;
  136. display: inline-block;
  137. position: absolute;
  138. border-radius: 3px;
  139. background-color: #69B862;
  140. }
  141. </style>