Skip to content

Commit

Permalink
feat: add homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 22, 2019
1 parent 8dc37e1 commit 73d02d1
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 64 deletions.
14 changes: 9 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type serverOptions struct {
HTTPBind string
ServiceOptions svc.Options
Debug bool
svc api.ServerServer
}

func serverOptionsFromCliContext(c *cli.Context) serverOptions {
Expand All @@ -132,6 +133,12 @@ func server(c *cli.Context) error {

opts := serverOptionsFromCliContext(c)

svc, err := svc.New(opts.ServiceOptions)
if err != nil {
return errors.Wrap(err, "failed to initialize service")
}
opts.svc = svc

errs := make(chan error)
go func() { errs <- errors.Wrap(startGRPCServer(ctx, &opts), "gRPC server error") }()
go func() { errs <- errors.Wrap(startHTTPServer(ctx, &opts), "HTTP server error") }()
Expand All @@ -157,6 +164,7 @@ func startHTTPServer(ctx context.Context, opts *serverOptions) error {
if err := views.Setup(&views.Options{
Router: router,
Debug: opts.Debug,
Svc: opts.svc,
}); err != nil {
return errors.Wrap(err, "failed to setup views")
}
Expand Down Expand Up @@ -224,11 +232,7 @@ func startGRPCServer(ctx context.Context, opts *serverOptions) error {
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(serverUnaryOpts...)),
)

svc, err := svc.New(opts.ServiceOptions)
if err != nil {
return errors.Wrap(err, "failed to initialize service")
}
api.RegisterServerServer(grpcServer, svc)
api.RegisterServerServer(grpcServer, opts.svc)
//if opts.WithReflection {
reflection.Register(grpcServer)
//}
Expand Down
23 changes: 20 additions & 3 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ func (e *Entries) append(entries ...*Entry) {
}
}

func NewManualEntry(title, URL, imageURL, description string, kind Entry_Kind) *Entry {
func NewManualEntry(title, URL, imageURL, description string, kind Entry_Kind, isExternal bool) *Entry {
return &Entry{
Title: title,
URL: URL,
Description: description,
ImageURL: imageURL,
Kind: kind,
IsExternal: isExternal,
}
}

Expand All @@ -46,8 +47,22 @@ func newEntries() *Entries {

func (d *Dashboard) hackEntries(limit int) (*Entries, error) {
entries := newEntries()
entries.append(NewManualEntry("Moi j'aime", "hackz/moijaime", "", "Générateur de phrase de moi j'aime", Entry_Hack))
entries.append(NewManualEntry("3615cryptage", "hackz/3615cryptage", "", "Messages codés de James Bond", Entry_Hack))
entries.append(NewManualEntry(
"Moi j'aime",
"hackz/moijaime",
"",
"Générateur de phrase de moi j'aime",
Entry_Hack,
false,
))
entries.append(NewManualEntry(
"3615cryptage",
"hackz/3615cryptage",
"",
"Messages codés de James Bond",
Entry_Hack,
false,
))

entries.shuffle()
if len(entries.Entries) < limit {
Expand Down Expand Up @@ -81,6 +96,7 @@ func (d *Dashboard) trackEntries(limit int) (*Entries, error) {
track.ArtworkUrl,
track.Description,
Entry_Track,
false,
))
}

Expand All @@ -102,6 +118,7 @@ func (d *Dashboard) merchEntries(limit int) (Entries, error) {
product.ImageURL,
"",
Entry_Merch,
true,
))
}

Expand Down
94 changes: 68 additions & 26 deletions pkg/dashboard/dashboard.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/dashboard/dashboard.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ message Entry {
string url = 2 [(gogoproto.customname) = "URL"];
string description = 3;
string image_url = 4 [(gogoproto.customname) = "ImageURL"];
Kind kind = 5;
bool is_external = 5;
Kind kind = 6;
}
4 changes: 4 additions & 0 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@
"image_url": {
"type": "string"
},
"is_external": {
"type": "boolean",
"format": "boolean"
},
"kind": {
"$ref": "#/definitions/EntryKind"
}
Expand Down
48 changes: 20 additions & 28 deletions templates/home.tmpl
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@
{{define "fulltitle"}}Camembert au lait crew{{end}}

{{define "content"}}
Maizonn
{{end}}




{{/*
{{ block title }}{{ images | length }} trucs{{ endblock }}
{{ block subtitle }}au hasard{{ endblock }}
*/}}


{{/*
{% extends "base.html" %}
{# set page_title = 'Coucou' #}
{% set columns = 4 %}
{% set grid_size = 12 // columns %}
{% set square_size = 250 %}
{% set neige = 0 %}
{{define "content"}}
{{ $columns := 4 }}
{{ $grid_size := div 12 $columns }}
{{ $square_size := 250 }}
{{ $neige := 0 }}

{% block title %}{{ images | length }} trucs{% endblock %}
{% block subtitle %}au hasard{% endblock %}

{% block content %}
<div class="row">
{% for image in images %}
{{ range $entry := .dashboard.Entries }}

<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">{# add rotate-random after christmas #}
<a href="{{ image.url }}" class="thumbnail"
width="{{square_size}}" height="{{square_size}}"
{% if image.external %} target="_blank"{% endif %}>
<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3 rotate-random">
<a href="{{ $entry.URL}}" class="thumbnail"
width="{{$square_size}}" height="{{$square_size}}"
{{ if $entry.IsExternal }} target="_blank"{{ end }}>
<div class="caption-wrapper">
<p class="caption">
{{ image.title }}
{{ $entry.Title }}
</p>
</div>
<img src="{{ image.img | cache_external_assets | resize('250x250', fill=1) }}"
<img src="{{ $entry.ImageURL | cache_external_assets | resize "250x250" "fill=1" }}"
class="img-responsive"
width="{{square_size}}" height="{{square_size}}" />
width="{{$square_size}}" height="{{$square_size}}" />
</a>
</div>

{% endfor %}
{{ end }}

</div>
<p class="well">Et plein d'autres..</p>
{% endblock %}
*/}}
{{end}}
9 changes: 8 additions & 1 deletion views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"sync"

"github.com/gorilla/mux"
"ultre.me/calcbiz/api"
"ultre.me/calcbiz/pkg/crew"
)

type Options struct {
Router *mux.Router
Debug bool
Svc api.ServerServer
}

func Setup(opts *Options) error {
Expand Down Expand Up @@ -75,7 +77,12 @@ type renderData map[string]interface{}

func (h *handlers) homeHandler(w http.ResponseWriter, r *http.Request) {
h.setDefaultHeaders(w)
data := renderData{"hello": "world"}
dashboard, err := h.opts.Svc.Dashboard(nil, &api.Void{})
if err != nil {
h.renderError(w, r, err)
return
}
data := renderData{"dashboard": dashboard}
h.render(w, r, "home.tmpl", data)
}

Expand Down

0 comments on commit 73d02d1

Please sign in to comment.