history.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <pw-section class="gray" label="History">
  3. <ul>
  4. <li id="filter-history">
  5. <input id="filter-history-input" type="text" placeholder="search history" :readonly="history.length === 0 || isClearingHistory" v-model="filterText">
  6. </li>
  7. </ul>
  8. <virtual-list class="virtual-list" :class="{filled: filteredHistory.length}" :size="89" :remain="Math.min(5, filteredHistory.length)">
  9. <ul v-for="(entry, index) in filteredHistory" :key="index" class="entry">
  10. <li>
  11. <label :for="'time#'+index">Time</label>
  12. <input :id="'time#'+index" type="text" readonly :value="entry.time" :title="entry.date">
  13. </li>
  14. <li class="method-list-item">
  15. <label :for="'time#'+index">Method</label>
  16. <input :id="'method#'+index" type="text" readonly :value="entry.method" :class="findEntryStatus(entry).className" :style="{'--status-code': entry.status}">
  17. <span class="entry-status-code">{{entry.status}}</span>
  18. </li>
  19. <li>
  20. <label :for="'url#'+index">URL</label>
  21. <input :id="'url#'+index" type="text" readonly :value="entry.url">
  22. </li>
  23. <li>
  24. <label :for="'path#'+index">Path</label>
  25. <input :id="'path#'+index" type="text" readonly :value="entry.path">
  26. </li>
  27. <div class="show-on-small-screen">
  28. <li>
  29. <label :for="'delete-button#'+index" class="hide-on-small-screen">&nbsp;</label>
  30. <button class="icon" :id="'delete-button#'+index" :disabled="isClearingHistory" @click="deleteHistory(entry)">
  31. <svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd">
  32. <path d="M5.662 23l-5.369-5.365c-.195-.195-.293-.45-.293-.707 0-.256.098-.512.293-.707l14.929-14.928c.195-.194.451-.293.707-.293.255 0 .512.099.707.293l7.071 7.073c.196.195.293.451.293.708 0 .256-.097.511-.293.707l-11.216 11.219h5.514v2h-12.343zm3.657-2l-5.486-5.486-1.419 1.414 4.076 4.072h2.829zm6.605-17.581l-10.677 10.68 5.658 5.659 10.676-10.682-5.657-5.657z" />
  33. </svg>
  34. </button>
  35. </li>
  36. <li>
  37. <label :for="'use-button#'+index" class="hide-on-small-screen">&nbsp;</label>
  38. <button class="icon" :id="'use-button#'+index" :disabled="isClearingHistory" @click="useHistory(entry)">
  39. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  40. <path d="M14.078 7.061l2.861 2.862-10.799 10.798-3.584.723.724-3.585 10.798-10.798zm0-2.829l-12.64 12.64-1.438 7.128 7.127-1.438 12.642-12.64-5.691-5.69zm7.105 4.277l2.817-2.82-5.691-5.689-2.816 2.817 5.69 5.692z" />
  41. </svg>
  42. </button>
  43. </li>
  44. </div>
  45. </ul>
  46. </virtual-list>
  47. <ul :class="{hidden: filteredHistory.length != 0 || history.length === 0 }">
  48. <li>
  49. <label>Nothing found for "{{filterText}}"</label>
  50. </li>
  51. </ul>
  52. <ul>
  53. <li v-if="!isClearingHistory">
  54. <button id="clear-history-button" :disabled="history.length === 0" @click="enableHistoryClearing">Clear All</button>
  55. </li>
  56. <li v-else>
  57. <div class="flex-wrap">
  58. <label for="clear-history-button">Are you sure?</label>
  59. <div>
  60. <button id="confirm-clear-history-button" @click="clearHistory">
  61. Yes
  62. </button>
  63. <button id="reject-clear-history-button" @click="disableHistoryClearing">
  64. No
  65. </button>
  66. </div>
  67. </div>
  68. </li>
  69. </ul>
  70. </pw-section>
  71. </template>
  72. <script>
  73. import VirtualList from 'vue-virtual-scroll-list'
  74. import section from "./section";
  75. import {
  76. findStatusGroup
  77. } from "../pages/index";
  78. const updateOnLocalStorage = (propertyName, property) => window.localStorage.setItem(propertyName, JSON.stringify(property));
  79. export default {
  80. components: {
  81. 'pw-section': section,
  82. VirtualList
  83. },
  84. data() {
  85. const localStorageHistory = JSON.parse(window.localStorage.getItem('history'));
  86. return {
  87. history: localStorageHistory || [],
  88. filterText: '',
  89. showFilter: false,
  90. isClearingHistory: false
  91. }
  92. },
  93. computed: {
  94. filteredHistory() {
  95. return this.history.filter(entry => {
  96. const filterText = this.filterText.toLowerCase();
  97. return Object.keys(entry).some(key => {
  98. let value = entry[key];
  99. value = typeof value !== 'string' ? value.toString() : value;
  100. return value.toLowerCase().includes(filterText);
  101. });
  102. });
  103. }
  104. },
  105. methods: {
  106. clearHistory() {
  107. this.history = [];
  108. this.filterText = '';
  109. this.disableHistoryClearing();
  110. updateOnLocalStorage('history', this.history);
  111. },
  112. useHistory(entry) {
  113. this.$emit('useHistory', entry);
  114. },
  115. findEntryStatus(entry) {
  116. const foundStatusGroup = findStatusGroup(entry.status);
  117. return foundStatusGroup || {
  118. className: ''
  119. };
  120. },
  121. deleteHistory(entry) {
  122. this.history.splice(this.history.indexOf(entry), 1);
  123. if (this.history.length === 0) {
  124. this.filterText = '';
  125. }
  126. updateOnLocalStorage('history', this.history);
  127. },
  128. addEntry(entry) {
  129. this.history.push(entry);
  130. updateOnLocalStorage('history', this.history);
  131. },
  132. enableHistoryClearing() {
  133. if (!this.history || !this.history.length) return;
  134. this.isClearingHistory = true;
  135. },
  136. disableHistoryClearing() {
  137. this.isClearingHistory = false;
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped lang="scss">
  143. .virtual-list {
  144. [readonly] {
  145. cursor: default;
  146. }
  147. }
  148. @media (max-width: 720px) {
  149. .virtual-list.filled {
  150. min-height: 380px;
  151. }
  152. }
  153. </style>