Merge remote-tracking branch 'origin/master'
This commit is contained in:
16
svc/main.go
16
svc/main.go
@@ -245,6 +245,22 @@ func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router
|
||||
wrapV3(routes.TestMailHandler(ml)),
|
||||
)
|
||||
|
||||
bindV3(r, pgDB,
|
||||
"/api/system/market-mail-mappings/lookups", "GET",
|
||||
"system", "update",
|
||||
wrapV3(routes.GetMarketMailMappingLookupsHandler(pgDB)),
|
||||
)
|
||||
bindV3(r, pgDB,
|
||||
"/api/system/market-mail-mappings", "GET",
|
||||
"system", "update",
|
||||
wrapV3(routes.GetMarketMailMappingsHandler(pgDB)),
|
||||
)
|
||||
bindV3(r, pgDB,
|
||||
"/api/system/market-mail-mappings/{marketId}", "PUT",
|
||||
"system", "update",
|
||||
wrapV3(routes.SaveMarketMailMappingHandler(pgDB)),
|
||||
)
|
||||
|
||||
// ============================================================
|
||||
// PERMISSIONS
|
||||
// ============================================================
|
||||
|
||||
26
svc/models/market_mail_mapping.go
Normal file
26
svc/models/market_mail_mapping.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
type MarketMailOption struct {
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
|
||||
type MarketOption struct {
|
||||
ID int64 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type MailOption struct {
|
||||
ID string `json:"id"`
|
||||
Email string `json:"email"`
|
||||
DisplayName string `json:"display_name"`
|
||||
}
|
||||
|
||||
type MarketMailMappingRow struct {
|
||||
MarketID int64 `json:"market_id"`
|
||||
MarketCode string `json:"market_code"`
|
||||
MarketTitle string `json:"market_title"`
|
||||
MailIDs []string `json:"mail_ids"`
|
||||
Mails []MarketMailOption `json:"mails"`
|
||||
}
|
||||
67
svc/queries/market_mail_mapping.go
Normal file
67
svc/queries/market_mail_mapping.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package queries
|
||||
|
||||
const GetActiveMarketsForMapping = `
|
||||
SELECT
|
||||
p.id,
|
||||
p.code,
|
||||
p.title
|
||||
FROM mk_sales_piy p
|
||||
WHERE p.is_active = true
|
||||
ORDER BY p.title, p.code
|
||||
`
|
||||
|
||||
const GetActiveMailsForMapping = `
|
||||
SELECT
|
||||
m.id::text,
|
||||
m.email,
|
||||
COALESCE(NULLIF(m.display_name, ''), m.email) AS display_name
|
||||
FROM mk_mail m
|
||||
WHERE m.is_active = true
|
||||
ORDER BY m.email
|
||||
`
|
||||
|
||||
const GetMarketMailMappingRows = `
|
||||
SELECT
|
||||
p.id,
|
||||
p.code,
|
||||
p.title,
|
||||
m.id::text,
|
||||
m.email,
|
||||
COALESCE(NULLIF(m.display_name, ''), m.email) AS display_name
|
||||
FROM mk_sales_piy p
|
||||
LEFT JOIN mk_market_mail mm
|
||||
ON mm.market_id = p.id
|
||||
LEFT JOIN mk_mail m
|
||||
ON m.id = mm.mail_id
|
||||
AND m.is_active = true
|
||||
WHERE p.is_active = true
|
||||
ORDER BY p.title, p.code, m.email
|
||||
`
|
||||
|
||||
const ExistsActiveMarketByID = `
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM mk_sales_piy p
|
||||
WHERE p.id = $1
|
||||
AND p.is_active = true
|
||||
)
|
||||
`
|
||||
|
||||
const ExistsActiveMailByID = `
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM mk_mail m
|
||||
WHERE m.id = $1
|
||||
AND m.is_active = true
|
||||
)
|
||||
`
|
||||
|
||||
const DeleteMarketMailsByMarketID = `
|
||||
DELETE FROM mk_market_mail
|
||||
WHERE market_id = $1
|
||||
`
|
||||
|
||||
const InsertMarketMailMapping = `
|
||||
INSERT INTO mk_market_mail (market_id, mail_id)
|
||||
VALUES ($1, $2)
|
||||
`
|
||||
244
svc/routes/market_mail_mapping.go
Normal file
244
svc/routes/market_mail_mapping.go
Normal file
@@ -0,0 +1,244 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bssapp-backend/models"
|
||||
"bssapp-backend/queries"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
type MarketMailSavePayload struct {
|
||||
MailIDs []string `json:"mail_ids"`
|
||||
}
|
||||
|
||||
type MarketMailLookupResponse struct {
|
||||
Markets []models.MarketOption `json:"markets"`
|
||||
Mails []models.MailOption `json:"mails"`
|
||||
}
|
||||
|
||||
func GetMarketMailMappingLookupsHandler(db *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
markets := make([]models.MarketOption, 0, 64)
|
||||
mails := make([]models.MailOption, 0, 128)
|
||||
|
||||
marketRows, err := db.Query(queries.GetActiveMarketsForMapping)
|
||||
if err != nil {
|
||||
http.Error(w, "markets lookup error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer marketRows.Close()
|
||||
|
||||
for marketRows.Next() {
|
||||
var item models.MarketOption
|
||||
if err := marketRows.Scan(&item.ID, &item.Code, &item.Title); err != nil {
|
||||
http.Error(w, "markets scan error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
markets = append(markets, item)
|
||||
}
|
||||
if err := marketRows.Err(); err != nil {
|
||||
http.Error(w, "markets rows error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
mailRows, err := db.Query(queries.GetActiveMailsForMapping)
|
||||
if err != nil {
|
||||
http.Error(w, "mails lookup error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer mailRows.Close()
|
||||
|
||||
for mailRows.Next() {
|
||||
var item models.MailOption
|
||||
if err := mailRows.Scan(&item.ID, &item.Email, &item.DisplayName); err != nil {
|
||||
http.Error(w, "mails scan error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
mails = append(mails, item)
|
||||
}
|
||||
if err := mailRows.Err(); err != nil {
|
||||
http.Error(w, "mails rows error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(MarketMailLookupResponse{
|
||||
Markets: markets,
|
||||
Mails: mails,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func GetMarketMailMappingsHandler(db *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
rows, err := db.Query(queries.GetMarketMailMappingRows)
|
||||
if err != nil {
|
||||
http.Error(w, "mapping query error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
byMarket := make(map[int64]*models.MarketMailMappingRow, 64)
|
||||
order := make([]int64, 0, 64)
|
||||
|
||||
for rows.Next() {
|
||||
var marketID int64
|
||||
var marketCode, marketTitle string
|
||||
var mailID sql.NullString
|
||||
var email sql.NullString
|
||||
var displayName sql.NullString
|
||||
|
||||
if err := rows.Scan(
|
||||
&marketID,
|
||||
&marketCode,
|
||||
&marketTitle,
|
||||
&mailID,
|
||||
&email,
|
||||
&displayName,
|
||||
); err != nil {
|
||||
http.Error(w, "mapping scan error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
row, ok := byMarket[marketID]
|
||||
if !ok {
|
||||
row = &models.MarketMailMappingRow{
|
||||
MarketID: marketID,
|
||||
MarketCode: marketCode,
|
||||
MarketTitle: marketTitle,
|
||||
MailIDs: make([]string, 0, 8),
|
||||
Mails: make([]models.MarketMailOption, 0, 8),
|
||||
}
|
||||
byMarket[marketID] = row
|
||||
order = append(order, marketID)
|
||||
}
|
||||
|
||||
if mailID.Valid && strings.TrimSpace(mailID.String) != "" {
|
||||
id := strings.TrimSpace(mailID.String)
|
||||
row.MailIDs = append(row.MailIDs, id)
|
||||
|
||||
label := strings.TrimSpace(displayName.String)
|
||||
if label == "" {
|
||||
label = strings.TrimSpace(email.String)
|
||||
}
|
||||
|
||||
row.Mails = append(row.Mails, models.MarketMailOption{
|
||||
ID: id,
|
||||
Label: label,
|
||||
})
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
http.Error(w, "mapping rows error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
list := make([]models.MarketMailMappingRow, 0, len(order))
|
||||
for _, marketID := range order {
|
||||
list = append(list, *byMarket[marketID])
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(list)
|
||||
}
|
||||
}
|
||||
|
||||
func SaveMarketMailMappingHandler(db *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
marketIDStr := mux.Vars(r)["marketId"]
|
||||
marketID, err := strconv.ParseInt(marketIDStr, 10, 64)
|
||||
if err != nil || marketID <= 0 {
|
||||
http.Error(w, "invalid market id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var payload MarketMailSavePayload
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
http.Error(w, "invalid payload", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var marketExists bool
|
||||
if err := db.QueryRow(queries.ExistsActiveMarketByID, marketID).Scan(&marketExists); err != nil {
|
||||
http.Error(w, "market validate error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if !marketExists {
|
||||
http.Error(w, "market not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
mailIDs := normalizeIDList(payload.MailIDs)
|
||||
for _, mailID := range mailIDs {
|
||||
var mailExists bool
|
||||
if err := db.QueryRow(queries.ExistsActiveMailByID, mailID).Scan(&mailExists); err != nil {
|
||||
http.Error(w, "mail validate error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if !mailExists {
|
||||
http.Error(w, "mail not found: "+mailID, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
http.Error(w, "transaction start error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
if _, err := tx.Exec(queries.DeleteMarketMailsByMarketID, marketID); err != nil {
|
||||
http.Error(w, "mapping delete error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for _, mailID := range mailIDs {
|
||||
if _, err := tx.Exec(queries.InsertMarketMailMapping, marketID, mailID); err != nil {
|
||||
http.Error(w, "mapping insert error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
http.Error(w, "transaction commit error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"success": true,
|
||||
"market_id": marketID,
|
||||
"mail_ids": mailIDs,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeIDList(ids []string) []string {
|
||||
seen := make(map[string]struct{}, len(ids))
|
||||
out := make([]string, 0, len(ids))
|
||||
|
||||
for _, raw := range ids {
|
||||
id := strings.TrimSpace(raw)
|
||||
if id == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[id]; ok {
|
||||
continue
|
||||
}
|
||||
seen[id] = struct{}{}
|
||||
out = append(out, id)
|
||||
}
|
||||
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
@@ -307,6 +307,12 @@ const menuItems = [
|
||||
label: 'Test Mail',
|
||||
to: '/app/test-mail',
|
||||
permission: 'system:update'
|
||||
},
|
||||
|
||||
{
|
||||
label: 'Piyasa Mail Eşleştirme',
|
||||
to: '/app/market-mail-mapping',
|
||||
permission: 'system:update'
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
@@ -444,6 +444,15 @@ function formatAmount(value, fraction = 2) {
|
||||
|
||||
<style scoped>
|
||||
.statement-page {
|
||||
--lvl1-top: 0px;
|
||||
--lvl1-h: 30px;
|
||||
--lvl2-h: 30px;
|
||||
--lvl3-h: 30px;
|
||||
--lvl3-shift-up: 78px;
|
||||
--lvl2-top: calc(var(--lvl1-top) + var(--lvl1-h));
|
||||
--lvl3-top: calc(var(--lvl2-top) + var(--lvl2-h));
|
||||
--lvl4-top: calc(var(--lvl3-top) + var(--lvl3-h));
|
||||
|
||||
height: calc(100vh - 56px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -505,8 +514,8 @@ function formatAmount(value, fraction = 2) {
|
||||
|
||||
.statement-table :deep(.header-row th) {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 30;
|
||||
top: var(--lvl1-top);
|
||||
z-index: 40;
|
||||
background: var(--q-primary);
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
@@ -532,11 +541,13 @@ function formatAmount(value, fraction = 2) {
|
||||
}
|
||||
|
||||
.currency-groups {
|
||||
position: relative;
|
||||
padding: 6px;
|
||||
background: #f8faff;
|
||||
}
|
||||
|
||||
.currency-group {
|
||||
position: relative;
|
||||
border-left: 4px solid var(--q-secondary);
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.08);
|
||||
border-right: 1px solid rgba(0, 0, 0, 0.08);
|
||||
@@ -547,8 +558,8 @@ function formatAmount(value, fraction = 2) {
|
||||
|
||||
.currency-level-head {
|
||||
position: sticky;
|
||||
top: 36px;
|
||||
z-index: 26;
|
||||
top: var(--lvl2-top);
|
||||
z-index: 34;
|
||||
display: grid;
|
||||
grid-template-columns: 48px 100px 80px 1.2fr 1.2fr 1.1fr 1.1fr 100px 110px 140px;
|
||||
align-items: center;
|
||||
@@ -562,8 +573,8 @@ function formatAmount(value, fraction = 2) {
|
||||
|
||||
.currency-group-header {
|
||||
position: sticky;
|
||||
top: 72px;
|
||||
z-index: 24;
|
||||
top: var(--lvl3-top);
|
||||
z-index: 32;
|
||||
display: grid;
|
||||
grid-template-columns: 48px 100px 80px 1.2fr 1.2fr 1.1fr 1.1fr 100px 110px 140px;
|
||||
align-items: center;
|
||||
@@ -619,14 +630,20 @@ function formatAmount(value, fraction = 2) {
|
||||
line-height: 1.2 !important;
|
||||
}
|
||||
|
||||
.detail-subtable :deep(.q-table__container),
|
||||
.detail-subtable :deep(.q-table__middle) {
|
||||
overflow: visible !important;
|
||||
max-height: none !important;
|
||||
}
|
||||
|
||||
.detail-subtable :deep(.q-table__top) {
|
||||
position: static;
|
||||
}
|
||||
|
||||
.detail-subtable :deep(thead th) {
|
||||
position: sticky;
|
||||
top: 72px;
|
||||
z-index: 22;
|
||||
top: calc(var(--lvl3-top) - var(--lvl3-shift-up));
|
||||
z-index: 35;
|
||||
background: #1f3b5b;
|
||||
color: #fff;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
|
||||
|
||||
216
ui/src/pages/MarketMailMapping.vue
Normal file
216
ui/src/pages/MarketMailMapping.vue
Normal file
@@ -0,0 +1,216 @@
|
||||
<template>
|
||||
<q-page v-if="canUpdateSystem" class="q-pa-md">
|
||||
<div class="row justify-end q-mb-md">
|
||||
<q-btn
|
||||
color="primary"
|
||||
icon="save"
|
||||
label="Degisiklikleri Kaydet"
|
||||
:loading="store.saving"
|
||||
:disable="!hasChanges"
|
||||
@click="saveChanges"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<q-table
|
||||
flat
|
||||
bordered
|
||||
dense
|
||||
row-key="market_id"
|
||||
:loading="store.loading"
|
||||
:rows="store.rows"
|
||||
:columns="columns"
|
||||
:rows-per-page-options="[0]"
|
||||
:pagination="{ rowsPerPage: 0 }"
|
||||
>
|
||||
<template #body-cell-mail_selector="props">
|
||||
<q-td :props="props">
|
||||
<q-select
|
||||
:model-value="editableByMarket[props.row.market_id] || []"
|
||||
:options="mailOptionsByMarket[props.row.market_id] || allMailOptions"
|
||||
option-value="id"
|
||||
option-label="label"
|
||||
emit-value
|
||||
map-options
|
||||
multiple
|
||||
use-chips
|
||||
use-input
|
||||
input-debounce="0"
|
||||
clearable
|
||||
dense
|
||||
outlined
|
||||
label="Mail ara ve sec"
|
||||
@filter="(val, update) => filterMailOptions(props.row.market_id, val, update)"
|
||||
@update:model-value="(val) => updateRowSelection(props.row.market_id, val)"
|
||||
/>
|
||||
</q-td>
|
||||
</template>
|
||||
</q-table>
|
||||
</q-page>
|
||||
|
||||
<q-page v-else class="q-pa-md flex flex-center">
|
||||
<div class="text-negative text-subtitle1">
|
||||
Bu module erisim yetkiniz yok.
|
||||
</div>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { usePermission } from 'src/composables/usePermission'
|
||||
import { useMarketMailMappingStore } from 'src/stores/marketMailMappingStore'
|
||||
|
||||
const $q = useQuasar()
|
||||
const store = useMarketMailMappingStore()
|
||||
|
||||
const { canUpdate } = usePermission()
|
||||
const canUpdateSystem = canUpdate('system')
|
||||
|
||||
const editableByMarket = ref({})
|
||||
const originalByMarket = ref({})
|
||||
const mailOptionsByMarket = ref({})
|
||||
|
||||
const columns = [
|
||||
{
|
||||
name: 'market_code',
|
||||
label: 'Piyasa Kodu',
|
||||
field: 'market_code',
|
||||
align: 'left'
|
||||
},
|
||||
{
|
||||
name: 'market_title',
|
||||
label: 'Piyasa',
|
||||
field: 'market_title',
|
||||
align: 'left'
|
||||
},
|
||||
{
|
||||
name: 'mail_selector',
|
||||
label: 'Mail Eslestirme',
|
||||
field: 'mail_selector',
|
||||
align: 'left'
|
||||
}
|
||||
]
|
||||
|
||||
const allMailOptions = computed(() =>
|
||||
(store.mails || []).map((m) => ({
|
||||
id: m.id,
|
||||
label: m.display_name || m.email
|
||||
}))
|
||||
)
|
||||
|
||||
const changedMarketIds = computed(() => {
|
||||
return (store.rows || [])
|
||||
.map((r) => Number(r.market_id))
|
||||
.filter((marketId) => {
|
||||
const current = normalizeList(editableByMarket.value[marketId] || [])
|
||||
const original = normalizeList(originalByMarket.value[marketId] || [])
|
||||
return !isEqualList(current, original)
|
||||
})
|
||||
})
|
||||
|
||||
const hasChanges = computed(() => changedMarketIds.value.length > 0)
|
||||
|
||||
function normalizeList (list) {
|
||||
return Array.from(
|
||||
new Set(
|
||||
(Array.isArray(list) ? list : [])
|
||||
.map((x) => String(x).trim())
|
||||
.filter(Boolean)
|
||||
)
|
||||
).sort()
|
||||
}
|
||||
|
||||
function isEqualList (a, b) {
|
||||
if (a.length !== b.length) return false
|
||||
for (let i = 0; i < a.length; i += 1) {
|
||||
if (a[i] !== b[i]) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function initEditableState () {
|
||||
const editable = {}
|
||||
const original = {}
|
||||
|
||||
;(store.rows || []).forEach((row) => {
|
||||
const marketId = Number(row.market_id)
|
||||
const selected = normalizeList(row.mail_ids || [])
|
||||
editable[marketId] = [...selected]
|
||||
original[marketId] = [...selected]
|
||||
})
|
||||
|
||||
editableByMarket.value = editable
|
||||
originalByMarket.value = original
|
||||
mailOptionsByMarket.value = {}
|
||||
}
|
||||
|
||||
function updateRowSelection (marketId, newValue) {
|
||||
editableByMarket.value = {
|
||||
...editableByMarket.value,
|
||||
[Number(marketId)]: normalizeList(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
function filterMailOptions (marketId, search, update) {
|
||||
update(() => {
|
||||
const q = String(search || '').trim().toLowerCase()
|
||||
if (!q) {
|
||||
mailOptionsByMarket.value = {
|
||||
...mailOptionsByMarket.value,
|
||||
[Number(marketId)]: allMailOptions.value
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const filtered = allMailOptions.value.filter((opt) =>
|
||||
String(opt.label || '').toLowerCase().includes(q)
|
||||
)
|
||||
|
||||
mailOptionsByMarket.value = {
|
||||
...mailOptionsByMarket.value,
|
||||
[Number(marketId)]: filtered
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function init () {
|
||||
try {
|
||||
await Promise.all([
|
||||
store.fetchLookups(),
|
||||
store.fetchRows()
|
||||
])
|
||||
initEditableState()
|
||||
} catch (err) {
|
||||
$q.notify({
|
||||
type: 'negative',
|
||||
message: err?.message || 'Piyasa-mail verileri yuklenemedi'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function saveChanges () {
|
||||
if (!hasChanges.value) return
|
||||
|
||||
try {
|
||||
for (const marketId of changedMarketIds.value) {
|
||||
await store.saveMarketMails(marketId, editableByMarket.value[marketId] || [])
|
||||
}
|
||||
await store.fetchRows()
|
||||
initEditableState()
|
||||
|
||||
$q.notify({
|
||||
type: 'positive',
|
||||
message: 'Degisiklikler kaydedildi'
|
||||
})
|
||||
} catch (err) {
|
||||
$q.notify({
|
||||
type: 'negative',
|
||||
message: err?.message || 'Kayit hatasi'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
init()
|
||||
})
|
||||
</script>
|
||||
@@ -222,6 +222,13 @@ const routes = [
|
||||
meta: { permission: 'system:update' }
|
||||
},
|
||||
|
||||
{
|
||||
path: 'market-mail-mapping',
|
||||
name: 'market-mail-mapping',
|
||||
component: () => import('../pages/MarketMailMapping.vue'),
|
||||
meta: { permission: 'system:update' }
|
||||
},
|
||||
|
||||
|
||||
/* ================= ORDERS ================= */
|
||||
|
||||
|
||||
48
ui/src/stores/marketMailMappingStore.js
Normal file
48
ui/src/stores/marketMailMappingStore.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import api from 'src/services/api'
|
||||
|
||||
export const useMarketMailMappingStore = defineStore('marketMailMapping', {
|
||||
state: () => ({
|
||||
loading: false,
|
||||
saving: false,
|
||||
markets: [],
|
||||
mails: [],
|
||||
rows: []
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async fetchLookups () {
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await api.get('/system/market-mail-mappings/lookups')
|
||||
const payload = res?.data || {}
|
||||
this.markets = Array.isArray(payload.markets) ? payload.markets : []
|
||||
this.mails = Array.isArray(payload.mails) ? payload.mails : []
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
async fetchRows () {
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await api.get('/system/market-mail-mappings')
|
||||
this.rows = Array.isArray(res?.data) ? res.data : []
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
async saveMarketMails (marketId, mailIds) {
|
||||
this.saving = true
|
||||
try {
|
||||
await api.put(`/system/market-mail-mappings/${marketId}`, {
|
||||
mail_ids: Array.isArray(mailIds) ? mailIds : []
|
||||
})
|
||||
} finally {
|
||||
this.saving = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user