Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polish-community-beth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Beth Davies
polish-community-beth
Commits
fdbc66f3
Commit
fdbc66f3
authored
9 months ago
by
Richard Githuba
Browse files
Options
Downloads
Patches
Plain Diff
now getting the categoryName via the api
parent
d129e39b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/resources/static/js/headings/headings.js
+133
-121
133 additions, 121 deletions
src/main/resources/static/js/headings/headings.js
with
133 additions
and
121 deletions
src/main/resources/static/js/headings/headings.js
+
133
−
121
View file @
fdbc66f3
// get category from url params
// get category from url params
const
urlParams
=
new
URLSearchParams
(
window
.
location
.
search
);
const
urlParams
=
new
URLSearchParams
(
window
.
location
.
search
);
const
categoryId
=
window
.
location
.
pathname
.
split
(
'
/
'
)[
2
];
// Assuming /categories/{id}
const
categoryId
=
window
.
location
.
pathname
.
split
(
'
/
'
)[
2
];
// Assuming /categories/{id}
cons
t
categoryName
=
urlParams
.
get
(
'
categoryName
'
)
;
le
t
categoryName
=
""
;
// fetch category headings from api
// fetch category headings from api
const
apiUrl
=
'
/getInfoByCategoryId
'
;
const
apiUrl
=
'
/getInfoByCategoryId
'
;
async
function
getCategoryName
(){
try
{
const
response
=
await
fetch
(
`/api/categories/
${
categoryId
}
`
)
if
(
!
response
.
ok
)
throw
new
Error
(
`Http error! status:
${
response
.
status
}
`
)
const
category
=
await
response
.
json
()
categoryName
=
category
.
categoryTitle
;
console
.
log
(
'
Category Name:
'
,
categoryName
);
}
catch
(
error
)
{
console
.
error
(
'
Error fetching category
'
,
error
);
}
}
async
function
fetchCategoryHeadings
()
{
async
function
fetchCategoryHeadings
()
{
try
{
try
{
const
response
=
await
fetch
(
`
${
apiUrl
}
/
${
categoryId
}
`
);
const
response
=
await
fetch
(
`
${
apiUrl
}
/
${
categoryId
}
`
);
...
@@ -33,9 +46,6 @@ function renderHeadings(headings) {
...
@@ -33,9 +46,6 @@ function renderHeadings(headings) {
const
title
=
document
.
createElement
(
'
h2
'
)
const
title
=
document
.
createElement
(
'
h2
'
)
title
.
innerHTML
=
`<i class="bi bi-file-earmark-text"></i>
${
heading
.
infoTitle
}
`
title
.
innerHTML
=
`<i class="bi bi-file-earmark-text"></i>
${
heading
.
infoTitle
}
`
// const description = document.createElement('p');
// description.textContent = heading.description
const
link
=
document
.
createElement
(
'
a
'
)
const
link
=
document
.
createElement
(
'
a
'
)
link
.
href
=
`/info/
${
heading
.
informationId
}
`
;
link
.
href
=
`/info/
${
heading
.
informationId
}
`
;
link
.
classList
.
add
(
'
heading-link
'
);
link
.
classList
.
add
(
'
heading-link
'
);
...
@@ -47,19 +57,19 @@ function renderHeadings(headings) {
...
@@ -47,19 +57,19 @@ function renderHeadings(headings) {
link
.
appendChild
(
readMore
);
link
.
appendChild
(
readMore
);
listItem
.
appendChild
(
title
)
listItem
.
appendChild
(
title
)
// listItem.appendChild(description)
listItem
.
appendChild
(
link
)
listItem
.
appendChild
(
link
)
container
.
appendChild
(
listItem
)
container
.
appendChild
(
listItem
)
});
});
}
}
// change the title of the page bases on category
async
function
init
()
{
await
getCategoryName
();
// change the title of the page based on category
document
.
getElementById
(
'
category-name
'
).
textContent
=
categoryName
?
`
${
categoryName
}
`
:
'
Category Name Not Found
'
;
document
.
getElementById
(
'
category-name
'
).
textContent
=
categoryName
?
`
${
categoryName
}
`
:
'
Category Name Not Found
'
;
// Fetch and render the category headings when the page loads
// Fetch and render the category headings when the page loads
fetchCategoryHeadings
();
fetchCategoryHeadings
();
// Get the category id from the url
// Get the category id from the url
function
getCategoryIdFromUrl
()
{
function
getCategoryIdFromUrl
()
{
const
path
=
window
.
location
.
pathname
;
const
path
=
window
.
location
.
pathname
;
...
@@ -80,7 +90,6 @@ function generateAddInfoPageUrl() {
...
@@ -80,7 +90,6 @@ function generateAddInfoPageUrl() {
generateAddInfoPageUrl
();
generateAddInfoPageUrl
();
// Function to toggle edit mode to enable multi-select for deletion
// Function to toggle edit mode to enable multi-select for deletion
function
toggleEditMode
()
{
function
toggleEditMode
()
{
const
container
=
document
.
getElementById
(
'
headings-container
'
);
const
container
=
document
.
getElementById
(
'
headings-container
'
);
...
@@ -188,3 +197,6 @@ async function deleteSelectedItems() {
...
@@ -188,3 +197,6 @@ async function deleteSelectedItems() {
// Attach event listeners to toggle edit button and perform deletion
// Attach event listeners to toggle edit button and perform deletion
document
.
getElementById
(
'
edit-mode-button
'
).
addEventListener
(
'
click
'
,
toggleEditMode
);
document
.
getElementById
(
'
edit-mode-button
'
).
addEventListener
(
'
click
'
,
toggleEditMode
);
document
.
getElementById
(
'
delete-button
'
).
addEventListener
(
'
click
'
,
deleteSelectedItems
);
document
.
getElementById
(
'
delete-button
'
).
addEventListener
(
'
click
'
,
deleteSelectedItems
);
}
init
();
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