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.

134 lines
3.4 KiB

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