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
2018-06-24 13:49:29 +00:00
//Preload []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-06-06 00:21:22 +00:00
CurrentUser User // TODO: Deprecate CurrentUser on the page structs and use a pointer here
2018-04-22 12:33:56 +00:00
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-06-24 13:49:29 +00:00
/ * func ( header * Header ) Preload ( name string ) {
header . Preload = append ( header . Preload , name )
2018-04-04 04:49:13 +00:00
} * /
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 )
}
2018-06-06 00:21:22 +00:00
func ( header * Header ) AddNotice ( name string ) {
header . NoticeList = append ( header . NoticeList , GetNoticePhrase ( 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 {
2018-06-06 00:21:22 +00:00
* Header
ItemList [ ] interface { }
Something interface { }
}
type SimplePage struct {
* Header
}
type ErrorPage struct {
* Header
Message string
2017-11-10 03:33:11 +00:00
}
2018-04-22 12:33:56 +00:00
type Paginator struct {
PageList [ ] int
Page int
LastPage int
}
2018-06-06 00:21:22 +00:00
type CustomPagePage struct {
* Header
Page * CustomPage
}
2017-11-10 03:33:11 +00:00
type TopicPage struct {
2018-05-27 09:36:35 +00:00
* Header
ItemList [ ] ReplyUser
Topic TopicUser
Poll Poll
Page int
LastPage int
2017-11-10 03:33:11 +00:00
}
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 {
2018-05-27 09:36:35 +00:00
* Header
ItemList [ ] * TopicsRow
Forum * Forum
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type ForumsPage struct {
2018-06-01 05:02:29 +00:00
* Header
ItemList [ ] Forum
2017-11-10 03:33:11 +00:00
}
type ProfilePage struct {
2018-06-01 05:02:29 +00:00
* Header
2017-11-10 03:33:11 +00:00
ItemList [ ] ReplyUser
ProfileOwner User
}
type CreateTopicPage struct {
2018-06-01 05:02:29 +00:00
* Header
ItemList [ ] Forum
FID int
2017-11-10 03:33:11 +00:00
}
type IPSearchPage struct {
2018-06-01 05:02:29 +00:00
* Header
ItemList map [ int ] * User
IP string
2017-11-10 03:33:11 +00:00
}
2018-05-27 09:36:35 +00:00
type EmailListPage struct {
2018-06-01 05:02:29 +00:00
* Header
ItemList [ ] Email
Something interface { }
2018-05-27 09:36:35 +00:00
}
2018-06-17 07:28:18 +00:00
type AccountDashPage struct {
* Header
MFASetup bool
}
2017-11-10 03:33:11 +00:00
type PanelStats struct {
Users int
Groups int
Forums int
2018-06-06 00:21:22 +00:00
Pages int
2017-11-10 03:33:11 +00:00
Settings int
WordFilters int
Themes int
Reports int
}
2018-06-06 00:21:22 +00:00
type BasePanelPage struct {
* Header
Stats PanelStats
Zone string
ReportForumID int
}
2017-11-10 03:33:11 +00:00
type PanelPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
ItemList [ ] interface { }
Something interface { }
2017-11-10 03:33:11 +00:00
}
type GridElement struct {
ID string
Body string
Order int // For future use
Class string
Background string
TextColour string
Note string
}
type PanelDashboardPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
2018-05-11 05:41:51 +00:00
GridItems [ ] GridElement
2017-11-10 03:33:11 +00:00
}
2018-05-27 09:36:35 +00:00
type PanelSetting struct {
* Setting
FriendlyName string
}
type PanelSettingPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
2018-05-27 09:36:35 +00:00
ItemList [ ] OptionLabel
Setting * PanelSetting
}
2018-06-06 00:21:22 +00:00
type PanelCustomPagesPage struct {
* BasePanelPage
ItemList [ ] * CustomPage
Paginator
}
type PanelCustomPageEditPage struct {
* BasePanelPage
Page * CustomPage
}
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 {
2018-06-06 00:21:22 +00:00
* BasePanelPage
2018-01-03 07:46:18 +00:00
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 {
2018-06-06 00:21:22 +00:00
* BasePanelPage
ItemList [ ] PanelAnalyticsRoutesItem
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 {
2018-06-06 00:21:22 +00:00
* BasePanelPage
ItemList [ ] PanelAnalyticsAgentsItem
TimeRange string
2018-01-09 07:39:29 +00:00
}
2018-01-05 22:47:13 +00:00
type PanelAnalyticsRoutePage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
2018-01-05 22:47:13 +00:00
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-06-06 00:21:22 +00:00
* BasePanelPage
2018-02-15 13:15:27 +00:00
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-06-06 00:21:22 +00:00
* BasePanelPage
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 {
2018-06-06 00:21:22 +00:00
* BasePanelPage
2018-05-11 05:41:51 +00:00
ItemList [ ] PanelMenuListItem
}
type PanelMenuPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
2018-05-13 06:56:59 +00:00
MenuID int
2018-05-11 05:41:51 +00:00
ItemList [ ] MenuItem
}
type PanelMenuItemPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
Item MenuItem
2018-05-11 05:41:51 +00:00
}
2017-11-10 03:33:11 +00:00
type PanelUserPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
2018-05-27 09:36:35 +00:00
ItemList [ ] * User
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type PanelGroupPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
ItemList [ ] GroupAdmin
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type PanelEditGroupPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
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 {
2018-06-06 00:21:22 +00:00
* BasePanelPage
ID int
Name string
Desc string
Active bool
Preset string
Groups [ ] GroupForumPermPreset
2017-11-10 03:33:11 +00:00
}
type NameLangToggle struct {
Name string
LangStr string
Toggle bool
}
2018-01-10 03:32:48 +00:00
type PanelEditForumGroupPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
ForumID int
GroupID int
Name string
Desc string
Active bool
Preset string
Perms [ ] NameLangToggle
2018-01-10 03:32:48 +00:00
}
2017-11-10 03:33:11 +00:00
type PanelEditGroupPermsPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
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 {
2018-06-06 00:21:22 +00:00
* BasePanelPage
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 {
2018-06-06 00:21:22 +00:00
* BasePanelPage
Logs [ ] PageLogItem
2018-05-16 10:46:14 +00:00
Paginator
}
type PageRegLogItem struct {
RegLogItem
ParsedReason string
}
type PanelRegLogsPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
Logs [ ] PageRegLogItem
2018-04-22 12:33:56 +00:00
Paginator
2017-11-10 03:33:11 +00:00
}
type PanelDebugPage struct {
2018-06-06 00:21:22 +00:00
* BasePanelPage
GoVersion string
DBVersion string
Uptime string
OpenConns int
DBAdapter string
2017-11-10 03:33:11 +00:00
}
type PageSimple struct {
Title string
Something interface { }
}
type AreYouSure struct {
URL string
Message string
}
// TODO: Write a test for this
2018-06-06 00:21:22 +00:00
func DefaultHeader ( w http . ResponseWriter , user User ) * Header {
return & Header { Site : Site , Theme : Themes [ fallbackTheme ] , CurrentUser : user , Writer : w }
2017-11-10 03:33:11 +00:00
}