From 34a72818b61e72840b2ba59a20bf25bd49b57d4a Mon Sep 17 00:00:00 2001 From: Dan Anstis Date: Sat, 14 Oct 2017 14:34:11 +1000 Subject: [PATCH 1/2] Add version to webui pages --- plex/version.go | 2 +- webui/handlers.go | 20 ++- webui/templates/_template.html | 96 +++++----- webui/templates/index.html | 96 +++++----- webui/templates/logs.html | 168 ++++++++++-------- .../templates/settings/promptCredentials.html | 120 +++++++------ webui/templates/settings/settings.html | 110 +++++++----- 7 files changed, 339 insertions(+), 273 deletions(-) diff --git a/plex/version.go b/plex/version.go index d4a958c..cf0cb83 100644 --- a/plex/version.go +++ b/plex/version.go @@ -1,4 +1,4 @@ package plex // Version contains the version of the app. -const Version = "0.2.0" +const Version = "0.3.0" diff --git a/webui/handlers.go b/webui/handlers.go index e948be6..eb9e380 100644 --- a/webui/handlers.go +++ b/webui/handlers.go @@ -2,6 +2,7 @@ package webui import ( "fmt" + "html/template" "log" "net/http" "os" @@ -12,21 +13,32 @@ import ( "github.com/danstis/Plex-Sync/plex" ) +// VersionInfo defines a struct to store the current version information. +type VersionInfo struct { + Version string +} + +var v = VersionInfo{Version: plex.Version} + // RootHandler returns the default page. func rootHandler(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, path.Join("webui", "templates", "index.html")) + tmpl := template.Must(template.ParseFiles(path.Join("webui", "templates", "index.html"))) + tmpl.Execute(w, v) } func settingsHandler(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, path.Join("webui", "templates", "settings", "settings.html")) + tmpl := template.Must(template.ParseFiles(path.Join("webui", "templates", "settings", "settings.html"))) + tmpl.Execute(w, v) } func tokenHandler(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, path.Join("webui", "templates", "settings", "promptCredentials.html")) + tmpl := template.Must(template.ParseFiles(path.Join("webui", "templates", "settings", "promptCredentials.html"))) + tmpl.Execute(w, v) } func logsHandler(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, path.Join("webui", "templates", "logs.html")) + tmpl := template.Must(template.ParseFiles(path.Join("webui", "templates", "logs.html"))) + tmpl.Execute(w, v) } func generalLogHeadHandler(w http.ResponseWriter, r *http.Request) { diff --git a/webui/templates/_template.html b/webui/templates/_template.html index 3708661..d58b835 100644 --- a/webui/templates/_template.html +++ b/webui/templates/_template.html @@ -2,59 +2,69 @@ - - - - plex-sync - - - - - - - - + -
+
-
-

Plex-Sync

-

Some text in here...

-
+
+

Plex-Sync

+

Some text in here...

+
-
- +
+ - - + + \ No newline at end of file diff --git a/webui/templates/index.html b/webui/templates/index.html index 3708661..d58b835 100644 --- a/webui/templates/index.html +++ b/webui/templates/index.html @@ -2,59 +2,69 @@ - - - - plex-sync - - - - - - - - + -
+
-
-

Plex-Sync

-

Some text in here...

-
+
+

Plex-Sync

+

Some text in here...

+
-
- +
+ - - + + \ No newline at end of file diff --git a/webui/templates/logs.html b/webui/templates/logs.html index 981567d..2772524 100644 --- a/webui/templates/logs.html +++ b/webui/templates/logs.html @@ -2,97 +2,109 @@ - - - - plex-sync - - - - - - - - - - - - + -
+
-
-

Logs

- -
+
+

Logs

+ +
- -
+ +
-
- +
+ - - - - + + + + \ No newline at end of file diff --git a/webui/templates/settings/promptCredentials.html b/webui/templates/settings/promptCredentials.html index 7345a22..bcacab7 100644 --- a/webui/templates/settings/promptCredentials.html +++ b/webui/templates/settings/promptCredentials.html @@ -2,74 +2,82 @@ - - - - plex-sync - - - - - - - - + -
+
-
- -
- Request new token - -
- - +
- - -
- - - +
+ Request new token -
+
+ + -
- + + +
- - + + + +
+ +
+ + + + \ No newline at end of file diff --git a/webui/templates/settings/settings.html b/webui/templates/settings/settings.html index efed02a..42604c2 100644 --- a/webui/templates/settings/settings.html +++ b/webui/templates/settings/settings.html @@ -2,64 +2,78 @@ - - - - plex-sync - - - - - - - - + -
+
-
-

