Port the web to bootstrap5

So it is responsive in phones.
This commit is contained in:
Las Zenow 2017-06-08 00:44:35 +00:00
parent 8af2ad3758
commit 6a3da59c75
40 changed files with 1131 additions and 849 deletions

View file

@ -27,7 +27,7 @@ func deleteHandler(h handler) {
}
book, err := h.db.GetBookID(id)
if err != nil {
h.sess.Notify("Book not found!", "The book with id '"+id+"' is not there", "error")
h.sess.Notify("Book not found!", "The book with id '"+id+"' is not there", "danger")
continue
}
err = h.db.UpdateSubmissionByBook(id, "Rejected", nil)
@ -124,7 +124,7 @@ func saveHandler(h handler) {
err := h.db.UpdateBook(id, book)
if err != nil {
log.Error("Updating book: ", err)
h.sess.Notify("Can't modify book!", err.Error(), "error")
h.sess.Notify("Can't modify book!", err.Error(), "danger")
} else {
h.sess.Notify("Book Modified!", "", "success")
}

View file

@ -15,7 +15,7 @@ func listHandler(h handler) {
list, err := h.db.GetBookList(listID)
if err != nil {
log.Error("Error loading list ", listID, ": ", err)
h.sess.Notify("Something went wrong!", "Could not load the list", "error")
h.sess.Notify("Something went wrong!", "Could not load the list", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
@ -52,7 +52,7 @@ func listPostHandler(h handler) {
userLists, err := h.db.GetListsByUser(h.sess.User)
if err != nil {
log.Error("Error loading user (", h.sess.User, ") lists: ", err)
h.sess.Notify("Something went wrong!", "Could not add book to the list", "error")
h.sess.Notify("Something went wrong!", "Could not add book to the list", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
@ -71,7 +71,7 @@ func listPostHandler(h handler) {
err = h.db.NewBookList(listID, listTitle, h.sess.User, []string{})
if err != nil {
log.Error("Error creating list ", listTitle, " by user ", h.sess.User, ": ", err)
h.sess.Notify("Something went wrong!", "Could not add book to the list", "error")
h.sess.Notify("Something went wrong!", "Could not add book to the list", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
@ -83,7 +83,7 @@ func listPostHandler(h handler) {
err = h.db.AddBookToList(listID, bookID)
if err != nil {
log.Error("Error adding book ", bookID, " to list ", listTitle, "(", listID, "): ", err)
h.sess.Notify("Something went wrong!", "Could not add book to the list", "error")
h.sess.Notify("Something went wrong!", "Could not add book to the list", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
@ -96,12 +96,12 @@ func listEditPostHandler(h handler) {
list, err := h.db.GetBookList(listID)
if err != nil || list == nil {
log.Error("Error loading list ", listID, ": ", err)
h.sess.Notify("Something went wrong!", "Could not save the list", "error")
h.sess.Notify("Something went wrong!", "Could not save the list", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
if h.sess.User != list.User.Username {
h.sess.Notify("You are not the owner of the list!", "You can't edit it", "error")
h.sess.Notify("You are not the owner of the list!", "You can't edit it", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
@ -111,7 +111,7 @@ func listEditPostHandler(h handler) {
err = h.db.UpdateBookList(listID, title, description)
if err != nil {
log.Error("Error editing list ", list.Title, "(", listID, "): ", err)
h.sess.Notify("Something went wrong!", "Could not edit the list", "error")
h.sess.Notify("Something went wrong!", "Could not edit the list", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
@ -126,12 +126,12 @@ func listRemoveHandler(h handler) {
list, err := h.db.GetBookList(listID)
if err != nil || list == nil {
log.Error("Error loading list ", listID, ": ", err)
h.sess.Notify("Something went wrong!", "Could not remove books from the list", "error")
h.sess.Notify("Something went wrong!", "Could not remove books from the list", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
if h.sess.User != list.User.Username {
h.sess.Notify("You are not the owner of the list!", "You can't remove books from it", "error")
h.sess.Notify("You are not the owner of the list!", "You can't remove books from it", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}
@ -139,7 +139,7 @@ func listRemoveHandler(h handler) {
err = h.db.DeleteBookFromList(listID, bookID)
if err != nil {
log.Error("Error remove book ", bookID, " from list ", listID, "): ", err)
h.sess.Notify("Something went wrong!", "Could not remove book", "error")
h.sess.Notify("Something went wrong!", "Could not remove book", "danger")
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
return
}

View file

@ -43,7 +43,7 @@ func submissionCommentHandler(h handler) {
err := h.db.UpdateSubmissionComment(submissionID, bookID, comment)
if err != nil {
log.Error("Adding comment (submission: ", submissionID, ", book: ", bookID, ") <", comment, ">: ", err)
h.sess.Notify("Error adding a comment!", "Can't add the comment rigt now. Try again later or report it to the site admins", "error")
h.sess.Notify("Error adding a comment!", "Can't add the comment rigt now. Try again later or report it to the site admins", "danger")
} else {
h.sess.Notify("Comment added!", "", "success")
}
@ -131,17 +131,17 @@ func storeHandler(h handler) {
}
book, err := h.db.GetBookID(id)
if err != nil {
h.sess.Notify("Book not found!", "The book with id '"+id+"' is not there", "error")
h.sess.Notify("Book not found!", "The book with id '"+id+"' is not there", "danger")
continue
}
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
h.sess.Notify("An error ocurred!", err.Error(), "danger")
log.Error("Error getting book for storing '", book.Title, "': ", err.Error())
continue
}
err = h.db.ActiveBook(id)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
h.sess.Notify("An error ocurred!", err.Error(), "danger")
log.Error("Error storing book '", book.Title, "': ", err.Error())
continue
}

View file

@ -23,6 +23,7 @@ var tmpl_funcs = map[string]interface{}{
"strings_join": stringsJoin,
"download_url": downloadUrl,
"size2mb": size2mb,
"mul": mul,
}
type Status struct {
@ -114,6 +115,10 @@ func size2mb(size int) float32 {
return float32(size) / (1024.0 * 1024.0)
}
func mul(a, b int) int {
return a * b
}
type DevTemplateExecutor struct {
assetsPath string
tpe string

View file

@ -92,7 +92,7 @@ func uploadPostHandler(h handler) {
const _2M int64 = (1 << 20) * 2
if h.ro {
h.sess.Notify("Upload failed!", "The library is in Read Only mode, no books can be uploaded", "error")
h.sess.Notify("Upload failed!", "The library is in Read Only mode, no books can be uploaded", "danger")
uploadHandler(h)
return
}
@ -109,13 +109,13 @@ func uploadPostHandler(h handler) {
submission := database.Submission{
SubmissionID: submissionID,
Filename: f.Filename,
Status: "Waiting to be processed",
Status: "Waiting to be processed, reload the page in few minutes",
}
file, err := f.Open()
if err != nil {
log.Error("Can not open uploaded file ", f.Filename, ": ", err)
h.sess.Notify("Upload problem!", "There was a problem with book "+f.Filename, "error")
h.sess.Notify("Upload problem!", "There was a problem with book "+f.Filename, "danger")
submission.Status = "It was not possible to read the book"
h.db.AddSubmission(submission, h.sess.User)
continue

View file

@ -30,7 +30,7 @@ func loginPostHandler(h handler) {
h.sess.Notify("Successful login!", "Welcome "+user, "success")
} else {
log.Warn("User ", user, " bad user or password")
h.sess.Notify("Invalid login!", "user or password invalid", "error")
h.sess.Notify("Invalid login!", "user or password invalid", "danger")
}
h.sess.Save(h.w, h.r)
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
@ -40,16 +40,16 @@ func createUserHandler(h handler) {
pass := h.r.FormValue("pass")
confirmPass := h.r.FormValue("confirmPass")
if pass != confirmPass {
h.sess.Notify("Registration error!", "Passwords don't match", "error")
h.sess.Notify("Registration error!", "Passwords don't match", "danger")
} else if pass == "" {
h.sess.Notify("Registration error!", "The password can't be empty", "error")
h.sess.Notify("Registration error!", "The password can't be empty", "danger")
} else {
user := strings.TrimSpace(h.r.FormValue("user"))
err := h.db.AddUser(user, pass)
if err == nil {
h.sess.Notify("Account created!", "Welcome "+user+". Now you can login", "success")
} else {
h.sess.Notify("Registration error!", err.Error(), "error")
h.sess.Notify("Registration error!", err.Error(), "danger")
}
}
h.sess.Save(h.w, h.r)
@ -91,14 +91,14 @@ func settingsHandler(h handler) {
pass2 := h.r.FormValue("password2")
switch {
case !h.db.ValidPassword(h.sess.User, current_pass):
h.sess.Notify("Password error!", "The current password given don't match with the user password. Try again", "error")
h.sess.Notify("Password error!", "The current password given don't match with the user password. Try again", "danger")
case pass1 != pass2:
h.sess.Notify("Passwords don't match!", "The new password and the confirmation password don't match. Try again", "error")
h.sess.Notify("Passwords don't match!", "The new password and the confirmation password don't match. Try again", "danger")
default:
err := h.db.SetPassword(h.sess.User, pass1)
if err != nil {
log.Warn("Can't update password for user ", h.sess.User, ": ", err)
h.sess.Notify("Password error!", "An error has ocurred updating the password in the database. Sorry.", "error")
h.sess.Notify("Password error!", "An error has ocurred updating the password in the database. Sorry.", "danger")
} else {
h.sess.Notify("Password updated!", "Your new password is correctly set.", "success")
}
@ -167,14 +167,14 @@ func userAdminPostHandler(h handler) {
if password != "" {
err := h.db.SetPassword(username, password)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
h.sess.Notify("An error ocurred!", err.Error(), "danger")
} else {
h.sess.Notify("Password updated!", "", "success")
}
} else if role != "" {
err := h.db.SetRole(username, role)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
h.sess.Notify("An error ocurred!", err.Error(), "danger")
} else {
h.sess.Notify("Role updated!", "", "success")
}
@ -194,11 +194,11 @@ func addUserHandler(h handler) {
role := h.r.FormValue("role")
err := h.db.AddUser(username, password)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
h.sess.Notify("An error ocurred!", err.Error(), "danger")
} else {
err := h.db.SetRole(username, role)
if err != nil {
h.sess.Notify("An error ocurred!", err.Error(), "error")
h.sess.Notify("An error ocurred!", err.Error(), "danger")
} else {
h.sess.Notify("User created!", "", "success")
}