Skip to content

Commit

Permalink
Add new description field to lists. Closes #925.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 1, 2022
1 parent 95b8df2 commit ef1f84e
Show file tree
Hide file tree
Showing 32 changed files with 76 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func install(lastVer string, db *sqlx.DB, fs stuffbin.FileSystem, prompt, idempo
models.ListTypePrivate,
models.ListOptinSingle,
pq.StringArray{"test"},
"",
); err != nil {
lo.Fatalf("error creating list: %v", err)
}
Expand All @@ -83,6 +84,7 @@ func install(lastVer string, db *sqlx.DB, fs stuffbin.FileSystem, prompt, idempo
models.ListTypePublic,
models.ListOptinDouble,
pq.StringArray{"test"},
"",
); err != nil {
lo.Fatalf("error creating list: %v", err)
}
Expand Down
20 changes: 20 additions & 0 deletions frontend/cypress/e2e/lists.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('Lists', () => {
cy.get('select[name=type]').select('public');
cy.get('select[name=optin]').select('double');
cy.get('input[name=tags]').clear().type(`tag${n}{enter}`);
cy.get('textarea[name=description]').clear().type(`desc${n}`);
cy.get('[data-cy=btn-save]').click();
cy.wait(100);
});
Expand Down Expand Up @@ -94,6 +95,7 @@ describe('Lists', () => {
cy.get('select[name=type]').select(t);
cy.get('select[name=optin]').select(o);
cy.get('input[name=tags]').type(`tag${n}{enter}${t}{enter}${o}{enter}`);
cy.get('textarea[name=description]').clear().type(`desc-${t}-${n}`);
cy.get('[data-cy=btn-save]').click();
cy.wait(200);

Expand Down Expand Up @@ -133,4 +135,22 @@ describe('Lists', () => {
cy.sortTable('thead th.cy-updated_at', [3, 4, 5, 6]);
cy.sortTable('thead th.cy-updated_at', [6, 5, 4, 3]);
});

it('Opens forms page', () => {
const apiUrl = Cypress.env('apiUrl');
cy.loginAndVisit(`${apiUrl}/subscription/form`);
cy.get('ul li').its('length').should('eq', 2);

const cases = [
{ 'name': 'list-public-single-2', 'description': 'desc-public-2' },
{ 'name': 'list-public-double-3', 'description': 'desc-public-3' }
];

cases.forEach((c, n) => {
cy.get('ul li').eq(n).then(($el) => {
cy.wrap($el).get('label').contains(c.name);
cy.wrap($el).get('.description').contains(c.description);
});
});
});
});
2 changes: 1 addition & 1 deletion frontend/src/views/Forms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<template v-for="l in publicLists"><span v-if="l.uuid in selected" :key="l.id" :set="id = l.uuid.substr(0, 5)">
&lt;p&gt;
&lt;input id=&quot;{{ id }}&quot; type=&quot;checkbox&quot; name=&quot;l&quot; checked value=&quot;{{ l.uuid }}&quot; /&gt;
&lt;label for=&quot;{{ id }}&quot;&gt;{{ l.name }}&lt;/label&gt;
&lt;label for=&quot;{{ id }}&quot;&gt;{{ l.name }}&lt;/label&gt;<template v-if="l.description">&lt;br /&gt;&lt;span&gt;{{ l.description }}&lt;/span&gt;</template>
&lt;/p&gt;</span></template>

&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;{{ $t('public.sub') }}&quot; /&gt;&lt;/p&gt;
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/views/ListForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<b-taginput v-model="form.tags" name="tags" ellipsis
icon="tag-outline" :placeholder="$t('globals.terms.tags')"></b-taginput>
</b-field>

