Skip to content

Commit

Permalink
'HW26118'
Browse files Browse the repository at this point in the history
  • Loading branch information
FINCoding committed Nov 26, 2018
1 parent 2e85177 commit 4be3171
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 32 deletions.
24 changes: 21 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
package main

import (
"net/http"
"html/template"
"fmt"

"github.com/tst_martini/models"
"github.com/go-martini/martini"
)

var discounts map[string]*models.discounts
var discounts map[string]*models.Discounts

func main() {
discounts := make(map[string]*models.discounts,0)
discounts = make(map[string]*models.Discounts,0)
m := martini.Classic()

staticOptions := martini.StaticOptions{Prefix:"static"}
m.Use(martini.Static("static", staticOptions))
m.Get("/", indexHandler)
m.Get("/write", writeHandler)
m.Get("/Save", saveDiscountsHandler)
m.Get("/test", func()string{
return "That's ok!"
})

m.Run()
}

func indexHandler( ){
func indexHandler(w http.ResponseWriter, r *http.Request){
t, err := template.ParseFiles("templates/index.html", "templates/header.html", "templates/footer.html")
if err != nil{
fmt.Fprintf(w, err.Error())
}
t.ExecuteTemplate(w, "index", nil)
}

func writeHandler(w http.ResponseWriter, r *http.Request){
t, err := template.ParseFiles("templates/index.html", "templates/header.html", "templates/footer.html")
if err != nil{
fmt.Fprintf(w, err.Error())
}
t.ExecuteTemplate(w, "write", nil)
}
5 changes: 3 additions & 2 deletions models/discounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package models

type Discounts struct{
id string
title string
description string
is_sc string
id_car string
}

func NewDiscounts(id, description, id_sc, id_car string){
return &Discounts(id, description, id_sc, id_car)
func NewDiscounts(id, title, description, id_sc, id_car string)*Discounts{
return &Discounts{id, title, description, id_sc, id_car}
}
4 changes: 2 additions & 2 deletions models/service_centres.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ type ServiceCentres struct{
id_car string
}

func NewSC(id, adress, id_car string){
return &ServiceCentres(id, adress, id_car)
func NewSC(id, adress, id_car string)*ServiceCentres{
return &ServiceCentres{id, adress, id_car}
}
7 changes: 7 additions & 0 deletions templates/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ define "footer" }}
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="static/js/bootstrap.min.js"></script>
</body>
</html>

{{ end }}
49 changes: 49 additions & 0 deletions templates/header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{ define "header" }}

<!--<!DOCTYPE html>-->
<html lang="en">
<head>
<h1>Hello world!</h1>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Go Blog Example</title>

<!-- Bootstrap -->
<link href="static/css/bootstrap.min.css" rel="stylesheet">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<link href="static/css/app.css" rel="stylesheet">

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="static/js/jquery-2.1.0.min.js"></script>
</head>
<body>

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Go Blog Example</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="/">Home</a></li>
<li><a href="/write">New Post</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>

{{ end }}
52 changes: 27 additions & 25 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<div>
{{ range $value := .Posts }}
<div class="row">
<div class="col-xs-2">
</div>
<div class="col-xs-8">
{{if $.IsAuthorized}}
<h1><a href="/edit/{{$value.Id}}">{{ $value.Title }}</a></h1>
{{else}}
<h1><a href="/view/{{$value.Id}}">{{ $value.Title }}</a></h1>
{{end}}
</div>
<div class="col-xs-2">
</div>
</div>
<div class="row">
<div class="col-xs-2">
</div>
<div class="col-xs-8">
{{ $value.ContentHtml | unescape }}
</div>
<div class="col-xs-2">
</div>
</div>
{{ end }}
{{ define "index" }}

{{ template "header" }}

{{ range $key, $value := . }}
<div class="row">
<div class="col-xs-2">
</div>
<div class="col-xs-8">
<h1><a href="/edit?id={{$key}}">{{ $value.description }}</a></h1>
</div>
<div class="col-xs-2">
</div>
</div>
<div class="row">
<div class="col-xs-2">
</div>
<div class="col-xs-8">
<!--{{ $value.Content }}-->
</div>
<div class="col-xs-2">
</div>
</div>
{{ end }}

{{ template "footer" }}

{{ end }}
32 changes: 32 additions & 0 deletions templates/write.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{ define "write" }}

{{ template "header" }}

<div class="row">
<div class="col-xs-4">
</div>
<div class="col-xs-4">
<form role="form" method="POST" action="/Save">
<input type="hidden" name="id" value="{{.Id}}" />
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" id="title" name="title" value="{{.Title}}" />
</div>
<div class="form-group">
<label>Description</label>
<textarea id="content" name="content">{{.Content}}</textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>

</div>
<div class="col-xs-4">
{{ if .Id }}
<a href="/delete?id={{.Id}}">Delete</a>
{{ end }}
</div>
</div>

{{ template "footer" }}

{{ end }}

0 comments on commit 4be3171

Please sign in to comment.