bootstrap migrate
This commit is contained in:
22
internal/kurious/ports/http/bootstrap/common.templ
Normal file
22
internal/kurious/ports/http/bootstrap/common.templ
Normal file
@ -0,0 +1,22 @@
|
||||
package bootstrap
|
||||
|
||||
templ button(title string, attributes templ.Attributes) {
|
||||
<button class="button" { attributes... }>{ title }</button>
|
||||
}
|
||||
|
||||
templ buttonRedirect(id, title string, linkTo string) {
|
||||
<button
|
||||
class="button"
|
||||
id={ "origin-link-" + id }
|
||||
>
|
||||
{ title }
|
||||
</button>
|
||||
|
||||
@onclickRedirect("origin-link-" + id, linkTo)
|
||||
}
|
||||
|
||||
script onclickRedirect(id, to string) {
|
||||
document.getElementById(id).onclick = () => {
|
||||
location.href = to
|
||||
}
|
||||
}
|
||||
55
internal/kurious/ports/http/bootstrap/core.templ
Normal file
55
internal/kurious/ports/http/bootstrap/core.templ
Normal file
@ -0,0 +1,55 @@
|
||||
package bootstrap
|
||||
|
||||
templ head() {
|
||||
<head>
|
||||
<title>Test page</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
|
||||
crossorigin="anonymous"
|
||||
/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
|
||||
crossorigin="anonymous"></script>
|
||||
</head>
|
||||
}
|
||||
|
||||
templ navbar() {
|
||||
<nav class="navbar navbar-expand-lg bg-body-tertiary w-auto">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">Kurious</a>
|
||||
<button
|
||||
class="navbar-toggler"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false"
|
||||
aria-label="Toggle navigation"
|
||||
>
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="#">На главную</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">О нас</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
}
|
||||
|
||||
templ footer() {
|
||||
<footer>
|
||||
<div>
|
||||
<span>(c) kurious, 2024. All rights reserved.</span>
|
||||
</div>
|
||||
</footer>
|
||||
}
|
||||
54
internal/kurious/ports/http/bootstrap/list.templ
Normal file
54
internal/kurious/ports/http/bootstrap/list.templ
Normal file
@ -0,0 +1,54 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
script breadcrumbsLoad() {
|
||||
const formFilterOnSubmit = event => {
|
||||
event.preventDefault();
|
||||
|
||||
const lt = document.getElementById('learning-type-filter');
|
||||
const ct = document.getElementById('course-thematic-filter');
|
||||
|
||||
const prefix = (lt !== null && lt.value !== '') ? `/courses/${lt.value}` : `/courses`;
|
||||
const out = (ct !== null && ct.value !== '') ? `${prefix}/${ct.value}` : prefix;
|
||||
|
||||
document.location.assign(out);
|
||||
return false;
|
||||
};
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const ff = document.getElementById('filter-form');
|
||||
if (ff === null) return;
|
||||
ff.addEventListener('submit', formFilterOnSubmit);
|
||||
});
|
||||
}
|
||||
|
||||
templ breadcrumbsItem(text, link string, isActive bool) {
|
||||
<li class={"breadcrumb-item", templ.KV("active", isActive)}>
|
||||
if link != "" {
|
||||
<a href={ templ.SafeURL(link) } itemprop="url">
|
||||
<span itemprop="title">{ text }</span>
|
||||
</a>
|
||||
} else {
|
||||
<span itemprop="url" itemprop="title">{ text }</span>
|
||||
}
|
||||
</li>
|
||||
}
|
||||
|
||||
templ breadcrumNode(params BreadcrumbsParams) {
|
||||
// TODO: add divider to nav style
|
||||
<nav
|
||||
aria-label="breadcrumbs"
|
||||
itemprop="breadcrumb"
|
||||
itemtype="https://schema.org/BreadcrumbList"
|
||||
itemscope
|
||||
>
|
||||
<ol class="breadcrumb">
|
||||
@breadcrumbsItem("Курсы", "/courses", params.ActiveCourseThematic.Empty())
|
||||
</ol>
|
||||
</nav>
|
||||
}
|
||||
|
||||
95
internal/kurious/ports/http/bootstrap/vars.go
Normal file
95
internal/kurious/ports/http/bootstrap/vars.go
Normal file
@ -0,0 +1,95 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getCompactedValue(value int) string {
|
||||
var (
|
||||
myValue float64
|
||||
dim string
|
||||
)
|
||||
switch {
|
||||
case value/1e6 > 0:
|
||||
cutted := value / 1e3
|
||||
myValue, dim = float64(cutted)/1e3, "m"
|
||||
case value/1e3 > 0:
|
||||
myValue, dim = float64(value/1e3), "k"
|
||||
default:
|
||||
myValue, dim = float64(value), ""
|
||||
}
|
||||
|
||||
return strings.TrimSuffix(strconv.FormatFloat(myValue, 'f', 3, 32), ".000") + dim
|
||||
}
|
||||
|
||||
func MakeNewStats(courses, clients, categories int) stats {
|
||||
return stats{
|
||||
CoursesCount: getCompactedValue(courses),
|
||||
ClientsCount: getCompactedValue(clients),
|
||||
CategoriesCount: getCompactedValue(categories),
|
||||
}
|
||||
}
|
||||
|
||||
type stats struct {
|
||||
CoursesCount string
|
||||
ClientsCount string
|
||||
CategoriesCount string
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (c Category) Empty() bool {
|
||||
return c == (Category{})
|
||||
}
|
||||
|
||||
type BreadcrumbsParams struct {
|
||||
ActiveLearningType Category
|
||||
ActiveCourseThematic Category
|
||||
}
|
||||
|
||||
type FilterFormParams struct {
|
||||
BreadcrumbsParams
|
||||
|
||||
AvailableLearningTypes []Category
|
||||
AvailableCourseThematics []Category
|
||||
}
|
||||
|
||||
func isEmpty(s string) bool {
|
||||
return s == ""
|
||||
}
|
||||
|
||||
type CourseInfo struct {
|
||||
ID string
|
||||
Name string
|
||||
FullPrice int
|
||||
ImageLink string
|
||||
OriginLink string
|
||||
}
|
||||
|
||||
type CategoryBaseInfo struct {
|
||||
ID string
|
||||
Name string
|
||||
Description string
|
||||
}
|
||||
|
||||
type CategoryContainer struct {
|
||||
CategoryBaseInfo
|
||||
|
||||
Subcategories []SubcategoryContainer
|
||||
}
|
||||
|
||||
type SubcategoryContainer struct {
|
||||
CategoryBaseInfo
|
||||
|
||||
Courses []CourseInfo
|
||||
}
|
||||
|
||||
type ListCoursesParams struct {
|
||||
FilterForm FilterFormParams
|
||||
|
||||
Categories []CategoryContainer
|
||||
}
|
||||
Reference in New Issue
Block a user