<b-field :label="$t('globals.fields.description')" label-position="on-border">
<b-input :maxlength="2000" v-model="form.description" name="description" type="textarea"
:placeholder="$t('globals.fields.description')"></b-input>
</b-field>
</section>
<footer class="modal-card-foot has-text-right">
<b-button @click="$parent.close()">{{ $t('globals.buttons.close') }}</b-button>
Expand Down
1 change: 1 addition & 0 deletions i18n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"globals.days.6": "dv.",
"globals.days.7": "ds.",
"globals.fields.createdAt": "Creat",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nom",
"globals.fields.status": "Estat",
Expand Down
1 change: 1 addition & 0 deletions i18n/cs-cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "So",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Vytvořeno",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Jméno",
"globals.fields.status": "Stav",
Expand Down
1 change: 1 addition & 0 deletions i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Sa",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Erstellt",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Name",
"globals.fields.status": "Status",
Expand Down
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"globals.days.6": "Fri",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Created",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Name",
"globals.fields.status": "Status",
Expand Down
1 change: 1 addition & 0 deletions i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Vie",
"globals.days.7": "Sáb",
"globals.fields.createdAt": "Creado",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nombre",
"globals.fields.status": "Estado",
Expand Down
1 change: 1 addition & 0 deletions i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Fri",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Created",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nimi",
"globals.fields.status": "Tila",
Expand Down
1 change: 1 addition & 0 deletions i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "sam.",
"globals.days.7": "Dim",
"globals.fields.createdAt": "Créé·e le",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nom",
"globals.fields.status": "Statut",
Expand Down
1 change: 1 addition & 0 deletions i18n/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Szombat",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Létrehozva",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Név",
"globals.fields.status": "Státusz",
Expand Down
1 change: 1 addition & 0 deletions i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "sab",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Creato il ",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nome",
"globals.fields.status": "Stato",
Expand Down
1 change: 1 addition & 0 deletions i18n/jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "",
"globals.days.7": "",
"globals.fields.createdAt": "作成済み",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "名前",
"globals.fields.status": "ステータス",
Expand Down
1 change: 1 addition & 0 deletions i18n/ml.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "ശനി",
"globals.days.7": "Sat",
"globals.fields.createdAt": "നിർമ്മിച്ചത്",
"globals.fields.description": "Description",
"globals.fields.id": "ഐഡി",
"globals.fields.name": "പേര്",
"globals.fields.status": "സ്ഥിതി",
Expand Down
1 change: 1 addition & 0 deletions i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Za",
"globals.days.7": "Zat",
"globals.fields.createdAt": "Aangemaakt",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Naam",
"globals.fields.status": "Status",
Expand Down
1 change: 1 addition & 0 deletions i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Sob",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Utworzone",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nazwa",
"globals.fields.status": "Status",
Expand Down
1 change: 1 addition & 0 deletions i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Sex",
"globals.days.7": "Sáb",
"globals.fields.createdAt": "Criado",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nome",
"globals.fields.status": "Status",
Expand Down
1 change: 1 addition & 0 deletions i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Sáb",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Criado a",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nome",
"globals.fields.status": "Estado",
Expand Down
1 change: 1 addition & 0 deletions i18n/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Sa",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Creat",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Nume",
"globals.fields.status": "Stare",
Expand Down
1 change: 1 addition & 0 deletions i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Сб",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Создано",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Имя",
"globals.fields.status": "Статус",
Expand Down
1 change: 1 addition & 0 deletions i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Cts",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Yaratılma",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "İsim",
"globals.fields.status": "Durum",
Expand Down
1 change: 1 addition & 0 deletions i18n/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "Thứ 7",
"globals.days.7": "Sat",
"globals.fields.createdAt": "Đã tạo",
"globals.fields.description": "Description",
"globals.fields.id": "ID",
"globals.fields.name": "Tên",
"globals.fields.status": "Trạng thái",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "星期五",
"globals.days.7": "星期六",
"globals.fields.createdAt": "已创建",
"globals.fields.description": "Description",
"globals.fields.id": "身份标识",
"globals.fields.name": "姓名",
"globals.fields.status": "状态",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"globals.days.6": "星期五",
"globals.days.7": "星期六",
"globals.fields.createdAt": "已創建",
"globals.fields.description": "Description",
"globals.fields.id": "身份標識",
"globals.fields.name": "姓名",
"globals.fields.status": "狀態",
Expand Down
4 changes: 2 additions & 2 deletions internal/core/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *Core) CreateList(l models.List) (models.List, error) {
// Insert and read ID.
var newID int
l.UUID = uu.String()
if err := c.q.CreateList.Get(&newID, l.UUID, l.Name, l.Type, l.Optin, pq.StringArray(normalizeTags(l.Tags))); err != nil {
if err := c.q.CreateList.Get(&newID, l.UUID, l.Name, l.Type, l.Optin, pq.StringArray(normalizeTags(l.Tags)), l.Description); err != nil {
c.log.Printf("error creating list: %v", err)
return models.List{}, echo.NewHTTPError(http.StatusInternalServerError,
c.i18n.Ts("globals.messages.errorCreating", "name", "{globals.terms.list}", "error", pqErrMsg(err)))
Expand All @@ -131,7 +131,7 @@ func (c *Core) CreateList(l models.List) (models.List, error) {

// UpdateList updates a given list.
func (c *Core) UpdateList(id int, l models.List) (models.List, error) {
res, err := c.q.UpdateList.Exec(id, l.Name, l.Type, l.Optin, pq.StringArray(normalizeTags(l.Tags)))
res, err := c.q.UpdateList.Exec(id, l.Name, l.Type, l.Optin, pq.StringArray(normalizeTags(l.Tags)), l.Description)
if err != nil {
c.log.Printf("error updating list: %v", err)
return models.List{}, echo.NewHTTPError(http.StatusInternalServerError,
Expand Down
7 changes: 6 additions & 1 deletion internal/migrations/v2.3.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ func V2_3_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error {
return err
}

// Insert appearance related settings.
// Add `description` field to lists.
if _, err := db.Exec(`ALTER TABLE lists ADD COLUMN IF NOT EXISTS "description" TEXT NOT NULL DEFAULT ''`); err != nil {
return err
}

// Insert new preference settings.
if _, err := db.Exec(`
INSERT INTO settings (key, value) VALUES
('privacy.allow_preferences', 'false')
Expand Down
1 change: 1 addition & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type List struct {
Type string `db:"type" json:"type"`
Optin string `db:"optin" json:"optin"`
Tags pq.StringArray `db:"tags" json:"tags"`
Description string `db:"description" json:"description"`
SubscriberCount int `db:"-" json:"subscriber_count"`
SubscriberCounts StringIntMap `db:"subscriber_statuses" json:"subscriber_statuses"`
SubscriberID int `db:"subscriber_id" json:"-"`
Expand Down
3 changes: 2 additions & 1 deletion queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,15 @@ SELECT * FROM lists WHERE (CASE WHEN $1 != '' THEN optin=$1::list_optin ELSE TRU
END) ORDER BY name;

-- name: create-list
INSERT INTO lists (uuid, name, type, optin, tags) VALUES($1, $2, $3, $4, $5) RETURNING id;
INSERT INTO lists (uuid, name, type, optin, tags, description) VALUES($1, $2, $3, $4, $5, $6) RETURNING id;

-- name: update-list
UPDATE lists SET
name=(CASE WHEN $2 != '' THEN $2 ELSE name END),
type=(CASE WHEN $3 != '' THEN $3::list_type ELSE type END),
optin=(CASE WHEN $4 != '' THEN $4::list_optin ELSE optin END),
tags=$5::VARCHAR(100)[],
description=(CASE WHEN $6 != '' THEN $6 ELSE description END),
updated_at=NOW()
WHERE id = $1;

Expand Down
1 change: 1 addition & 0 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CREATE TABLE lists (
type list_type NOT NULL,
optin list_optin NOT NULL DEFAULT 'single',
tags VARCHAR(100)[],
description TEXT NOT NULL DEFAULT '',

created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
Expand Down
13 changes: 12 additions & 1 deletion static/public/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ a:hover {
}
label {
cursor: pointer;
color: #666;
color: #444;
}
h1,
h2,
Expand Down Expand Up @@ -118,7 +118,18 @@ input[disabled] {
.lists {
list-style-type: none;
padding: 0;
margin-bottom: 30px;
}
.lists li {
margin: 0 0 5px 0;
}
.lists .description {
margin: 0 0 15px 0;
font-size: 0.875em;
line-height: 1.3rem;
color: #888;
margin-left: 25px;
}
.form .nonce {
display: none;
}
Expand Down
3 changes: 3 additions & 0 deletions static/public/templates/subscription-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ <h2>{{ L.T "globals.terms.lists" }}</h2>
<li>
<input checked="true" id="l-{{ $l.UUID}}" type="checkbox" name="l" value="{{ $l.UUID }}" >
<label for="l-{{ $l.UUID}}">{{ $l.Name }}</label>
{{ if ne $l.Description "" }}
<p class="description">{{ $l.Description }}</p>
{{ end }}
</li>
{{ end }}
</ul>
Expand Down

0 comments on commit ef1f84e

Please sign in to comment.