You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
5.8KB

  1. <template>
  2. <div id="ubenchmarks">
  3. <v-card class="bench elevation-5" :loading="loading">
  4. <v-alert v-for="(alert, i) in this.alerts" :key="i" :type="alert.type">{{ alert.message }}</v-alert>
  5. <v-card-title>
  6. <h2>Unconfirmed Benchmarks</h2>
  7. <v-spacer></v-spacer>
  8. <v-text-field class="search" v-model="search" append-icon="magnify" label="Search" single-line hide-details></v-text-field>
  9. </v-card-title>
  10. <v-data-table v-model="selected" show-select :search="search" multi-sort :headers="headers" :items="benchmarks" :items-per-page="5">
  11. <template v-slot:item.timestamp="{ item }">
  12. <span>{{ new Date(item.timestamp).toLocaleDateString() }}</span>
  13. </template>
  14. </v-data-table>
  15. <div class="buttons">
  16. <v-btn @click="update(false)" color="red">Delete</v-btn>
  17. <v-btn @click="update(true)" color="green">Confirm</v-btn>
  18. </div>
  19. </v-card>
  20. <h4>Back to confirmed <router-link to="/">Benchmarks</router-link></h4>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. loading: true,
  28. search: "",
  29. selected: [],
  30. headers: [
  31. {
  32. text: "Vendor",
  33. align: "start",
  34. value: "vendor"
  35. },
  36. {
  37. text: "Model",
  38. value: "model"
  39. },
  40. {
  41. text: "Memory",
  42. value: "memory"
  43. },
  44. {
  45. text: "Hashrate (h/s)",
  46. value: "hashrate"
  47. },
  48. {
  49. text: "Watts (w)",
  50. value: "watts"
  51. },
  52. {
  53. text: "Miner",
  54. value: "minerVersion"
  55. },
  56. {
  57. text: "Submitted On",
  58. value: "timestamp",
  59. class: "Date"
  60. },
  61. {
  62. text: "User",
  63. value: "owner"
  64. }
  65. ],
  66. benchmarks: [],
  67. alerts: []
  68. }
  69. },
  70. mounted() {
  71. let token = localStorage.getItem("token")
  72. if (token == null) //TODO must wait App.mounted()
  73. {
  74. this.$router.push("/login")
  75. return
  76. }
  77. let headers = new Headers();
  78. headers.append("Authorization", "Bearer " + token)
  79. fetch(this.$api + "/api/unconfirmedBenchmarks", { headers: headers }).then(result => result.json()).then(json => {
  80. console.log(json)
  81. this.benchmarks = json
  82. this.loading = false
  83. })
  84. },
  85. methods: {
  86. update(confirm) {
  87. let headers = new Headers();
  88. let token = localStorage.getItem("token")
  89. headers.append("Authorization", "Bearer " + token)
  90. let localSelected = this.selected
  91. for (let bench of localSelected)
  92. {
  93. fetch(this.$api + "/api/" + (confirm ? "confirm" : "delete"), {
  94. method: "POST",
  95. headers: headers,
  96. body: JSON.stringify({
  97. benchID: bench.id
  98. })
  99. }).then(result => result.json()).then(json => {
  100. this.alerts.push({
  101. type: json.success ? "success" : "error",
  102. message: json.message
  103. })
  104. setTimeout(() => this.alerts.shift(), 5000)
  105. if (json.success) {
  106. let index = this.benchmarks.findIndex(x => x.id == bench.id)
  107. this.benchmarks.splice(index, 1)
  108. this.selected.shift()
  109. }
  110. })
  111. }
  112. }
  113. }
  114. }
  115. </script>
  116. <style scoped>
  117. .bench {
  118. margin: 10%;
  119. margin-top: 5%;
  120. margin-bottom: 2%;
  121. padding: 2%;
  122. }
  123. .buttons {
  124. display: flex;
  125. justify-content: space-evenly;
  126. }
  127. </style>