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.

103 lines
2.4 KiB

  1. <template>
  2. <div id="regex-create">
  3. <div class="regex-header">
  4. <template v-if=" ! regex">
  5. <h1> New regex searcher </h1>
  6. <InputText v-model="name"
  7. type="text"
  8. placeholder="Enter searcher name"
  9. class="input">
  10. </InputText>
  11. </template>
  12. <Button @click="onSave" :disabled="( ! name && ! regex) || ! pattern">
  13. Save
  14. </Button>
  15. </div>
  16. <div class="regex-box">
  17. <div class="main">
  18. <pattern-box v-model="pattern"></pattern-box>
  19. <text-box :pattern="pattern"
  20. :flags="flags">
  21. </text-box>
  22. <flags v-model="flags"></flags>
  23. </div>
  24. <aside>
  25. <side-bar></side-bar>
  26. </aside>
  27. </div>
  28. </div>
  29. </template>
  30. <script lang="ts">
  31. import {Component, Prop, Vue} from "vue-property-decorator";
  32. import TextBox from './TextBox.vue';
  33. import PatternBox from './PatternBox.vue';
  34. import Flags from './Flags.vue';
  35. import SideBar from './SideBar.vue';
  36. @Component({
  37. name: 'RegexCreate',
  38. components: {
  39. TextBox,
  40. PatternBox,
  41. Flags,
  42. SideBar,
  43. },
  44. })
  45. export default class Create extends Vue {
  46. private name: string = '';
  47. private pattern: string = '';
  48. private flags: Array<string> = ['g', 'i'];
  49. @Prop({
  50. default: '',
  51. })
  52. public readonly regex!: string;
  53. onSave() {
  54. if ( ! this.regex) {
  55. this.save();
  56. return;
  57. }
  58. this.$emit('updated', this.pattern);
  59. }
  60. async save() {
  61. try {
  62. const { data } = await (window as any).axios.post('/regex', {
  63. name: this.name,
  64. expression: this.pattern,
  65. });
  66. this.$toast.add({
  67. severity: 'success',
  68. summary: 'Searcher created.',
  69. life: 1000,
  70. });
  71. setTimeout(() => {
  72. window.location.href = `/searchers/${data.searcher.id}`;
  73. }, 1000);
  74. } catch (e) {
  75. console.log(e);
  76. console.log('Something went wrong.');
  77. }
  78. }
  79. created() {
  80. if (this.regex) {
  81. this.pattern = this.regex;
  82. }
  83. }
  84. };
  85. </script>