2025-05-06 06:45:49 +00:00
|
|
|
|
import { DataType } from 'devextreme/common'
|
|
|
|
|
|
import { PivotGridDataType } from 'devextreme/ui/pivot_grid/data_source'
|
2025-08-12 08:39:06 +00:00
|
|
|
|
import { MULTIVALUE_DELIMITER } from '../../constants/app.constant'
|
2025-09-28 20:22:18 +00:00
|
|
|
|
import { ChartSeriesDto } from '@/proxy/admin/charts/models'
|
2025-05-06 06:45:49 +00:00
|
|
|
|
|
2025-09-18 22:09:58 +00:00
|
|
|
|
export interface GridExtraFilterState {
|
|
|
|
|
|
fieldName: string
|
|
|
|
|
|
operator: string
|
|
|
|
|
|
controlType: string
|
|
|
|
|
|
value: string
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-06 06:45:49 +00:00
|
|
|
|
// sayfaya dinamik olarak css style ekler
|
|
|
|
|
|
export function addCss(css: string) {
|
|
|
|
|
|
if (css.startsWith('http') || css.startsWith('/')) {
|
|
|
|
|
|
const style = document.createElement('link')
|
|
|
|
|
|
style.rel = 'stylesheet'
|
|
|
|
|
|
style.href = css
|
|
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(style)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const style = document.createElement('style')
|
|
|
|
|
|
style.type = 'text/css'
|
|
|
|
|
|
style.innerHTML = css
|
|
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(style)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// sayfaya dinamik olarak js ekler
|
|
|
|
|
|
export function addJs(js: string) {
|
|
|
|
|
|
if (js.startsWith('http') || js.startsWith('/')) {
|
|
|
|
|
|
const script = document.createElement('script')
|
|
|
|
|
|
script.type = 'text/javascript'
|
|
|
|
|
|
script.src = js
|
|
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(script)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
eval(js)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function controlStyleCondition(data: any, fieldName: any, style: any) {
|
|
|
|
|
|
// condition sadece data satırlarında yapılır
|
|
|
|
|
|
if (style.rowType != 'data') return true
|
|
|
|
|
|
|
|
|
|
|
|
switch (style.condition) {
|
|
|
|
|
|
case '=':
|
|
|
|
|
|
return style.conditionValue == data[fieldName]
|
|
|
|
|
|
case '<>':
|
|
|
|
|
|
return style.conditionValue != data[fieldName]
|
|
|
|
|
|
case '<':
|
|
|
|
|
|
return style.conditionValue > data[fieldName]
|
|
|
|
|
|
case '<=':
|
|
|
|
|
|
return style.conditionValue >= data[fieldName]
|
|
|
|
|
|
case '>':
|
|
|
|
|
|
return style.conditionValue < data[fieldName]
|
|
|
|
|
|
case '>=':
|
|
|
|
|
|
return style.conditionValue <= data[fieldName]
|
|
|
|
|
|
case 'contains':
|
|
|
|
|
|
return data[fieldName].includes(style.conditionValue)
|
|
|
|
|
|
case 'endswith':
|
|
|
|
|
|
return data[fieldName].endsWith(style.conditionValue)
|
|
|
|
|
|
case 'isblank':
|
|
|
|
|
|
return data[fieldName] == null
|
|
|
|
|
|
case 'isnotblank':
|
|
|
|
|
|
return data[fieldName] != null
|
|
|
|
|
|
case 'notcontains':
|
|
|
|
|
|
return data[fieldName].indexOf(style.conditionValue) === -1
|
|
|
|
|
|
case 'startswith':
|
|
|
|
|
|
return data[fieldName].startsWith(style.conditionValue)
|
|
|
|
|
|
case 'between':
|
|
|
|
|
|
return false // TODO:
|
|
|
|
|
|
case 'anyof': // anyof icin style.conditionValue obje olmalıdır: ['Val1','Val2']
|
|
|
|
|
|
return JSON.parse(style.conditionValue).some(data[fieldName])
|
|
|
|
|
|
case 'noneof': // noneof icin style.conditionValue obje olmalıdır: ['Val1','Val2']
|
|
|
|
|
|
return JSON.parse(style.conditionValue).findIndex((el: any) => el == data[fieldName]) < 0
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function pivotFieldConvertDataType(fieldDbType?: DataType): PivotGridDataType {
|
|
|
|
|
|
switch (fieldDbType) {
|
|
|
|
|
|
case 'date':
|
|
|
|
|
|
case 'datetime':
|
|
|
|
|
|
return 'date'
|
|
|
|
|
|
case 'number':
|
|
|
|
|
|
return 'number'
|
|
|
|
|
|
case 'boolean':
|
|
|
|
|
|
return 'number'
|
|
|
|
|
|
case 'object':
|
|
|
|
|
|
case 'string':
|
|
|
|
|
|
return 'string'
|
|
|
|
|
|
default:
|
|
|
|
|
|
return 'string'
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function setGridPanelColor(color: any) {
|
|
|
|
|
|
const pnl = document.getElementsByClassName(
|
|
|
|
|
|
'dx-datagrid-header-panel',
|
|
|
|
|
|
) as HTMLCollectionOf<HTMLElement>
|
|
|
|
|
|
if (pnl?.length) {
|
|
|
|
|
|
pnl[0].style.backgroundColor = color
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// CustomStore icerisindeki insert, update ve delete islemleri icin servis adresini olusturur
|
|
|
|
|
|
export function getServiceAddress(value: string) {
|
|
|
|
|
|
if (value && value.startsWith('http')) return value
|
|
|
|
|
|
if (value && value.startsWith('/')) value = value.slice(1)
|
|
|
|
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function isNotEmpty(value: any) {
|
|
|
|
|
|
return value !== undefined && value !== null && value !== ''
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getLoadOptions(loadOptions: any, params: any) {
|
|
|
|
|
|
// Muhtemel loadOptions'lar
|
|
|
|
|
|
;[
|
|
|
|
|
|
'skip',
|
|
|
|
|
|
'take',
|
|
|
|
|
|
'sort',
|
|
|
|
|
|
'totalSummary',
|
|
|
|
|
|
'requireTotalCount',
|
|
|
|
|
|
'searchOperation',
|
|
|
|
|
|
'filter',
|
|
|
|
|
|
'group',
|
|
|
|
|
|
'groupSummary',
|
|
|
|
|
|
'requireGroupCount',
|
|
|
|
|
|
'parentIds',
|
|
|
|
|
|
'searchExpr',
|
|
|
|
|
|
'searchValue',
|
|
|
|
|
|
'select',
|
|
|
|
|
|
'userData',
|
2025-09-28 20:22:18 +00:00
|
|
|
|
'chart',
|
2025-05-06 06:45:49 +00:00
|
|
|
|
].forEach(function (i) {
|
|
|
|
|
|
//if (i in loadOptions && isNotEmpty(loadOptions[i])) {
|
|
|
|
|
|
// params[i] = JSON.stringify(loadOptions[i]);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if (i in loadOptions && isNotEmpty(loadOptions[i])) {
|
|
|
|
|
|
if (i == 'skip') {
|
|
|
|
|
|
params.skip = loadOptions[i]
|
|
|
|
|
|
} else if (i == 'take') {
|
|
|
|
|
|
params.take = loadOptions[i]
|
|
|
|
|
|
} else if (i == 'sort') {
|
|
|
|
|
|
//Gelen veri yapisi: [{ selector: 'CultureName', desc: false }, { selector: 'X', desc: true }]
|
|
|
|
|
|
params.sort = loadOptions[i]
|
|
|
|
|
|
.map((x: any) => `${x.selector} ${x.desc ? 'desc' : 'asc'}`)
|
|
|
|
|
|
.join(MULTIVALUE_DELIMITER)
|
|
|
|
|
|
} else if (i == 'totalSummary') {
|
|
|
|
|
|
//gelen veri yapisi: [{"selector":"OrderNumber","summaryType":"count"},{"selector":"SaleAmount","summaryType":"sum"}]
|
|
|
|
|
|
params.totalSummary = loadOptions[i]
|
|
|
|
|
|
.map((x: any) => `${x.selector} ${x.summaryType}`)
|
|
|
|
|
|
.join(MULTIVALUE_DELIMITER)
|
|
|
|
|
|
} else if (i == 'requireTotalCount') {
|
|
|
|
|
|
params.requireTotalCount = loadOptions[i]
|
|
|
|
|
|
} else if (i == 'searchOperation') {
|
|
|
|
|
|
params.searchOperation = loadOptions[i]
|
|
|
|
|
|
} else if (i == 'filter') {
|
|
|
|
|
|
//[
|
|
|
|
|
|
// ["dataField", "=", 10],
|
|
|
|
|
|
// "and",
|
|
|
|
|
|
// [
|
|
|
|
|
|
// ["anotherDataField", "<", 3],
|
|
|
|
|
|
// "or",
|
|
|
|
|
|
// ["anotherDataField", ">", 11]
|
|
|
|
|
|
// ]
|
|
|
|
|
|
//]
|
|
|
|
|
|
//console.log('filter', loadOptions)
|
|
|
|
|
|
params.filter = loadOptions[i]
|
|
|
|
|
|
} else if (i == 'requireGroupCount') {
|
|
|
|
|
|
params.requireGroupCount = loadOptions[i]
|
|
|
|
|
|
}
|
|
|
|
|
|
// Yukaridakiler servis tarafinda da implemente edildi //
|
|
|
|
|
|
else if (i == 'group') {
|
|
|
|
|
|
//Gelen veri yapisi:
|
|
|
|
|
|
// [{ selector: 'CultureName', desc: false }, { selector: 'X', groupInterval: 'year', desc: true }]
|
|
|
|
|
|
// GroupInterval sadece tarihlerde var
|
|
|
|
|
|
//group Interval türleri: HeaderFilterGroupInterval
|
|
|
|
|
|
//console.log('group:', loadOptions[i])
|
|
|
|
|
|
params.group = loadOptions[i]
|
|
|
|
|
|
.map(
|
|
|
|
|
|
(x: any) =>
|
|
|
|
|
|
`${x.selector} ${x.desc ? 'desc' : 'asc'} ${x.isExpanded}${
|
|
|
|
|
|
x.groupInterval ? ' ' + x.groupInterval : ''
|
|
|
|
|
|
}`,
|
|
|
|
|
|
)
|
|
|
|
|
|
.join(MULTIVALUE_DELIMITER)
|
|
|
|
|
|
// => CultureName asc false|TextDate asc false year
|
|
|
|
|
|
} else if (i == 'groupSummary') {
|
|
|
|
|
|
//Gelen veri yapisi: [{"selector":"Id","summaryType":"count"}]
|
|
|
|
|
|
//Not: Birden fazla eleman ile karsilasilmadi
|
|
|
|
|
|
params.groupSummary = loadOptions[i]
|
|
|
|
|
|
.map((x: any) => `${x.selector} ${x.summaryType}`)
|
|
|
|
|
|
.join(MULTIVALUE_DELIMITER)
|
|
|
|
|
|
// => SalesAmount sum|SalesAmount avg
|
|
|
|
|
|
}
|
|
|
|
|
|
//else if (i == 'userData') {
|
|
|
|
|
|
// params.searchOperation = loadOptions[i];
|
|
|
|
|
|
// console.log('userData: ', loadOptions[i]);
|
|
|
|
|
|
//}
|
|
|
|
|
|
else if (i == 'searchValue') {
|
|
|
|
|
|
params.searchValue = loadOptions[i]
|
|
|
|
|
|
} else if (i == 'searchExpr') {
|
|
|
|
|
|
params.searchExpr = loadOptions[i]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FormEditingExtraItem
|
|
|
|
|
|
// Devexpress Gridde kaydete basılınca
|
|
|
|
|
|
// formda gözükecek olan EditingFormDto.Items elemanları gelmiyor
|
|
|
|
|
|
// Sadece grid'de tanımlanmış columnları getiriyor.
|
|
|
|
|
|
// Bu elemanları da getirmesi için aşağıdaki şekilde,
|
|
|
|
|
|
// JSON value varsa bunları kendi field'ına setliyoruz
|
|
|
|
|
|
export function setFormEditingExtraItemValues(values: any) {
|
|
|
|
|
|
var jsonFields: Record<string, Record<string, string>> = {}
|
|
|
|
|
|
// jsonField örn:
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Options: {
|
|
|
|
|
|
// TemplateName: 1,
|
|
|
|
|
|
// MailTemplate: 2
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
Object.keys(values).forEach((key) => {
|
|
|
|
|
|
if (key.includes(':')) {
|
|
|
|
|
|
const fieldData = key.split(':') // Options:TemplateName
|
|
|
|
|
|
if (!jsonFields[fieldData[0]]) {
|
|
|
|
|
|
jsonFields[fieldData[0]] = {}
|
|
|
|
|
|
}
|
|
|
|
|
|
jsonFields[fieldData[0]][fieldData[1]] = values[key]
|
|
|
|
|
|
delete values[key]
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
Object.keys(jsonFields).forEach((jsonField) => {
|
|
|
|
|
|
values[jsonField] = JSON.stringify(jsonFields[jsonField])
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
}
|
2025-09-28 20:22:18 +00:00
|
|
|
|
|
|
|
|
|
|
export function buildSeriesDto(seriesList: ChartSeriesDto[]) {
|
|
|
|
|
|
if (!seriesList || seriesList.length === 0) return []
|
|
|
|
|
|
|
|
|
|
|
|
// her seri için dto oluştur
|
|
|
|
|
|
return seriesList.map((s) => ({
|
|
|
|
|
|
...s,
|
|
|
|
|
|
argumentField: 'ArgumentField',
|
|
|
|
|
|
valueField: s.name,
|
|
|
|
|
|
}))
|
|
|
|
|
|
}
|