Settings

- - - -
+
+

Settings

-
- + - - +
+ +
+ + + + \ No newline at end of file From 1acafe8cf46cf3607b2949c74709ec56b1e8a4ff Mon Sep 17 00:00:00 2001 From: Dan Anstis Date: Sat, 14 Oct 2017 15:04:38 +1000 Subject: [PATCH 2/2] Show selected shows on Home page --- CHANGELOG.md | 7 ++++++- plex/server.go | 16 ++++++++-------- plex/server_test.go | 2 +- webui/handlers.go | 11 ++++++++--- webui/templates/index.html | 8 ++++++-- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f741b..b89fa60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [v0.3.0] +### Added +- Show selected shows on home page. +- Version to WebUI pages. ## [v0.2.0] ### Added @@ -32,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - App would attempt to sync even if a token was not obtained. - Spaces in TV Show names cause errors. -[unreleased]: https://github.com/danstis/Plex-Sync/compare/v0.2.0...HEAD +[unreleased]: https://github.com/danstis/Plex-Sync/compare/v0.3.0...HEAD +[v0.3.0]: https://github.com/danstis/Plex-Sync/compare/v0.2.0...v0.3.0 [v0.2.0]: https://github.com/danstis/Plex-Sync/compare/v0.1.0...v0.2.0 [v0.1.0]: https://github.com/danstis/Plex-Sync/compare/v0.0.1...v0.1.0 diff --git a/plex/server.go b/plex/server.go index 0091f00..8f1baeb 100644 --- a/plex/server.go +++ b/plex/server.go @@ -13,11 +13,11 @@ import ( // Host defines the data to be stored for server objects type Host struct { - Name string - Hostname string - Port int - Ssl bool - Token string + Name string + Hostname string + Port int + Ssl bool + Token string } var ( @@ -99,7 +99,7 @@ func SyncWatchedTv(source, destination Host) error { log.Printf("Syncing watched Tv Shows from %q to %q", source.Name, destination.Name) // Return all selected shows - ss, err := selectedShows() + ss, err := SelectedShows() if err != nil { return err } @@ -151,8 +151,8 @@ func SyncWatchedTv(source, destination Host) error { return nil } -// selectedShows returns the selected tv shows from the tvShowsFile -func selectedShows() ([]string, error) { +// SelectedShows returns the selected tv shows from the tvShowsFile +func SelectedShows() ([]string, error) { file, err := os.Open(tvShowFile) if err != nil { return nil, fmt.Errorf("failed to open tvshows file %q", tvShowFile) diff --git a/plex/server_test.go b/plex/server_test.go index 2923a8d..0a74460 100644 --- a/plex/server_test.go +++ b/plex/server_test.go @@ -85,7 +85,7 @@ func Test_selectedShows(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := selectedShows() + got, err := SelectedShows() if (err != nil) != tt.wantErr { t.Errorf("selectedShows() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/webui/handlers.go b/webui/handlers.go index eb9e380..68303fe 100644 --- a/webui/handlers.go +++ b/webui/handlers.go @@ -13,12 +13,17 @@ import ( "github.com/danstis/Plex-Sync/plex" ) -// VersionInfo defines a struct to store the current version information. -type VersionInfo struct { +// PageData defines a struct to store the current version information. +type PageData struct { Version string + Shows []string } -var v = VersionInfo{Version: plex.Version} +var ss, _ = plex.SelectedShows() +var v = PageData{ + Version: plex.Version, + Shows: ss, +} // RootHandler returns the default page. func rootHandler(w http.ResponseWriter, r *http.Request) { diff --git a/webui/templates/index.html b/webui/templates/index.html index d58b835..2aa21bc 100644 --- a/webui/templates/index.html +++ b/webui/templates/index.html @@ -55,8 +55,12 @@
-

Plex-Sync

-

Some text in here...

+

Welcome to Plex-Sync

+ {{if .Shows}} +

Selected Shows:

+ {{range .Shows}} +

{{.}}

+ {{end}} {{end}}