Requiere una versión mayor a la 4 de JHipster y cuya definición sea AngularJS
Para tener temas Bootswatch en lugar del tema por defecto sólo tiene que sustituir el css bootstrap con el css del tema bootswatch. Sin embargo, si desea un conmutador de tema fresco para cambiar entre los temas de Bootswatch dinámicamente, a continuación, siga esta sugerencia.
Nota: reemplace ‘pscApp’ con el nombre generado de su aplicación.
Agrege los siguientes ficheros:
Controlador
Agrega el siguiente controlador como
bootswatch.controller.js bajo la ruta
webapp/app/components/bootswatch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ( function () {
'use strict' ;
angular
.module( 'pscApp' )
.controller( 'BootswatchController' , BootswatchController);
BootswatchController.$inject = [ '$scope' , 'BootSwatchService' ];
function BootswatchController ($scope, BootSwatchService) {
BootSwatchService.get().then( function (themes) {
$scope.themes = themes.themes;
$scope.themes.unshift({name: 'Default' ,css: '' });
});
}
})();
|
Servicio
Agrega el siguiente servicio como
bootswatch.service.js bajo la ruta
webapp/app/components/bootswatch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ( function () {
'use strict' ;
angular
.module( 'pscApp' )
.factory( 'BootSwatchService' , BootSwatchService);
BootSwatchService.$inject = [ '$http' ];
function BootSwatchService ($http) {
return {
get: function () {
return data.themes;
} );
}
};
}
})();
|
Directiva
Agrega la siguiente directiva como
bootswatch.directive.js bajo la ruta
webapp/app/components/bootswatch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ( function () {
'use strict' ;
angular
.module( 'pscApp' )
.directive( 'jhSwitchTheme' , jhSwitchTheme);
function jhSwitchTheme () {
return {
restrict: 'A' ,
scope: {
theme : '=jhSwitchTheme'
},
link: function (scope, element, attrs) {
var currentTheme = $( "#bootswatch-css" ).attr( 'title' );
if (scope.theme.name === currentTheme){
element.parent().addClass( "active" );
}
element.on( 'click' , function (){
$( "#bootswatch-css" ).attr( "href" , scope.theme.css);
$( ".theme-link" ).removeClass( "active" );
element.parent().addClass( "active" );
});
}
};
}
})();
|
En el index.html:
Agregue lo siguiente al archivo index.html después de la tarea de construcción CSS vendor.css para que éstas no se minifiquen y compacten por tarea de compilación.
Añada en el header
1 2 3 4 5 6 7 8 9 10 11 |
...
< link href = "" id = "bootswatch-css" rel = "stylesheet" title = "Default" >
< link href = "content/css/main.css" rel = "stylesheet" >
|
Añada lo siguiente en el pie de página
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | < div class = "footer" ng-cloak = "" >
< div data-translate = "footer" >
This is your footer</ div >
< div class = "btn-group dropup" is-open = "status.isopen" ng-controller = "BootswatchController" uib-dropdown = "" >
< button class = "btn btn-primary" id = "single-button" ng-disabled = "disabled" type = "button" uib-dropdown-toggle = "" >
< span class = "glyphicon glyphicon-adjust" ></ span >
< span class = "hidden-tablet" data-translate = "global.menu.theme" >Theme</ span >
< span class = "caret" ></ span >
</ button >
< ul aria-labelledby = "single-button" class = "dropdown-menu" role = "menu" uib-dropdown-menu = "" >
< li class = "theme-link" ng-repeat = "theme in themes" role = "menuitem" >
</ li >
</ ul >
</ div >
</ div >
|
Agrege los siguientes script tags en el fichero index.html manualmente.
Si ‘gulp inject’ falla, recibirá errores de angular
1 2 3 4 |
<script src="app/components/bootswatch/bootswatch.controller.js"> </script>
<script src="app/components/bootswatch/bootswatch.directive.js"> </script>
<script src="app/components/bootswatch/bootswatch.service.js"> </script>
|