juci-core: fixed the juci-theme-picker direcitve to work again
authorReidar Cederqvist <reidar.cederqvist@gmail.com>
Thu, 19 Jul 2018 11:38:58 +0000 (13:38 +0200)
committerSukru Senli <sukru.senli@inteno.se>
Sat, 1 Sep 2018 09:23:00 +0000 (11:23 +0200)
juci/access.json
juci/src/js/juci.js
juci/src/widgets/juci-config.js
juci/src/widgets/theme-picker.html
juci/src/widgets/theme-picker.js
juci/ubus/juci.core

index 6e48742..bf351ab 100644 (file)
@@ -41,7 +41,8 @@
                "read": {
                        "ubus": {
                                "juci.core": [
-                                       "default_password"
+                                       "default_password",
+                                       "get_themes"
                                ],
                                "session": [
                                        "access",
index 2012008..66a6456 100644 (file)
                "homepage":             { dvalue: "overview", type: String },
                "language_debug":       { dvalue: false, type: String },
                "force_passwd_change":  { dvalue: false, type: Boolean },
-               "default_language":     { dvalue: "en", type: String }
+               "default_language":     { dvalue: "en", type: String },
+               "theme":                { dvalue: "", type: String }
        });
 
        UCI.juci.$registerSectionType("login", {
index c71ab81..24eef24 100644 (file)
@@ -161,7 +161,7 @@ JUCI.app
                                $scope.numUnsavedChanges();
                                console.log("Saved uci configuration!");
                                //$scope.$apply();
-                               location.reload();
+                               location.reload(true);
                        }).fail(function(errors){
                                $scope.errors = errors.map(function(e){return e;});
                                $scope.$emit("errors", errors);
index 47152eb..643f61a 100644 (file)
@@ -1,5 +1,3 @@
-<div ng-controller="JuciThemePickerController">
-       <div class="form-group">
-               <juci-select ng-model="selectedTheme" ng-items="themes" on-change="onChangeTheme()" placeholder="{{'Select Theme'|translate}}"></juci-select>
-       </div>
+<div class="form-group">
+       <juci-select ng-model="selectedTheme.value" ng-items="themes" placeholder="{{'Select Theme'|translate}}"></juci-select>
 </div>
index 6b444ad..bd9eae2 100644 (file)
@@ -22,23 +22,20 @@ JUCI.app
 .directive("juciThemePicker", function(){
        return {
                templateUrl: "/widgets/theme-picker.html", 
-               replace: true
+               replace: true,
+               controller: "JuciThemePickerController"
         };  
 })
-.controller("JuciThemePickerController", function($scope, $theme, $config){
-       $scope.themes = $config.themes.map(function(x){
-               var item = {
-                       value: x, 
-                       label: x
-               }; 
-               if(x == $theme.getCurrentTheme()) $scope.selectedTheme = item; 
-               return item; 
-       }); 
-       if(!$scope.selectedTheme) $scope.selectedTheme = $scope.themes[0]; 
-       $scope.onChangeTheme = function(){
-               //alert($scope.selectedTheme.id); 
-               $theme.changeTheme($scope.selectedTheme.value).done(function(){
-                       window.location.reload(); 
-               });
-       }
+.controller("JuciThemePickerController", function($rpc, $scope, $theme, $config){
+       $scope.selectedTheme = $config.get("settings.juci.theme");
+       $rpc.$call("juci.core", "get_themes").done(function(data){
+               if(data && data.themes) {
+                       $scope.themes = data.themes.map(function(theme){
+                               return { value: theme.theme, label: theme.label };
+                       });
+               }
+               $scope.$apply();
+       }).fail(function(e){
+               console.error("couldn't call juci.core get_themes", e);
+       });
 }); 
index b3a6708..b7aee8e 100755 (executable)
@@ -5,7 +5,8 @@
 case "$1" in
        list)
                echo '{
-                       "default_password":{"username":"Str"}
+                       "default_password":{"username":"Str"},
+                       "get_themes": { }
                }'
        ;;
        call)
@@ -32,6 +33,29 @@ case "$1" in
                                fi
                                json_dump
                        ;;
+                       get_themes)
+                               json_init
+                               [ -d "/www/themes" ] || {
+                                       json_add_string "error" "No themes folder found"
+                                       json_dump
+                                       exit 0
+                               }
+                               files="$(find /www/themes/ -type f)"
+                               json_add_array "themes"
+                               for file in $files; do
+                                       file_name=${file##*/}
+                                       file_unziped=${file_name%.gz}
+                                       theme=${file_unziped%.js}
+                                       name=${theme#*juci-theme-}
+                                       name_up=$(echo $name | tr '[a-z]' '[A-Z]')
+                                       json_add_object
+                                       json_add_string "theme" "$theme"
+                                       json_add_string "label" "$name_up"
+                                       json_close_object
+                               done
+                               json_close_array
+                               json_dump
+                               ;;
                        *) return 1 ;;
                esac
        ;;