ConvertAccounts.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <main>
  3. <h1>Convert accounts</h1>
  4. <hr/>
  5. <br/>
  6. <p>Select/deselect all:</p>
  7. <button class="button" v-for="version in versions" @click="toggleVersion(version)">{{version}}</button>
  8. <br/>
  9. <br/>
  10. <data-table ref="accounts-datatable"
  11. :fields="accountsFields"
  12. :sort-order="accountsSortOrder"
  13. :data="accountsLocalData"
  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. <button @click="convertAccounts()" v-if="!convertingAccounts" class="button">Migrate accounts</button>
  29. <br/>
  30. <br/>
  31. <h1>Convert schemas</h1>
  32. <hr/>
  33. <br/>
  34. <input v-model="importConvertSchemaName"/>
  35. <button @click="importConvertSchema()" class="button">Import convert schema</button>
  36. <br/>
  37. <br/>
  38. <data-table ref="convert-schema-datatable"
  39. :fields="convertSchemasFields"
  40. :sort-order="convertSchemasSortOrder"
  41. :data="convertSchemasLocalData"
  42. >
  43. <div slot="actions-slot" slot-scope="props">
  44. <router-link
  45. :to="`/convert/view/${props.data.schemaId}`"
  46. class="button"
  47. >
  48. View convert schema
  49. </router-link>
  50. </div>
  51. </data-table>
  52. </main>
  53. </template>
  54. <script>
  55. import io from "../../io.js";
  56. import DataTable from '../components/DataTable.vue';
  57. export default {
  58. components: { DataTable },
  59. data: () => {
  60. return {
  61. accounts: [],
  62. convertSchemas: [],
  63. versions: [],
  64. selectedAccounts: [],
  65. convertingAccounts: false,
  66. accountsFields: [
  67. {
  68. name: "select-slot",
  69. displayName: ""
  70. },
  71. {
  72. name: "name",
  73. displayName: "Name"
  74. },
  75. {
  76. name: "version",
  77. displayName: "Version"
  78. },
  79. {
  80. name: "actions-slot",
  81. displayName: "Actions"
  82. }
  83. ],
  84. accountsSortOrder: [
  85. {
  86. field: "name",
  87. order: "desc"
  88. },
  89. {
  90. field: "version",
  91. order: "asc"
  92. }
  93. ],
  94. convertSchemasFields: [
  95. {
  96. name: "versionFrom",
  97. displayName: "Version from"
  98. },
  99. {
  100. name: "versionTo",
  101. displayName: "Version to"
  102. },
  103. {
  104. name: "actions-slot",
  105. displayName: "Actions"
  106. }
  107. ],
  108. convertSchemasSortOrder: [
  109. {
  110. field: "versionFrom",
  111. order: "asc"
  112. },
  113. {
  114. field: "versionTo",
  115. order: "asc"
  116. }
  117. ],
  118. importConvertSchemaName: ""
  119. }
  120. },
  121. computed: {
  122. accountsLocalData: function() {
  123. return this.accounts.map(account => {
  124. return {
  125. name: account.fields.name[0].name,
  126. version: account.version,
  127. accountId: account._id
  128. };
  129. });
  130. },
  131. convertSchemasLocalData: function() {
  132. return this.convertSchemas.map(schema => {
  133. return {
  134. versionFrom: schema.versionFrom,
  135. versionTo: schema.versionTo,
  136. schemaId: schema._id
  137. };
  138. });
  139. }
  140. },
  141. methods: {
  142. importConvertSchema() {
  143. this.socket.emit("convertSchema.import", this.importConvertSchemaName, (res) => {
  144. console.log(res);
  145. alert(res.status);
  146. });
  147. },
  148. convertAccounts() {
  149. this.convertingAccounts = true;
  150. this.socket.emit("account.migrateAccounts", this.selectedAccounts, (res) => {
  151. console.log(res);
  152. alert(`Migrated accounts. Successful: ${res.successful}; failed: ${res.failed}`);
  153. location.reload();
  154. });
  155. },
  156. toggleCheckbox(accountId) {
  157. const selectedAccountIndex = this.selectedAccounts.indexOf(accountId);
  158. if (selectedAccountIndex === -1) this.selectedAccounts.push(accountId);
  159. else this.selectedAccounts.splice(selectedAccountIndex, 1);
  160. },
  161. toggleVersion(version) {
  162. let allAccountsChecked = true;
  163. this.accounts.forEach(account => {
  164. if (account.version === version && this.selectedAccounts.indexOf(account._id) === -1) allAccountsChecked = false;
  165. });
  166. let toggleTo;
  167. if (allAccountsChecked) toggleTo = false;
  168. else toggleTo = true;
  169. this.accounts.forEach(account => {
  170. if (account.version === version) {
  171. let selectedAccountIndex = this.selectedAccounts.indexOf(account._id);
  172. if (toggleTo && selectedAccountIndex === -1) this.selectedAccounts.push(account._id);
  173. if (!toggleTo && selectedAccountIndex !== -1) this.selectedAccounts.splice(selectedAccountIndex, 1);
  174. }
  175. });
  176. }
  177. },
  178. mounted() {
  179. io.getSocket(socket => {
  180. this.socket = socket;
  181. socket.emit("account.getAll", res => {
  182. console.log(res);
  183. this.accounts = res.accounts;
  184. });
  185. socket.emit("accountSchema.getAllVersions", res => {
  186. this.versions = res.versions;
  187. });
  188. socket.emit("convertSchema.getAll", res => {
  189. this.convertSchemas = res.schemas;
  190. });
  191. });
  192. }
  193. };
  194. </script>
  195. <style lang="scss" scoped>
  196. .checkbox {
  197. height: 32px;
  198. width: 32px;
  199. background-color: white;
  200. border: .5px #464646 solid;
  201. border-radius: 3px;
  202. cursor: pointer;
  203. position: relative;
  204. box-sizing: border-box;
  205. &.disabled {
  206. cursor:auto;
  207. }
  208. }
  209. .checkbox.checked::after {
  210. content: "";
  211. width: 26px;
  212. height: 26px;
  213. left: 2px;
  214. top: 2px;
  215. display: inline-block;
  216. position: absolute;
  217. border-radius: 3px;
  218. background-color: #69B862;
  219. }
  220. </style>