From f93cb5aad52767fa05956667664645fed39b1920 Mon Sep 17 00:00:00 2001 From: okalintu Date: Thu, 30 Mar 2017 15:24:08 +0300 Subject: [PATCH] Remove boilerplate from infoadmin controllers --- .../html/generic_external_image_create.html | 2 +- infoscreen/static/js/infoadmin_controllers.js | 63 +++++++------------ .../static/js/infoscreen_controllers.js | 5 +- 3 files changed, 24 insertions(+), 46 deletions(-) diff --git a/infoscreen/static/html/generic_external_image_create.html b/infoscreen/static/html/generic_external_image_create.html index a20359c..fecff8c 100644 --- a/infoscreen/static/html/generic_external_image_create.html +++ b/infoscreen/static/html/generic_external_image_create.html @@ -1,4 +1,4 @@ -
+
Create new image. Enter name and full url for any image available in internet (eg. https://i.imgur.com/XXSSqDG.gif)
diff --git a/infoscreen/static/js/infoadmin_controllers.js b/infoscreen/static/js/infoadmin_controllers.js index d6b3515..512bd6e 100644 --- a/infoscreen/static/js/infoadmin_controllers.js +++ b/infoscreen/static/js/infoadmin_controllers.js @@ -123,43 +123,6 @@ app.controller('infoadmin_ctrl', function($scope, $http, $window, ItemList, Inst }); ItemList.loadItems(); }); -app.controller('infoadmin_externalimage_create', function($scope, $http,ItemList){ - $scope.item = {} - $scope.send = function(){ - $http.post("/infoscreen/create_external_image", $scope.item).then(ItemList.loadItems) - } -}); -app.controller('infoadmin_abbitem_create', function($scope, $http,ItemList){ - $scope.item = {} - $scope.send = function(){ - $http.post("/infoscreen/create_abbitem", $scope.item).then(ItemList.loadItems) - } -}); -app.controller('infoadmin_sossoitem_create', function($scope, $http,ItemList){ - $scope.item = {} - $scope.send = function(){ - $http.post("/infoscreen/create_sossoitem", $scope.item).then(ItemList.loadItems) - } -}); -app.controller('infoadmin_eventitem_create', function($scope, $http,ItemList){ - $scope.item = {} - $scope.send = function(){ - $http.post("/infoscreen/create_eventitem", $scope.item).then(ItemList.loadItems) - } -}); - -app.controller('infoadmin_hslitem_create', function($scope, $http,ItemList){ - $scope.item = {} - $scope.send = function(){ - $http.post("/infoscreen/create_hslitem", $scope.item).then(ItemList.loadItems) - } -}); -app.controller('infoadmin_websiteitem_create', function($scope, $http,ItemList){ - $scope.item = {} - $scope.send = function(){ - $http.post("/infoscreen/create_websiteitem", $scope.item).then(ItemList.loadItems) - } -}); app.controller('infoadmin_image_create', ['$scope', 'Upload', '$timeout',"ItemList", function ($scope, Upload, $timeout,ItemList) { $scope.send = function(file) { @@ -182,9 +145,25 @@ app.controller('infoadmin_image_create', ['$scope', 'Upload', '$timeout',"ItemLi } }]); -app.controller('infoadmin_apyitem_create', function($scope, $http,ItemList){ - $scope.item = {} - $scope.send = function(){ - $http.post("/infoscreen/create_apyitem", $scope.item).then(ItemList.loadItems) +function itemGenerator(create_url){ + return function($scope, $http, ItemList){ + $scope.item = {} + $scope.send = function(){ + $http.post(create_url, $scope.item).then(ItemList.loadItems) + } } -}); +} +function controllerGenerator(name){ + app.controller("infoadmin_" + name + "_create", + itemGenerator("/infoscreen/create_" + name)); +} +var simple_controllers = [ + "external_image", + "abbitem", + "sossoitem", + "eventitem", + "hslitem", + "websiteitem", + "apyitem", +]; +_.each(simple_controllers, controllerGenerator); diff --git a/infoscreen/static/js/infoscreen_controllers.js b/infoscreen/static/js/infoscreen_controllers.js index 7af5069..f9a2e58 100644 --- a/infoscreen/static/js/infoscreen_controllers.js +++ b/infoscreen/static/js/infoscreen_controllers.js @@ -129,7 +129,7 @@ app.controller('timetableCtrl', objects=data['data']; for(var objectIndex in objects){ var stop = objects[objectIndex]; - + var lineIndex; for (lineIndex in stop['lines']){ var elem=stop['lines'][lineIndex].split(":"); @@ -165,7 +165,7 @@ app.controller('timetableCtrl', departure['stop']="A. A. puisto" var trigger = true; for (var arrIndex = $scope.arr.length - 1; arrIndex >= 0; arrIndex--) { - if ($scope.arr[arrIndex]['bus'] == departure['bus'] && + if ($scope.arr[arrIndex]['bus'] == departure['bus'] && $scope.arr[arrIndex]['laststop'] == departure['laststop']) { if ($scope.arr[arrIndex]['dist'] == departure['dist']){ @@ -226,4 +226,3 @@ app.controller('timetableCtrl', var inter3=$interval(updateTime, 1000); } ); -