Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

large refactoring

goenning947d67117f5e
diff --git a/app/middlewares/cache.go b/app/middlewares/cache.go
deleted file mode 100644
index 9393959f1..000000000
--- a/app/middlewares/cache.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package middlewares
-
-import "github.com/getfider/fider/app/pkg/web"
-
-// OneYearCache adds Cache-Control header for one year
-func OneYearCache() web.MiddlewareFunc {
- return func(next web.HandlerFunc) web.HandlerFunc {
- return func(c web.Context) error {
- c.Response().Header().Add("Cache-Control", "public, max-age=30672000")
- return next(c)
- }
- }
-}
diff --git a/app/middlewares/cache_test.go b/app/middlewares/cache_test.go
deleted file mode 100644
index 2d485ed10..000000000
--- a/app/middlewares/cache_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package middlewares_test
-
-import (
- "net/http"
- "testing"
-
- "github.com/getfider/fider/app/middlewares"
- "github.com/getfider/fider/app/mock"
- "github.com/getfider/fider/app/pkg/web"
- . "github.com/onsi/gomega"
-)
-
-func TestCache(t *testing.T) {
- RegisterTestingT(t)
-
- server := mock.NewServer()
- server.Use(middlewares.OneYearCache())
- handler := func(c web.Context) error {
- return c.NoContent(http.StatusOK)
- }
-
- status, response := server.Execute(handler)
-
- Expect(status).To(Equal(http.StatusOK))
- Expect(response.Header().Get("Cache-Control")).To(Equal("public, max-age=30672000"))
-}
diff --git a/app/pkg/web/engine.go b/app/pkg/web/engine.go
index b0b77b405..d5a78d350 100644
--- a/app/pkg/web/engine.go
+++ b/app/pkg/web/engine.go
@@ -28,18 +28,35 @@ type Engine struct {
func New(settings *models.AppSettings) *Engine {
router := echo.New()
router.Use(middleware.Gzip())
- router.Static("/favicon.ico", "favicon.ico")
- router.Logger = createLogger()
+ configureAssets(router)
+ router.Logger = NewLogger()
router.Renderer = NewHTMLRenderer(settings, router.Logger)
router.HTTPErrorHandler = errorHandler
return &Engine{router: router}
}
+func configureAssets(router *echo.Echo) {
+ assets := router.Group("/assets")
+ assets.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
+ return func(c echo.Context) error {
+ c.Response().Header().Add("Cache-Control", "public, max-age=30672000")
+ return next(c)
+ }
+ })
+ assets.Static("/favicon.ico", "favicon.ico")
+ assets.Static("/", "dist")
+}
+
//Start an HTTP server.
func (e *Engine) Start(address string) {
e.router.Logger.Fatal(e.router.Start(address))
}
+//Use middleware on root router
+func (e *Engine) Use(middleware MiddlewareFunc) {
+ e.router.Use(wrapMiddleware(middleware))
+}
+
//Group is our router group wrapper
type Group struct {
group *echo.Group
@@ -91,7 +108,7 @@ func errorHandler(e error, c echo.Context) {
}
}
-func createLogger() echo.Logger {
+func NewLogger() echo.Logger {
logger := log.New("")
logger.SetHeader(`${level} [${time_rfc3339}]`)
diff --git a/public/admin/HomePage.tsx b/public/admin/HomePage.tsx
index 4d097f8ba..e823bdd9d 100644
--- a/public/admin/HomePage.tsx
+++ b/public/admin/HomePage.tsx
@@ -1,7 +1,7 @@
-import * as React from "react";
+import * as React from 'react';
-import { Footer } from "../shared/Footer";
-import { Header } from "../shared/Header";
+import { Footer } from '../shared/Footer';
+import { Header } from '../shared/Header';
export class HomePage extends React.Component<{}, {}> {
@@ -12,10 +12,10 @@ export class HomePage extends React.Component<{}, {}> {
public render() {
return <div>
<Header />
- <div className="ui container">
- <h1 className="ui header">Administration</h1>
- <span>You're a Member or Admin!</span>
- </div>
+ <div className="ui container">
+ <h1 className="ui header">Administration</h1>
+ <span>You're a Member or Admin!</span>
+ </div>
<Footer />
</div>;
}
diff --git a/public/index.tsx b/public/index.tsx
index 816d85e13..824a918f2 100644
--- a/public/index.tsx
+++ b/public/index.tsx
@@ -1,17 +1,17 @@
-import * as React from "react";
-import * as ReactDOM from "react-dom";
+import * as React from 'react';
+import * as ReactDOM from 'react-dom';
-import { HomePage as AdminHomePage } from "./admin/HomePage";
-import { HomePage as SiteHomePage } from "./site/HomePage";
-import { ShowIdeaPage } from "./site/ShowIdeaPage";
-import { setup } from "./storage";
+import { HomePage as AdminHomePage } from './admin/HomePage';
+import { HomePage as SiteHomePage } from './site/HomePage';
+import { ShowIdeaPage } from './site/ShowIdeaPage';
+import { setup } from './storage';
-import "./style/main.scss";
+import './style/main.scss';
const pathRegex = [
- { regex: new RegExp("^\/$"), component: <SiteHomePage /> },
- { regex: new RegExp("^\/admin$"), component: <AdminHomePage /> },
- { regex: new RegExp("^\/ideas\/\\d+.*$"), component: <ShowIdeaPage /> },
+ { regex: new RegExp('^\/$'), component: <SiteHomePage /> },
+ { regex: new RegExp('^\/admin$'), component: <AdminHomePage /> },
+ { regex: new RegExp('^\/ideas\/\\d+.*$'), component: <ShowIdeaPage /> },
];
@@ -27,9 +27,9 @@ const resolveRootComponent = (path: string): JSX.Element => {
setup();
-document.addEventListener("DOMContentLoaded", () => {
+document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(
resolveRootComponent(location.pathname),
- document.getElementById("root")
+ document.getElementById('root')
);
});
diff --git a/public/models.ts b/public/models.ts
deleted file mode 100644
index cee9a88aa..000000000
--- a/public/models.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-export interface Tenant {
- id: number;
- name: string;
- domain: string;
-}
-
-export interface User {
- id: number;
- name: string;
- email: string;
- supportedIdeas: number[];
- role: number;
-}
-
-export interface Idea {
- id: number;
- number: number;
- slug: string;
- title: string;
- description: string;
- createdOn: string;
- status: number;
- user: User;
- response: IdeaResponse;
- totalSupporters: number;
-}
-
-export const IdeaNew = 0;
-export const IdeaStarted = 1;
-export const IdeaCompleted = 2;
-export const IdeaDeclined = 3;
-
-export const IdeaStatusMetadata: { [key: number]: any} = { };
-
-IdeaStatusMetadata[IdeaNew] = {
- title: "New",
- showStatus: false,
- closed: false,
- color: "black",
-};
-
-IdeaStatusMetadata[IdeaStarted] = {
- title: "Started",
- showStatus: true,
- closed: false,
- color: "blue",
-};
-
-IdeaStatusMetadata[IdeaCompleted] = {
- title: "Completed",
- showStatus: true,
- closed: true,
- color: "green",
-};
-
-IdeaStatusMetadata[IdeaDeclined] = {
- title: "Declined",
- showStatus: true,
- closed: true,
- color: "red",
-};
-
-export interface IdeaResponse {
- user: User;
- text: string;
- respondedOn: Date;
-}
-
-export interface Comment {
- id: number;
- content: string;
- createdOn: string;
- user: User;
-}
diff --git a/public/models/idea.ts b/public/models/idea.ts
new file mode 100644
index 000000000..782ea3b72
--- /dev/null
+++ b/public/models/idea.ts
@@ -0,0 +1,56 @@
+import { User } from './identity';
+
+export interface Idea {
+ id: number;
+ number: number;
+ slug: string;
+ title: string;
+ description: string;
+ createdOn: string;
+ status: number;
+ user: User;
+ response: IdeaResponse;
+ totalSupporters: number;
+}
+
+export class IdeaStatus {
+ constructor(public value: number,
+ public title: string,
+ public show: boolean,
+ public closed: boolean,
+ public color: string) { }
+
+ public static New = new IdeaStatus(0, 'New', false, false, 'black');
+ public static Started = new IdeaStatus(1, 'Started', true, false, 'blue');
+ public static Completed = new IdeaStatus(2, 'Completed', true, true, 'green');
+ public static Declined = new IdeaStatus(3, 'Declined', true, true, 'red');
+
+ public static Get(value: number): IdeaStatus {
+ for (const status of IdeaStatus.All) {
+ if (status.value === value) {
+ return status;
+ }
+ }
+ throw new Error(`IdeaStatus not found for value ${value}.`);
+ }
+
+ public static All = [
+ IdeaStatus.New,
+ IdeaStatus.Started,
+ IdeaStatus.Completed,
+ IdeaStatus.Declined
+ ];
+}
+
+export interface IdeaResponse {
+ user: User;
+ text: string;
+ respondedOn: Date;
+}
+
+export interface Comment {
+ id: number;
+ content: string;
+ createdOn: string;
+ user: User;
+}
diff --git a/public/models/identity.ts b/public/models/identity.ts
new file mode 100644
index 000000000..8748a0e82
--- /dev/null
+++ b/public/models/identity.ts
@@ -0,0 +1,13 @@
+export interface Tenant {
+ id: number;
+ name: string;
+ domain: string;
+}
+
+export interface User {
+ id: number;
+ name: string;
+ email: string;
+ supportedIdeas: number[];
+ role: number;
+}
diff --git a/public/models/index.ts b/public/models/index.ts
new file mode 100644
index 000000000..f5c677802
--- /dev/null
+++ b/public/models/index.ts
@@ -0,0 +1,2 @@
+export * from './idea';
+export * from './identity';
diff --git a/public/shared/CommentInput.tsx b/public/shared/CommentInput.tsx
index 799b63ae4..b873011c0 100644
--- a/public/shared/CommentInput.tsx
+++ b/public/shared/CommentInput.tsx
@@ -1,10 +1,10 @@
-import axios from "axios";
-import * as React from "react";
+import axios from 'axios';
+import * as React from 'react';
-import { Idea } from "../models";
-import { getCurrentUser } from "../storage";
-import { DisplayError } from "./Common";
-import { SocialSignInList } from "./SocialSignInList";
+import { Idea } from '../models';
+import { getCurrentUser } from '../storage';
+import { DisplayError } from './Common';
+import { SocialSignInList } from './SocialSignInList';
interface CommentInputProps {
idea: Idea;
@@ -20,7 +20,7 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu
constructor() {
super();
this.state = {
- content: "",
+ content: '',
clicked: false
};
}
@@ -47,7 +47,7 @@ export class CommentInput extends React.Component<CommentInputProps, CommentInpu
public render() {
const user = getCurrentUser();
- const buttonClasses = `ui blue labeled submit icon button ${this.state.clicked && "loading disabled"}`;
+ const buttonClasses = `ui blue labeled submit icon button ${this.state.clicked && 'loading disabled'}`;
const addComment = user ? <form className="ui reply form">
<DisplayError error={this.state.error} />
diff --git a/public/shared/Common.tsx b/public/shared/Common.tsx
index f2133a88d..da31ba1b7 100644
--- a/public/shared/Common.tsx
+++ b/public/shared/Common.tsx
@@ -1,13 +1,13 @@
-import * as React from "react";
-import * as moment from "moment";
-import md5 = require("md5");
-import { AxiosError, AxiosResponse } from "axios";
-import { get, getCurrentUser } from "../storage";
-import { User, IdeaResponse, IdeaStatusMetadata } from "../models";
+import * as React from 'react';
+import * as moment from 'moment';
+import md5 = require('md5');
+import { AxiosError, AxiosResponse } from 'axios';
+import { get, getCurrentUser } from '../storage';
+import { User, IdeaResponse, IdeaStatus } from '../models';
export const Gravatar = (props: {email?: string}) => {
- const hash = props.email ? md5(props.email) : "";
- return <img className="ui avatar image" src={ "https://www.gravatar.com/avatar/" + hash } />;
+ const hash = props.email ? md5(props.email) : '';
+ return <img className="ui avatar image" src={ 'https://www.gravatar.com/avatar/' + hash } />;
};
export const MultiLineText = (props: {text?: string}) => {
@@ -15,7 +15,7 @@ export const MultiLineText = (props: {text?: string}) => {
return <p></p>;
}
- return <div>{props.text.split("\n").map((item, i) =>
+ return <div>{props.text.split('\n').map((item, i) =>
<span>{item}<br/></span>
)}</div>;
};
@@ -34,8 +34,8 @@ export const DisplayError = (props: {error?: Error}) => {
};
export const EnvironmentInfo = () => {
- const settings = get<any>("settings");
- if (settings.Environment.toLowerCase() !== "production") {
+ const settings = get<any>('settings');
+ if (settings.Environment.toLowerCase() !== 'production') {
return <div className="ui mini negative message no-border no-margin">
Env: { settings.Environment } |
Compiler: { settings.Compiler } |
@@ -46,9 +46,8 @@ export const EnvironmentInfo = () => {
return <div/>;
};
-export const IdeaStatusRibbon = (props: { status: number }) => {
- const metadata = IdeaStatusMetadata[props.status];
- return <span className={`ui ribbon label ${metadata.color}`}>{ metadata.title }</span>;
+export const IdeaStatusRibbon = (props: { status: IdeaStatus }) => {
+ return <span className={`ui ribbon label ${props.status.color}`}>{ props.status.title }</span>;
};
interface IdeaResponseProps {
@@ -57,11 +56,11 @@ interface IdeaResponseProps {
}
export const ShowIdeaResponse = (props: IdeaResponseProps): JSX.Element => {
- const metadata = IdeaStatusMetadata[props.status];
+ const status = IdeaStatus.Get(props.status);
- if (props.response && metadata.showStatus) {
+ if (props.response && status.show) {
return <div className="fdr-response item ui raised segment">
- <IdeaStatusRibbon status={props.status} />
+ <IdeaStatusRibbon status={status} />
<div className="info">
<Gravatar email={props.response.user.email}/> <u>{props.response.user.name}</u>
<span title={props.response.respondedOn.toString()}>
diff --git a/public/shared/Footer.tsx b/public/shared/Footer.tsx
index c0dab9f74..2d43f092b 100644
--- a/public/shared/Footer.tsx
+++ b/public/shared/Footer.tsx
@@ -1,5 +1,5 @@
-import * as React from "react";
-const logo = require("../imgs/logo.png");
+import * as React from 'react';
+const logo = require('../imgs/logo.png');
export const Footer = () => {
return <div id="footer" className="ui vertical footer segment">
diff --git a/public/shared/Header.tsx b/public/shared/Header.tsx
index 3822afc18..51b00c081 100644
--- a/public/shared/Header.tsx
+++ b/public/shared/Header.tsx
@@ -1,8 +1,8 @@
-import * as React from "react";
-import { User, Tenant } from "../models";
-import { get, getCurrentUser, isStaff } from "../storage";
-import { EnvironmentInfo, Gravatar } from "./Common";
-import { SocialSignInList } from "./SocialSignInList";
+import * as React from 'react';
+import { User, Tenant } from '../models';
+import { get, getCurrentUser, isStaff } from '../storage';
+import { EnvironmentInfo, Gravatar } from './Common';
+import { SocialSignInList } from './SocialSignInList';
export class Header extends React.Component<{}, {}> {
private dropdown: HTMLElement;
@@ -14,7 +14,7 @@ export class Header extends React.Component<{}, {}> {
super(props);
this.user = getCurrentUser();
- this.tenant = get<Tenant>("tenant");
+ this.tenant = get<Tenant>('tenant');
}
public componentDidMount() {
@@ -22,7 +22,7 @@ export class Header extends React.Component<{}, {}> {
inline: true,
hoverable: true,
popup: this.list,
- position : "bottom right"
+ position : 'bottom right'
});
}
@@ -57,7 +57,7 @@ export class Header extends React.Component<{}, {}> {
</a>
<a ref={(e) => { this.dropdown = e; } } className="item right signin">
<Gravatar email={this.user.email} />
- { this.user.name || "Sign in" }
+ { this.user.name || 'Sign in' }
<i className="dropdown icon"></i>
</a>
</div>
diff --git a/public/shared/ResponseForm.tsx b/public/shared/ResponseForm.tsx
index 0b37635c3..c1eebdd17 100644
--- a/public/shared/ResponseForm.tsx
+++ b/public/shared/ResponseForm.tsx
@@ -1,8 +1,8 @@
-import axios from "axios";
-import * as React from "react";
-import * as storage from "../storage";
-import { User, Comment, Idea } from "../models";
-import { DisplayError } from "./Common";
+import axios from 'axios';
+import * as React from 'react';
+import * as storage from '../storage';
+import { User, Comment, Idea } from '../models';
+import { DisplayError } from './Common';
interface ResponseFormProps {
idea: Idea;
diff --git a/public/shared/SocialSignInButton.tsx b/public/shared/SocialSignInButton.tsx
index 052c046d5..d64095ade 100644
--- a/public/shared/SocialSignInButton.tsx
+++ b/public/shared/SocialSignInButton.tsx
@@ -1,9 +1,9 @@
-import * as React from "react";
-import { get } from "../storage";
+import * as React from 'react';
+import { get } from '../storage';
interface SocialSignInButtonProps {
provider: string;
- size: "small" | "normal";
+ size: 'small' | 'normal';
}
interface SocialSignInButtonState {
clicked: boolean;
@@ -18,22 +18,22 @@ export class SocialSignInButton extends React.Component<SocialSignInButtonProps,
}
public render() {
- const auth = get<any>("auth");
- const providerClassName = this.props.provider === "google" ? "google plus" : "facebook";
- const providerDisplayName = this.props.provider === "google" ? "Google" : "Facebook";
+ const auth = get<any>('auth');
+ const providerClassName = this.props.provider === 'google' ? 'google plus' : 'facebook';
+ const providerDisplayName = this.props.provider === 'google' ? 'Google' : 'Facebook';
const oauthUrl = `${auth.endpoint}/oauth/${this.props.provider}?redirect=${location.href}`;
const cssClasses = `ui button
${providerClassName}
- ${this.state.clicked ? "loading disabled" : ""}
- ${this.props.size === "small" ? "circular icon" : "fluid"}`;
+ ${this.state.clicked ? 'loading disabled' : ''}
+ ${this.props.size === 'small' ? 'circular icon' : 'fluid'}`;
- if (this.props.size === "small") {
+ if (this.props.size === 'small') {
return <a href={oauthUrl} className={cssClasses} onClick={() => this.setState({clicked: true})}>
- <i className={providerClassName + " icon"}></i>
+ <i className={providerClassName + ' icon'}></i>
</a>;
} else {
return <a href={oauthUrl} className={cssClasses} onClick={() => this.setState({clicked: true})}>
- <i className={providerClassName + " icon"}></i>
+ <i className={providerClassName + ' icon'}></i>
Sign in with { providerDisplayName }
</a>;
}
diff --git a/public/shared/SocialSignInList.tsx b/public/shared/SocialSignInList.tsx
index 9229c7e32..c0a2389e3 100644
--- a/public/shared/SocialSignInList.tsx
+++ b/public/shared/SocialSignInList.tsx
@@ -1,6 +1,6 @@
-import * as React from "react";
-import { get } from "../storage";
-import { SocialSignInButton } from "./SocialSignInButton";
+import * as React from 'react';
+import { get } from '../storage';
+import { SocialSignInButton } from './SocialSignInButton';
interface AuthSettings {
endpoint: string;
@@ -11,13 +11,13 @@ interface AuthSettings {
}
interface SocialSignInListProps {
- size: "small" | "normal";
- orientation: "horizontal" | "vertical";
+ size: 'small' | 'normal';
+ orientation: 'horizontal' | 'vertical';
}
export const SocialSignInList = (props: SocialSignInListProps) => {
- const settings = get<AuthSettings>("auth");
- const cssClasses = props.orientation === "horizontal" ? "horizontal divided" : "";
+ const settings = get<AuthSettings>('auth');
+ const cssClasses = props.orientation === 'horizontal' ? 'horizontal divided' : '';
const google = settings.providers.google &&
<div className="item">
diff --git a/public/shared/SupportCounter.tsx b/public/shared/SupportCounter.tsx
index 47fba9346..5ef80611d 100644
--- a/public/shared/SupportCounter.tsx
+++ b/public/shared/SupportCounter.tsx
@@ -1,8 +1,8 @@
-import axios from "axios";
-import * as React from "react";
-import { Idea, User, IdeaStatusMetadata } from "../models";
-import * as storage from "../storage";
-import { SocialSignInList } from "./SocialSignInList";
+import axios from 'axios';
+import * as React from 'react';
+import { Idea, User, IdeaStatus } from '../models';
+import * as storage from '../storage';
+import { SocialSignInList } from './SocialSignInList';
interface SupportCounterProps {
user: User;
@@ -33,8 +33,8 @@ export class SupportCounter extends React.Component<SupportCounterProps, Support
inline: true,
hoverable: true,
popup: this.list,
- on: "click",
- position : "bottom left"
+ on: 'click',
+ position : 'bottom left'
});
return;
}
@@ -45,7 +45,7 @@ export class SupportCounter extends React.Component<SupportCounterProps, Support
return;
}
- const action = this.state.supported ? "unsupport" : "support";
+ const action = this.state.supported ? 'unsupport' : 'support';
try {
await axios.post(`/api/ideas/${this.props.idea.number}/${action}`);
@@ -61,7 +61,7 @@ export class SupportCounter extends React.Component<SupportCounterProps, Support
}
public render() {
- const metadata = IdeaStatusMetadata[this.props.idea.status];
+ const status = IdeaStatus.Get(this.props.idea.status);
const support = <div className="ui mini violet inverted animated button"
onClick={async () => await this.supportOrUndo()}>
@@ -87,7 +87,7 @@ export class SupportCounter extends React.Component<SupportCounterProps, Support
<div className="value">
{ this.state.total }
</div>
- { metadata.closed ? disabled : this.state.supported ? undo : support }
+ { status.closed ? disabled : this.state.supported ? undo : support }
</div>
</div>
<div ref={(e) => { this.list = e; } } className="ui popup transition hidden">
diff --git a/public/site/HomePage.tsx b/public/site/HomePage.tsx
index e7bc4b991..cc1118e8d 100644
--- a/public/site/HomePage.tsx
+++ b/public/site/HomePage.tsx
@@ -1,13 +1,13 @@
-import * as moment from "moment";
-import * as React from "react";
-import { Idea, User } from "../models";
-import * as storage from "../storage";
-import { Gravatar, MultiLineText, ShowIdeaResponse } from "../shared/Common";
-import { SupportCounter } from "../shared/SupportCounter";
+import * as moment from 'moment';
+import * as React from 'react';
+import { Idea, User } from '../models';
+import * as storage from '../storage';
+import { Gravatar, MultiLineText, ShowIdeaResponse } from '../shared/Common';
+import { SupportCounter } from '../shared/SupportCounter';
-import { Footer } from "../shared/Footer";
-import { Header } from "../shared/Header";
-import { IdeaInput } from "./IdeaInput";
+import { Footer } from '../shared/Footer';
+import { Header } from '../shared/Header';
+import { IdeaInput } from './IdeaInput';
export class HomePage extends React.Component<{}, {}> {
private user: User;
@@ -16,7 +16,7 @@ export class HomePage extends React.Component<{}, {}> {
constructor(props: {}) {
super(props);
this.user = storage.getCurrentUser();
- this.ideas = storage.get<Idea[]>("ideas") || [];
+ this.ideas = storage.get<Idea[]>('ideas') || [];
}
public render() {
diff --git a/public/site/IdeaInput.tsx b/public/site/IdeaInput.tsx
index 93ff35d65..a5ff53e42 100644
--- a/public/site/IdeaInput.tsx
+++ b/public/site/IdeaInput.tsx
@@ -1,8 +1,8 @@
-import axios from "axios";
-import * as React from "react";
-import { getCurrentUser } from "../storage";
-import { DisplayError } from "../shared/Common";
-import { SocialSignInList } from "../shared/SocialSignInList";
+import axios from 'axios';
+import * as React from 'react';
+import { getCurrentUser } from '../storage';
+import { DisplayError } from '../shared/Common';
+import { SocialSignInList } from '../shared/SocialSignInList';
interface IdeaInputState {
title: string;
@@ -16,7 +16,7 @@ export class IdeaInput extends React.Component<{}, IdeaInputState> {
constructor() {
super();
this.state = {
- title: "",
+ title: '',
clicked: false
};
}
@@ -28,7 +28,7 @@ export class IdeaInput extends React.Component<{}, IdeaInputState> {
});
try {
- await axios.post("/api/ideas", {
+ await axios.post('/api/ideas', {
title: this.state.title,
description: this.description.value
});
@@ -44,7 +44,7 @@ export class IdeaInput extends React.Component<{}, IdeaInputState> {
public render() {
const user = getCurrentUser();
- const buttonClasses = `ui primary button ${this.state.clicked && "loading disabled"}`;
+ const buttonClasses = `ui primary button ${this.state.clicked && 'loading disabled'}`;
const details = user ?
<div>
<div className="field">
diff --git a/public/site/ShowIdeaPage.tsx b/public/site/ShowIdeaPage.tsx
index 359a78639..68fc5c562 100644
--- a/public/site/ShowIdeaPage.tsx
+++ b/public/site/ShowIdeaPage.tsx
@@ -1,17 +1,17 @@
-import * as moment from "moment";
-import * as React from "react";
-import * as storage from "../storage";
+import * as moment from 'moment';
+import * as React from 'react';
+import * as storage from '../storage';
-import { User, Comment, Idea } from "../models";
-import { CommentInput } from "../shared/CommentInput";
-import { Gravatar, MultiLineText, ShowIdeaResponse } from "../shared/Common";
-import { SocialSignInButton } from "../shared/SocialSignInButton";
-import { SupportCounter } from "../shared/SupportCounter";
-import { ResponseForm } from "../shared/ResponseForm";
+import { User, Comment, Idea } from '../models';
+import { CommentInput } from '../shared/CommentInput';
+import { Gravatar, MultiLineText, ShowIdeaResponse } from '../shared/Common';
+import { SocialSignInButton } from '../shared/SocialSignInButton';
+import { SupportCounter } from '../shared/SupportCounter';
+import { ResponseForm } from '../shared/ResponseForm';
-import { Footer } from "../shared/Footer";
-import { Header } from "../shared/Header";
-import { IdeaInput } from "./IdeaInput";
+import { Footer } from '../shared/Footer';
+import { Header } from '../shared/Header';
+import { IdeaInput } from './IdeaInput';
export class ShowIdeaPage extends React.Component<{}, {}> {
private user: User;
@@ -22,8 +22,8 @@ export class ShowIdeaPage extends React.Component<{}, {}> {
super(props);
this.user = storage.getCurrentUser();
- this.idea = storage.get<Idea>("idea");
- this.comments = storage.get<Comment[]>("comments") || [];
+ this.idea = storage.get<Idea>('idea');
+ this.comments = storage.get<Comment[]>('comments') || [];
}
public render() {
diff --git a/public/storage.ts b/public/storage.ts
index 84523fdac..c0f3e7961 100644
--- a/public/storage.ts
+++ b/public/storage.ts
@@ -1,4 +1,4 @@
-import { User } from "./models";
+import { User } from './models';
const w: any = window;
@@ -10,11 +10,11 @@ export function setup() {
}
export function setUser(user: User) {
- set<User>("user", user);
+ set<User>('user', user);
}
export function getCurrentUser(): User {
- return get<User>("user");
+ return get<User>('user');
}
export function isStaff() {
diff --git a/public/tsd.d.ts b/public/tsd.d.ts
index a97dc02e1..e8fe72b01 100644
--- a/public/tsd.d.ts
+++ b/public/tsd.d.ts
@@ -1,4 +1,3 @@
-
interface JQuery {
popup(args: any): any;
}
diff --git a/router.go b/router.go
index 4c53d86fb..d777fc9b8 100644
--- a/router.go
+++ b/router.go
@@ -23,21 +23,14 @@ type AppServices struct {
// GetMainEngine returns main HTTP engine
func GetMainEngine(settings *models.AppSettings, db *dbx.Database) *web.Engine {
r := web.New(settings)
-
- assets := r.Group("/assets")
- {
- assets.Use(middlewares.OneYearCache())
- assets.Static("/", "dist")
- }
+ r.Use(middlewares.Setup(db))
+ r.Use(middlewares.Tenant())
+ r.Use(middlewares.AddServices())
+ r.Use(middlewares.JwtGetter())
+ r.Use(middlewares.JwtSetter())
public := r.Group("")
{
- public.Use(middlewares.Setup(db))
- public.Use(middlewares.Tenant())
- public.Use(middlewares.AddServices())
- public.Use(middlewares.JwtGetter())
- public.Use(middlewares.JwtSetter())
-
public.Get("/", handlers.Index())
public.Get("/ideas/:number", handlers.IdeaDetails())
public.Get("/ideas/:number/*", handlers.IdeaDetails())
@@ -47,11 +40,6 @@ func GetMainEngine(settings *models.AppSettings, db *dbx.Database) *web.Engine {
private := r.Group("")
{
- private.Use(middlewares.Setup(db))
- private.Use(middlewares.Tenant())
- private.Use(middlewares.AddServices())
- private.Use(middlewares.JwtGetter())
- private.Use(middlewares.JwtSetter())
private.Use(middlewares.IsAuthenticated())
private.Post("/api/ideas", handlers.PostIdea())
@@ -63,10 +51,6 @@ func GetMainEngine(settings *models.AppSettings, db *dbx.Database) *web.Engine {
auth := r.Group("/oauth")
{
- auth.Use(middlewares.Setup(db))
- auth.Use(middlewares.Tenant())
- auth.Use(middlewares.AddServices())
-
auth.Get("/facebook", handlers.Login(oauth.FacebookProvider))
auth.Get("/facebook/callback", handlers.OAuthCallback(oauth.FacebookProvider))
auth.Get("/google", handlers.Login(oauth.GoogleProvider))
@@ -75,11 +59,6 @@ func GetMainEngine(settings *models.AppSettings, db *dbx.Database) *web.Engine {
admin := r.Group("/admin")
{
- admin.Use(middlewares.Setup(db))
- admin.Use(middlewares.Tenant())
- admin.Use(middlewares.AddServices())
- admin.Use(middlewares.JwtGetter())
- admin.Use(middlewares.JwtSetter())
admin.Use(middlewares.IsAuthenticated())
admin.Use(middlewares.IsAuthorized(models.RoleMember, models.RoleAdministrator))
diff --git a/tslint.json b/tslint.json
index c4ee74f24..29a3deebd 100644
--- a/tslint.json
+++ b/tslint.json
@@ -14,6 +14,9 @@
"no-var-requires": false,
"member-ordering": [
false
+ ],
+ "quotemark": [
+ true, "single", "jsx-double"
]
}
}
\ No newline at end of file
diff --git a/views/base.html b/views/base.html
index 684fbf2ff..dc7df2222 100644
--- a/views/base.html
+++ b/views/base.html
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1">
- <link rel="icon" type="image/x-icon" href="/favicon.ico">
+ <link rel="icon" type="image/x-icon" href="/assets/favicon.ico">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.9/semantic.min.css" integrity="sha256-lCqHBvboFPu7gyEswcz5UdbXKyB6FDOtfbOeMvUEfkY=" crossorigin="anonymous" />
<link rel="stylesheet" href="/assets/css/{{ .__StyleBundle }}" />
<title>{{template "title" .}}</title>