remove style, since we can add it from about
This commit is contained in:
parent
e49f5193e2
commit
07538e4011
11 changed files with 42 additions and 120 deletions
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
const schemaVersion = 8
|
||||
const schemaVersion = 9
|
||||
|
||||
func Migrate(db *sql.DB) {
|
||||
var currentVersion int
|
||||
|
|
|
|||
|
|
@ -42,4 +42,6 @@ alter column about TYPE TEXT;`,
|
|||
add column email varchar(500) not null DEFAULT '';`,
|
||||
"schema_version_8": `alter table statuses
|
||||
add column face varchar(1) not null DEFAULT '🙂';`,
|
||||
"schema_version_9": `alter table users
|
||||
drop column style;`,
|
||||
}
|
||||
|
|
|
|||
2
storage/sql/schema_version_9.sql
Normal file
2
storage/sql/schema_version_9.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
alter table users
|
||||
drop column style;
|
||||
|
|
@ -4,10 +4,10 @@ import (
|
|||
"status/model"
|
||||
)
|
||||
|
||||
const queryFindName = `SELECT name, hash, created_at, homepage, about, style, picture, email FROM users WHERE name=lower($1);`
|
||||
const queryFindName = `SELECT name, hash, created_at, homepage, about, picture, email FROM users WHERE name=lower($1);`
|
||||
|
||||
func (s *Storage) queryUser(q string, params ...interface{}) (user model.User, err error) {
|
||||
err = s.db.QueryRow(q, params...).Scan(&user.Name, &user.Hash, &user.CreatedAt, &user.Homepage, &user.About, &user.Style, &user.Picture, &user.Email)
|
||||
err = s.db.QueryRow(q, params...).Scan(&user.Name, &user.Hash, &user.CreatedAt, &user.Homepage, &user.About, &user.Picture, &user.Email)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -77,11 +77,11 @@ func (s *Storage) DeleteUser(username string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (s *Storage) UpdateSettings(username, homepage, about, style, picture, email string) error {
|
||||
stmt, err := s.db.Prepare(`UPDATE users SET homepage = $1, about = $2, style = $3, picture = $4, email = $5 WHERE name = $6;`)
|
||||
func (s *Storage) UpdateSettings(username, homepage, about, picture, email string) error {
|
||||
stmt, err := s.db.Prepare(`UPDATE users SET homepage = $1, about = $2, picture = $3, email = $4 WHERE name = $5;`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = stmt.Exec(homepage, about, style, picture, email, username)
|
||||
_, err = stmt.Exec(homepage, about, picture, email, username)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,58 +47,21 @@ var TplCommonMap = map[string]string{
|
|||
{{ end }}`,
|
||||
"status_form": `{{ define "status_form" }}
|
||||
<div style="margin-bottom: 1em">
|
||||
{{ range $i, $v := faces }}
|
||||
<div class="radio">
|
||||
<input type="radio" id="face1" name="face" value="🙂" {{ if or (eq .Face "🙂") (eq .Face "") }}checked{{ end }}>
|
||||
<label for="face1">🙂</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face2" name="face" value="😎" {{ if eq .Face "😎" }}checked{{ end }}>
|
||||
<label for="face2">😎</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face3" name="face" value="😛" {{ if eq .Face "😛" }}checked{{ end }}>
|
||||
<label for="face3">😛</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face4" name="face" value="🥰" {{ if eq .Face "🥰" }}checked{{ end }}>
|
||||
<label for="face4">🥰</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face5" name="face" value="👽" {{ if eq .Face "👽" }}checked{{ end }}>
|
||||
<label for="face5">👽</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face6" name="face" value="😱" {{ if eq .Face "😱" }}checked{{ end }}>
|
||||
<label for="face6">😱</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face7" name="face" value="🤗" {{ if eq .Face "🤗" }}checked{{ end }}>
|
||||
<label for="face7">🤗</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face8" name="face" value="😯" {{ if eq .Face "😯" }}checked{{ end }}>
|
||||
<label for="face8">😯</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face9" name="face" value="🤒" {{ if eq .Face "🤒" }}checked{{ end }}>
|
||||
<label for="face9">🤒</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face10" name="face" value="😡" {{ if eq .Face "😡" }}checked{{ end }}>
|
||||
<label for="face10">😡</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face11" name="face" value="🥺" {{ if eq .Face "🥺" }}checked{{ end }}>
|
||||
<label for="face11">🥺</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face12" name="face" value="🥳" {{ if eq .Face "🥳" }}checked{{ end }}>
|
||||
<label for="face12">🥳</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face13" name="face" value="☕" {{ if eq .Face "☕" }}checked{{ end }}>
|
||||
<label for="face13">☕</label>
|
||||
<input
|
||||
type="radio"
|
||||
id="face{{ $i }}"
|
||||
name="face"
|
||||
value="{{ $v }}"
|
||||
{{ if eq $i 0 }}
|
||||
{{ if or (eq $.Face $v) (eq $.Face "") }}checked{{ end }}
|
||||
{{ else }}
|
||||
{{ if eq $.Face $v }}checked{{ end }}
|
||||
{{ end }}>
|
||||
<label for="face{{ $i }}">{{ $v }}</label>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="field">
|
||||
<textarea name="content" maxlength="140" placeholder="What's new?" required style="width: 100%; box-sizing: border-box; height: 100px;" autofocus>{{ .Content }}</textarea>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
type SettingsForm struct {
|
||||
Homepage string
|
||||
About string
|
||||
Style string
|
||||
Picture string
|
||||
Email string
|
||||
}
|
||||
|
|
@ -16,7 +15,6 @@ func NewSettingsForm(r *http.Request) *SettingsForm {
|
|||
return &SettingsForm{
|
||||
Homepage: r.FormValue("homepage"),
|
||||
About: r.FormValue("about"),
|
||||
Style: r.FormValue("style"),
|
||||
Picture: r.FormValue("picture"),
|
||||
Email: r.FormValue("email"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,11 +283,6 @@ var TplMap = map[string]string{
|
|||
<label for="about">about</label>
|
||||
<textarea name="about" id="about" rows="20">{{ .User.About }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="style">style</label>
|
||||
<textarea name="style" id="style" rows="20">{{ .User.Style }}</textarea>
|
||||
</div>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -1,57 +1,20 @@
|
|||
{{ define "status_form" }}
|
||||
<div style="margin-bottom: 1em">
|
||||
{{ range $i, $v := faces }}
|
||||
<div class="radio">
|
||||
<input type="radio" id="face1" name="face" value="🙂" {{ if or (eq .Face "🙂") (eq .Face "") }}checked{{ end }}>
|
||||
<label for="face1">🙂</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face2" name="face" value="😎" {{ if eq .Face "😎" }}checked{{ end }}>
|
||||
<label for="face2">😎</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face3" name="face" value="😛" {{ if eq .Face "😛" }}checked{{ end }}>
|
||||
<label for="face3">😛</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face4" name="face" value="🥰" {{ if eq .Face "🥰" }}checked{{ end }}>
|
||||
<label for="face4">🥰</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face5" name="face" value="👽" {{ if eq .Face "👽" }}checked{{ end }}>
|
||||
<label for="face5">👽</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face6" name="face" value="😱" {{ if eq .Face "😱" }}checked{{ end }}>
|
||||
<label for="face6">😱</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face7" name="face" value="🤗" {{ if eq .Face "🤗" }}checked{{ end }}>
|
||||
<label for="face7">🤗</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face8" name="face" value="😯" {{ if eq .Face "😯" }}checked{{ end }}>
|
||||
<label for="face8">😯</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face9" name="face" value="🤒" {{ if eq .Face "🤒" }}checked{{ end }}>
|
||||
<label for="face9">🤒</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face10" name="face" value="😡" {{ if eq .Face "😡" }}checked{{ end }}>
|
||||
<label for="face10">😡</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face11" name="face" value="🥺" {{ if eq .Face "🥺" }}checked{{ end }}>
|
||||
<label for="face11">🥺</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face12" name="face" value="🥳" {{ if eq .Face "🥳" }}checked{{ end }}>
|
||||
<label for="face12">🥳</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<input type="radio" id="face13" name="face" value="☕" {{ if eq .Face "☕" }}checked{{ end }}>
|
||||
<label for="face13">☕</label>
|
||||
<input
|
||||
type="radio"
|
||||
id="face{{ $i }}"
|
||||
name="face"
|
||||
value="{{ $v }}"
|
||||
{{ if eq $i 0 }}
|
||||
{{ if or (eq $.Face $v) (eq $.Face "") }}checked{{ end }}
|
||||
{{ else }}
|
||||
{{ if eq $.Face $v }}checked{{ end }}
|
||||
{{ end }}>
|
||||
<label for="face{{ $i }}">{{ $v }}</label>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="field">
|
||||
<textarea name="content" maxlength="140" placeholder="What's new?" required style="width: 100%; box-sizing: border-box; height: 100px;" autofocus>{{ .Content }}</textarea>
|
||||
|
|
|
|||
|
|
@ -25,11 +25,6 @@
|
|||
<label for="about">about</label>
|
||||
<textarea name="about" id="about" rows="20">{{ .User.About }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="style">style</label>
|
||||
<textarea name="style" id="style" rows="20">{{ .User.Style }}</textarea>
|
||||
</div>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ func (h *Handler) updateSettings(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
f := form.NewSettingsForm(r)
|
||||
if err := h.storage.UpdateSettings(user, f.Homepage, f.About, f.Style, f.Picture, f.Email); err != nil {
|
||||
if err := h.storage.UpdateSettings(user, f.Homepage, f.About, f.Picture, f.Email); err != nil {
|
||||
serverError(w, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,11 @@ func (h *Handler) initTpl() {
|
|||
}
|
||||
|
||||
for name, content := range TplMap {
|
||||
views[name] = template.Must(template.New("main").Parse(commonTemplates + content))
|
||||
views[name] = template.Must(template.New("main").Funcs(template.FuncMap{
|
||||
"faces": func() []string {
|
||||
return []string{"☕", "🙂", "🙃", "😇", "😋", "😐", "😴", "😎", "🤓", "🧐", "😭", "😡", "💀", "🤖",
|
||||
"🍺", "🍷"}
|
||||
}}).Parse(commonTemplates + content))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue