2017-11-10 03:33:11 +00:00
package common
import (
"html/template"
2017-11-29 02:34:02 +00:00
"net/http"
2017-11-10 03:33:11 +00:00
"sync"
"time"
)
2018-04-03 04:34:07 +00:00
// TODO: Allow resources in spots other than /static/ and possibly even external domains (e.g. CDNs)
2018-04-04 04:49:13 +00:00
// TODO: Preload Trumboyg on Cosora on the forum list
2018-04-22 12:33:56 +00:00
type Header struct {
Title string
2018-04-04 04:49:13 +00:00
NoticeList [ ] string
Scripts [ ] string
//PreloadScripts []string
2017-11-10 03:33:11 +00:00
Stylesheets [ ] string
Widgets PageWidgets
2017-11-11 04:06:16 +00:00
Site * site
2017-11-13 09:23:43 +00:00
Settings SettingMap
2017-12-01 02:04:29 +00:00
Themes map [ string ] * Theme // TODO: Use a slice containing every theme instead of the main map for speed?
Theme * Theme
2017-11-10 03:33:11 +00:00
//TemplateName string // TODO: Use this to move template calls to the router rather than duplicating them over and over and over?
2018-04-22 12:33:56 +00:00
CurrentUser User // TODO: Deprecate CurrentUser on the page structs
Zone string
MetaDesc string
Writer http . ResponseWriter
ExtData ExtData
2017-11-10 03:33:11 +00:00
}
2018-04-22 12:33:56 +00:00
func ( header * Header ) AddScript ( name string ) {
2018-04-04 04:49:13 +00:00
header . Scripts = append ( header . Scripts , name )
}
2018-04-22 12:33:56 +00:00
/ * func ( header * Header ) PreloadScript ( name string ) {
2018-04-04 04:49:13 +00:00
header . PreloadScripts = append ( header . PreloadScripts , name )
} * /
2018-04-22 12:33:56 +00:00
func ( header * Header ) AddSheet ( name string ) {
2018-04-04 04:49:13 +00:00
header . Stylesheets = append ( header . Stylesheets , name )
}
2017-11-10 03:33:11 +00:00
// TODO: Add this to routes which don't use templates. E.g. Json APIs.
type HeaderLite struct {
2017-11-11 04:06:16 +00:00
Site * site
2017-11-10 03:33:11 +00:00
Settings SettingMap
ExtData ExtData
}
type PageWidgets struct {
LeftSidebar template . HTML
RightSidebar template . HTML
}
// TODO: Add a ExtDataHolder interface with methods for manipulating the contents?
// ? - Could we use a sync.Map instead?
type ExtData struct {
2017-11-11 04:06:16 +00:00
Items map [ string ] interface { } // Key: pluginname
2017-11-10 03:33:11 +00:00
sync . RWMutex
}
type Page struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
ItemList [ ] interface { }
Something interface { }
}
2018-04-22 12:33:56 +00:00
type Paginator struct {
PageList [ ] int
Page int
LastPage int
}
2017-11-10 03:33:11 +00:00
type TopicPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
ItemList [ ] ReplyUser
Topic TopicUser
2018-01-26 05:53:34 +00:00
Poll Poll
2017-11-10 03:33:11 +00:00
Page int
LastPage int
}
2018-04-22 12:33:56 +00:00
type TopicListPage struct {
* Header
2017-11-10 03:33:11 +00:00
TopicList [ ] * TopicsRow
ForumList [ ] Forum
DefaultForum int
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type ForumPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
ItemList [ ] * TopicsRow
Forum * Forum
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type ForumsPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
ItemList [ ] Forum
}
type ProfilePage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
ItemList [ ] ReplyUser
ProfileOwner User
}
type CreateTopicPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
ItemList [ ] Forum
FID int
}
type IPSearchPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
ItemList map [ int ] * User
IP string
}
type PanelStats struct {
Users int
Groups int
Forums int
Settings int
WordFilters int
Themes int
Reports int
}
type PanelPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2017-11-10 03:33:11 +00:00
ItemList [ ] interface { }
Something interface { }
}
type GridElement struct {
ID string
Body string
Order int // For future use
Class string
Background string
TextColour string
Note string
}
type PanelDashboardPage struct {
2018-05-11 05:41:51 +00:00
* Header
Stats PanelStats
Zone string
GridItems [ ] GridElement
2017-11-10 03:33:11 +00:00
}
2018-01-03 07:46:18 +00:00
type PanelTimeGraph struct {
Series [ ] int64 // The counts on the left
Labels [ ] int64 // unixtimes for the bottom, gets converted into 1:00, 2:00, etc. with JS
}
2018-01-08 08:53:51 +00:00
type PanelAnalyticsItem struct {
Time int64
Count int64
}
2018-01-03 07:46:18 +00:00
type PanelAnalyticsPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2018-01-03 07:46:18 +00:00
Stats PanelStats
Zone string
PrimaryGraph PanelTimeGraph
2018-01-08 08:53:51 +00:00
ViewItems [ ] PanelAnalyticsItem
TimeRange string
2018-01-03 07:46:18 +00:00
}
2018-01-04 10:23:33 +00:00
type PanelAnalyticsRoutesItem struct {
Route string
Count int
}
type PanelAnalyticsRoutesPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2018-01-04 10:23:33 +00:00
Stats PanelStats
Zone string
2018-01-05 22:47:13 +00:00
ItemList [ ] PanelAnalyticsRoutesItem
2018-01-17 11:13:08 +00:00
TimeRange string
2018-01-05 22:47:13 +00:00
}
2018-01-09 07:39:29 +00:00
type PanelAnalyticsAgentsItem struct {
2018-02-04 08:15:20 +00:00
Agent string
FriendlyAgent string
Count int
2018-01-09 07:39:29 +00:00
}
type PanelAnalyticsAgentsPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2018-01-09 07:39:29 +00:00
Stats PanelStats
Zone string
ItemList [ ] PanelAnalyticsAgentsItem
2018-01-17 11:13:08 +00:00
TimeRange string
2018-01-09 07:39:29 +00:00
}
2018-01-05 22:47:13 +00:00
type PanelAnalyticsRoutePage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2018-01-05 22:47:13 +00:00
Stats PanelStats
Zone string
Route string
PrimaryGraph PanelTimeGraph
2018-01-14 12:03:20 +00:00
ViewItems [ ] PanelAnalyticsItem
2018-01-08 08:53:51 +00:00
TimeRange string
2018-01-04 10:23:33 +00:00
}
2018-01-10 03:32:48 +00:00
type PanelAnalyticsAgentPage struct {
2018-02-15 13:15:27 +00:00
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2018-02-15 13:15:27 +00:00
Stats PanelStats
Zone string
Agent string
2018-02-04 08:15:20 +00:00
FriendlyAgent string
2018-02-15 13:15:27 +00:00
PrimaryGraph PanelTimeGraph
TimeRange string
2018-01-10 03:32:48 +00:00
}
2017-11-10 03:33:11 +00:00
type PanelThemesPage struct {
2018-05-11 05:41:51 +00:00
* Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2017-12-01 02:04:29 +00:00
PrimaryThemes [ ] * Theme
VariantThemes [ ] * Theme
2017-11-10 03:33:11 +00:00
}
2018-05-11 05:41:51 +00:00
type PanelMenuListItem struct {
2018-05-15 05:59:52 +00:00
Name string
2018-05-11 05:41:51 +00:00
ID int
ItemCount int
}
type PanelMenuListPage struct {
* Header
Stats PanelStats
Zone string
ItemList [ ] PanelMenuListItem
}
type PanelMenuPage struct {
* Header
Stats PanelStats
Zone string
2018-05-13 06:56:59 +00:00
MenuID int
2018-05-11 05:41:51 +00:00
ItemList [ ] MenuItem
}
type PanelMenuItemPage struct {
* Header
Stats PanelStats
Zone string
Item MenuItem
}
2017-11-10 03:33:11 +00:00
type PanelUserPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2017-11-10 03:33:11 +00:00
ItemList [ ] User
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type PanelGroupPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2017-11-10 03:33:11 +00:00
ItemList [ ] GroupAdmin
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type PanelEditGroupPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2017-11-10 03:33:11 +00:00
ID int
Name string
Tag string
Rank string
DisableRank bool
}
type GroupForumPermPreset struct {
Group * Group
Preset string
}
type PanelEditForumPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2017-11-10 03:33:11 +00:00
ID int
Name string
Desc string
Active bool
Preset string
Groups [ ] GroupForumPermPreset
}
type NameLangToggle struct {
Name string
LangStr string
Toggle bool
}
2018-01-10 03:32:48 +00:00
type PanelEditForumGroupPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2018-01-10 03:32:48 +00:00
Stats PanelStats
Zone string
ForumID int
GroupID int
Name string
Desc string
Active bool
Preset string
Perms [ ] NameLangToggle
}
2017-11-10 03:33:11 +00:00
type PanelEditGroupPermsPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2017-11-10 03:33:11 +00:00
ID int
Name string
LocalPerms [ ] NameLangToggle
GlobalPerms [ ] NameLangToggle
}
2017-11-11 04:06:16 +00:00
type BackupItem struct {
2017-11-10 03:33:11 +00:00
SQLURL string
// TODO: Add an easier to parse format here for Gosora to be able to more easily reimport portions of the dump and to strip unnecessary data (e.g. table defs and parsed post data)
Timestamp time . Time
}
type PanelBackupPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2017-11-11 04:06:16 +00:00
Backups [ ] BackupItem
2017-11-10 03:33:11 +00:00
}
2018-05-16 10:46:14 +00:00
type PageLogItem struct {
2017-11-10 03:33:11 +00:00
Action template . HTML
IPAddress string
DoneAt string
}
type PanelLogsPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2018-05-16 10:46:14 +00:00
Logs [ ] PageLogItem
Paginator
}
type PageRegLogItem struct {
RegLogItem
ParsedReason string
}
type PanelRegLogsPage struct {
Title string
CurrentUser User
Header * Header
Stats PanelStats
Zone string
Logs [ ] PageRegLogItem
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type PanelDebugPage struct {
Title string
CurrentUser User
2018-04-22 12:33:56 +00:00
Header * Header
2017-11-10 03:33:11 +00:00
Stats PanelStats
2017-12-27 23:38:37 +00:00
Zone string
2018-04-22 12:33:56 +00:00
GoVersion string
DBVersion string
2017-11-10 03:33:11 +00:00
Uptime string
OpenConns int
DBAdapter string
}
type PageSimple struct {
Title string
Something interface { }
}
type AreYouSure struct {
URL string
Message string
}
// TODO: Write a test for this
2018-04-22 12:33:56 +00:00
func DefaultHeader ( w http . ResponseWriter ) * Header {
return & Header { Site : Site , Theme : Themes [ fallbackTheme ] , CurrentUser : GuestUser , Writer : w }
2017-11-10 03:33:11 +00:00
}