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
4598a772
Commit
4598a772
authored
Mar 22, 2020
by
Александр Чаплыгин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Таблица статистики по кампании
parent
d27cae25
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
22 deletions
+103
-22
styles-amsystem.css
src/public/css/styles-amsystem.css
+1
-1
amsystem-campaign.js
src/public/js/adm/amsystem-campaign.js
+102
-21
No files found.
src/public/css/styles-amsystem.css
View file @
4598a772
...
@@ -250,7 +250,7 @@ textarea#campaign-stat-cats
...
@@ -250,7 +250,7 @@ textarea#campaign-stat-cats
text-align
:
center
;
text-align
:
center
;
}
}
#graph-stat
#
chart-
graph-stat
{
{
height
:
370px
;
height
:
370px
;
}
}
...
...
src/public/js/adm/amsystem-campaign.js
View file @
4598a772
...
@@ -74,13 +74,20 @@ $(document).ready(function () {
...
@@ -74,13 +74,20 @@ $(document).ready(function () {
$statError
=
$
(
'.chart-graph-stat-error'
,
$statWrap
),
$statError
=
$
(
'.chart-graph-stat-error'
,
$statWrap
),
selectorStatChart
=
'#chart-graph-stat'
,
selectorStatChart
=
'#chart-graph-stat'
,
$statChart
=
$
(
selectorStatChart
,
$statWrap
),
$statChart
=
$
(
selectorStatChart
,
$statWrap
),
$statTable
=
$
(
'.b-table_wrapp.report'
,
$statWrap
),
$statTable
Wrap
=
$
(
'.b-table_wrapp.report'
,
$statWrap
),
$table
CampaignStat
=
$
(
'#table-line'
,
$statTable
),
$table
Stat
=
$
(
'#table-line'
,
$statTableWrap
),
targetActionValue
=
$
(
'input[name=target_action]:checked'
).
val
(),
targetActionValue
=
$
(
'input[name=target_action]:checked'
).
val
(),
chart
,
chart
,
activeLine
,
activeLine
,
activeLines
,
activeLines
,
currencyFields
=
[
'money'
];
activeLinesId
,
currencyFields
=
[
'money'
],
dateTimeFields
=
[
'period'
],
$table
=
$
(
'#table-line'
),
$tableContent
=
$
(
'<tbody>'
),
$tableBody
=
$table
.
find
(
'tbody'
).
first
();
// Добавление впереди 0 у однозначных значений
// Добавление впереди 0 у однозначных значений
function
pad
(
number
)
{
function
pad
(
number
)
{
...
@@ -100,21 +107,17 @@ $(document).ready(function () {
...
@@ -100,21 +107,17 @@ $(document).ready(function () {
function
valueFormat
(
value
,
ratio
,
id
)
function
valueFormat
(
value
,
ratio
,
id
)
{
{
var
var
dataLine
=
activeLines
[
parseInt
(
id
.
replace
(
'data'
,
''
))
-
1
],
dataLine
=
activeLines
Id
[
parseInt
(
id
.
replace
(
'data'
,
''
))
-
1
],
isCurrencyValue
=
currencyFields
.
indexOf
(
dataLine
)
>
-
1
,
isCurrencyValue
=
currencyFields
.
indexOf
(
dataLine
)
>
-
1
,
format
=
(
isCurrencyValue
)
?
d3
.
format
(
',.2f'
)
:
d3
.
format
(
',.0f'
);
format
=
(
isCurrencyValue
)
?
d3
.
format
(
',.2f'
)
:
d3
.
format
(
',.0f'
);
if
(
dataLine
==
'OrderSum'
)
{
format
=
d3
.
format
(
',.0f'
);
}
if
(
parseFloat
(
format
(
value
))
==
0
&&
value
!=
0
)
{
if
(
parseFloat
(
format
(
value
))
==
0
&&
value
!=
0
)
{
var
accuracy
=
Math
.
abs
(
Math
.
floor
(
Math
.
log10
(
value
)));
var
accuracy
=
Math
.
abs
(
Math
.
floor
(
Math
.
log10
(
value
)));
return
value
.
toFixed
(
accuracy
);
return
value
.
toFixed
(
accuracy
);
}
}
if
(
isCurrencyValue
)
{
if
(
isCurrencyValue
)
{
return
format
(
value
)
+
' грн.'
;
return
format
(
value
)
/* + ' грн.'*/
;
}
else
{
}
else
{
return
format
(
value
);
return
format
(
value
);
}
}
...
@@ -130,6 +133,21 @@ $(document).ready(function () {
...
@@ -130,6 +133,21 @@ $(document).ready(function () {
}
}
function
valueFormatTable
(
value
,
currentActiveLine
)
{
var
isCurrencyValue
=
currencyFields
.
indexOf
(
currentActiveLine
)
>
-
1
,
format
=
d3
.
format
(
',.0f'
);
if
(
isCurrencyValue
)
format
=
d3
.
format
(
',.2f'
);
if
(
currentActiveLine
==
'ctr'
)
format
=
d3
.
format
(
',.2f'
);
if
(
isCurrencyValue
)
return
format
(
value
)
/* + ' грн.'*/
;
if
(
currentActiveLine
==
'ctr'
)
return
format
(
value
)
+
' %'
;
return
format
(
value
);
}
// Получение данных для отрисовки графика Stat при старте:
// Получение данных для отрисовки графика Stat при старте:
if
(
$
(
'#campaign-stat'
).
val
()
&&
$
(
'#campaign-stat-total'
).
val
())
{
if
(
$
(
'#campaign-stat'
).
val
()
&&
$
(
'#campaign-stat-total'
).
val
())
{
dataStat
=
JSON
.
parse
(
$
(
'#campaign-stat'
).
val
());
dataStat
=
JSON
.
parse
(
$
(
'#campaign-stat'
).
val
());
...
@@ -146,7 +164,7 @@ $(document).ready(function () {
...
@@ -146,7 +164,7 @@ $(document).ready(function () {
$statInfo
.
show
();
$statInfo
.
show
();
$statError
.
hide
();
$statError
.
hide
();
$statChart
.
hide
();
$statChart
.
hide
();
$statTable
.
hide
();
$statTable
Wrap
.
hide
();
}
}
function
ShowError
()
function
ShowError
()
...
@@ -154,12 +172,12 @@ $(document).ready(function () {
...
@@ -154,12 +172,12 @@ $(document).ready(function () {
$statError
.
show
();
$statError
.
show
();
$statInfo
.
hide
();
$statInfo
.
hide
();
$statChart
.
hide
();
$statChart
.
hide
();
$statTable
.
hide
();
$statTable
Wrap
.
hide
();
}
}
function
getCheckedCategories
()
{
function
getCheckedCategories
()
{
var
listCats
=
[];
var
listCats
=
[];
$
(
'thead th input[type="checkbox"]'
,
$table
Campaign
Stat
).
each
(
function
(){
$
(
'thead th input[type="checkbox"]'
,
$tableStat
).
each
(
function
(){
if
(
$
(
this
).
is
(
":checked"
))
{
if
(
$
(
this
).
is
(
":checked"
))
{
listCats
.
push
(
$
(
this
).
data
(
'field'
));
listCats
.
push
(
$
(
this
).
data
(
'field'
));
}
}
...
@@ -185,8 +203,6 @@ $(document).ready(function () {
...
@@ -185,8 +203,6 @@ $(document).ready(function () {
// Определяем выбранные категории для графика:
// Определяем выбранные категории для графика:
selectedCategoriesId
=
getCheckedCategories
();
selectedCategoriesId
=
getCheckedCategories
();
console
.
log
(
'AAA renderChart selectedCategoriesId'
,
selectedCategoriesId
);
// Скрываем график, если в таблице не выбраны категории:
// Скрываем график, если в таблице не выбраны категории:
if
(
selectedCategoriesId
.
length
==
0
)
{
if
(
selectedCategoriesId
.
length
==
0
)
{
$statChart
.
hide
();
$statChart
.
hide
();
...
@@ -195,8 +211,6 @@ $(document).ready(function () {
...
@@ -195,8 +211,6 @@ $(document).ready(function () {
$statChart
.
show
();
$statChart
.
show
();
}
}
console
.
log
(
'AAA activeLines = '
,
activeLines
);
var
i
=
0
;
var
i
=
0
;
Object
.
keys
(
activeLines
).
forEach
(
function
(
activeLineItem
){
Object
.
keys
(
activeLines
).
forEach
(
function
(
activeLineItem
){
if
(
selectedCategoriesId
.
indexOf
(
activeLineItem
)
>
-
1
)
{
if
(
selectedCategoriesId
.
indexOf
(
activeLineItem
)
>
-
1
)
{
...
@@ -209,8 +223,6 @@ $(document).ready(function () {
...
@@ -209,8 +223,6 @@ $(document).ready(function () {
}
}
});
});
console
.
log
(
'AAA dataColumnsTemp '
,
dataColumnsTemp
);
chart
=
c3
.
generate
({
chart
=
c3
.
generate
({
bindto
:
selectorStatChart
,
bindto
:
selectorStatChart
,
data
:
{
data
:
{
...
@@ -272,9 +284,75 @@ $(document).ready(function () {
...
@@ -272,9 +284,75 @@ $(document).ready(function () {
};
};
function
renderTable
()
{
function
renderTable
()
{
console
.
log
(
'AAA renderTable'
);
var
dataTable
=
dataStat
,
dataPeriod
=
dataStat
[
'period'
],
dataTableForSort
=
[],
$selectedField
=
$
(
'thead th b.selected'
,
$table
),
$row
,
sortField
=
false
,
isDesc
=
true
;
// Определение поля для сортировки строк в таблице:
if
(
$selectedField
.
length
>
0
)
{
sortField
=
$selectedField
.
attr
(
'id'
);
isDesc
=
$selectedField
.
hasClass
(
'desc'
);
}
if
(
!
sortField
)
{
sortField
=
'period'
;
isDesc
=
true
;
}
//console.log('AAA sortField = ', sortField, ' isDesc = ', isDesc);
// Подготовка данных для сортировки:
dataPeriod
.
forEach
(
function
(
dataTableItem
,
ind
){
var
dataTableSortItem
=
{};
dataTableSortItem
[
'period'
]
=
dataTableItem
;
activeLinesId
.
forEach
(
function
(
activeLine
){
dataTableSortItem
[
activeLine
]
=
dataTable
[
activeLine
][
ind
];
});
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
];
}
});
// Отрисовка таблицы:
dataTableForSort
.
forEach
(
function
(
item
){
$row
=
$
(
'<tr>'
);
$row
.
append
(
$
(
'<td>'
).
html
(
item
[
'period'
]));
activeLinesId
.
forEach
(
function
(
line
){
$row
.
append
(
$
(
'<td class="'
+
line
+
'">'
).
html
(
valueFormatTable
(
item
[
line
],
line
)));
});
$row
.
appendTo
(
$tableContent
);
});
// Добавляем строку "Итого" для отчета 'common':
$row
=
$
(
'<tr class="total">'
);
$row
.
append
(
$
(
'<td>'
).
html
(
"Итого"
));
activeLinesId
.
forEach
(
function
(
item
){
$row
.
append
(
$
(
'<td>'
).
html
(
valueFormatTable
(
dataStatTotal
[
item
],
item
)));
});
$row
.
appendTo
(
$tableContent
);
$tableBody
.
html
(
''
).
append
(
$tableContent
.
children
());
$statTableWrap
.
show
();
};
};
/*
switch(targetActionValue) {
switch(targetActionValue) {
case 'load':
case 'load':
activeLine = 'views';
activeLine = 'views';
...
@@ -286,8 +364,11 @@ $(document).ready(function () {
...
@@ -286,8 +364,11 @@ $(document).ready(function () {
activeLine = 'clicks';
activeLine = 'clicks';
break;
break;
}
}
*/
activeLine
=
'views'
;
activeLines
=
JSON
.
parse
(
$
(
'#campaign-stat-cats'
).
val
());
activeLines
=
JSON
.
parse
(
$
(
'#campaign-stat-cats'
).
val
());
activeLinesId
=
Object
.
keys
(
activeLines
);
if
(
dataStat
)
{
if
(
dataStat
)
{
// Отрисовка графика и таблицы по стартовым данным:
// Отрисовка графика и таблицы по стартовым данным:
...
@@ -300,11 +381,11 @@ $(document).ready(function () {
...
@@ -300,11 +381,11 @@ $(document).ready(function () {
}
else
{
}
else
{
ShowInfo
();
ShowInfo
();
$statChart
.
hide
();
$statChart
.
hide
();
$statTable
.
hide
();
$statTable
Wrap
.
hide
();
}
}
// Клик на checkbox в названии поля таблицы:
// Клик на checkbox в названии поля таблицы:
var
$tableHeadColsChecks
=
$
(
'thead th input[type="checkbox"]'
,
$table
Campaign
Stat
);
var
$tableHeadColsChecks
=
$
(
'thead th input[type="checkbox"]'
,
$tableStat
);
$tableHeadColsChecks
.
on
(
'change'
,
function
(){
$tableHeadColsChecks
.
on
(
'change'
,
function
(){
renderChart
();
renderChart
();
});
});
...
...
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