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