{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}

<div class="panel panel-default panel-queue-mapping">
  <div class="panel-heading">
    <div class="panel-title">
      Queue Mappings
      <a href="#queueMappingsCollapsiblePanel" id="collapseQueueMappingsBtn" data-toggle="collapse" {{bind-attr class=":pull-right isCollapsed:collapsed"}}><i {{bind-attr class=":fa isCollapsed:fa-plus:fa-minus"}}></i></a>
    </div>
  </div>
  <div id="queueMappingsCollapsiblePanel" {{bind-attr class=":panel-collapse :collapse isCollapsed::in"}}>
    <div class="panel-body">
      <div class="container-fluid">
        <div class="row">
          <label>User to Queue Mappings (Precedence is from top to botttom)</label>
        </div>
        <div class="row">
          <ul id="qMappingList" class="list-group">
            {{#each qm in queueMappings}}
              <li class="list-group-item">{{queueMappingParser qm}}<span class="pull-right remove-mapping-icon" {{action "removeQueueMapping" qm}}><i class="fa fa-times"></i></span></li>
            {{else}}
              <span>No queue mappings defined</span>
            {{/each}}
          </ul>
        </div>

        <div class="add-queue-mapping-container">
          <div class="row">
            <div class="btn-group btn-group-sm">
              <button type="button" class="btn btn-default btn-primary" name="button" {{action "showMappingOptions"}}>Add Mapping</button>
            </div>
          </div>
          {{#if isShowing}}
            <div class="queue-mapping-options">
              <div class="row">
                <div class="radio">
                  <label title="Assign job to queue with same name as user">
                    {{view view.radioButton selectionBinding="selectedMapping" name="queueMappingType" value="u:%user:%user"}}
                    User %user -> queue %user
                  </label>
                </div>
              </div>
              <div class="row">
                <div class="radio">
                  <label title="Assign job to queue with same name as user's primary group">
                    {{view view.radioButton selectionBinding="selectedMapping" name="queueMappingType" value="u:%user:%primary_group"}}
                    User %user -> queue %primary_group
                  </label>
                </div>
              </div>
              <div class="row">
                <div class="radio">
                  <label>
                    {{view view.radioButton selectionBinding="selectedMapping" name="queueMappingType" value="u:%name:%qname"}}
                    Assign users to queue
                  </label>
                </div>
                {{#if isCustomUserMapping}}
                  <div class="row">
                    <div class="col-md-2">
                      <span>Users</span>
                    </div>
                    <div class="col-md-10">
                      <div class="form-group">
                        {{input type="text" class="form-control" value=customUserMappings size="30" placeholder="Comma-separated list of users"}}
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-2">
                      <span>Queue</span>
                    </div>
                    <div class="col-md-5">
                      <div class="form-group">
                        {{view Ember.Select
                          class="form-control"
                          content=leafQueueNames
                          value=selectedLeafQueueNameForUsers
                          prompt="Select Queue"}}
                      </div>
                    </div>
                  </div>
                {{/if}}
              </div>
              <div class="row">
                <div class="radio">
                  <label>
                    {{view view.radioButton selectionBinding="selectedMapping" name="queueMappingType" value="g:%name:%qname"}}
                    Assign groups to queue
                  </label>
                </div>
                {{#if isCustomGroupMapping}}
                  <div class="row">
                    <div class="col-md-2">
                      <span>Groups</span>
                    </div>
                    <div class="col-md-10">
                      <div class="form-group">
                        {{input type="text" class="form-control" value=customGroupMappings size="30" placeholder="Comma-separated list of groups"}}
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-2">
                      <span>Queue</span>
                    </div>
                    <div class="col-md-5">
                      <div class="form-group">
                        {{view Ember.Select
                          class="form-control"
                          content=leafQueueNames
                          value=selectedLeafQueueNameForGroups
                          prompt="Select Queue"}}
                      </div>
                    </div>
                  </div>
                {{/if}}
              </div>
              <div class="row">
                <div class="btn-group btn-group-xs pull-right">
                  <button type="button" class="btn btn-default btn-primary" name="button" {{action "addQueueMapping"}}>&nbsp;&nbsp;Add&nbsp;&nbsp;</button>
                  <button type="button" class="btn btn-default" name="button" {{action "hideMappingOptions"}}>Cancel</button>
                </div>
              </div>
            </div>
          {{/if}}
        </div>

        <div class="row">
          <div class="checkbox">
            <label>
              {{input type="checkbox" name="queueMappingOverride" checked=mappingsOverrideEnable}}
              Allow user to override queue mapping
            </label>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
