diff --git a/admin/api/public.go b/admin/api/public.go index 9feb5c55..17d2d983 100644 --- a/admin/api/public.go +++ b/admin/api/public.go @@ -2,6 +2,7 @@ package api import ( "encoding/json" + "fmt" "os" "path" @@ -11,9 +12,9 @@ import ( var TeamsDir string func init() { - router.GET("/api/public.json", apiHandler(getPublic)) - router.DELETE("/api/public.json", apiHandler(deletePublic)) - router.PUT("/api/public.json", apiHandler(savePublic)) + router.GET("/api/public/:sid", apiHandler(getPublic)) + router.DELETE("/api/public/:sid", apiHandler(deletePublic)) + router.PUT("/api/public/:sid", apiHandler(savePublic)) } type FICPublicScene struct { @@ -52,23 +53,23 @@ func savePublicTo(path string, s []FICPublicScene) error { } } -func getPublic(_ httprouter.Params, body []byte) (interface{}, error) { - if _, err := os.Stat(path.Join(TeamsDir, "_public", "public.json")); !os.IsNotExist(err) { - return readPublic(path.Join(TeamsDir, "_public", "public.json")) +func getPublic(ps httprouter.Params, body []byte) (interface{}, error) { + if _, err := os.Stat(path.Join(TeamsDir, "_public", fmt.Sprintf("public%s.json", ps.ByName("sid")))); !os.IsNotExist(err) { + return readPublic(path.Join(TeamsDir, "_public", fmt.Sprintf("public%s.json", ps.ByName("sid")))) } else { return []FICPublicScene{}, nil } } -func deletePublic(_ httprouter.Params, body []byte) (interface{}, error) { - if err := savePublicTo(path.Join(TeamsDir, "_public", "public.json"), []FICPublicScene{}); err != nil { +func deletePublic(ps httprouter.Params, body []byte) (interface{}, error) { + if err := savePublicTo(path.Join(TeamsDir, "_public", fmt.Sprintf("public%s.json", ps.ByName("sid"))), []FICPublicScene{}); err != nil { return nil, err } else { return []FICPublicScene{}, err } } -func savePublic(_ httprouter.Params, body []byte) (interface{}, error) { +func savePublic(ps httprouter.Params, body []byte) (interface{}, error) { var scenes []FICPublicScene if err := json.Unmarshal(body, &scenes); err != nil { return nil, err @@ -80,7 +81,7 @@ func savePublic(_ httprouter.Params, body []byte) (interface{}, error) { } } - if err := savePublicTo(path.Join(TeamsDir, "_public", "public.json"), scenes); err != nil { + if err := savePublicTo(path.Join(TeamsDir, "_public", fmt.Sprintf("public%s.json", ps.ByName("sid"))), scenes); err != nil { return nil, err } else { return scenes, err diff --git a/admin/index.go b/admin/index.go index 08d4fb7b..7aab5c96 100644 --- a/admin/index.go +++ b/admin/index.go @@ -33,7 +33,7 @@ const indextpl = ` - + diff --git a/admin/static.go b/admin/static.go index aaeb89aa..ee9d4b17 100644 --- a/admin/static.go +++ b/admin/static.go @@ -19,7 +19,7 @@ func init() { api.Router().GET("/events/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { http.ServeFile(w, r, path.Join(StaticDir, "index.html")) }) - api.Router().GET("/public", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + api.Router().GET("/public/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { http.ServeFile(w, r, path.Join(StaticDir, "index.html")) }) api.Router().GET("/settings/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { diff --git a/admin/static/index.html b/admin/static/index.html index 61d4f4a7..9601ce03 100644 --- a/admin/static/index.html +++ b/admin/static/index.html @@ -31,7 +31,7 @@ - + diff --git a/admin/static/js/app.js b/admin/static/js/app.js index bf2a4439..ac299eed 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -41,7 +41,7 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"]) controller: "TeamController", templateUrl: "views/team-stats.html" }) - .when("/public", { + .when("/public/:screenId", { controller: "PublicController", templateUrl: "views/public.html" }) @@ -77,7 +77,7 @@ angular.module("FICApp") }) }) .factory("Scene", function($resource) { - return $resource("/api/public.json", null, { + return $resource("/api/public/:screenId", { screenId: '@id' }, { 'update': {method: 'PUT', isArray: true}, }) }) @@ -377,11 +377,20 @@ angular.module("FICApp") }; }) - .controller("PublicController", function($scope, $rootScope, Scene, Theme, Teams, Exercice) { - $scope.scenes = Scene.query(); + .controller("PublicController", function($scope, $rootScope, $routeParams, $location, Scene, Theme, Teams, Exercice) { + $scope.screens = [0,1,2,3,4,5,6,7,8,9]; + $scope.screenid = $routeParams.screenId; + $scope.scenes = Scene.query({ screenId: $routeParams.screenId }); $scope.themes = Theme.query(); $scope.teams = Teams.get(); + $scope.chScreen = function(sid) { + if ($scope.screenid) + $location.url("/public/" + $scope.screenid); + else + $location.url("/public/"); + } + $scope.types = { "welcome": "Messages de bienvenue", "countdown": "Compte à rebours", @@ -462,9 +471,10 @@ angular.module("FICApp") ]; } }; + $scope.saveScenes = function() { $scope.someUpdt = false; - var prms = Scene.update($scope.scenes); + var prms = Scene.update({ screenId: $scope.screenid }, $scope.scenes); prms.$promise.then(function() { $rootScope.newBox('success', 'Scene successfully published!'); }, function(response) { diff --git a/admin/static/views/public.html b/admin/static/views/public.html index 46eab8a9..2274433f 100644 --- a/admin/static/views/public.html +++ b/admin/static/views/public.html @@ -1,6 +1,7 @@

Interface publique +