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.

279 lines
9.0 KiB

3 years ago
3 years ago
3 years ago
  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. <!-- <Panel :header="searcher.name">-->
  88. <!-- <template #icons>-->
  89. <!-- <a-->
  90. <!-- class="p-panel-header-icon p-link"-->
  91. <!-- v-if="editable"-->
  92. <!-- :href="`/searchers/${searcher.id}/edit`"-->
  93. <!-- >-->
  94. <!-- <span class="pi pi-cog"></span>-->
  95. <!-- </a>-->
  96. <!-- </template>-->
  97. <!-- <div class="p-d-flex p-jc-start">-->
  98. <!-- <h5>{{ searcher.description }}</h5>-->
  99. <!-- <Timeline :value="searcher.rows">-->
  100. <!-- <template #opposite="slotProps">-->
  101. <!-- <small class="p-text-secondary">-->
  102. <!-- {{ slotProps.index + 1 }}-->
  103. <!-- </small>-->
  104. <!-- </template>-->
  105. <!-- <template #content="slotProps">-->
  106. <!-- <ScrollPanel-->
  107. <!-- style="max-width: 90vw; height: 125px"-->
  108. <!-- class="searcher-list"-->
  109. <!-- >-->
  110. <!-- <div-->
  111. <!-- v-for="(-->
  112. <!-- searcherItem, columnIndex-->
  113. <!-- ) in slotProps.item"-->
  114. <!-- :key="`column-${columnIndex}`"-->
  115. <!-- >-->
  116. <!-- <div class="box is-plain p-shadow-5">-->
  117. <!-- <template-->
  118. <!-- v-if="-->
  119. <!-- searcherItem.hasOwnProperty('name')-->
  120. <!-- "-->
  121. <!-- >-->
  122. <!-- <searcher-show-->
  123. <!-- :editable="false"-->
  124. <!-- :searcher="searcherItem"-->
  125. <!-- ></searcher-show>-->
  126. <!-- </template>-->
  127. <!-- <template v-else>-->
  128. <!-- <b>{{ searcherItem.expression }}</b>-->
  129. <!-- </template>-->
  130. <!-- </div>-->
  131. <!-- </div>-->
  132. <!-- </ScrollPanel>-->
  133. <!-- <Divider />-->
  134. <!-- </template>-->
  135. <!-- </Timeline>-->
  136. <!-- </div>-->
  137. <!-- </Panel>-->
  138. </div>
  139. </template>
  140. <script lang="ts">
  141. import {Component, Vue, Prop} from "vue-property-decorator";
  142. import {eventBus} from "@/app";
  143. @Component({
  144. name: 'SearcherShow',
  145. components: {
  146. 'searchers-editor': () => import('./Create.vue'),
  147. },
  148. })
  149. export default class Show extends Vue {
  150. private editing: boolean = false;
  151. private deleting: boolean = false;
  152. @Prop({default: {}})
  153. public readonly searcher!: any;
  154. @Prop({default: true})
  155. public readonly editable!: boolean;
  156. @Prop({default: true})
  157. public readonly standalone!: boolean;
  158. onEdit() {
  159. if (this.standalone) {
  160. window.location.href = `/searchers/${this.searcher.id}/edit`;
  161. return;
  162. }
  163. this.editing = true;
  164. }
  165. onDelete() {
  166. if (this.standalone) {
  167. this.deleting = true;
  168. return;
  169. }
  170. this.$emit('deleted');
  171. }
  172. async confirmDelete() {
  173. try {
  174. await (window as any).axios.delete(`/searchers/${this.searcher.id}`);
  175. this.$toast.add({
  176. severity: 'success',
  177. summary: 'Searcher deleted.',
  178. life: 3000,
  179. });
  180. window.location.href = '/searchers';
  181. } catch (e) {
  182. console.log(e);
  183. }
  184. }
  185. onDeleted(rowIndex: number, columnIndex: number) {
  186. this.searcher.rows[rowIndex].splice(columnIndex, 1);
  187. if (this.searcher.rows[rowIndex].length === 0) {
  188. this.searcher.rows.splice(rowIndex, 1);
  189. }
  190. if (this.searcher.rows.length === 0) {
  191. this.$emit('deleted');
  192. }
  193. }
  194. onRegexUpdated(regex: string) {
  195. this.$set(this.searcher, 'expression', regex);
  196. this.editing = false;
  197. }
  198. onSearcherUpdated(searcher: any) {
  199. this.$set(this.searcher, 'name', searcher.name);
  200. this.$set(this.searcher, 'rows', searcher.rows);
  201. this.editing = false;
  202. }
  203. get ducklingSearcher(): boolean {
  204. return this.searcher.type !== 'custom' && ! this.searcher.hasOwnProperty('expression');
  205. }
  206. public async changeRoute(url: string) {
  207. window.location.href = url;
  208. }
  209. created() {
  210. eventBus.$on('changeRoute', this.changeRoute);
  211. }
  212. };
  213. </script>
  214. <style lang="scss" scoped>
  215. ::v-deep .p-timeline-event-opposite {
  216. flex: 0 !important;
  217. }
  218. ::v-deep .p-timeline-event-content {
  219. margin-bottom: 25px;
  220. }
  221. ::v-deep .searcher-list {
  222. .p-scrollpanel-content {
  223. display: flex;
  224. flex-direction: row;
  225. padding-top: 25px
  226. }
  227. .p-scrollpanel-bar {
  228. background-color: #1976d2;
  229. opacity: 1;
  230. transition: background-color 0.3s;
  231. }
  232. }
  233. </style>