Skip to content

Commit

Permalink
implement archiving for topics
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Sep 16, 2020
1 parent 70a1238 commit 6b6809a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions locales/all.es-ar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
translation: "Editar tema"
- id: new-topic-content-help
translation: "Contenido a postear. Soporta markdown"
- id: new-topic-archive-help
translation: "Marcar el asunto como resuelto."
- id: new-topic-title-help
translation: "Nombre descriptivo del tema."
- id: new-topic-content-placeholder
Expand Down Expand Up @@ -190,6 +192,8 @@
translation: "Respuesta agregada"

# direct translations
- id: archive
translation: "Archivar"
- id: description
translation: "Descripción"
- id: logo
Expand Down
1 change: 1 addition & 0 deletions migrations/20200816221314_create_topics.up.fizz
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ create_table("topics") {
t.Column("author_id", "uuid", {})
t.Column("category_id", "uuid", {})
t.Column("deleted", "bool", {})
t.Column("archived", "bool", {})
t.Column("subscribers", "varchar[]", {"null": true})
t.Timestamps()
}
11 changes: 8 additions & 3 deletions models/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Topic struct {
Content string `json:"content" db:"content" form:"content"`
AuthorID uuid.UUID `json:"author_id" db:"author_id"`
CategoryID uuid.UUID `json:"category_id" db:"category_id" `
Archived bool `jsonL:"archived" db:"archived" form:"archive"`
Deleted bool `json:"deleted" db:"deleted"`
Subscribers slices.UUID `json:"subscribers" db:"subscribers"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
Expand Down Expand Up @@ -108,9 +109,13 @@ func (t *Topic) RemoveSubscriber(id uuid.UUID) {

type Topics []Topic

func (t Topics) Len() int { return len(t) }
func (t Topics) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t Topics) Less(i, j int) bool { return t[i].CreatedAt.After(t[j].CreatedAt) }
func (t Topics) Len() int { return len(t) }
func (t Topics) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t Topics) Less(i, j int) bool {
// Un branchless algorithm para que ande mas rapido
return (( t[i].Archived == t[j].Archived ) && t[i].CreatedAt.After(t[j].CreatedAt) ) ||
(( t[i].Archived != t[j].Archived ) && ( t[j].Archived ) )
}

// String is not required by pop and may be deleted
func (t Topics) String() string {
Expand Down
2 changes: 1 addition & 1 deletion templates/categories/index.plush.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h4><%= t("category-no-topics-found") %></h4>
<div class="card mb-1 rounded-0" id="<%= topic.ID %>">
<a href="<%= topicGetPath( ctxTopic ) %>">
<div class="card-header bg-secondary text-white rounded-0">
<%= topic.Title %>
<%= if (topic.Archived) { %><%= icon("archive-fill",1,1) %><% } %> <%= topic.Title %>
<%= for (author) in topic.Authors() { %>
<span class="float-right">
<%= avatar(derefUser(author)) %>
Expand Down
12 changes: 12 additions & 0 deletions templates/topics/create.plush.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<%= if (current_user) {
let content = ""
let title = ""
let archived = false
let status = "new"
if (topic) {
content = topic.Content
title = topic.Title
archived = topic.Archived
status = "edit"
}
%>
Expand All @@ -26,6 +28,16 @@ <h2><%= t(status+"-topic-headline") %></h2>
<span class="help-block"><%=t("new-topic-title-help") %></span>
</div>
</div>

<!-- Single checkbox (inline) -->
<div class="form-group">
<label class="col-md-4 control-label" for="archive"><%= t("archive") %></label>
<input type="checkbox" name="archive" id="archive" value="true" <%= if (archived) { %> checked<% } %>>
<div class="col-md-4">
<span class="help-block"><%= t("new-topic-archive-help") %></span>
</div>
</div>

<!-- Textarea -->
<div class="form-group">
<label class="col-md-8 control-label" for="content"><%= t("content") %></label>
Expand Down

0 comments on commit 6b6809a

Please sign in to comment.