Browse Source

Dislay PDF mockup as test page

master
Immanuel Onyeka 1 year ago
parent
commit
290746a438
7 changed files with 66 additions and 6 deletions
  1. +3
    -0
      migrations/0_29092022_setup_tables.sql
  2. +52
    -6
      skouter.go
  3. +0
    -0
      views/app.tpl
  4. +0
    -0
      views/home.tpl
  5. +0
    -0
      views/master.tpl
  6. +0
    -0
      views/terms.tpl
  7. +11
    -0
      views/test.tpl

+ 3
- 0
migrations/0_29092022_setup_tables.sql View File

@@ -3,6 +3,7 @@
CREATE TABLE branch ( CREATE TABLE branch (
id INT AUTO_INCREMENT, id INT AUTO_INCREMENT,
type ENUM('NMLS', 'FSRA') NOT NULL, type ENUM('NMLS', 'FSRA') NOT NULL,
letterhead BLOB(102400) NOT NULL DEFAULT 0,
num VARCHAR(40) NOT NULL, num VARCHAR(40) NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); );
@@ -15,6 +16,8 @@ CREATE TABLE user (
password CHAR(64) NOT NULL, password CHAR(64) NOT NULL,
verified BOOLEAN, verified BOOLEAN,
branch_id INT NULL, branch_id INT NULL,
avatar BLOB(102400) NOT NULL DEFAULT 0,
letterhead BLOB(102400) NOT NULL DEFAULT 0,
/* The password should be a SHA256 hash in hex format. It's length doesn't /* The password should be a SHA256 hash in hex format. It's length doesn't
* vary */ * vary */
country ENUM('Canada', 'USA'), country ENUM('Canada', 'USA'),


+ 52
- 6
skouter.go View File

@@ -148,14 +148,16 @@ var (
) )


var paths = map[string]string { var paths = map[string]string {
"home": "home.tpl",
"terms": "terms.tpl",
"app": "app.tpl",
"home": "views/home.tpl",
"terms": "views/terms.tpl",
"app": "views/app.tpl",
"test": "views/test.tpl",
} }


var pages = map[string]Page { var pages = map[string]Page {
"home": cache("home", "Home"), "home": cache("home", "Home"),
"terms": cache("terms", "Terms and Conditions"), "terms": cache("terms", "Terms and Conditions"),
"test": cache("test", "PDF test"),
"app": cache("app", "App"), "app": cache("app", "App"),
} }


@@ -176,7 +178,7 @@ func (c UserClaims) Valid() error {
} }


func cache(name string, title string) Page { func cache(name string, title string) Page {
var p = []string{"master.tpl", paths[name]}
var p = []string{"views/master.tpl", paths[name]}
tpl := template.Must(template.ParseFiles(p...)) tpl := template.Must(template.ParseFiles(p...))
return Page{tpl: tpl, return Page{tpl: tpl,
Title: title, Title: title,
@@ -1512,6 +1514,47 @@ func validateEstimate(w http.ResponseWriter, db *sql.DB, r *http.Request) {
if err != nil { http.Error(w, err.Error(), 406); return } if err != nil { http.Error(w, err.Error(), 406); return }
} }


func showPDF(w http.ResponseWriter, r *http.Request) {
// var args []string

// p := r.URL.Path
db, err := sql.Open("mysql",
fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/skouter",
config["DBUser"],
config["DBPass"]))

// w.Header().Set("Content-Type", "application/json; charset=UTF-8")
err = db.Ping()
if err != nil {
fmt.Println("Bad database configuration: %v\n", err)
panic(err)
// maybe os.Exit(1) instead
}
var pa = template.Must(template.ParseFiles("views/master.tpl",
"views/test.tpl"))
// claims, err := getClaims(r)
if err != nil { w.WriteHeader(500); return }
users, err := queryUsers(db, 1)
info := struct {
Title string
Name string
User User
}{
Title: "test PDF",
Name: "idk-random-name",
User: users[0],
}
// fmt.Println(info)
err = pa.Execute(w, info)
if err != nil {fmt.Println(err)}

}

func api(w http.ResponseWriter, r *http.Request) { func api(w http.ResponseWriter, r *http.Request) {
var args []string var args []string


@@ -1595,9 +1638,9 @@ func api(w http.ResponseWriter, r *http.Request) {
} }


func route(w http.ResponseWriter, r *http.Request) { func route(w http.ResponseWriter, r *http.Request) {
var page Page
var page Page
var args []string var args []string
p := r.URL.Path
p := r.URL.Path


switch { switch {
case r.Method == "GET" && match(p, "/", &args): case r.Method == "GET" && match(p, "/", &args):
@@ -1606,6 +1649,9 @@ func route(w http.ResponseWriter, r *http.Request) {
page = pages[ "terms" ] page = pages[ "terms" ]
case match(p, "/app", &args): case match(p, "/app", &args):
page = pages[ "app" ] page = pages[ "app" ]
case match(p, "/test", &args):
showPDF(w, r)
return
default: default:
http.NotFound(w, r) http.NotFound(w, r)
return return


app.tpl → views/app.tpl View File


home.tpl → views/home.tpl View File


master.tpl → views/master.tpl View File


terms.tpl → views/terms.tpl View File


+ 11
- 0
views/test.tpl View File

@@ -0,0 +1,11 @@
{{define "header"}}
<header class="default fade-in">
</header>
{{end}}

{{define "main"}}
<main class='fade-in-2'>
<div>hello world {{.User.Title}}</div>
<section>TESTING</section>
</main>
{{end}}

Loading…
Cancel
Save