Fix delete mode to use list of child id's instead of loop

This commit is contained in:
Jonathan Wong 2015-09-27 22:43:42 -07:00
parent 200a85adcf
commit 8b52548016
2 changed files with 23 additions and 22 deletions

View file

@ -269,14 +269,13 @@ history_table_options = {
// toggle the parent button to danger // toggle the parent button to danger
$(row).find('button[data-id="' + rowData['id'] + '"]').toggleClass('btn-warning').toggleClass('btn-danger'); $(row).find('button[data-id="' + rowData['id'] + '"]').toggleClass('btn-warning').toggleClass('btn-danger');
// check if any child rows are not selected // check if any child rows are not selected
for (var i = rowData['reference_id']; i <= rowData['id']; i++) { var group_ids = rowData['group_ids'].split(',').map(Number);
var index = $.inArray(i, history_to_delete); group_ids.forEach(function (id) {
var index = $.inArray(id, history_to_delete);
if (index == -1) { if (index == -1) {
// if any child row is not selected, toggle parent button to warning $(row).find('button[data-id="' + rowData['id'] + '"]').addClass('btn-warning').removeClass('btn-danger');
$(row).find('button[data-id="' + rowData['id'] + '"]').toggleClass('btn-warning').toggleClass('btn-danger');
break;
} }
} });
} }
if (rowData['group_count'] != 1 && rowData['reference_id'] in history_child_table) { if (rowData['group_count'] != 1 && rowData['reference_id'] in history_child_table) {
@ -350,12 +349,13 @@ $('#history_table').on('click', '> tbody > tr > td.delete-control > button', fun
// if grouped rows // if grouped rows
if ($(this).hasClass('btn-warning')) { if ($(this).hasClass('btn-warning')) {
// add all grouped rows to history_to_delete // add all grouped rows to history_to_delete
for (var i = rowData['reference_id']; i <= rowData['id']; i++) { var group_ids = rowData['group_ids'].split(',').map(Number);
var index = $.inArray(i, history_to_delete); group_ids.forEach(function (id) {
var index = $.inArray(id, history_to_delete);
if (index == -1) { if (index == -1) {
history_to_delete.push(i); history_to_delete.push(id);
} }
} });
$(this).toggleClass('btn-warning').toggleClass('btn-danger'); $(this).toggleClass('btn-warning').toggleClass('btn-danger');
if (row.child.isShown()) { if (row.child.isShown()) {
// if child table is visible, toggle all child buttons to danger // if child table is visible, toggle all child buttons to danger
@ -363,12 +363,13 @@ $('#history_table').on('click', '> tbody > tr > td.delete-control > button', fun
} }
} else { } else {
// remove all grouped rows to history_to_delete // remove all grouped rows to history_to_delete
for (var i = rowData['reference_id']; i <= rowData['id']; i++) { var group_ids = rowData['group_ids'].split(',').map(Number);
var index = $.inArray(i, history_to_delete); group_ids.forEach(function (id) {
var index = $.inArray(id, history_to_delete);
if (index != -1) { if (index != -1) {
history_to_delete.splice(index, 1); history_to_delete.splice(index, 1);
} }
} });
$(this).toggleClass('btn-warning').toggleClass('btn-danger'); $(this).toggleClass('btn-warning').toggleClass('btn-danger');
if (row.child.isShown()) { if (row.child.isShown()) {
// if child table is visible, toggle all child buttons to warning // if child table is visible, toggle all child buttons to warning
@ -553,14 +554,14 @@ function createChildTable(row, rowData) {
tr.parents('tr').prev().find('td.delete-control > button.btn-warning').toggleClass('btn-warning').toggleClass('btn-danger'); tr.parents('tr').prev().find('td.delete-control > button.btn-warning').toggleClass('btn-warning').toggleClass('btn-danger');
// check if any child rows are not selected // check if any child rows are not selected
for (var i = rowData['reference_id']; i <= rowData['id']; i++) { var group_ids = rowData['group_ids'].split(',').map(Number);
var index = $.inArray(i, history_to_delete); group_ids.forEach(function (id) {
var index = $.inArray(id, history_to_delete);
if (index == -1) { if (index == -1) {
// if any child row is not selected, toggle parent button to warning // if any child row is not selected, toggle parent button to warning
tr.parents('tr').prev().find('td.delete-control > button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger'); tr.parents('tr').prev().find('td.delete-control > button.btn-danger').addClass('btn-warning').removeClass('btn-danger');
break;
} }
} });
}); });
} }

View file

@ -59,9 +59,9 @@ class DataFactory(object):
'((CASE WHEN view_offset IS NULL THEN 0.1 ELSE view_offset * 1.0 END) / \ '((CASE WHEN view_offset IS NULL THEN 0.1 ELSE view_offset * 1.0 END) / \
(CASE WHEN session_history_metadata.duration IS NULL THEN 1.0 ELSE session_history_metadata.duration * 1.0 END) * 100) AS percent_complete', (CASE WHEN session_history_metadata.duration IS NULL THEN 1.0 ELSE session_history_metadata.duration * 1.0 END) * 100) AS percent_complete',
'session_history_media_info.video_decision', 'session_history_media_info.video_decision',
'COUNT(*) AS group_count',
'session_history_media_info.audio_decision', 'session_history_media_info.audio_decision',
'session_history.user_id as user_id' 'COUNT(*) AS group_count',
'GROUP_CONCAT(session_history.id) AS group_ids'
] ]
try: try:
query = data_tables.ssp_query(table_name='session_history', query = data_tables.ssp_query(table_name='session_history',
@ -127,10 +127,10 @@ class DataFactory(object):
"parent_media_index": item["parent_media_index"], "parent_media_index": item["parent_media_index"],
"thumb": thumb, "thumb": thumb,
"video_decision": item["video_decision"], "video_decision": item["video_decision"],
"audio_decision": item["audio_decision"],
"watched_status": watched_status, "watched_status": watched_status,
"group_count": item["group_count"], "group_count": item["group_count"],
"audio_decision": item["audio_decision"], "group_ids": item["group_ids"]
"user_id": item["user_id"]
} }
rows.append(row) rows.append(row)