Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
addcpm-json
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Александр Чаплыгин
addcpm-json
Commits
8eb49388
Commit
8eb49388
authored
Jan 31, 2019
by
Александр Чаплыгин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Оптимизроовал код по сортировке в таблицах отчетов
parent
54fa6062
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
99 deletions
+71
-99
script-feeds-stat-table.js
src/public/js/script-feeds-stat-table.js
+71
-99
No files found.
src/public/js/script-feeds-stat-table.js
View file @
8eb49388
...
...
@@ -8,7 +8,8 @@ $(document).ready(function(){
currentActiveLine
,
dataTable
,
currencyFields
=
[
'admoney'
,
'salemoney'
,
'usdollarmoney'
,
'localmoney'
,
'AdMoney'
,
'OrderSum'
,
'Price'
],
notFormatFields
=
[
'Timestamp'
,
'Basket'
];
notFormatFields
=
[
'Timestamp'
,
'Basket'
],
dateTimeFields
=
[
'Timestamp'
,
'period'
];
// Шаблон содержимого ячейки Basket
var
templateBasketContent
=
_
.
template
(
'
\
n'
+
...
...
@@ -59,12 +60,14 @@ $(document).ready(function(){
{
var
dataPeriod
=
dataLineChartStat
[
'period'
];
//dataTable = dataLineChartStat;
dataTable
=
dataLineChartStat
;
/*
dataTable = {};
for (var key in dataLineChartStat) {
dataTable[key] = dataLineChartStat[key];
}
//console.log('AAA dataTable = ', dataLineChartStat.report);
console.log('AAA dataTable = ', dataLineChartStat.report);
*/
// Сортировка строк в таблице:
var
...
...
@@ -77,107 +80,76 @@ $(document).ready(function(){
isDesc
=
$selectedField
.
hasClass
(
'desc'
);
}
if
(
sortField
)
{
//console.log('AAA sortField = ', sortField, ' isDesc = ', isDesc);
var
dataTableForSort
=
[];
dataTable
.
period
.
forEach
(
function
(
dataTableItem
,
ind
){
var
dataTableSortItem
=
{};
dataTableSortItem
[
'period'
]
=
dataTableItem
;
activeLines
.
forEach
(
function
(
activeLine
){
dataTableSortItem
[
activeLine
]
=
dataTable
[
activeLine
][
ind
];
});
dataTableForSort
.
push
(
dataTableSortItem
);
//console.log('AAA sortField = ', sortField, ' isDesc = ', isDesc);
if
(
!
sortField
)
{
switch
(
dataLineChartStat
.
report
)
{
case
'common'
:
sortField
=
'period'
;
isDesc
=
true
;
break
;
case
'transaction'
:
sortField
=
'Timestamp'
;
isDesc
=
true
;
break
;
default
:
sortField
=
'period'
;
isDesc
=
true
;
break
;
}
}
var
dataTableForSort
=
[];
dataTable
.
period
.
forEach
(
function
(
dataTableItem
,
ind
){
var
dataTableSortItem
=
{};
dataTableSortItem
[
'period'
]
=
dataTableItem
;
activeLines
.
forEach
(
function
(
activeLine
){
dataTableSortItem
[
activeLine
]
=
dataTable
[
activeLine
][
ind
];
});
//console.log('AAA dataTableForSort 111= ', dataTableForSort);
dataTableForSort
.
sort
(
function
(
a
,
b
){
if
(
sortField
==
'Timestamp'
)
{
dataTableForSort
.
push
(
dataTableSortItem
);
});
dataTableForSort
.
sort
(
function
(
a
,
b
){
if
(
dateTimeFields
.
indexOf
(
sortField
)
>
-
1
)
{
var
aT
=
new
Date
(
a
[
sortField
]),
bT
=
new
Date
(
b
[
sortField
]);
return
(
isDesc
)
?
bT
-
aT
:
aT
-
bT
;
}
else
{
return
(
isDesc
)
?
b
[
sortField
]
-
a
[
sortField
]
:
a
[
sortField
]
-
b
[
sortField
];
}
});
//console.log('AAA dataTableForSort = ', dataTableForSort);
dataTableForSort
.
forEach
(
function
(
item
){
$row
=
$
(
'<tr>'
);
$row
.
append
(
$
(
'<td>'
).
html
(
item
[
'period'
]));
activeLines
.
forEach
(
function
(
line
){
if
(
line
==
'Basket'
)
{
var
dataBasket
=
item
[
line
];
currentActiveLine
=
'Price'
;
$row
.
append
(
$
(
'<td class="'
+
line
+
'">'
).
append
(
templateBasketContent
({
data
:
dataBasket
,
formatPrice
:
valueFormat
})));
}
else
if
(
line
==
'Timestamp'
)
{
var
aT
=
new
Date
(
a
[
sortField
]),
bT
=
new
Date
(
b
[
sortField
]);
return
(
isDesc
)
?
bT
-
aT
:
aT
-
bT
;
dateTimeValue
=
item
[
line
].
split
(
' '
),
dateVal
=
dateTimeValue
[
0
],
timeVal
=
dateTimeValue
[
1
].
split
(
':'
),
timeValCorrected
=
timeVal
[
0
]
+
':'
+
timeVal
[
1
];
$row
.
append
(
$
(
'<td class="'
+
line
+
'">'
).
append
(
templateTimestampContent
({
data
:
{
date
:
dateVal
,
time
:
timeValCorrected
}
})));
}
else
{
if
(
isDesc
)
{
return
b
[
sortField
]
-
a
[
sortField
];
}
else
{
return
a
[
sortField
]
-
b
[
sortField
];
}
currentActiveLine
=
line
;
$row
.
append
(
$
(
'<td class="'
+
line
+
'">'
).
html
(
valueFormat
(
item
[
line
])));
}
});
//console.log('AAA dataTableForSort = ', dataTableForSort);
dataTableForSort
.
forEach
(
function
(
item
){
$row
=
$
(
'<tr>'
);
$row
.
append
(
$
(
'<td>'
).
html
(
item
[
'period'
]));
activeLines
.
forEach
(
function
(
line
){
if
(
line
==
'Basket'
)
{
var
dataBasket
=
item
[
line
];
currentActiveLine
=
'Price'
;
$row
.
append
(
$
(
'<td class="'
+
line
+
'">'
).
append
(
templateBasketContent
({
data
:
dataBasket
,
formatPrice
:
valueFormat
})));
}
else
if
(
line
==
'Timestamp'
)
{
var
dateTimeValue
=
item
[
line
].
split
(
' '
),
dateVal
=
dateTimeValue
[
0
],
timeVal
=
dateTimeValue
[
1
].
split
(
':'
),
timeValCorrected
=
timeVal
[
0
]
+
':'
+
timeVal
[
1
];
$row
.
append
(
$
(
'<td class="'
+
line
+
'">'
).
append
(
templateTimestampContent
({
data
:
{
date
:
dateVal
,
time
:
timeValCorrected
}
})));
}
else
{
currentActiveLine
=
line
;
$row
.
append
(
$
(
'<td class="'
+
line
+
'">'
).
html
(
valueFormat
(
item
[
line
])));
}
});
$row
.
appendTo
(
$tableContent
);
});
}
else
{
for
(
var
i
=
dataPeriod
.
length
-
1
;
i
>=
0
;
i
--
)
{
var
date
=
dataPeriod
[
i
],
values
=
{};
activeLines
.
forEach
(
function
(
activeLine
){
currentActiveLine
=
activeLine
;
values
[
activeLine
]
=
valueFormat
(
dataTable
[
activeLine
][
i
]);
});
$row
=
$
(
'<tr>'
);
$row
.
append
(
$
(
'<td>'
).
html
(
date
));
activeLines
.
forEach
(
function
(
item
){
if
(
item
==
'Basket'
)
{
var
dataBasket
=
values
[
item
];
currentActiveLine
=
'Price'
;
$row
.
append
(
$
(
'<td class="'
+
item
+
'">'
).
append
(
templateBasketContent
({
data
:
dataBasket
,
formatPrice
:
valueFormat
})));
}
else
if
(
item
==
'Timestamp'
)
{
var
dateTimeValue
=
values
[
item
].
split
(
' '
),
dateVal
=
dateTimeValue
[
0
],
timeVal
=
dateTimeValue
[
1
].
split
(
':'
),
timeValCorrected
=
timeVal
[
0
]
+
':'
+
timeVal
[
1
];
$row
.
append
(
$
(
'<td class="'
+
item
+
'">'
).
append
(
templateTimestampContent
({
data
:
{
date
:
dateVal
,
time
:
timeValCorrected
}
})));
}
else
{
$row
.
append
(
$
(
'<td class="'
+
item
+
'">'
).
html
(
values
[
item
]));
}
});
$row
.
appendTo
(
$tableContent
);
}
}
$row
.
appendTo
(
$tableContent
);
});
// Добавляем строку "Итого" для отчета 'common':
if
(
dataLineChartStat
.
report
==
'common'
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment