Sfoglia il codice sorgente

Dislay PDF mockup as test page

master
Immanuel Onyeka 1 anno fa
parent
commit
290746a438
7 ha cambiato i file con 66 aggiunte e 6 eliminazioni
  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 Vedi File

@@ -3,6 +3,7 @@
CREATE TABLE branch (
id INT AUTO_INCREMENT,
type ENUM('NMLS', 'FSRA') NOT NULL,
letterhead BLOB(102400) NOT NULL DEFAULT 0,
num VARCHAR(40) NOT NULL,
PRIMARY KEY (id)
);
@@ -15,6 +16,8 @@ CREATE TABLE user (
password CHAR(64) NOT NULL,
verified BOOLEAN,
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
* vary */
country ENUM('Canada', 'USA'),


+ 52
- 6
skouter.go Vedi File

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

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 {
"home": cache("home", "Home"),
"terms": cache("terms", "Terms and Conditions"),
"test": cache("test", "PDF test"),
"app": cache("app", "App"),
}

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

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...))
return Page{tpl: tpl,
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 }
}

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) {
var args []string

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

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

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


app.tpl → views/app.tpl Vedi File


home.tpl → views/home.tpl Vedi File


master.tpl → views/master.tpl Vedi File


terms.tpl → views/terms.tpl Vedi File


+ 11
- 0
views/test.tpl Vedi 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…
Annulla
Salva