Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Emergency Alert Application
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
marinos
Emergency Alert Application
Commits
f6c97648
Commit
f6c97648
authored
4 months ago
by
Elisabethein
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'emergency-alert-application/main' into Elisabet
parents
27e2b3c4
97f256e6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
eaa_frontend/src/pages/KnowledgeBase.vue
+77
-13
77 additions, 13 deletions
eaa_frontend/src/pages/KnowledgeBase.vue
with
77 additions
and
13 deletions
eaa_frontend/src/pages/KnowledgeBase.vue
+
77
−
13
View file @
f6c97648
...
...
@@ -173,11 +173,17 @@ export default {
editGeneralMaterial
:
false
,
editselectedSpeciesGroup
:
''
,
alertShown
:
false
,
user
:
{
id
:
null
,
species
:
[]
},
};
},
created
()
{
this
.
fetchMaterials
();
this
.
fetchSpeciesGroups
();
this
.
fetchUser
().
then
(()
=>
{
this
.
fetchMaterials
();
this
.
fetchSpeciesGroups
();
});
},
computed
:
{
hasJuhtkondRole
()
{
...
...
@@ -215,7 +221,7 @@ export default {
const
token
=
this
.
getAuthToken
();
try
{
const
response
=
await
fetch
(
'
http://localhost:8080/api/materials/add
'
,
{
//const response = await fetch('api/materials/add', {
//const response = await fetch('api/materials/add', {
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
...
...
@@ -252,7 +258,7 @@ export default {
const
token
=
this
.
getAuthToken
();
try
{
const
response
=
await
fetch
(
'
http://localhost:8080/api/materials/all
'
,
{
//const response = await fetch('api/materials/all', {
//const response = await fetch('api/materials/all', {
method
:
'
GET
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
...
...
@@ -284,8 +290,7 @@ export default {
this
.
upperSpeciesList
=
data
.
map
(
group
=>
group
.
name
);
}
else
if
(
response
.
status
===
403
)
{
this
.
handleUnauthorized
();
}
else
{
}
else
{
console
.
error
(
'
Failed to fetch species groups:
'
,
response
.
status
);
}
}
catch
(
error
)
{
...
...
@@ -300,7 +305,7 @@ export default {
const
token
=
this
.
getAuthToken
();
try
{
const
response
=
await
fetch
(
`http://localhost:8080/api/materials/delete/
${
material
.
id
}
`
,
{
//const response = await fetch(`api/materials/delete/${material.id}`, {
//const response = await fetch(`api/materials/delete/${material.id}`, {
method
:
'
DELETE
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
...
...
@@ -337,7 +342,7 @@ export default {
const
token
=
this
.
getAuthToken
();
try
{
const
response
=
await
fetch
(
`http://localhost:8080/api/materials/update/
${
this
.
editMaterialId
}
`
,
{
//const response = await fetch(`api/materials/update/${this.editMaterialId}`, {
//const response = await fetch(`api/materials/update/${this.editMaterialId}`, {
method
:
'
PUT
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
...
...
@@ -364,23 +369,79 @@ export default {
},
filterMaterials
()
{
this
.
filteredMaterials
=
this
.
materials
.
filter
(
material
=>
{
// Kontrollime, kas m
ater
j
al
vastab valitud liigigruppidele ja otsingusõnale
filterMaterials
ForSearch
()
{
// Filtreerime ainult nende materjalide põhjal, mis on juba kasutaja grupi järgi filtreeritud
this
.
filteredM
ater
i
al
s
=
this
.
filteredMaterials
.
filter
(
material
=>
{
const
matchesSpeciesGroup
=
this
.
selectedSpecies
.
length
===
0
||
this
.
selectedSpecies
.
some
(
group
=>
material
.
selectedSpeciesGroup
===
group
);
const
matchesSearchTerm
=
material
.
title
.
toLowerCase
().
includes
(
this
.
searchTerm
.
toLowerCase
())
||
material
.
description
.
toLowerCase
().
includes
(
this
.
searchTerm
.
toLowerCase
());
// Kontrollime, kas materjal vastab valitud materjalitüübile (üldine või kõik)
const
matchesMaterialType
=
this
.
selectedMaterialType
===
'
all
'
||
(
this
.
selectedMaterialType
===
'
general
'
&&
material
.
generalMaterial
===
true
);
// Tagastame, kui kõik filtrid on täidetud
return
matchesSpeciesGroup
&&
matchesSearchTerm
&&
matchesMaterialType
;
});
},
filterMaterialsForUser
()
{
// Leiab kasutajale ainult üldised või tema liigigrupi materjalid
this
.
filteredMaterials
=
this
.
materials
.
filter
(
material
=>
{
const
matchesUserSpeciesGroup
=
material
.
generalMaterial
===
true
||
this
.
user
.
species
.
some
(
userGroup
=>
{
return
String
(
material
.
selectedSpeciesGroup
)
===
String
(
userGroup
.
name
);
});
return
matchesUserSpeciesGroup
;
});
},
filterMaterials
()
{
// Kui kasutaja ei ole juhtkonnas, siis rakendame kasutaja liigigruppide filtri
if
(
!
this
.
hasJuhtkondRole
)
{
this
.
filterMaterialsForUser
();
}
// Seejärel rakendame otsingutermini ja materjalitüübi filtri
this
.
filterMaterialsForSearch
();
},
async
fetchUser
()
{
const
currentUser
=
this
.
$store
.
state
.
user
;
// Assuming user data is stored in the store
// Fetch species for the current user
const
[
species
]
=
await
Promise
.
all
([
this
.
fetchData
(
`users/
${
currentUser
.
id
}
/species`
)
]);
// Merge fetched data into user object
this
.
user
=
{
...
currentUser
,
species
:
species
||
[]
};
},
async
fetchData
(
endpoint
)
{
const
token
=
this
.
getAuthToken
();
const
response
=
await
fetch
(
`http://localhost:8080/api/
${
endpoint
}
`
,
{
//const response = await fetch(`api/${endpoint}`, {
method
:
'
GET
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
Authorization
'
:
`Bearer
${
token
}
`
,
},
});
if
(
!
response
.
ok
)
{
if
(
response
.
status
===
403
)
{
this
.
handleUnauthorized
();
}
else
{
console
.
error
(
`Failed to fetch data`
);
}
return
null
;
}
return
response
.
json
();
},
},
};
...
...
@@ -596,6 +657,7 @@ input[type="text"] {
width
:
400px
;
max-width
:
90%
;
}
.custom-dropdown
,
.filters-section
{
display
:
flex
;
...
...
@@ -604,6 +666,7 @@ input[type="text"] {
width
:
80%
;
margin-bottom
:
20px
;
}
.custom-dropdown
,
.filters
{
display
:
flex
;
...
...
@@ -612,6 +675,7 @@ input[type="text"] {
width
:
40%
;
margin-bottom
:
20px
;
}
.custom-dropdown
{
width
:
100%
;
padding
:
8px
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment