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.

174 lines
5.0 KiB

  1. <template>
  2. <div id="searchers-create">
  3. <div>
  4. <h1> {{ searcher.id ? 'Edit' : 'New' }} searcher </h1>
  5. <InputText v-model="name"
  6. type="text"
  7. placeholder="Enter searcher name"
  8. class="input">
  9. </InputText>
  10. <Button @click="onSave" :disabled=" ! name || rows.length === 0">
  11. Save
  12. </Button>
  13. </div>
  14. <div v-if="standalone">
  15. <p>
  16. A searcher may contain multiple compounded searchers on multiple rows and columns.
  17. </p>
  18. <p>
  19. Each searcher in a row is extending the searching criteria on the content resulted from the
  20. previous row searchers.
  21. </p>
  22. </div>
  23. <div v-for="(row, rowIndex) in rows"
  24. :key="`row-${rowIndex}`"
  25. class="searchers-row flex-row">
  26. <div v-for="(searcher, columnIndex) in row"
  27. :key="`column-${columnIndex}`"
  28. class="searcher box">
  29. <searcher-show :searcher="searcher"
  30. :editable="true"
  31. :standalone="false"
  32. @deleted="onRemoveItem(rowIndex, columnIndex)">
  33. </searcher-show>
  34. </div>
  35. <add-box :ignore-searcher-ids="searcher.id ? [searcher.id] : []"
  36. @added="(searcher) => { onSearcherAdded(searcher, rowIndex); }">
  37. </add-box>
  38. </div>
  39. <div class="searchers-row flex-row">
  40. <add-box @added="onNewRowSearcherAdded">
  41. </add-box>
  42. </div>
  43. </div>
  44. </template>
  45. <script lang="ts">
  46. import {Component, Prop, Vue} from "vue-property-decorator";
  47. import AddBox from './AddBox.vue';
  48. import SearcherShow from './Show.vue';
  49. @Component({
  50. name: 'SearcherCreate',
  51. components: {
  52. AddBox,
  53. SearcherShow,
  54. },
  55. })
  56. export default class Create extends Vue {
  57. private id: String = '';
  58. private name: String = '';
  59. private rows: Array<Array<any>> = [];
  60. @Prop({
  61. default: () => {
  62. return {
  63. id: '',
  64. name: '',
  65. rows: [],
  66. };
  67. }
  68. })
  69. public readonly searcher!: any;
  70. @Prop({default: true})
  71. public readonly standalone!: boolean;
  72. onNewRowSearcherAdded(searcher: Object) {
  73. const length = this.rows.push([]);
  74. this.onSearcherAdded(searcher, length - 1);
  75. }
  76. async onSearcherAdded(searcher: any, rowIndex: number) {
  77. try {
  78. const { data } = await (window as any).axios.get(`/searchers/${searcher.id}`);
  79. this.rows[rowIndex].push(data.searcher);
  80. } catch (e) {
  81. }
  82. }
  83. onSave() {
  84. if (this.standalone) {
  85. this.save();
  86. return;
  87. }
  88. const updatedSearcher = Object.assign(this.searcher, {
  89. name: this.name,
  90. rows: this.rows,
  91. });
  92. this.$emit('updated', updatedSearcher);
  93. }
  94. async save() {
  95. try {
  96. const searcher = this.id ? await this.update() : await this.create();
  97. window.location.href = `/searchers/${searcher.id}`;
  98. } catch (e) {
  99. console.log(e);
  100. console.log('Something went wrong.');
  101. }
  102. }
  103. async update() {
  104. const { data } = await (window as any).axios.put(`/searchers/${this.id}`, {
  105. name: this.name,
  106. rows: this.rows,
  107. });
  108. return data.searcher;
  109. }
  110. async create() {
  111. const { data } = await (window as any).axios.post('/searchers', {
  112. name: this.name,
  113. rows: this.rows,
  114. });
  115. return data.searcher;
  116. }
  117. onRemoveItem(rowIndex: number, columnIndex: number) {
  118. if (
  119. this.rows[rowIndex][columnIndex].hasOwnProperty('rows') &&
  120. this.rows[rowIndex][columnIndex].rows.length === 0
  121. ) {
  122. this.$toast.add({
  123. severity: 'info',
  124. summary: `${this.searcher.name} searcher deleted`,
  125. detail: 'The searcher has been deleted as well because it does not have any searching data..',
  126. life: 4000,
  127. });
  128. }
  129. this.rows[rowIndex].splice(columnIndex, 1);
  130. if (this.rows[rowIndex].length === 0) {
  131. this.rows.splice(rowIndex, 1);
  132. }
  133. }
  134. created() {
  135. // Editing.
  136. if (this.searcher.id) {
  137. this.id = this.searcher.id;
  138. this.rows = this.searcher.rows;
  139. this.name = this.searcher.name;
  140. }
  141. }
  142. };
  143. </script>