2023-11-12 18:21:05 +08:00
|
|
|
<template>
|
2023-12-21 18:57:52 +08:00
|
|
|
<div
|
2024-01-04 16:47:40 +08:00
|
|
|
v-if="canConnectRows"
|
2023-12-21 18:57:52 +08:00
|
|
|
ref="repositoryItemRelationshipsModal"
|
|
|
|
@keydown.esc="close"
|
|
|
|
id="repositoryItemRelationshipsModal"
|
|
|
|
tabindex="-1"
|
|
|
|
role="dialog"
|
2023-11-12 18:21:05 +08:00
|
|
|
class="modal ">
|
|
|
|
<div class="modal-dialog modal-sm" role="document">
|
2023-12-12 00:05:54 +08:00
|
|
|
<div class="modal-content w-[400px] m-auto">
|
2023-11-12 18:21:05 +08:00
|
|
|
|
|
|
|
<!-- header -->
|
|
|
|
<div class="modal-header h-[76px] flex !flex-col gap-[6px]">
|
|
|
|
|
|
|
|
<!-- header title with close icon -->
|
|
|
|
<div class="h-[30px] w-full flex flex-row-reverse">
|
|
|
|
<i id="close-icon" class="sn-icon sn-icon-close ml-auto cursor-pointer my-auto mx-0" data-dismiss="modal"
|
2023-12-11 17:43:47 +08:00
|
|
|
aria-label="Close" @click="close"></i>
|
2023-11-12 18:21:05 +08:00
|
|
|
<h4 class="modal-title" id="modal-destroy-team-label">
|
|
|
|
{{ i18n.t('repositories.item_card.repository_item_relationships_modal.header_title') }}
|
|
|
|
</h4>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- header subtitle -->
|
|
|
|
<div class="h-10 overflow-hidden break-words text-sn-dark-grey text-sm font-normal leading-5"
|
|
|
|
style="-webkit-box-orient: vertical; -webkit-line-clamp: 2; display: -webkit-box;">
|
|
|
|
{{ i18n.t('repositories.item_card.repository_item_relationships_modal.header_subtitle') }}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2023-12-12 00:05:54 +08:00
|
|
|
<div class="modal-body flex flex-col gap-6" :class="{ '!pb-3': notification }">
|
2023-11-12 18:21:05 +08:00
|
|
|
<!-- inventory -->
|
|
|
|
<div class="flex flex-col gap-[7px]">
|
|
|
|
<div class="h-5 whitespace-nowrap overflow-auto">
|
|
|
|
{{ i18n.t('repositories.item_card.repository_item_relationships_modal.inventory_section_title') }}</div>
|
|
|
|
<div class="h-11">
|
2023-12-11 17:43:47 +08:00
|
|
|
<select-search ref="ChangeSelectedInventoryDropdownSelector" @change="changeSelectedInventory" :value="selectedInventoryValue"
|
|
|
|
:options="inventoryOptions"
|
|
|
|
:isLoading="isLoadingInventories"
|
|
|
|
:lazyLoadEnabled="true"
|
|
|
|
:optionsUrl="inventoriesUrl"
|
2023-11-12 18:21:05 +08:00
|
|
|
:placeholder="i18n.t('repositories.item_card.repository_item_relationships_modal.select_inventory_placeholder')"
|
|
|
|
:noOptionsPlaceholder="i18n.t('repositories.item_card.repository_item_relationships_modal.select_inventory_no_options_placeholder')"
|
|
|
|
:searchPlaceholder="i18n.t('repositories.item_card.repository_item_relationships_modal.select_inventory_placeholder')"
|
2023-12-11 17:43:47 +08:00
|
|
|
@update-options="updateInventories"
|
|
|
|
@reached-end="fetchInventories"
|
2023-11-28 20:15:42 +08:00
|
|
|
></select-search>
|
2023-11-12 18:21:05 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- item -->
|
|
|
|
<div class="flex flex-col gap-[7px]">
|
|
|
|
<div class="h-5 whitespace-nowrap overflow-auto">
|
|
|
|
{{ i18n.t('repositories.item_card.repository_item_relationships_modal.item_section_title') }}</div>
|
|
|
|
<div class="h-11">
|
2023-12-11 17:43:47 +08:00
|
|
|
<ChecklistSearch
|
|
|
|
ref="ChangeSelectedItemChecklistSelector"
|
|
|
|
:shouldUpdateWithoutValues="true"
|
|
|
|
:lazyLoadEnabled="true"
|
|
|
|
:withButtons="false"
|
|
|
|
:withEditCursor="false"
|
|
|
|
optionsClassName="max-h-[300px]"
|
|
|
|
:optionsUrl="inventoryItemsUrl"
|
|
|
|
:options="itemOptions"
|
2023-11-12 18:21:05 +08:00
|
|
|
:placeholder="i18n.t('repositories.item_card.repository_item_relationships_modal.select_item_placeholder')"
|
|
|
|
:noOptionsPlaceholder="i18n.t('repositories.item_card.repository_item_relationships_modal.select_item_no_options_placeholder')"
|
2023-12-11 17:43:47 +08:00
|
|
|
:initialSelectedValues="selectedItemValues"
|
2023-11-12 18:21:05 +08:00
|
|
|
:shouldUpdateOnToggleClose="true"
|
2023-12-11 17:43:47 +08:00
|
|
|
:params="itemParams"
|
|
|
|
@update-options="updateInventoryItems"
|
|
|
|
@update="selectedItemValues = $event"
|
|
|
|
@reached-end="() => fetchInventoryItems(selectedInventoryValue)"
|
|
|
|
></ChecklistSearch>
|
2023-11-12 18:21:05 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- relationship -->
|
|
|
|
<div class="flex flex-col gap-[7px]">
|
|
|
|
<div class="h-5 whitespace-nowrap overflow-auto">
|
|
|
|
{{ i18n.t('repositories.item_card.repository_item_relationships_modal.relationship_section_title') }}
|
|
|
|
</div>
|
|
|
|
<div class="h-11">
|
2023-12-11 17:43:47 +08:00
|
|
|
<Select
|
|
|
|
ref="ChangeSelectedRelationshipDropdownSelector"
|
|
|
|
class="hover:border-sn-sleepy-grey"
|
|
|
|
@change="selectedRelationshipValue = $event"
|
|
|
|
:value="selectedRelationshipValue"
|
|
|
|
:options="[['parent', 'Parent'], ['child', 'Child']]"
|
2023-11-12 18:21:05 +08:00
|
|
|
:placeholder="i18n.t('repositories.item_card.repository_item_relationships_modal.select_relationship_placeholder')"
|
2023-12-11 17:43:47 +08:00
|
|
|
></Select>
|
2023-11-12 18:21:05 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2023-12-12 00:05:54 +08:00
|
|
|
<!-- Notification -->
|
|
|
|
<template v-if="notification">
|
|
|
|
<hr class="bg-sn-light-grey mb-6 mt-3" />
|
|
|
|
<div class="w-full mb-6">
|
|
|
|
<div class="flex align-center gap-2.5">
|
|
|
|
<img class="w-6 h-6" :src="notificationIconPath" alt="warning" />
|
|
|
|
<span class="my-auto">{{ notification.message }}</span>
|
|
|
|
</div>
|
|
|
|
<div v-html="notification.support_html" class="pl-2.5"></div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-11-12 18:21:05 +08:00
|
|
|
<!-- footer -->
|
|
|
|
<div class="modal-footer">
|
|
|
|
<div class="flex justify-end gap-4">
|
2023-12-11 17:43:47 +08:00
|
|
|
<button class="btn btn-secondary w-[78px] h-10 whitespace-nowrap" @click="close">
|
2023-11-12 18:21:05 +08:00
|
|
|
{{ i18n.t('repositories.item_card.repository_item_relationships_modal.cancel_button') }}
|
|
|
|
</button>
|
2023-12-11 17:43:47 +08:00
|
|
|
<button class="btn btn-primary w-[59px] h-10 whitespace-nowrap"
|
|
|
|
:class="{ 'disabled': !shouldEnableAddButton }" @click="() => addRelation(selectedRelationshipValue)">
|
2023-11-12 18:21:05 +08:00
|
|
|
{{ i18n.t('repositories.item_card.repository_item_relationships_modal.add_button') }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import SelectSearch from '../shared/select_search.vue';
|
2023-12-11 17:43:47 +08:00
|
|
|
import ChecklistSearch from '../shared/checklist_search.vue';
|
|
|
|
import Select from '../shared/select.vue';
|
2023-11-12 18:21:05 +08:00
|
|
|
import ChecklistSelect from '../shared/checklist_select.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'RepositoryItemRelationshipsModal',
|
|
|
|
components: {
|
|
|
|
'select-search': SelectSearch,
|
2023-12-11 17:43:47 +08:00
|
|
|
ChecklistSearch,
|
|
|
|
Select,
|
2023-11-12 18:21:05 +08:00
|
|
|
'checklist-select': ChecklistSelect,
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
window.repositoryItemRelationshipsModal = this;
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2023-12-11 17:43:47 +08:00
|
|
|
isLoadingInventories: false,
|
|
|
|
inventoriesUrl: '',
|
|
|
|
inventoryItemsUrl: '',
|
|
|
|
createConnectionUrl: '',
|
|
|
|
createConnectionUrlValue: '',
|
2023-11-12 18:21:05 +08:00
|
|
|
selectedInventoryValue: null,
|
|
|
|
selectedItemValues: [],
|
|
|
|
selectedRelationshipValue: null,
|
2023-12-11 17:43:47 +08:00
|
|
|
inventoryOptions: [],
|
|
|
|
itemOptions: [],
|
|
|
|
nextInventoriesPage: 1,
|
|
|
|
nextItemsPage: 1,
|
|
|
|
itemParams: [],
|
2023-12-12 00:05:54 +08:00
|
|
|
notification: null,
|
|
|
|
notificationIconPath: null,
|
2024-01-04 16:47:40 +08:00
|
|
|
canConnectRows: null
|
2023-11-12 18:21:05 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
shouldEnableAddButton() {
|
|
|
|
return ((this.selectedInventoryValue !== null) && (this.selectedRelationshipValue !== null) && (this.selectedItemValues.length > 0))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2023-12-11 17:43:47 +08:00
|
|
|
fetchInventories() {
|
|
|
|
if (!this.nextInventoriesPage) return;
|
|
|
|
|
|
|
|
this.loadingInventories = true;
|
|
|
|
$.ajax({
|
|
|
|
url: `${this.inventoriesUrl}?page=${this.nextInventoriesPage}`,
|
|
|
|
success: (result) => {
|
|
|
|
this.inventoryOptions = this.inventoryOptions.concat(result.data.map((val) => [val.id, val.name]));
|
|
|
|
this.loadingInventories = false;
|
|
|
|
this.nextInventoriesPage = result.next_page;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchInventoryItems(inventoryValue = null) {
|
|
|
|
if (!inventoryValue || !this.nextItemsPage) return;
|
|
|
|
|
|
|
|
this.loadingItems = true;
|
|
|
|
$.ajax({
|
|
|
|
url: `${this.inventoryItemsUrl}/?page=${this.nextItemsPage}&repository_id=${inventoryValue}`,
|
|
|
|
success: (result) => {
|
|
|
|
this.itemOptions = this.itemOptions.concat(result.data.map((val) => ({ id: val.id, label: val.name })));
|
|
|
|
this.loadingItems = false;
|
|
|
|
this.nextItemsPage = result.next_page;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
updateInventories(currentOptions, result) {
|
|
|
|
this.inventoryOptions = currentOptions.concat(result.data?.map((val) => [val.id, val.name]));
|
2023-11-12 18:21:05 +08:00
|
|
|
},
|
2023-12-11 17:43:47 +08:00
|
|
|
updateInventoryItems(currentOptions, result) {
|
|
|
|
this.itemOptions = currentOptions.concat(result.data.map(({ id, name }) => ({ id, label: name })));
|
2023-11-12 18:21:05 +08:00
|
|
|
},
|
2023-12-11 17:43:47 +08:00
|
|
|
show(params = {}) {
|
2023-12-12 00:05:54 +08:00
|
|
|
const {
|
|
|
|
relation,
|
|
|
|
optionUrls,
|
|
|
|
addRelationCallback,
|
|
|
|
notificationIconPath,
|
|
|
|
notification,
|
2024-01-04 16:47:40 +08:00
|
|
|
canConnectRows
|
2023-12-12 00:05:54 +08:00
|
|
|
} = params;
|
2023-12-11 17:43:47 +08:00
|
|
|
this.inventoriesUrl = optionUrls.inventories_url;
|
|
|
|
this.inventoryItemsUrl = optionUrls.inventory_items_url;
|
|
|
|
this.createConnectionUrl = optionUrls.create_url;
|
|
|
|
this.addRelationCallback = addRelationCallback;
|
2023-12-12 00:05:54 +08:00
|
|
|
this.notificationIconPath = notificationIconPath;
|
|
|
|
this.notification = notification;
|
2024-01-04 16:47:40 +08:00
|
|
|
this.canConnectRows = canConnectRows;
|
2023-12-21 18:57:52 +08:00
|
|
|
this.$nextTick(() => {
|
|
|
|
$(this.$refs.repositoryItemRelationshipsModal).modal('show');
|
|
|
|
});
|
2023-12-12 00:05:54 +08:00
|
|
|
|
2023-12-11 17:43:47 +08:00
|
|
|
if (['parent', 'child'].includes(relation)) {
|
|
|
|
this.selectedRelationshipValue = relation;
|
2023-11-12 18:21:05 +08:00
|
|
|
}
|
2023-12-11 17:43:47 +08:00
|
|
|
this.$nextTick(() => {
|
|
|
|
this.fetchInventories();
|
|
|
|
});
|
2023-11-12 18:21:05 +08:00
|
|
|
},
|
|
|
|
changeSelectedInventory(value) {
|
|
|
|
this.selectedInventoryValue = value;
|
2023-12-11 17:43:47 +08:00
|
|
|
this.itemOptions = [];
|
|
|
|
this.nextItemsPage = 1;
|
|
|
|
if (value) {
|
|
|
|
this.loadingItems = true;
|
|
|
|
this.itemParams = [`repository_id=${value}`];
|
|
|
|
}
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.fetchInventoryItems(value);
|
|
|
|
});
|
2023-11-12 18:21:05 +08:00
|
|
|
},
|
2023-12-11 17:43:47 +08:00
|
|
|
close() {
|
|
|
|
Object.assign(this.$data, {
|
|
|
|
selectedInventoryValue: null,
|
|
|
|
selectedItemValues: [],
|
|
|
|
selectedRelationshipValue: null,
|
|
|
|
nextInventoriesPage: 1,
|
|
|
|
nextItemsPage: 1,
|
|
|
|
inventoriesUrl: '',
|
|
|
|
inventoryItemsUrl: '',
|
|
|
|
createConnectionUrl: '',
|
|
|
|
itemOptions: [],
|
|
|
|
inventoryOptions: [],
|
|
|
|
itemParams: [],
|
2024-01-04 16:47:40 +08:00
|
|
|
canConnectRows: null
|
2023-12-11 17:43:47 +08:00
|
|
|
});
|
2023-11-12 18:21:05 +08:00
|
|
|
$(this.$refs.repositoryItemRelationshipsModal).modal('hide');
|
|
|
|
},
|
2023-12-11 17:43:47 +08:00
|
|
|
addRelation(relation) {
|
|
|
|
const $this = this;
|
|
|
|
$.ajax({
|
|
|
|
url: this.createConnectionUrl,
|
|
|
|
method: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
repository_row_connection: {
|
|
|
|
relation: this.selectedRelationshipValue,
|
|
|
|
relation_ids: this.selectedItemValues,
|
|
|
|
connection_repository_id: this.selectedInventoryValue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
success: (result) => {
|
|
|
|
$this.addRelationCallback(result, relation);
|
|
|
|
if ($('.dataTable')[0]) $('.dataTable').DataTable().ajax.reload(null, false);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
this.close();
|
2023-11-12 18:21:05 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|