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.

158 lines
4.1 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div id="regex-create">
  3. <Card>
  4. <template #title v-if=" ! regex">
  5. New regex searcher
  6. </template>
  7. <template #content>
  8. <div class="p-fluid p-formgrid p-grid">
  9. <div class="p-field p-col-12 p-md-6">
  10. <label for="name">Enter searcher name</label>
  11. <InputText v-model="name"
  12. type="text"
  13. name="name"
  14. id="name">
  15. </InputText>
  16. </div>
  17. <div class="p-field p-col-12 p-md-6">
  18. <label for="tag">Enter searcher tag (optional)</label>
  19. <InputText v-model="tag"
  20. type="text"
  21. name="tag"
  22. id="tag">
  23. </InputText>
  24. </div>
  25. </div>
  26. </template>
  27. <template #footer>
  28. <Button @click="onSave"
  29. :disabled="( ! name && ! regex) || ! pattern"
  30. class="p-button-raised">
  31. Save
  32. </Button>
  33. </template>
  34. </Card>
  35. <Card>
  36. <template #content>
  37. <div class="regex-box">
  38. <div class="main">
  39. <pattern-box v-model="pattern"></pattern-box>
  40. <text-box :pattern="pattern"
  41. :flags="flags">
  42. </text-box>
  43. <flags v-model="flags"></flags>
  44. </div>
  45. <aside>
  46. <side-bar></side-bar>
  47. </aside>
  48. </div>
  49. </template>
  50. </Card>
  51. </div>
  52. </template>
  53. <script lang="ts">
  54. import {Component, Prop, Vue} from "vue-property-decorator";
  55. import TextBox from './TextBox.vue';
  56. import PatternBox from './PatternBox.vue';
  57. import Flags from './Flags.vue';
  58. import SideBar from './SideBar.vue';
  59. import { eventBus } from "@/app";
  60. @Component({
  61. name: 'RegexCreate',
  62. components: {
  63. TextBox,
  64. PatternBox,
  65. Flags,
  66. SideBar,
  67. },
  68. })
  69. export default class Create extends Vue {
  70. private name: string = '';
  71. private tag: string = '';
  72. private pattern: string = '';
  73. private flags: Array<string> = ['g', 'i'];
  74. @Prop({
  75. default: '',
  76. })
  77. public readonly regex!: string;
  78. @Prop({
  79. default: false,
  80. })
  81. public readonly standalone!: boolean;
  82. onSave() {
  83. if ( ! this.regex) {
  84. this.save();
  85. return;
  86. }
  87. this.$emit('updated', this.pattern);
  88. }
  89. async save() {
  90. try {
  91. const { data } = await (window as any).axios.post('/regex', {
  92. name: this.name,
  93. tag: this.tag,
  94. expression: this.pattern,
  95. });
  96. this.$toast.add({
  97. severity: 'success',
  98. summary: 'Searcher created.',
  99. life: 1000,
  100. });
  101. if ( ! this.standalone) {
  102. setTimeout(() => {
  103. window.location.href = `/searchers/${data.searcher.id}`;
  104. }, 1000);
  105. return;
  106. }
  107. this.$emit('searcher', data.searcher);
  108. } catch (e) {
  109. console.log(e);
  110. console.log('Something went wrong.');
  111. }
  112. }
  113. public async changeRoute(url: string) {
  114. if (this.pattern !== '' && this.pattern !== undefined) {
  115. if (this.name === '' || this.name === undefined) {
  116. this.name = 'Unnamed regex - ' + Date.now();
  117. }
  118. await this.save();
  119. }
  120. window.location.href = url;
  121. }
  122. created() {
  123. if (this.regex) {
  124. this.pattern = this.regex;
  125. }
  126. eventBus.$on('changeRoute', this.changeRoute);
  127. }
  128. };
  129. </script>
  130. <style lang="scss" scoped>
  131. #regex-create {
  132. margin-top: 25px;
  133. }
  134. </style>