Skip to content

Commit e8fc136

Browse files
author
Tristan LOSADA BENINI
committed
feat(astrapia): add QueryConditions logic
NETANOL-230
1 parent ea865ca commit e8fc136

File tree

5 files changed

+65
-36
lines changed

5 files changed

+65
-36
lines changed

Astrapia/components/GraphFilterMenu.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const props = defineProps({
2121
2222
const emit = defineEmits<{
2323
layersFetched: [],
24-
menuOpened: [boolean]
24+
menuOpened: [boolean],
25+
queryConditions: [any]
2526
}>();
2627
2728
const graphFilterMenuState = ref({
@@ -35,6 +36,7 @@ const graphFilterMenuState = ref({
3536
async function getLayersOfLayout() {
3637
const layoutData = await layoutService.getLayoutByName(graphFilterMenuState.value.selectedLayout.name);
3738
graphFilterMenuState.value.selectedLayout.layers = layoutData.layers;
39+
emit('queryConditions', layoutData.queryConditions);
3840
emit('layersFetched');
3941
}
4042

Astrapia/components/QueryConditionButton.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<font-awesome-icon icon="fa-solid fa-filter" />
77
</button>
88
</div>
9-
<QueryConditionForm v-if="isVisible" @isVisible="toggleForm" :layout="layout"/>
9+
<QueryConditionForm v-if="isVisible" @isVisible="toggleForm" :layout="layout" :queryConditions="queryConditions"/>
1010
</div>
1111
</template>
1212

@@ -16,11 +16,13 @@ import { ref } from 'vue';
1616
import QueryConditionForm from "~/components/QueryConditionForm.vue";
1717
1818
const props = defineProps<{
19-
layout: string
19+
layout: any,
20+
queryConditions: any
2021
}>();
2122
2223
const isVisible = ref(false);
2324
const layout = props.layout;
25+
const queryConditions = props.queryConditions;
2426
2527
const toggleForm = () => {
2628
isVisible.value = !isVisible.value;

Astrapia/components/QueryConditionForm.vue

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</div>
3535
<div class="subtitle">Port Whitelist:</div>
3636
<div class="port-input-container">
37-
<input class="first-tag-condition-editing-input" type="number" v-model="selectedPort" placeholder="Enter Port Number" @keydown.enter.prevent="addPort">
37+
<input class="first-tag-condition-editing-input" type="text" v-model="selectedPort" placeholder="Enter Port Number" @keydown.enter.prevent="addPort">
3838
<font-awesome-icon icon="fa-solid fa-plus" class="adding-icon" @click="addPort"/>
3939
</div>
4040
<div v-for="(port, index) in portsWhitelist" :key="index" class="whitelist-item">
@@ -60,7 +60,8 @@ const emit = defineEmits<{
6060
}>()
6161
6262
const props = defineProps<{
63-
layout: string
63+
layout: any,
64+
queryConditions: any
6465
}>();
6566
6667
const allowDuplicates = ref(true);
@@ -79,7 +80,6 @@ const saveForm = () => {
7980
dataProtocolsWhitelist: dataProtocolsWhitelist.value,
8081
portsWhitelist: portsWhitelist.value
8182
};
82-
console.log(jsonData);
8383
LayoutService.setQueryConditions('test',jsonData);
8484
cancelForm();
8585
};
@@ -92,8 +92,8 @@ const cancelForm = () => {
9292
emit('isVisible');
9393
};
9494
95-
const addProtocol = (type) => {
96-
const selectedProtocol = type === 'flow' ? selectedFlowProtocols : selectedDataProtocols;
95+
const addProtocol = (type: string) => {
96+
const selectedProtocol: string = type === 'flow' ? selectedFlowProtocols : selectedDataProtocols;
9797
if (selectedProtocol && !flowProtocolsWhitelist.value.includes(selectedProtocol) && !dataProtocolsWhitelist.value.includes(selectedProtocol)) {
9898
if (type === 'flow') {
9999
flowProtocolsWhitelist.value.push(selectedProtocol);
@@ -108,7 +108,7 @@ const addProtocol = (type) => {
108108
}
109109
};
110110
111-
const removeProtocol = (type, index) => {
111+
const removeProtocol = (type: string, index: number) => {
112112
if (type === 'flow') {
113113
flowProtocolsWhitelist.value.splice(index, 1);
114114
} else {
@@ -117,8 +117,8 @@ const removeProtocol = (type, index) => {
117117
};
118118
119119
const addPort = () => {
120-
const port = parseInt(selectedPort);
121-
if (!isNaN(port) && !portsWhitelist.value.includes(port)) {
120+
const port: number = parseInt(selectedPort);
121+
if (!isNaN(port) && port <= 65535 && !portsWhitelist.value.includes(port)) {
122122
portsWhitelist.value.push(port);
123123
selectedPort = '';
124124
}
@@ -136,6 +136,10 @@ const handleOverlayClick = (event) => {
136136
};
137137
138138
onMounted(() => {
139+
allowDuplicates.value = props.queryConditions.allowDuplicates;
140+
flowProtocolsWhitelist.value = props.queryConditions.flowProtocolsWhitelist;
141+
dataProtocolsWhitelist.value = props.queryConditions.dataProtocolsWhitelist;
142+
portsWhitelist.value = props.queryConditions.portsWhitelist;
139143
document.addEventListener('keydown', (event) => {
140144
if (event.key === 'Escape') {
141145
cancelForm();
@@ -146,13 +150,16 @@ onMounted(() => {
146150
</script>
147151

148152
<style scoped>
149-
.first-tag-condition-editing-input{
153+
154+
155+
.first-tag-condition-editing-input {
150156
border: 1px solid #424242;
151157
border-radius: 4px;
152-
font-size: 2vh;
158+
font-size: 1.5vh;
153159
width: 90%;
154-
padding: 2%;
155-
margin: 0.5vh 0;
160+
padding: 4px;
161+
margin-bottom: 10px;
162+
background: white;
156163
}
157164
158165
.first-tag-condition-editing-input:focus {
@@ -164,30 +171,40 @@ onMounted(() => {
164171
align-items: center;
165172
margin-bottom: 5px;
166173
margin-left: 15px;
174+
font-size: 1.5vh;
175+
width: 40%;
167176
}
168177
169178
.dot {
170179
margin-right: 10px;
171-
font-size: 1.2em;
180+
font-size: 1.5vh;
172181
}
173182
174183
.protocol-text {
175-
margin-right: 10px;
184+
display: inline-block;
185+
white-space: nowrap;
186+
overflow: hidden;
187+
text-overflow: ellipsis;
188+
}
189+
190+
.removal-icon {
191+
margin-left: auto;
192+
cursor: pointer;
176193
}
177194
178195
.port-input-container {
179196
display: flex;
180197
align-items: center;
198+
width: 90%;
181199
}
182200
183201
.port-input-container input {
184202
margin-right: 10px;
203+
flex: 1;
185204
}
186205
187-
.port-input-container button {
188-
padding: 8px 16px;
189-
border: none;
190-
border-radius: 5px;
206+
.adding-icon {
207+
margin-bottom: 10px;
191208
cursor: pointer;
192209
}
193210
@@ -214,37 +231,33 @@ onMounted(() => {
214231
border-radius: 5px;
215232
max-height: 400px;
216233
overflow-y: auto;
234+
margin-bottom: 10px;
235+
width: 35vh;
236+
box-sizing: border-box;
217237
}
218238
219239
.title {
220240
font-weight: bold;
221-
font-size: 24px;
241+
font-size: 3vh;
222242
margin-bottom: 10px;
223243
}
224244
225245
.layout-title{
226-
font-size: 18px;
246+
font-size: 2vh;
227247
margin-bottom: 15px;
228248
}
229249
230250
.subtitle {
231251
font-size: 12px;
232-
margin-bottom: 10px;
252+
margin-bottom: 5px;
233253
color: #666;
234254
}
235255
236256
.subtitle-duplicates {
237257
font-size: 1.8vh;
238258
margin-bottom: 10px;
239259
color: #666;
240-
}
241-
242-
.query-condition-form input,
243-
.query-condition-form select {
244-
margin-bottom: 10px;
245-
width: 100%;
246-
padding: 8px;
247-
box-sizing: border-box;
260+
margin-top: 10px;
248261
}
249262
250263
.button-container {
@@ -309,12 +322,13 @@ onMounted(() => {
309322
.theme-checkbox:checked, .scrollable-selector-include-exclude-traffic input[type="checkbox"]:checked {
310323
background-position: 100%;
311324
}
325+
312326
.scrollable-selector-include-exclude-traffic {
313327
display: flex;
314328
flex-direction: row;
315329
align-items: center;
316330
justify-content: space-between;
317-
width: 70%;
331+
width: 60%;
318332
font-size: 2vh;
319333
}
320334
</style>

Astrapia/pages/topology.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<div class="topology-menu">
33
<Dropdown class="layout-dropdown" @changeLayout="handleLayoutChange" />
44
<Graph :data="data" @intervalAmount="handleIntervalAmount"/>
5-
<GraphFilterMenu v-bind:layout="layout" @menuOpened="handleMenuOpened" @layersFetched="fetchAndUpdateGraph"/>
5+
<GraphFilterMenu v-bind:layout="layout" @menuOpened="handleMenuOpened" @layersFetched="fetchAndUpdateGraph" @queryConditions="handleQueryConditions"/>
66
<TopologyTimeframeSelector v-if="data && layout" class="topology-timeframe"
77
@change="handleTimeframeSelection"
88
:from-value="timeframeSelectorFrom"
99
:to-value="timeframeSelectorTo"/>
10-
<QueryConditionButton v-if="data && layout" class="query-conditions" :layout="layout"/>
10+
<QueryConditionButton v-if="data && layout" class="query-conditions" :layout="layout" :queryConditions="queryConditions"/>
1111
</div>
1212
</template>
1313

@@ -25,6 +25,7 @@ const layout = ref('');
2525
const timeframeSelectorFrom = ref(new Date(new Date().getTime() - 2 * 60 * 1000).toISOString().slice(0,16))
2626
const timeframeSelectorTo = ref(new Date().toISOString().slice(0,16))
2727
const data = ref();
28+
const queryConditions = ref(null);
2829
const intervalAmount = ref<number>(0);
2930
3031
let fetchInterval: NodeJS.Timeout | null = null;
@@ -36,6 +37,10 @@ const handleTimeframeSelection = (from: string, to: string) => {
3637
fetchAndUpdateGraph();
3738
}
3839
40+
const handleQueryConditions = (conditions: any) => {
41+
queryConditions.value = conditions;
42+
};
43+
3944
const handleIntervalAmount = (amount: number) => {
4045
intervalAmount.value = amount;
4146
if (fetchInterval) {

Astrapia/services/layoutService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ export interface Layouts {
77

88
export interface Layout {
99
name: string,
10-
layers: []
10+
layers: [],
11+
queryConditions: {
12+
allowDuplicates: boolean,
13+
dataProtocolsWhitelist: [],
14+
flowProtocolsWhitelist: [],
15+
portsWhitelist: []
16+
}
1117
}
1218

1319
class LayoutService {

0 commit comments

Comments
 (0)