czwartek, 22 września 2016

How to add new menu and static page in JHipster

Let’s start with new menu entry

Open /src/main/webapp/app/layouts/navbar/navbar.html and find:



 <li ui-sref-active="active">
                    <a ui-sref="home" ng-click="vm.collapseNavbar()">
                        <span class="glyphicon glyphicon-home"></span>
                        <span class="hidden-sm" data-translate="global.menu.home">Home</span>
                    </a>
                </li>





After this section add new entry:


                <li ng-class="{active: vm.$state.includes('admins-jobs')}" has-authority="ROLE_ADMIN" ng-switch-when="true" uib-dropdown class="dropdown pointer">
                    <a class="dropdown-toggle" uib-dropdown-toggle href="" id="admins-jobs">
                        <span>
                            <span class="glyphicon glyphicon-th-list"></span>
                            <span class="hidden-sm" data-translate="">
                                Admin's Jobs
                            </span>
                            <b class="caret"></b>
                        </span>
                    </a>
                        <li ui-sref-active="active" >
                            <a ui-sref="static" ng-click="vm.collapseNavbar()">
                                <span class="glyphicon glyphicon-asterisk"></span>&nbsp;
                                <span data-translate="">Static page</span>
                            </a>
                        </li>
                    </ul>                
                </li>




It looks like this:





In /src/main/webapp/app/ create new catalog /static and copy there /src/main/webapp/app/home content.
Change filenames from home to static.


In static.html I left only:

<div ng-cloak>
    <div class="row">
        <div class="col-md-4">
            <span class="hipster img-responsive img-rounded"></span>
        </div>
        <div class="col-md-8">
            <h1 >Welcome, Java Hipster!</h1>
            <p class="lead" >This is your static test</p>


        </div>
    </div>
</div>




In static.state.js change:


      $stateProvider.state('home', {
to
      $stateProvider.state('static', {

---------
          url: '/',
to
          url: '/static',

---------
          parent: 'app', - change parent folder if you need

---------
                   templateUrl: 'app/home/home.html',
                   controller: 'HomeController',
to
                   templateUrl: 'app/static/static.html',
                   controller: 'StaticController',

---------

My resolve section:


           resolve: {
               translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
                   $translatePartialLoader.addPart('global');
                   return $translate.refresh();
               }]
           }

If it’s static page, you don’t need static.controller.js.








1 komentarz:

  1. Or use this nice plugin to generate it:
    http://www.jhipster.tech/modules/marketplace/#/details/generator-jhipster-nav-element

    OdpowiedzUsuń