base.vue 4.9 KB
Newer Older
K
Kushal Pandya 已提交
1
<script>
2
import $ from 'jquery';
3
import { __ } from '~/locale';
K
Kushal Pandya 已提交
4
import LabelsSelect from '~/labels_select';
5
import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidden_input.vue';
K
Kushal Pandya 已提交
6

C
Clement Ho 已提交
7
import { GlLoadingIcon } from '@gitlab/ui';
K
Kushal Pandya 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import DropdownTitle from './dropdown_title.vue';
import DropdownValue from './dropdown_value.vue';
import DropdownValueCollapsed from './dropdown_value_collapsed.vue';
import DropdownButton from './dropdown_button.vue';
import DropdownHeader from './dropdown_header.vue';
import DropdownSearchInput from './dropdown_search_input.vue';
import DropdownFooter from './dropdown_footer.vue';
import DropdownCreateLabel from './dropdown_create_label.vue';

export default {
  components: {
    DropdownTitle,
    DropdownValue,
    DropdownValueCollapsed,
    DropdownButton,
    DropdownHiddenInput,
    DropdownHeader,
    DropdownSearchInput,
    DropdownFooter,
    DropdownCreateLabel,
28
    GlLoadingIcon,
K
Kushal Pandya 已提交
29 30 31 32 33 34 35
  },
  props: {
    showCreate: {
      type: Boolean,
      required: false,
      default: false,
    },
36 37 38 39 40
    isProject: {
      type: Boolean,
      required: false,
      default: false,
    },
K
Kushal Pandya 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    abilityName: {
      type: String,
      required: true,
    },
    context: {
      type: Object,
      required: true,
    },
    namespace: {
      type: String,
      required: false,
      default: '',
    },
    updatePath: {
      type: String,
      required: false,
      default: '',
    },
    labelsPath: {
      type: String,
      required: true,
    },
    labelsWebUrl: {
      type: String,
      required: false,
      default: '',
    },
    labelFilterBasePath: {
      type: String,
      required: false,
      default: '',
    },
    canEdit: {
      type: Boolean,
      required: false,
      default: false,
    },
78 79 80 81 82 83 84 85 86 87
    enableScopedLabels: {
      type: Boolean,
      require: false,
      default: false,
    },
    scopedLabelsDocumentationLink: {
      type: String,
      require: false,
      default: '#',
    },
K
Kushal Pandya 已提交
88 89 90 91 92
  },
  computed: {
    hiddenInputName() {
      return this.showCreate ? `${this.abilityName}[label_names][]` : 'label_id[]';
    },
93 94 95 96 97 98 99 100 101 102 103 104 105 106
    createLabelTitle() {
      if (this.isProject) {
        return __('Create project label');
      }

      return __('Create group label');
    },
    manageLabelsTitle() {
      if (this.isProject) {
        return __('Manage project labels');
      }

      return __('Manage group labels');
    },
K
Kushal Pandya 已提交
107 108 109 110 111
  },
  mounted() {
    this.labelsDropdown = new LabelsSelect(this.$refs.dropdownButton, {
      handleClick: this.handleClick,
    });
112
    $(this.$refs.dropdown).on('hidden.gl.dropdown', this.handleDropdownHidden);
K
Kushal Pandya 已提交
113 114 115 116 117
  },
  methods: {
    handleClick(label) {
      this.$emit('onLabelClick', label);
    },
118 119 120 121 122 123
    handleCollapsedValueClick() {
      this.$emit('toggleCollapse');
    },
    handleDropdownHidden() {
      this.$emit('onDropdownClose');
    },
K
Kushal Pandya 已提交
124 125 126 127 128
  },
};
</script>

<template>
K
Kushal Pandya 已提交
129
  <div class="block labels js-labels-block">
K
Kushal Pandya 已提交
130 131 132
    <dropdown-value-collapsed
      v-if="showCreate"
      :labels="context.labels"
133
      @onValueClick="handleCollapsedValueClick"
K
Kushal Pandya 已提交
134
    />
M
Mike Greiling 已提交
135
    <dropdown-title :can-edit="canEdit" />
136 137 138 139 140 141
    <dropdown-value
      :labels="context.labels"
      :label-filter-base-path="labelFilterBasePath"
      :scoped-labels-documentation-link="scopedLabelsDocumentationLink"
      :enable-scoped-labels="enableScopedLabels"
    >
K
Kushal Pandya 已提交
142 143
      <slot></slot>
    </dropdown-value>
M
Mike Greiling 已提交
144
    <div v-if="canEdit" class="selectbox js-selectbox" style="display: none;">
K
Kushal Pandya 已提交
145 146 147 148
      <dropdown-hidden-input
        v-for="label in context.labels"
        :key="label.id"
        :name="hiddenInputName"
149
        :value="label.id"
K
Kushal Pandya 已提交
150
      />
M
Mike Greiling 已提交
151
      <div ref="dropdown" class="dropdown">
K
Kushal Pandya 已提交
152 153 154 155 156 157 158 159
        <dropdown-button
          :ability-name="abilityName"
          :field-name="hiddenInputName"
          :update-path="updatePath"
          :labels-path="labelsPath"
          :namespace="namespace"
          :labels="context.labels"
          :show-extra-options="!showCreate"
160 161
          :scoped-labels-documentation-link="scopedLabelsDocumentationLink"
          :enable-scoped-labels="enableScopedLabels"
K
Kushal Pandya 已提交
162 163 164 165 166 167 168
        />
        <div
          class="dropdown-menu dropdown-select dropdown-menu-paging
dropdown-menu-labels dropdown-menu-selectable"
        >
          <div class="dropdown-page-one">
            <dropdown-header v-if="showCreate" />
M
Mike Greiling 已提交
169
            <dropdown-search-input />
170
            <div class="dropdown-content" data-qa-selector="labels_dropdown_content"></div>
M
Mike Greiling 已提交
171
            <div class="dropdown-loading"><gl-loading-icon /></div>
K
Kushal Pandya 已提交
172 173 174
            <dropdown-footer
              v-if="showCreate"
              :labels-web-url="labelsWebUrl"
175 176
              :create-label-title="createLabelTitle"
              :manage-labels-title="manageLabelsTitle"
K
Kushal Pandya 已提交
177 178 179 180
            />
          </div>
          <dropdown-create-label
            v-if="showCreate"
181 182
            :is-project="isProject"
            :header-title="createLabelTitle"
K
Kushal Pandya 已提交
183 184 185 186 187 188
          />
        </div>
      </div>
    </div>
  </div>
</template>