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.

135 lines
4.3 KiB

  1. <template>
  2. <div>
  3. <h1> Searchers </h1>
  4. <div v-if=" ! allowSelect" style="margin-bottom: 1rem;">
  5. <Button class="fc-button p-button-success" label="Add searcher" @click="createSearcher()"/>
  6. </div>
  7. <div class="content">
  8. <DataTable
  9. :value.sync="searchers"
  10. :selection.sync="selectedSearcher"
  11. dataKey="id"
  12. :selectionMode="allowSelect ? 'single' : ''"
  13. class="p-datatable-md"
  14. :paginator="true"
  15. :rows="10"
  16. paginatorTemplate="CurrentPageReport FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown"
  17. currentPageReportTemplate="Showing {first} to {last} of {totalRecords}"
  18. :rowsPerPageOptions="[10,20,50]">
  19. <Column v-if="allowSelect" selectionMode="single" headerStyle="width: 3em"></Column>
  20. <Column header="Name" sortable>
  21. <template #body="slotProps">
  22. {{ slotProps.data.name }}
  23. </template>
  24. </Column>
  25. <Column header="Actions" headerStyle="text-align: right">
  26. <template #body="slotProps">
  27. <div class="action-buttons" style="text-align: right">
  28. <Button
  29. :disabled="slotProps.data.type !== 'custom'"
  30. label="Open"
  31. icon="pi pi-folder-open"
  32. class="p-button-sm"
  33. @click.stop="onOpen(slotProps.data.id)"/>
  34. <Button
  35. :disabled="slotProps.data.type !== 'custom'"
  36. label="Edit"
  37. icon="pi pi-pencil"
  38. class="p-button-sm p-button-success"
  39. @click.stop="onEdit(slotProps.data.id)"/>
  40. <Button
  41. :disabled="slotProps.data.type !== 'custom'"
  42. label="Delete"
  43. icon="pi pi-times"
  44. class="p-button-sm p-button-danger"
  45. @click.stop="onDelete(slotProps.data.id)"/>
  46. </div>
  47. </template>
  48. </Column>
  49. </DataTable>
  50. </div>
  51. </div>
  52. </template>
  53. <script lang="ts">
  54. import {Component, Prop, Vue, Watch} from "vue-property-decorator";
  55. import {Searcher} from "@/interfaces/Searcher";
  56. import { eventBus } from "@/app";
  57. @Component({
  58. })
  59. export default class Index extends Vue {
  60. private searchers: Array<Searcher> = [];
  61. private selectedSearcher: any = {};
  62. @Prop({default: false})
  63. public readonly allowSelect!: boolean;
  64. @Prop({default: () => []})
  65. public readonly ignoreSearcherIds!: Array<string>;
  66. async boot() {
  67. try {
  68. const { data } = await (window as any).axios.get('/searchers');
  69. this.searchers = data.searchers.filter((searcher: Searcher) => {
  70. return ! this.ignoreSearcherIds.includes(searcher.id);
  71. });
  72. } catch (e) {
  73. }
  74. }
  75. onOpen(id: string) {
  76. window.open(this.getURL(id), '_self');
  77. }
  78. onEdit(id: string) {
  79. window.open(this.getURL(id) + '/edit', '_self');
  80. }
  81. async onDelete(id: string) {
  82. try {
  83. await (window as any).axios.delete(`/searchers/${id}`);
  84. this.$toast.add({
  85. severity: 'success',
  86. summary: 'Searcher deleted.',
  87. life: 3000,
  88. });
  89. this.searchers = this.searchers.filter(x => x.id !== id);
  90. } catch (e) {
  91. console.log(e);
  92. }
  93. }
  94. getURL(id: string) {
  95. return `/searchers/${id}`;
  96. }
  97. @Watch('selectedSearcher')
  98. selectedSearcherIdChanged(value: any) {
  99. this.$emit('selected', value);
  100. }
  101. public async changeRoute(url: string) {
  102. window.location.href = url;
  103. }
  104. createSearcher() {
  105. window.location.href = '/searchers/create';
  106. }
  107. created() {
  108. this.boot();
  109. eventBus.$on('changeRoute', this.changeRoute);
  110. }
  111. };
  112. </script>