Skip to content

Commit

Permalink
making go templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tsawler committed Feb 21, 2021
1 parent b1c0171 commit b0ea025
Show file tree
Hide file tree
Showing 14 changed files with 608 additions and 34 deletions.
6 changes: 6 additions & 0 deletions cmd/web/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ func routes(app *config.AppConfig) http.Handler {

mux.Get("/", handlers.Repo.Home)
mux.Get("/about", handlers.Repo.About)
mux.Get("/generals-quarters", handlers.Repo.Generals)
mux.Get("/majors-suite", handlers.Repo.Majors)
mux.Get("/search-availability", handlers.Repo.Availability)
mux.Get("/contact", handlers.Repo.Contact)

mux.Get("/make-reservation", handlers.Repo.Reservation)

fileServer := http.FileServer(http.Dir("./static/"))
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))
Expand Down
25 changes: 25 additions & 0 deletions pkg/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,28 @@ func (m *Repository) About(w http.ResponseWriter, r *http.Request) {
StringMap: stringMap,
})
}

// Reservation renders the make a reservation page and displays form
func (m *Repository) Reservation(w http.ResponseWriter, r *http.Request) {
render.RenderTemplate(w, "make-reservation.page.tmpl", &models.TemplateData{})
}

// Generals renders the room page
func (m *Repository) Generals(w http.ResponseWriter, r *http.Request) {
render.RenderTemplate(w, "generals.page.tmpl", &models.TemplateData{})
}

// Majors renders the room page
func (m *Repository) Majors(w http.ResponseWriter, r *http.Request) {
render.RenderTemplate(w, "majors.page.tmpl", &models.TemplateData{})
}

// Availability renders the search availability page
func (m *Repository) Availability(w http.ResponseWriter, r *http.Request) {
render.RenderTemplate(w, "search-availability.page.tmpl", &models.TemplateData{})
}

// Contact renders the contact page
func (m *Repository) Contact(w http.ResponseWriter, r *http.Request) {
render.RenderTemplate(w, "contact.page.tmpl", &models.TemplateData{})
}
20 changes: 20 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.my-footer {
height: 5em;
background-color: #163b65;
margin-top: 1.5em;
padding: 1em;
color: white;
font-size: 80%;
}

.room-image {
max-width: 50%;
}

.notie-container {
box-shadow: none;
}

.datepicker {
z-index: 10000;
}
Binary file added static/images/generals-quarters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/marjors-suite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions templates/about.page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@
<div class="row">
<div class="col">
<h1>This is the about page</h1>
<p>This is a paragraph of text</p>
<p>This is a paragraph of text</p>

<p>This came from the template: {{index .StringMap "test"}}</p>

<p>
{{if ne (index .StringMap "remote_ip") ""}}
Your remote ip address is {{index .StringMap "remote_ip"}}
{{else}}
I don't know your ip address yet. Visit the <a href="/">home page</a> so I can set it.
{{end}}
</p>
</div>
</div>
</div>
Expand Down
250 changes: 241 additions & 9 deletions templates/base.layout.tmpl
Original file line number Diff line number Diff line change
@@ -1,31 +1,263 @@
{{define "base"}}
<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<title>My Nice Page</title>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l"
crossorigin="anonymous">
integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/datepicker-bs4.min.css">
<link rel="stylesheet" type="text/css" href="https://unpkg.com/notie/dist/notie.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/styles.css">

<style>
.btn-outline-secondary {
color: aqua;
border-color: #6c757d;
}

p {

{{block "css" .}}
}

.paraClass {
font-size: 3em;
}

.secondClass {
color: red;
}

#lastPara {
text-decoration: underline;
}
</style>

{{end}}
</head>

<body>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/about">About</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Rooms
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="/generals-quarters">General's Quarters</a>
<a class="dropdown-item" href="/majors-suite">Major's Suite</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="/search-availability">Book Now</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact">Contact</a>
</li>

</ul>
</div>
</nav>

{{block "content" .}}

{{end}}


<footer class="my-footer">
<div class="row">
<div class="col">
left
</div>

<div class="col">
center
</div>

<div class="col">
right
</div>
</div>
</footer>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/datepicker-full.min.js"></script>
<script src="https://unpkg.com/notie"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.min.js"></script>


{{block "js" .}}

{{end}}

<script>
let attention = Prompt();

(function () {
'use strict';
window.addEventListener('load', function () {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
let forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
Array.prototype.filter.call(forms, function (form) {
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();


function notify(msg, msgType) {
notie.alert({
type: msgType,
text: msg,
})
}

function notifyModal(title, text, icon, confirmationButtonText) {
Swal.fire({
title: title,
html: text,
icon: icon,
confirmButtonText: confirmationButtonText
})
}

function Prompt() {
let toast = function (c) {
const{
msg = '',
icon = 'success',
position = 'top-end',

} = c;

const Toast = Swal.mixin({
toast: true,
title: msg,
position: position,
icon: icon,
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
}
})

Toast.fire({})
}

let success = function (c) {
const {
msg = "",
title = "",
footer = "",
} = c

Swal.fire({
icon: 'success',
title: title,
text: msg,
footer: footer,
})

}

let error = function (c) {
const {
msg = "",
title = "",
footer = "",
} = c

Swal.fire({
icon: 'error',
title: title,
text: msg,
footer: footer,
})

}

async function custom(c) {
const {
msg = "",
title = "",
} = c;

const { value: formValues } = await Swal.fire({
title: title,
html: msg,
backdrop: false,
focusConfirm: false,
showCancelButton: true,
willOpen: () => {
const elem = document.getElementById("reservation-dates-modal");
const rp = new DateRangePicker(elem, {
format: 'yyyy-mm-dd',
showOnFocus: true,
})
},
didOpen: () => {
document.getElementById("start").removeAttribute("disabled");
document.getElementById("end").removeAttribute("disabled");
},
preConfirm: () => {
return [
document.getElementById('start').value,
document.getElementById('end').value
]
}
})

if (formValues) {
Swal.fire(JSON.stringify(formValues))
}
}

return {
toast: toast,
success: success,
error: error,
custom: custom,
}
}

</script>

</body>

</html>
{{end}}
12 changes: 12 additions & 0 deletions templates/contact.page.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{template "base" .}}

{{define "content"}}
<div class="container">
<div class="row">
<div class="col">
<h1>This is the contact page</h1>

</div>
</div>
</div>
{{end}}
Loading

0 comments on commit b0ea025

Please sign in to comment.