Skip to content

Commit

Permalink
feat: implement hackz listing
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 27, 2019
1 parent f016be1 commit 2344405
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 131 deletions.
196 changes: 115 additions & 81 deletions api/api.pb.go

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions api/api.pb.gw.go

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

1 change: 1 addition & 0 deletions api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ service Server {

rpc Ping(Void) returns (Pong) { option (google.api.http) = { get: "/api/ping" }; };
rpc Dashboard(Void) returns (calcbiz.dashboard.Entries) { option (google.api.http) = {get: "/api/dashboard"}; }
rpc Hackz(Void) returns (calcbiz.dashboard.Entries) { option (google.api.http) = {get: "/api/hackz"}; }
rpc Crew(Void) returns (calcbiz.crew.Crew) { option (google.api.http) = {get: "/api/crew"}; }
rpc Numberinfo(NumberinfoInput) returns (NumberinfoOutput) { option (google.api.http) = {get: "/api/numberinfo/{number}"}; }
rpc Recettator(RecettatorInput) returns (RecettatorOutput) { option (google.api.http) = {get: "/api/recettator"}; }
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ type serverOptions struct {
}

func serverOptionsFromCliContext(c *cli.Context) serverOptions {
if c.Int("soundcloud-user-id") == 0 || c.String("soundcloud-client-id") == "" {
zap.L().Warn("SoundCloud is not configured")
}
return serverOptions{
GRPCBind: c.String("grpc-bind"),
HTTPBind: c.String("http-bind"),
Expand Down
8 changes: 6 additions & 2 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (d *Dashboard) hackEntries(limit int) (*Entries, error) {
entries.append(NewManualEntry(
"Calculatrice.exe",
"hackz/calculatrice.exe",
"/img/hackz/calculatrice.exe/logo.jpg",
"/img/hackz/calculatrice/logo.jpg",
"Pour faire des mathématiques ou d'autres sciences",
Entry_Hack,
false,
Expand All @@ -98,7 +98,7 @@ func (d *Dashboard) hackEntries(limit int) (*Entries, error) {
entries.append(NewManualEntry(
"Ultreme Tetris",
"hackz/ultreme-tetris",
"/img/hackz/ultreme-tetris/logo.jpg",
"/img/hackz/tetris/logo.jpg",
"Pour les balèzes",
Entry_Hack,
false,
Expand Down Expand Up @@ -182,6 +182,10 @@ func (d *Dashboard) merchEntries(limit int) (Entries, error) {
return entries, nil
}

func (d *Dashboard) Hackz() (*Entries, error) {
return d.hackEntries(100)
}

func (d *Dashboard) Random() (*Entries, error) {
entries := newEntries()

Expand Down
4 changes: 4 additions & 0 deletions svc/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (svc *svc) Dashboard(_ context.Context, input *api.Void) (*dashboard.Entrie
return svc.dashboard.Random()
}

func (svc *svc) Hackz(_ context.Context, input *api.Void) (*dashboard.Entries, error) {
return svc.dashboard.Hackz()
}

func (svc *svc) Crew(_ context.Context, input *api.Void) (*crew.Crew, error) {
return &crew.CALC, nil
}
Expand Down
16 changes: 16 additions & 0 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@
]
}
},
"/api/hackz": {
"get": {
"operationId": "Hackz",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/dashboardEntries"
}
}
},
"tags": [
"Server"
]
}
},
"/api/kryptos/decrypt": {
"post": {
"operationId": "KryptosDecrypt",
Expand Down
72 changes: 71 additions & 1 deletion templates/hackz.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
{{define "title"}}Hackz{{end}}

{{/*
{% block title %}Des hackz{% endblock %}
{% block subtitle %}à l'unité{% endblock %}
*/}}

{{define "content"}}
Hackzzzz
{{ $columns := 3 }}
{{ $grid_size := div 12 $columns }}
{{ $square_size := 250 }}


<div class="row">
{{ range $entry := .hackz.Entries }}

<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">
{{ $entry.Title }}
</p>
</div>
<img src="{{ $entry.ImageURL | cache_external_assets | resize "250x250" "fill=1" }}"
class="img-responsive"
width="{{$square_size}}" height="{{$square_size}}" />
</a>
</div>

{{ end }}

</div>
<p class="well">Et plein d'autres..</p>
{{end}}


{{/*
{% block main_column %}
<div class="row">
{% for hack in hackz : %}

<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 rotate-random">
<a href="{{ hack.url }}" class="thumbnail"
width="{{square_size}}" height="{{square_size}}">
<div class="caption-wrapper">
<p class="caption">
{{ hack.title }}
</p>
</div>
<img width="{{square_size}}" height="{{square_size}}" class="img-responsive"
src="{{ hack.img | cache_external_assets | resize('250x250', fill=1) }}"
/>
</a>
</div>

{% endfor %}
</div>
{% endblock %}

{% block secondary_column %}
<h2>Hackzers les plus {{ mot_cool() }} <small>(pour l'instant !)</small></h2>
<ul>
{% for scor in hackzers %}
<li>#{{ loop.index }} {{ scor.login }} avec {{ scor.score }} {{ mot_debile_qui_se_mange() }}</li>
{% endfor %}
</ul>
<a href="{{ url_for('scorz_top') }}">
<button type="submit" class="btn btn-lg btn-success">
Le top du top
</button>
</a>
{% endblock %}
*/}}
46 changes: 0 additions & 46 deletions templates/old/hackz.html

This file was deleted.

5 changes: 5 additions & 0 deletions views/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"html/template"
"net/http"
"path"
"strings"

"github.com/gobuffalo/packd"
"github.com/gobuffalo/packr"
Expand All @@ -27,6 +28,10 @@ func (h *handlers) loadTemplates() error {
layoutContent := ""
pageContents := map[string]string{}
err := box.Walk(func(filepath string, file packd.File) error {
if strings.HasPrefix(path.Base(filepath), ".#") {
// ignore temporary files
return nil
}
switch path.Dir(filepath) {
case ".":
pageContents[filepath] = file.String()
Expand Down
7 changes: 6 additions & 1 deletion views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func (h *handlers) copaingsHandler(w http.ResponseWriter, r *http.Request) {

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

0 comments on commit 2344405

Please sign in to comment.