Skip to content

Commit

Permalink
feature: Discovery operations (list,create,run,delete)
Browse files Browse the repository at this point in the history
  • Loading branch information
abugraokkali committed Dec 27, 2023
1 parent e0dfea8 commit 8fe460a
Show file tree
Hide file tree
Showing 15 changed files with 585 additions and 25 deletions.
8 changes: 8 additions & 0 deletions db.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
"url": "#/assets",
"key": "assets"
},
{
"name": {
"tr": "Keşifler",
"en": "Discoveries"
},
"url": "#/discoveries",
"key": "discoveries"
},
{
"name": {
"tr": "Profiller",
Expand Down
74 changes: 74 additions & 0 deletions frontend/src/components/Select/Profile.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<script setup lang="ts">
import { useProfileStore } from "@/stores/profile"
import type { IProfile } from "@/models/Profile"
import { computed, onMounted, ref } from "vue"
import { useI18n } from "vue-i18n"
const store = useProfileStore()
const { t } = useI18n()
const props = defineProps<{
profile: IProfile
}>()
const emit = defineEmits<{
(event: "update:profile", ...args: any[]): void
}>()
const value = computed({
get() {
return props.profile
},
set(value) {
emit("update:profile", value)
},
})
const createDebounce = () => {
let timeout: number | undefined = 0
return function (fnc: () => void, delayMs: any) {
clearTimeout(timeout)
timeout = setTimeout(() => {
fnc()
}, delayMs || 500)
}
}
const searchDebounce = createDebounce()
const loading = ref(true)
const search = (query: string) => {
loading.value = true
searchDebounce(() => {
store
.fetch({
search: query,
per_page: 20,
})
.then(() => {
loading.value = false
})
}, 300)
}
onMounted(() => {
store.fetch().then(() => {
loading.value = false
})
})
</script>

<template>
<n-select
v-model:value="value"
filterable
:placeholder="t('profile.select.placeholder')"
:options="store.get.records"
:loading="loading"
clearable
remote
:clear-filter-after-select="false"
@search="search"
label-field="name"
value-field="id"
/>
</template>
8 changes: 4 additions & 4 deletions frontend/src/components/Table/AsyncStore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,16 @@ const handlePageChange = (currentPage: any) => {
query(currentPage)
}
const handleFilterChange = (filters: any) => {
const handleFilterChange = (filter: any) => {
loading.value = true
Object.keys(filters).forEach((item) => {
Object.keys(filter).forEach((item) => {
filters.value = filters.value.filter((i: IData) => {
return i.key != item
})
if (filters[item] && filters[item].length > 0) {
if (filter[item] && filter[item].length > 0) {
filters.value.push({
key: item,
value: filters[item],
value: filter[item],
})
}
})
Expand Down
52 changes: 52 additions & 0 deletions frontend/src/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"name": "Name",
"updated_at": "Updated At"
},
"select": {
"placeholder": "Type to search profile"
},
"fetch": {
"messages": {
"error": "An error occurred while fetching profiles."
Expand Down Expand Up @@ -78,5 +81,54 @@
"error": "An error occurred while deleting profile."
}
}
},
"discovery": {
"title": "Discoveries",
"description": "You can start a new discovery or view your previous discoveries here.",
"table": {
"ip_range": "IP Range",
"profile": "Profile",
"discovery_status": "Discovery Status",
"message": "Message",
"updated_at": "Last Scan"
},
"status": {
"pending": "Pending",
"in_progress": "In Progress",
"done": "Done",
"error": "Error"
},
"fetch": {
"messages": {
"error": "An error occurred while fetching discoveries."
}
},
"create": {
"title": "Create Discovery",
"inputs": {
"ip_range": "IP Range",
"profile": "Profile"
},
"rules": {
"ip_range": "IP Range is required.",
"profile": "Profile is required."
},
"messages": {
"success": "Discovery created successfully.",
"error": "An error occurred while creating discovery."
}
},
"run": {
"messages": {
"success": "Scan started successfully.",
"error": "An error occurred while starting scan."
}
},
"delete": {
"messages": {
"success": "Discovery deleted successfully.",
"error": "An error occurred while deleting discovery."
}
}
}
}
46 changes: 46 additions & 0 deletions frontend/src/localization/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"name": "Ad",
"updated_at": "Güncellenme Tarihi"
},
"select": {
"placeholder": "Profil aramak için yazın"
},
"fetch": {
"messages": {
"error": "Profiller getirilirken bir hata oluştu."
Expand Down Expand Up @@ -78,5 +81,48 @@
"error": "Profil silinirken bir hata oluştu."
}
}
},
"discovery": {
"title": "Keşifler",
"description": "Burada yeni bir keşif başlatabilir veya önceki keşiflerinizi görüntüleyebilirsiniz.",
"table": {
"ip_range": "IP Aralığı",
"profile": "Profil",
"discovery_status": "Keşif Durumu",
"message": "Mesaj",
"updated_at": "Son Tarama"
},
"fetch": {
"messages": {
"error": "Keşifler getirilirken bir hata oluştu."
}
},
"create": {
"title": "Keşif Oluştur",
"inputs": {
"ip_range": "IP Aralığı",
"profile": "Profil"
},
"rules": {
"ip_range": "IP Aralığı zorunludur.",
"profile": "Profil zorunludur."
},
"messages": {
"success": "Keşif başarıyla oluşturuldu.",
"error": "Keşif oluşturulurken bir hata oluştu."
}
},
"run": {
"messages": {
"success": "Tarama başarıyla başlatıldı.",
"error": "Tarama başlatılırken bir hata oluştu."
}
},
"delete": {
"messages": {
"success": "Keşif başarıyla silindi.",
"error": "Keşif silinirken bir hata oluştu."
}
}
}
}
29 changes: 15 additions & 14 deletions frontend/src/models/Asset.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { IDiscovery } from "./Discovery"

export interface IAsset {
id: string
created_at: string
updated_at: string
deleted_at: string
hostname: string
address: string
serial_number: string
vendor: string
model: string
discovery_id: string
discovery: any
packages: any
}

id: string
created_at: string
updated_at: string
deleted_at: string
hostname: string
address: string
serial_number: string
vendor: string
model: string
discovery_id: string
discovery: IDiscovery
packages: any
}
6 changes: 3 additions & 3 deletions frontend/src/models/Column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export interface IColumn {
ellipsis?: {
tooltip: boolean
}
render?: (record: any) => JSX.Element
render?: (record: any) => any
type?: string
options?: string[]
filter?: (value: any) => boolean
filter?: (value: any, row: any) => boolean
filterOptions?: any
customFilter?: boolean
defaultFilterOptionValues?: any
renderExpand?: (record: any) => JSX.Element
renderExpand?: (record: any) => any
resizable?: boolean
}
18 changes: 18 additions & 0 deletions frontend/src/models/Discovery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { IProfile } from "./Profile"

export interface IDiscovery {
id: string
created_at: string
updated_at: string
deleted_at: string
ip_range: string
profile_id: string
profile: IProfile
discovery_status: string
message: string
}

export interface IDiscoveryCreate {
ip_range: string
profile_id: string | null
}
6 changes: 4 additions & 2 deletions frontend/src/models/Profile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { IDiscovery } from "./Discovery"

export interface IProfile {
id: string
created_at: string
updated_at: string
deleted_at: any
deleted_at: string
name: string
username: string
password: string
discoveries: any[]
discoveries: IDiscovery[]
}

export interface IProfileCreate {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const router = createRouter({
name: "assets",
component: () => import("@/views/pages/Assets.vue"),
},
{
path: "/discoveries",
name: "discoveries",
component: () => import("@/views/pages/Discoveries.vue"),
},
{
path: "/profiles",
name: "profiles",
Expand Down
Loading

0 comments on commit 8fe460a

Please sign in to comment.