Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

show idea page

goenning797696acc8cc
diff --git a/app/feedback/handler.go b/app/feedback/handler.go
index 9f254d950..782d32da0 100644
--- a/app/feedback/handler.go
+++ b/app/feedback/handler.go
@@ -3,6 +3,10 @@ package feedback
import (
"net/http"
+ "strconv"
+
+ "fmt"
+
"github.com/WeCanHearYou/wechy/app/identity"
"github.com/labstack/echo"
)
@@ -57,3 +61,20 @@ func (h IndexHandlder) Post() echo.HandlerFunc {
})
}
}
+
+// Details shows details of given Idea by id
+func (h IndexHandlder) Details() echo.HandlerFunc {
+ return func(c echo.Context) error {
+ tenant := c.Get("Tenant").(*identity.Tenant)
+ ideaID, _ := strconv.Atoi(c.Param("id"))
+ idea, err := h.ideaService.GetByID(tenant.ID, int64(ideaID))
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ return c.Render(200, "idea.html", echo.Map{
+ "Tenant": tenant,
+ "Idea": idea,
+ })
+ }
+}
diff --git a/app/feedback/handler_test.go b/app/feedback/handler_test.go
index 64b07274d..6b699e21e 100644
--- a/app/feedback/handler_test.go
+++ b/app/feedback/handler_test.go
@@ -11,6 +11,10 @@ import (
type mockIdeaService struct{}
+func (svc mockIdeaService) GetByID(tenantID, ideaID int64) (*feedback.Idea, error) {
+ return new(feedback.Idea), nil
+}
+
func (svc mockIdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {
return make([]*feedback.Idea, 0), nil
}
diff --git a/app/feedback/service.go b/app/feedback/service.go
index 984a79f42..9b20e18ff 100644
--- a/app/feedback/service.go
+++ b/app/feedback/service.go
@@ -2,6 +2,7 @@ package feedback
// IdeaService contains read and write operations for ideas
type IdeaService interface {
+ GetByID(tenantID, ideaID int64) (*Idea, error)
GetAll(tenantID int64) ([]*Idea, error)
Save(tenantID, userID int64, title, description string) (*Idea, error)
}
diff --git a/app/postgres/feedback.go b/app/postgres/feedback.go
index 899759610..efa411204 100644
--- a/app/postgres/feedback.go
+++ b/app/postgres/feedback.go
@@ -6,6 +6,7 @@ import (
"time"
"github.com/WeCanHearYou/wechy/app/feedback"
+ "github.com/WeCanHearYou/wechy/app/identity"
)
// IdeaService contains read and write operations for ideas
@@ -35,6 +36,27 @@ func (svc IdeaService) GetAll(tenantID int64) ([]*feedback.Idea, error) {
return ideas, nil
}
+// GetByID returns idea by given id
+func (svc IdeaService) GetByID(tenantID, ideaID int64) (*feedback.Idea, error) {
+ rows, err := svc.DB.Query(`SELECT i.id, i.title, i.description, i.created_on, u.id, u.name, u.email
+ FROM ideas i
+ LEFT JOIN users u
+ ON u.id = i.user_id
+ WHERE i.tenant_id = $1
+ AND i.id = $2
+ ORDER BY i.created_on DESC`, tenantID, ideaID)
+ if err != nil {
+ return nil, err
+ }
+
+ if rows.Next() {
+ idea := &feedback.Idea{}
+ rows.Scan(&idea.ID, &idea.Title, &idea.Description, &idea.CreatedOn, &idea.User.ID, &idea.User.Name, &idea.User.Email)
+ return idea, nil
+ }
+ return nil, identity.ErrNotFound
+}
+
// Save a new idea in the database
func (svc IdeaService) Save(tenantID, userID int64, title, description string) (*feedback.Idea, error) {
tx, err := svc.DB.Begin()
diff --git a/app/renderer.go b/app/renderer.go
index a78e12a37..01e50918f 100644
--- a/app/renderer.go
+++ b/app/renderer.go
@@ -34,6 +34,7 @@ func NewHTMLRenderer(logger echo.Logger) *HTMLRenderer {
//TODO: load all templates automatically
renderer.add("index.html")
+ renderer.add("idea.html")
renderer.add("404.html")
renderer.add("500.html")
diff --git a/app/router.go b/app/router.go
index 21f66ddd2..4fcf6dfeb 100644
--- a/app/router.go
+++ b/app/router.go
@@ -78,6 +78,8 @@ func GetMainEngine(ctx *WechyServices) *echo.Echo {
appGroup.Use(identity.MultiTenant(ctx.Tenant))
appGroup.GET("/", feedback.Index(ctx.Idea).List())
+ appGroup.GET("/ideas/:id", feedback.Index(ctx.Idea).Details())
+
appGroup.GET("/logout", identity.OAuth(ctx.OAuth, ctx.User).Logout())
appGroup.POST("/api/ideas", feedback.Index(ctx.Idea).Post())
appGroup.GET("/api/status", Status(ctx.Health, ctx.Settings))
diff --git a/migrations/201703240709_remove_col_tenants.up.sql b/migrations/201703240709_remove_col_tenants.up.sql
new file mode 100644
index 000000000..b3d8d7053
--- /dev/null
+++ b/migrations/201703240709_remove_col_tenants.up.sql
@@ -0,0 +1,2 @@
+alter table tenants drop column modified_on;
+alter table tenants alter column created_on drop default;
\ No newline at end of file
diff --git a/migrations/201703240710_create_comments.up.sql b/migrations/201703240710_create_comments.up.sql
new file mode 100644
index 000000000..dc47af006
--- /dev/null
+++ b/migrations/201703240710_create_comments.up.sql
@@ -0,0 +1,9 @@
+create table if not exists comments (
+ id serial primary key,
+ content text null,
+ idea_id int not null,
+ user_id int not null,
+ created_on timestamptz not null,
+ foreign key (idea_id) references ideas(id),
+ foreign key (user_id) references users(id)
+);
\ No newline at end of file
diff --git a/public/components/Root.tsx b/public/components/Root.tsx
index ab23a1f39..a96e914e7 100644
--- a/public/components/Root.tsx
+++ b/public/components/Root.tsx
@@ -15,9 +15,9 @@ export class Root extends React.Component<{}, {}> {
const ideasList = ideas.map((x) =>
<div className="item" key={x.id}>
<div className="content">
- <div className="header">
+ <a href={`/ideas/${x.id}`} className="header">
<i className="idea icon"></i>{ x.title }
- </div>
+ </a>
<div className="description">
<MultiLineText text={ x.description } />
</div>
diff --git a/public/components/ShowIdeaRoot.tsx b/public/components/ShowIdeaRoot.tsx
new file mode 100644
index 000000000..e72bfa849
--- /dev/null
+++ b/public/components/ShowIdeaRoot.tsx
@@ -0,0 +1,32 @@
+import * as moment from "moment";
+import * as React from "react";
+import { Idea } from "../models";
+import * as storage from "../storage";
+import { Gravatar, MultiLineText } from "./Common";
+
+import { Footer } from "./Footer";
+import { Header } from "./Header";
+import { IdeaInput } from "./IdeaInput";
+
+export class ShowIdeaRoot extends React.Component<{}, {}> {
+ public render() {
+ const idea = storage.get<Idea>("idea");
+
+ return <div>
+ <Header />
+ <div className="ui container">
+ <h1 className="ui header">{ idea.title }</h1>
+
+ <p>{ idea.description }</p>
+
+ <p>
+ <Gravatar email={idea.user.email}/> <u>{idea.user.name}</u>
+ &nbsp;shared <u title={idea.createdOn}>{ moment(idea.createdOn).fromNow() }</u>
+ </p>
+
+ <p><a href="/">Back</a></p>
+ </div>
+ <Footer />
+ </div>;
+ }
+}
diff --git a/public/init.tsx b/public/init.tsx
index 4c04a8169..ae0646369 100644
--- a/public/init.tsx
+++ b/public/init.tsx
@@ -3,10 +3,26 @@ import * as React from "react";
import * as ReactDOM from "react-dom";
import { Root } from "./components/Root";
+import { ShowIdeaRoot } from "./components/ShowIdeaRoot";
+
+const pathRegex = [
+ { regex: new RegExp("^\/$"), component: <Root /> },
+ { regex: new RegExp("^\/ideas\/\\d+$"), component: <ShowIdeaRoot /> },
+];
+
+const resolveRootComponent = (path: string): JSX.Element => {
+ for (const entry of pathRegex) {
+ if (entry.regex.test(path)) {
+ return entry.component;
+ }
+ }
+
+ return <div />;
+};
export default function init() {
ReactDOM.render(
- location.pathname === "/" ? <Root /> : <div />,
+ resolveRootComponent(location.pathname),
document.getElementById("root")
);
}
diff --git a/views/idea.html b/views/idea.html
new file mode 100644
index 000000000..ef00ee875
--- /dev/null
+++ b/views/idea.html
@@ -0,0 +1,9 @@
+{{define "title"}}
+ {{ .Tenant.Name }}
+{{end}}
+
+{{define "javascript"}}
+ set("idea", {{ .Idea }});
+{{end}}
+
+{{define "content"}}{{end}}
\ No newline at end of file