Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
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.

191 lines
5.7 KiB

  1. <template>
  2. <div id="searchers-show">
  3. <div>
  4. <h1 v-if="editable">
  5. {{ searcher.hasOwnProperty('name') ? searcher.name : searcher.expression }}
  6. </h1>
  7. <h3 v-if=" ! editable">
  8. {{ searcher.hasOwnProperty('name') ? searcher.name : searcher.expression }}
  9. </h3>
  10. <h5>{{ searcher.description }}</h5>
  11. <div v-if="editable && ! ducklingSearcher" style="margin-bottom: 1rem;">
  12. <a @click="onEdit">
  13. <Button class="fc-button">
  14. Edit
  15. </Button>
  16. </a>
  17. <a @click="onDelete">
  18. <Button class="fc-button p-button-danger">
  19. Delete
  20. </Button>
  21. </a>
  22. </div>
  23. </div>
  24. <div v-if=" ! editing"
  25. v-for="(row, rowIndex) in searcher.rows"
  26. :key="`row-${rowIndex}`"
  27. class="searchers-row flex-row">
  28. <div v-for="(searcherItem, columnIndex) in row"
  29. :key="`column-${columnIndex}`"
  30. class="searcher box"
  31. :class="{'is-highlighted': searcher.hasOwnProperty('highlight')}">
  32. <template v-if="searcherItem.hasOwnProperty('name')">
  33. <searcher-show :editable=" ! standalone && editable"
  34. :standalone="standalone"
  35. :searcher="searcherItem"
  36. @deleted="onDeleted(rowIndex, columnIndex)">
  37. </searcher-show>
  38. </template>
  39. <template v-else>
  40. <b>{{ searcherItem.expression }}</b>
  41. <p>
  42. <!-- // Show example here, so for example the user has to input the example in order to save-->
  43. <!-- // the regex, show highlight, so apply regex on example text-->
  44. </p>
  45. </template>
  46. </div>
  47. </div>
  48. <Dialog v-if="editing"
  49. header="Edit searcher"
  50. position="center"
  51. :visible.sync="editing"
  52. :closable="true"
  53. :style="{width: '100vw', height: '100vh',}"
  54. :modal="true">
  55. <searchers-editor v-if="searcher.hasOwnProperty('name')"
  56. :searcher="searcher"
  57. :standalone="true"
  58. @updated="onSearcherUpdated">
  59. </searchers-editor>
  60. <regex-create v-if="searcher.hasOwnProperty('expression')"
  61. :regex="searcher.expression"
  62. @updated="onRegexUpdated">
  63. </regex-create>
  64. </Dialog>
  65. <Dialog
  66. header="Delete searcher"
  67. :visible.sync="deleting"
  68. :style="{width: '50vw'}"
  69. :contentStyle="{overflow: 'visible'}"
  70. id="remove-searcher-dialog"
  71. ref="remove-searcher-dialog">
  72. <p>
  73. Are you sure you want to delete this searcher?
  74. </p>
  75. <template #footer>
  76. <Button label="Close"
  77. icon="pi pi-times"
  78. @click="deleting = false"
  79. class="p-button-text"/>
  80. <Button
  81. label="Delete searcher"
  82. icon="pi pi-check"
  83. class="p-button-danger p-button-outlined p-button-sm"
  84. @click="confirmDelete"/>
  85. </template>
  86. </Dialog>
  87. </div>
  88. </template>
  89. <script lang="ts">
  90. import {Component, Vue, Prop} from "vue-property-decorator";
  91. @Component({
  92. name: 'SearcherShow',
  93. components: {
  94. 'searchers-editor': () => import('./Create.vue'),
  95. },
  96. })
  97. export default class Show extends Vue {
  98. private editing: boolean = false;
  99. private deleting: boolean = false;
  100. @Prop({default: {}})
  101. public readonly searcher!: any;
  102. @Prop({default: true})
  103. public readonly editable!: boolean;
  104. @Prop({default: true})
  105. public readonly standalone!: boolean;
  106. onEdit() {
  107. if (this.standalone) {
  108. window.location.href = `/searchers/${this.searcher.id}/edit`;
  109. return;
  110. }
  111. this.editing = true;
  112. }
  113. onDelete() {
  114. if (this.standalone) {
  115. this.deleting = true;
  116. return;
  117. }
  118. this.$emit('deleted');
  119. }
  120. async confirmDelete() {
  121. try {
  122. await (window as any).axios.delete(`/searchers/${this.searcher.id}`);
  123. this.$toast.add({
  124. severity: 'success',
  125. summary: 'Searcher deleted.',
  126. life: 3000,
  127. });
  128. window.location.href = '/searchers';
  129. } catch (e) {
  130. console.log(e);
  131. }
  132. }
  133. onDeleted(rowIndex: number, columnIndex: number) {
  134. this.searcher.rows[rowIndex].splice(columnIndex, 1);
  135. if (this.searcher.rows[rowIndex].length === 0) {
  136. this.searcher.rows.splice(rowIndex, 1);
  137. }
  138. if (this.searcher.rows.length === 0) {
  139. this.$emit('deleted');
  140. }
  141. }
  142. onRegexUpdated(regex: string) {
  143. this.$set(this.searcher, 'expression', regex);
  144. this.editing = false;
  145. }
  146. onSearcherUpdated(searcher: any) {
  147. this.$set(this.searcher, 'name', searcher.name);
  148. this.$set(this.searcher, 'rows', searcher.rows);
  149. this.editing = false;
  150. }
  151. get ducklingSearcher(): boolean {
  152. return this.searcher.type !== 'custom' && ! this.searcher.hasOwnProperty('expression');
  153. }
  154. };
  155. </script>