From db8370e40cf3ce4e0e30ba89c6c0d1531704b2ce Mon Sep 17 00:00:00 2001 From: Sergey Shkurov Date: Fri, 28 Apr 2023 01:05:02 +0200 Subject: [PATCH] Add ability to delete patterns --- .gitignore | 17 +---- .idea/codeStyles/Project.xml | 69 -------------------- .idea/codeStyles/codeStyleConfig.xml | 5 -- .idea/discord.xml | 9 --- .idea/inspectionProfiles/Project_Default.xml | 6 -- .idea/jsLibraryMappings.xml | 6 -- .idea/misc.xml | 6 -- .idea/modules.xml | 8 --- .idea/packmate-frontend.iml | 8 --- .idea/saveactions_settings.xml | 13 ---- .idea/vcs.xml | 11 ---- src/App.vue | 17 ++--- src/components/Packet.vue | 1 + src/components/PatternsDropdown.vue | 34 ++++++++-- src/components/SidebarStream.vue | 5 +- 15 files changed, 45 insertions(+), 170 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/codeStyles/codeStyleConfig.xml delete mode 100644 .idea/discord.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/packmate-frontend.iml delete mode 100644 .idea/saveactions_settings.xml delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index f91b2ef..15ee84c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,14 @@ -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/dictionaries -.idea/**/shelf -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml -.idea/**/gradle.xml -.idea/**/libraries +.idea cmake-build-debug/ cmake-build-release/ -.idea/**/mongoSettings.xml *.iws out/ .idea_modules/ atlassian-ide-plugin.xml -.idea/replstate.xml com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties -.idea/httpRequests *.bak /.tgitconfig logs diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 5000502..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 79ee123..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml deleted file mode 100644 index 59b11d1..0000000 --- a/.idea/discord.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 03d9549..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index d23208f..0000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 28a804d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index e6ec75a..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/packmate-frontend.iml b/.idea/packmate-frontend.iml deleted file mode 100644 index c956989..0000000 --- a/.idea/packmate-frontend.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/saveactions_settings.xml b/.idea/saveactions_settings.xml deleted file mode 100644 index a897ed6..0000000 --- a/.idea/saveactions_settings.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 78cface..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 043ffbd..5fc053a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -100,10 +100,6 @@ this.addPatternFromWs(parsed.value); break; } - case 'DELETE_PATTERN': { - this.deletePatternFromWs(parsed.value); - break; - } case 'COUNTERS_UPDATE': { const data = parsed.value; this.$store.commit('setCurrentPacketsCount', data.totalPackets); @@ -171,10 +167,15 @@ }; }, addPatternFromWs(pattern) { - this.$store.commit('addPattern', pattern); - }, - deletePatternFromWs(id) { - this.$store.commit('setPatterns', this.$store.state.patterns.filter(o => o.id !== id)); + const foundIndex = this.$store.state.patterns.findIndex(el => el.id === pattern.id); + if (foundIndex === -1) { + this.$store.commit('addPattern', pattern); + return; + } + + let newPatterns = this.$store.state.patterns.slice(); + newPatterns.splice(foundIndex, 1, pattern); + this.$store.commit('setPatterns', newPatterns); }, togglePatternFromWs(id, enabled) { this.$store.state.patterns.forEach(pattern => { diff --git a/src/components/Packet.vue b/src/components/Packet.vue index 2e3ade9..99fdb7f 100644 --- a/src/components/Packet.vue +++ b/src/components/Packet.vue @@ -124,6 +124,7 @@ }, {}); // Array to object let offset = 0; this.packet.matches + .filter(match => !patterns[match.patternId].deleted) .sort((a, b) => a.startPosition - b.startPosition) .forEach(match => { const pattern = patterns[match.patternId]; diff --git a/src/components/PatternsDropdown.vue b/src/components/PatternsDropdown.vue index 3bcac6a..9e16d59 100644 --- a/src/components/PatternsDropdown.vue +++ b/src/components/PatternsDropdown.vue @@ -10,7 +10,7 @@ All streams - @@ -36,16 +36,22 @@ - - + + @@ -56,6 +62,11 @@ mounted() { this.updatePatterns(); }, + computed: { + existingPatterns: function () { + return this.$store.state.patterns.filter(p => !p.deleted) + }, + }, methods: { getSearchTypeValue(searchType, value) { if (searchType === 'REGEX') return `/${value}/`; @@ -113,7 +124,7 @@ togglePattern(pattern) { const enabled = !pattern.enabled; console.debug('Toggling pattern', pattern); - this.$http.post(`pattern/${pattern.id}/`, null, { + this.$http.post(`pattern/${pattern.id}/enable`, null, { params: { enabled, }, @@ -130,6 +141,21 @@ console.error('Failed to toggle pattern', e); }); }, + deletePattern(pattern) { + console.debug('Deleting pattern', pattern); + + this.$http.delete(`pattern/${pattern.id}`, null) + .then(() => { + console.debug('Done deleting pattern'); + this.$emit('patternAddComplete'); + }).catch(e => { + this.$bvToast.toast(`Failed to delete pattern: ${e}`, { + title: 'Error', + variant: 'danger', + }); + console.error('Failed to delete pattern', e); + }); + }, }, }; diff --git a/src/components/SidebarStream.vue b/src/components/SidebarStream.vue index 612dfb0..89cc6bd 100644 --- a/src/components/SidebarStream.vue +++ b/src/components/SidebarStream.vue @@ -15,7 +15,7 @@
- {{ pattern.name }} @@ -44,6 +44,9 @@ shouldShowServiceName: function () { return this.$route?.params?.servicePort === undefined; }, + notDeletedFoundPatterns: function () { + return this.stream.foundPatterns.filter(p => !p.deleted); + }, }, data: function () { return {