Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-06-19 23:37:47 +03:00
parent 10c173d41d
commit c0b6214ce6

View File

@@ -2,8 +2,8 @@
<q-page v-if="canUpdateSystem" class="q-pa-md">
<div class="row items-center justify-between q-mb-md">
<div>
<div class="text-h6">Kullanici Fiyat Grubu Eslestirme</div>
<div class="text-caption text-grey-7">Fiyat Listesi ekraninda kullanicinin gorebilecegi fiyat gruplarini belirler.</div>
<div class="text-h6">Fiyat Grubu Kullanici Eslestirme</div>
<div class="text-caption text-grey-7">Sol tarafta fiyat grubu, sagda o grubu gorebilecek kullanicilar yer alir.</div>
</div>
<q-btn
color="primary"
@@ -19,18 +19,18 @@
flat
bordered
dense
row-key="user_id"
row-key="value"
:loading="store.loading"
:rows="store.rows"
:rows="priceGroupRows"
:columns="columns"
:rows-per-page-options="[0]"
:pagination="{ rowsPerPage: 0 }"
>
<template #body-cell-price_groups="props">
<template #body-cell-users="props">
<q-td :props="props">
<q-select
:model-value="editableByUser[props.row.user_id] || []"
:options="store.priceGroupOptions"
:model-value="editableByGroup[props.row.value] || []"
:options="userOptions"
option-value="value"
option-label="label"
emit-value
@@ -40,14 +40,14 @@
clearable
dense
outlined
label="Fiyat gruplari"
@update:model-value="(val) => updateRowSelection(props.row.user_id, val)"
label="Kullanicilar"
@update:model-value="(val) => updateGroupSelection(props.row.value, val)"
>
<template #before-options>
<q-item clickable @click="selectAll(props.row.user_id)">
<q-item-section>Tumunu Sec</q-item-section>
<q-item clickable @click="selectAll(props.row.value)">
<q-item-section>Tum Kullanicilari Sec</q-item-section>
</q-item>
<q-item clickable @click="clearAll(props.row.user_id)">
<q-item clickable @click="clearAll(props.row.value)">
<q-item-section>Temizle</q-item-section>
</q-item>
<q-separator />
@@ -76,30 +76,52 @@ const store = useOrderPriceListUserPriceGroupStore()
const { canUpdate } = usePermission()
const canUpdateSystem = canUpdate('system')
const editableByUser = ref({})
const originalByUser = ref({})
const editableByGroup = ref({})
const originalByGroup = ref({})
const columns = [
{ name: 'username', label: 'Kullanici Kodu', field: 'username', align: 'left', sortable: true },
{ name: 'full_name', label: 'Ad Soyad', field: 'full_name', align: 'left', sortable: true },
{ name: 'email', label: 'E-Posta', field: 'email', align: 'left' },
{ name: 'price_groups', label: 'Gorebilecegi Fiyat Gruplari', field: 'price_groups', align: 'left' }
{ name: 'price_group', label: 'Fiyat Grubu', field: 'label', align: 'left', sortable: true },
{ name: 'users', label: 'Bu Fiyat Grubunu Gorebilen Kullanicilar', field: 'users', align: 'left' }
]
const changedUsers = computed(() => {
const priceGroupRows = computed(() => store.priceGroupOptions || [])
const userOptions = computed(() => {
return (store.rows || [])
.map((r) => Number(r.user_id || 0))
.map((row) => {
const id = Number(row.user_id || 0)
if (!id) return null
const username = String(row.username || '').trim()
const fullName = String(row.full_name || '').trim()
const email = String(row.email || '').trim()
const details = [fullName, email].filter(Boolean).join(' - ')
return {
value: id,
label: details ? `${username || id} (${details})` : String(username || id)
}
})
.filter(Boolean)
.filter((id) => !isEqualList(normalizeList(editableByUser.value[id] || []), normalizeList(originalByUser.value[id] || [])))
})
const hasChanges = computed(() => changedUsers.value.length > 0)
const changedGroups = computed(() => {
return (store.priceGroupOptions || [])
.map((r) => String(r.value || '').trim())
.filter(Boolean)
.filter((group) => !isEqualList(normalizeUserIdList(editableByGroup.value[group] || []), normalizeUserIdList(originalByGroup.value[group] || [])))
})
function normalizeList (list) {
const hasChanges = computed(() => changedGroups.value.length > 0)
function normalizePriceGroupList (list) {
const allowed = new Set((store.priceGroupOptions || []).map((x) => x.value))
return Array.from(new Set((Array.isArray(list) ? list : []).map((x) => String(x).trim()).filter((x) => allowed.has(x)))).sort()
}
function normalizeUserIdList (list) {
const allowed = new Set(userOptions.value.map((x) => x.value))
return Array.from(new Set((Array.isArray(list) ? list : []).map((x) => Number(x || 0)).filter((x) => allowed.has(x)))).sort((a, b) => a - b)
}
function isEqualList (a, b) {
if (a.length !== b.length) return false
for (let i = 0; i < a.length; i += 1) {
@@ -111,29 +133,68 @@ function isEqualList (a, b) {
function initEditableState () {
const editable = {}
const original = {}
for (const option of store.priceGroupOptions || []) {
const group = String(option.value || '').trim()
if (!group) continue
editable[group] = []
original[group] = []
}
for (const row of store.rows || []) {
const id = Number(row.user_id || 0)
if (!id) continue
const selected = normalizeList(row.price_groups || [])
editable[id] = [...selected]
original[id] = [...selected]
for (const group of normalizePriceGroupList(row.price_groups || [])) {
editable[group] = normalizeUserIdList([...(editable[group] || []), id])
original[group] = normalizeUserIdList([...(original[group] || []), id])
}
}
editableByUser.value = editable
originalByUser.value = original
editableByGroup.value = editable
originalByGroup.value = original
}
function updateRowSelection (userId, newValue) {
const id = Number(userId || 0)
if (!id) return
editableByUser.value = { ...editableByUser.value, [id]: normalizeList(newValue) }
function updateGroupSelection (priceGroup, newValue) {
const group = String(priceGroup || '').trim()
if (!group) return
editableByGroup.value = { ...editableByGroup.value, [group]: normalizeUserIdList(newValue) }
}
function selectAll (userId) {
updateRowSelection(userId, store.priceGroupOptions.map((x) => x.value))
function selectAll (priceGroup) {
updateGroupSelection(priceGroup, userOptions.value.map((x) => x.value))
}
function clearAll (userId) {
updateRowSelection(userId, [])
function clearAll (priceGroup) {
updateGroupSelection(priceGroup, [])
}
function buildUserPriceGroupsFromGroupState () {
const byUser = {}
for (const user of userOptions.value) {
byUser[user.value] = []
}
for (const group of Object.keys(editableByGroup.value || {})) {
for (const userId of normalizeUserIdList(editableByGroup.value[group] || [])) {
byUser[userId] = normalizePriceGroupList([...(byUser[userId] || []), group])
}
}
return byUser
}
function buildOriginalUserPriceGroups () {
const byUser = {}
for (const row of store.rows || []) {
const id = Number(row.user_id || 0)
if (!id) continue
byUser[id] = normalizePriceGroupList(row.price_groups || [])
}
return byUser
}
function changedUserIdsFromGroupState () {
const nextByUser = buildUserPriceGroupsFromGroupState()
const originalByUser = buildOriginalUserPriceGroups()
return Object.keys(nextByUser)
.map((id) => Number(id || 0))
.filter(Boolean)
.filter((id) => !isEqualList(normalizePriceGroupList(nextByUser[id] || []), normalizePriceGroupList(originalByUser[id] || [])))
}
async function init () {
@@ -148,8 +209,9 @@ async function init () {
async function saveChanges () {
if (!hasChanges.value) return
try {
for (const id of changedUsers.value) {
await store.saveUserPriceGroups(id, editableByUser.value[id] || [])
const nextByUser = buildUserPriceGroupsFromGroupState()
for (const id of changedUserIdsFromGroupState()) {
await store.saveUserPriceGroups(id, nextByUser[id] || [])
}
await store.fetchRows()
initEditableState()