[% BLOCK makeSubMenu %]
  <li class="nav-item dropdown" [% IF id; HTML.attributes(id => id); END %] >
    <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown">[% title %]<b class="caret"></b></a>
    <div class="dropdown-menu[% IF align == 'right' %] dropdown-menu-right[% END %]">
      [% content %]
    </div>
  </li>
[% END %]
[% showPrivate = (isPrivateHydra && c.user_exists) || ! isPrivateHydra %]

[% IF showPrivate %]
<ul class="navbar-nav mr-auto">

  [% IF c.user_exists %]
    [% INCLUDE navItem uri = c.uri_for(c.controller('User').action_for('dashboard'), [c.user.username]) title = "Dashboard" %]
  [% END %]

  [% WRAPPER makeSubMenu title="Status" %]
    [% INCLUDE menuItem
       uri = c.uri_for(c.controller('Root').action_for('queue_summary'))
       title = "Queue ("_ nrRunningBuilds _"/"_ nrQueuedBuilds _")" %]
    [% INCLUDE menuItem
       uri = c.uri_for(c.controller('Root').action_for('status'))
       title = "Running builds" %]
    [% INCLUDE menuItem
       uri = c.uri_for(c.controller('Root').action_for('machines'))
       title = "Machine status" %]
    [% INCLUDE menuItem
       uri = c.uri_for(c.controller('Root').action_for('evals'))
       title = "Latest evaluations" %]
    [% INCLUDE menuItem
       uri = c.uri_for(c.controller('Root').action_for('all'))
       title = "Latest builds" %]
    [% INCLUDE menuItem
       uri = c.uri_for(c.controller('Root').action_for('steps'))
       title = "Latest steps" %]
  [% END %]

  [% IF project %]
    [% WRAPPER makeSubMenu title="Project"  %]
      <h6 class="dropdown-header">[% HTML.escape(project.name) %]</h6>
      <div class="dropdown-divider"></div>
      [% INCLUDE menuItem uri = c.uri_for(c.controller('Project').action_for('project'), [project.name]) title = "Overview" %]
      [% INCLUDE menuItem uri = c.uri_for(c.controller('Project').action_for('all'), [project.name]) title = "Latest builds" %]
      [% INCLUDE menuItem uri = c.uri_for('/project' project.name 'channel' 'latest') title = "Channel" %]
    [% END %]
  [% END %]

  [% IF jobset %]
    [% WRAPPER makeSubMenu title="Jobset" %]
      <h6 class="dropdown-header">[% HTML.escape(jobset.name) %]</h6>
      <div class="dropdown-divider"></div>
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Jobset').action_for('jobset'), [project.name, jobset.name])
        title = "Overview" %]
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Jobset').action_for('evals'), [project.name, jobset.name])
        title = "Evaluations" %]
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Jobset').action_for('all'), [project.name, jobset.name])
        title = "Latest builds" %]
      [% INCLUDE menuItem uri = c.uri_for('/jobset' project.name jobset.name 'channel' 'latest') title = "Channel" %]
    [% END %]
  [% END %]

  [% IF job %]
    [% WRAPPER makeSubMenu title="Job" %]
      <h6 class="dropdown-header">[% HTML.escape(job) %]</h6>
      <div class="dropdown-divider"></div>
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Job').action_for('overview'), [project.name, jobset.name, job])
        title = "Overview" %]
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Job').action_for('all'), [project.name, jobset.name, job])
        title = "Latest builds" %]
      [% INCLUDE menuItem uri = c.uri_for('/job' project.name jobset.name job 'channel' 'latest') title = "Channel" %]
    [% END %]
  [% END %]

  [% IF c.user_exists && (c.check_user_roles('admin') ||
                          c.check_user_roles('create-projects')) %]
    [% WRAPPER makeSubMenu title="Admin" %]
      [% IF c.check_user_roles('admin') || c.check_user_roles('create-projects') %]
        [% INCLUDE menuItem uri = c.uri_for(c.controller('Project').action_for('create')) title = "Create project" %]
        <div class="dropdown-divider"></div>
      [% END %]
      [% IF c.check_user_roles('admin') %]
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Admin').action_for('machines'))
        title = "Manage machines" %]
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Admin').action_for('managenews'))
        title = "Manage news" %]
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Admin').action_for('users'))
        title = "Manage users" %]
      <div class="dropdown-divider"></div>
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Admin').action_for('clear_queue_non_current'))
        title = "Cancel queued non-current builds"
        confirmmsg = "Are you sure you want to cancel all non-current builds?"
        class = "" %]
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Admin').action_for('clearfailedcache'))
        title = "Clear failed builds cache"
        confirmmsg = "Are you sure you want to clear the failed builds cache?"
        class = "" %]
      [% INCLUDE menuItem
        uri = c.uri_for(c.controller('Admin').action_for('clearvcscache'))
        title = "Clear VCS caches"
        confirmmsg = "Are you sure you want to clear the VCS cache?"
        class = "" %]
      [% END %]
    [% END %]
  [% END %]

</ul>
[% END %]

[% IF showPrivate %]
  <form class="form-inline" action="[% c.uri_for('/search') %]">
    <input name="query" type="text" class="form-control" placeholder="Search" [% HTML.attributes(value => c.req.params.query) %]/>
  </form>
[% END %]

<ul class="navbar-nav">

  [% IF c.user_exists %]
    [% INCLUDE navItem uri = c.uri_for(c.controller('User').action_for('edit'), [c.user.username]) title = "Preferences" %]
    <li class="nav-item">
      <a class="nav-link" href="#" onclick="signOut();">Sign out</a>
    </li>
  [% ELSE %]
    [% WRAPPER makeSubMenu title="Sign in" id="sign-in-menu" align="right" %]
      [% IF c.config.enable_google_login %]
        <div style="display: none" class="g-signin2" data-onsuccess="onGoogleSignIn" data-theme="dark"></div>
        <a class="dropdown-item" href="#" id="google-signin">Sign in with Google</a>
        <div class="dropdown-divider"></div>
      [% END %]
      [% IF c.config.github_client_id %]
        <a class="dropdown-item" href="/github-redirect?after=[% c.req.path %]">Sign in with GitHub</a>
        <div class="dropdown-divider"></div>
      [% END %]
      <a class="dropdown-item" href="#hydra-signin" data-toggle="modal">Sign in with a Hydra account</a>
    [% END %]
  [% END %]

</ul>