Open platform to collect and prioritize feedback
initial development of #31
goenningfdfadf2010ad
diff --git a/app/models/feedback.go b/app/models/feedback.goindex 22db3f1ac..44e80a0f8 100644--- a/app/models/feedback.go+++ b/app/models/feedback.go@@ -6,12 +6,13 @@ import (//Idea represents an idea on a tenant boardtype Idea struct {- ID int `json:"id" db:"id"`- Number int `json:"number" db:"number"`- Title string `json:"title" db:"title"`- Description string `json:"description" db:"description"`- CreatedOn time.Time `json:"createdOn" db:"created_on"`- User *User `json:"user" db:"user"`+ ID int `json:"id" db:"id"`+ Number int `json:"number" db:"number"`+ Title string `json:"title" db:"title"`+ Description string `json:"description" db:"description"`+ CreatedOn time.Time `json:"createdOn" db:"created_on"`+ User *User `json:"user" db:"user"`+ TotalSupporters int `json:"totalSupporters" db:"supporters"`}//Comment represents an user comment on an ideadiff --git a/app/storage/postgres/idea.go b/app/storage/postgres/idea.goindex bf8c57b27..22cde4348 100644--- a/app/storage/postgres/idea.go+++ b/app/storage/postgres/idea.go@@ -20,7 +20,8 @@ var (i.number,i.title,i.description,- i.created_on,+ i.created_on,+ i.supporters,u.id AS user_id,u.name AS user_name,u.email AS user_email@@ -105,8 +106,8 @@ func (s *IdeaStorage) Save(tenantID, userID int, title, description string) (*moidea.Title = titleidea.Description = description- row := tx.QueryRow(`INSERT INTO ideas (title, number, description, tenant_id, user_id, created_on)- VALUES ($1, (SELECT COALESCE(MAX(number), 0) + 1 FROM ideas i WHERE i.tenant_id = $3), $2, $3, $4, $5)+ row := tx.QueryRow(`INSERT INTO ideas (title, number, description, tenant_id, user_id, created_on, supporters)+ VALUES ($1, (SELECT COALESCE(MAX(number), 0) + 1 FROM ideas i WHERE i.tenant_id = $3), $2, $3, $4, $5, 0)RETURNING id`, title, description, tenantID, userID, time.Now())if err = row.Scan(&idea.ID); err != nil {tx.Rollback()diff --git a/app/storage/postgres/idea_test.go b/app/storage/postgres/idea_test.goindex 342c73ac6..e62b28285 100644--- a/app/storage/postgres/idea_test.go+++ b/app/storage/postgres/idea_test.go@@ -17,8 +17,8 @@ func TestIdeaStorage_GetAll(t *testing.T) {now := time.Now()- db.Execute("INSERT INTO ideas (title, number, description, created_on, tenant_id, user_id) VALUES ('Idea #1', 1, 'Description #1', $1, 300, 300)", now)- db.Execute("INSERT INTO ideas (title, number, description, created_on, tenant_id, user_id) VALUES ('Idea #2', 2, 'Description #2', $1, 300, 301)", now)+ db.Execute("INSERT INTO ideas (title, number, description, created_on, tenant_id, user_id, supporters) VALUES ('Idea #1', 1, 'Description #1', $1, 300, 300, 0)", now)+ db.Execute("INSERT INTO ideas (title, number, description, created_on, tenant_id, user_id, supporters) VALUES ('Idea #2', 2, 'Description #2', $1, 300, 301, 5)", now)svc := &postgres.IdeaStorage{DB: db}ideas, err := svc.GetAll(300)@@ -30,11 +30,13 @@ func TestIdeaStorage_GetAll(t *testing.T) {Expect(ideas[0].Number).To(Equal(1))Expect(ideas[0].Description).To(Equal("Description #1"))Expect(ideas[0].User.Name).To(Equal("Jon Snow"))+ Expect(ideas[0].TotalSupporters).To(Equal(0))Expect(ideas[1].Title).To(Equal("Idea #2"))Expect(ideas[1].Number).To(Equal(2))Expect(ideas[1].Description).To(Equal("Description #2"))Expect(ideas[1].User.Name).To(Equal("Arya Stark"))+ Expect(ideas[1].TotalSupporters).To(Equal(5))}func TestIdeaStorage_SaveAndGet(t *testing.T) {@@ -55,6 +57,7 @@ func TestIdeaStorage_SaveAndGet(t *testing.T) {Expect(err).To(BeNil())Expect(dbIdea.ID).To(Equal(1))Expect(dbIdea.Number).To(Equal(1))+ Expect(dbIdea.TotalSupporters).To(Equal(0))Expect(dbIdea.Title).To(Equal("My new idea"))Expect(dbIdea.Description).To(Equal("with this description"))Expect(dbIdea.User.ID).To(Equal(1))diff --git a/migrations/201704181821_add_supporters.up.sql b/migrations/201704181821_add_supporters.up.sqlnew file mode 100644index 000000000..2587b4591--- /dev/null+++ b/migrations/201704181821_add_supporters.up.sql@@ -0,0 +1,14 @@+ALTER TABLE ideas ADD supporters INT;++UPDATE ideas SET supporters = 0;++ALTER TABLE ideas ALTER COLUMN supporters SET NOT NULL;++CREATE TABLE IF NOT EXISTS idea_supporters (+ user_id int not null,+ idea_id int not null,+ created_on timestamptz not null,+ primary key (user_id, idea_id),+ foreign key (idea_id) references ideas(id),+ foreign key (user_id) references users(id)+);\ No newline at end of filediff --git a/public/components/root.tsx b/public/components/root.tsxindex d5c33414d..ce0ac00e5 100644--- a/public/components/root.tsx+++ b/public/components/root.tsx@@ -14,9 +14,22 @@ export class Root extends React.Component<{}, {}> {const ideasList = ideas.map((x) =><div className="item" key={x.id}>+ <div className="ui small statistics">+ <div className="statistic">+ <div className="value">+ { x.totalSupporters }+ </div>+ <div className="ui mini primary animated button">+ <div className="visible content">Want</div>+ <div className="hidden content">+ <i className="heart icon"></i>+ </div>+ </div>+ </div>+ </div><div className="content"><a href={`/ideas/${x.number}`} className="header">- <i className="idea icon"></i> { x.title }+ <i className="idea icon"></i> { x.totalSupporters } { x.title }</a><div className="description"><MultiLineText text={ x.description } />@@ -30,7 +43,7 @@ export class Root extends React.Component<{}, {}> {const displayIdeas = (ideas.length > 0) ? <div><h3>Top Ideas</h3>- <div className="ui divided items">+ <div className="ui divided unstackable items">{ ideasList }</div></div>diff --git a/public/components/show_idea_root.tsx b/public/components/show_idea_root.tsxindex 90642c4d4..fd2d6075f 100644--- a/public/components/show_idea_root.tsx+++ b/public/components/show_idea_root.tsx@@ -37,15 +37,36 @@ export class ShowIdeaRoot extends React.Component<{}, {}> {return <div><Header /><div className="ui container">- <h1 className="ui header">{ idea.title }</h1>+ <div className="ui items unstackable">+ <div className="item">- <p>{ idea.description }</p>+ <div className="ui small statistics">+ <div className="statistic">+ <div className="value">+ { idea.totalSupporters }+ </div>+ <div className="ui mini primary animated button">+ <div className="visible content">Want</div>+ <div className="hidden content">+ <i className="heart icon"></i>+ </div>+ </div>+ </div>+ </div>++ <div className="idea-header">+ <h1 className="ui header">{ idea.title }</h1>- <p>- #{ idea.number } shared by - <Gravatar email={idea.user.email}/> <u>{idea.user.name}</u> - <span title={idea.createdOn}>{ moment(idea.createdOn).fromNow() }</span>- </p>+ <p>+ #{ idea.number } shared by + <Gravatar email={idea.user.email}/> <u>{idea.user.name}</u> + <span title={idea.createdOn}>{ moment(idea.createdOn).fromNow() }</span>+ </p>+ </div>+ </div>+ </div>++ <p>{ idea.description }</p><div className="ui comments"><h3 className="ui dividing header">Comments</h3>diff --git a/public/css/main.css b/public/css/main.cssindex 38e4244bc..d8733126f 100644--- a/public/css/main.css+++ b/public/css/main.css@@ -6,13 +6,8 @@margin-top: 40px;}-.ideas-list .vote-col {- text-align: center;- width: 140px;-}--.ideas-list .vote-col div {- display: block;+.ideas-list .ui.items > .item > .content {+ margin-left: 20px;}#footer {@@ -21,4 +16,8 @@.right {text-align: right;+}++.idea-header {+ margin-left: 20px;}\ No newline at end of filediff --git a/public/models.ts b/public/models.tsindex 34a96d7e5..75f51b331 100644--- a/public/models.ts+++ b/public/models.ts@@ -17,6 +17,7 @@ export interface Idea {description: string;createdOn: string;user: User;+ totalSupporters: number;}export interface Comment {