ConvertAccounts.vue 4.1 KB

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