From: David Kalnischkies Date: Mon, 28 Aug 2023 20:24:38 +0000 (+0000) Subject: Do not use number hardcoding in recording details dialog X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b944feb3ce3cb459213f4d0135ad4d9307b29767;p=thirdparty%2Ftvheadend.git Do not use number hardcoding in recording details dialog Programmers can count, we all know that, so instead of proofing (and occasionally failing) it in code, lets do away with hardcoding here and just use an object with named members which is also a bit shorter and easier to extend. --- diff --git a/src/webui/static/app/dvr.js b/src/webui/static/app/dvr.js index 8b90b3516..104353be1 100644 --- a/src/webui/static/app/dvr.js +++ b/src/webui/static/app/dvr.js @@ -48,121 +48,95 @@ tvheadend.dvrDetails = function(grid, index) { } function getDialogContent(d) { - var params = d[0].params; - var chicon = params[0].value; - var title = params[1].value; - var subtitle = params[2].value; - var summary = params[3].value; - var episode = params[4].value; - var start_real = params[5].value; - var stop_real = params[6].value; - var duration = params[7].value; - var desc = params[8].value; - var status = params[9].value; - var filesize = params[10].value; - var comment = params[11].value; - var duplicate = params[12].value; - var autorec_caption = params[13].value; - var timerec_caption = params[14].value; - var image = params[15].value; - var copyright_year = params[16].value; - var credits = params[17].value; - var keyword = params[18].value; - var category = params[19].value; - var first_aired = params[20].value; - var genre = params[21].value; - /* channelname is unused param 22 */ - var fanart_image = params[23].value; - /* broadcast is unused param 24 */ - var age_rating = params[25].value; - var rating_label = params[26].value; - var rating_icon = params[27].value; - let filename = params[28].value; + var event = {}; + for (var param of d[0].params) { + if ('value' in param) + event[param.id] = param.value; + else if ('default' in param) + event[param.id] = param.default; + } var content = '
' + '
' + '
'; - var but; - - if (chicon != null && chicon.length > 0) { - content += ''; + if (event.channel_icon != null && event.channel_icon.length > 0) { + content += ''; } else { - chicon = null; + event.channel_icon = null; } - if (chicon) + if (event.channel_icon) content += '
'; - if (duplicate) - content += '
' + _('Will be skipped') + '
' + _('because it is a rerun of:') + '
' + tvheadend.niceDate(duplicate * 1000) + '
'; + if (event.duplicate) + content += '
' + _('Will be skipped') + '
' + _('because it is a rerun of:') + '
' + tvheadend.niceDate(event.duplicate * 1000) + '
'; - var icons = tvheadend.getContentTypeIcons({"category" : category, "genre" : genre}, "x-dialog-category-large-icon"); + var icons = tvheadend.getContentTypeIcons({"category" : event.category, "genre" : event.genre}, "x-dialog-category-large-icon"); if (icons) content += '
' + icons + '
'; - var displayTitle = title; - if (copyright_year) - displayTitle += " (" + copyright_year + ")"; - if (title) + var displayTitle = event.disp_title; + if (event.copyright_year) + displayTitle += " (" + event.copyright_year + ")"; + if (event.disp_title) content += '
' + displayTitle + '
'; - if (subtitle && (!desc || (desc && subtitle != desc))) - content += '
' + subtitle + '
'; - if (episode) - content += '
' + episode + '
'; - if (start_real) - content += '
' + _('Scheduled Start Time') + ':' + tvheadend.niceDate(start_real * 1000) + '
'; - if (stop_real) - content += '
' + _('Scheduled Stop Time') + ':' + tvheadend.niceDate(stop_real * 1000) + '
'; + if (event.disp_subtitle && (!event.disp_description || (event.disp_description && event.disp_subtitle != event.disp_description))) + content += '
' + event.disp_subtitle + '
'; + if (event.episode_disp) + content += '
' + event.episode_disp + '
'; + if (event.start_real) + content += '
' + _('Scheduled Start Time') + ':' + tvheadend.niceDate(event.start_real * 1000) + '
'; + if (event.stop_real) + content += '
' + _('Scheduled Stop Time') + ':' + tvheadend.niceDate(event.stop_real * 1000) + '
'; /* We have to *1000 here (and not in epg.js) since Date requires ms and epgStore has it already converted */ - if (first_aired) - content += '
' + _('First Aired') + ':' + tvheadend.niceDateYearMonth(first_aired * 1000, start_real * 1000) + '
'; - if (duration) - content += '
' + _('Duration') + ':' + parseInt(duration / 60) + ' ' + _('min') + '
'; - if (chicon) { + if (event.first_aired) + content += '
' + _('First Aired') + ':' + tvheadend.niceDateYearMonth(event.first_aired * 1000, event.start_real * 1000) + '
'; + if (event.duration) + content += '
' + _('Duration') + ':' + parseInt(event.duration / 60) + ' ' + _('min') + '
'; + if (event.channel_icon) { content += '
'; /* x-epg-left */ content += '
'; } // If we have no image then use fanart image instead. content += '
'; - if (image != null && image.length > 0) { - content += ''; - } else if (fanart_image != null && fanart_image.length > 0) { - content += ''; + if (event.image != null && event.image.length > 0) { + content += ''; + } else if (event.fanart_image != null && event.fanart_image.length > 0) { + content += ''; } content += '
'; content += '
'; - if (summary && (!subtitle || subtitle != summary)) - content += '
' + summary + '
'; - if (desc) { - content += '
' + tvheadend.labelFormattingParser(desc) + '
'; + if (event.disp_summary && (!event.disp_subtitle || event.disp_subtitle != event.disp_summary)) + content += '
' + event.disp_summary + '
'; + if (event.disp_description) { + content += '
' + tvheadend.labelFormattingParser(event.disp_description) + '
'; content += '
'; } - content += tvheadend.getDisplayCredits(credits); - if (keyword) - content += tvheadend.sortAndAddArray(keyword, _('Keywords')); - if (category) - content += tvheadend.sortAndAddArray(category, _('Categories')); - - if (rating_icon) - content += ''; - - if (age_rating) - content += '
' + _('Age Rating') + ':' + age_rating + '
'; - if (rating_label) - content += '
' + _('Parental Rating') + ':' + rating_label + '
'; - if (status) - content += '
' + _('Status') + ':' + status + '
'; - if (filesize) - content += '
' + _('File size') + ':' + parseInt(filesize / 1000000) + ' MB
'; - if (filename && (tvheadend.uiviewlevel ? tvheadend.uiviewlevel : tvheadend.uilevel) !== 'basic') // Only show for 'advanced' and 'expert' levels. - content += '
' + _('File name') + ':' + filename + '
'; - if (comment) - content += '
' + _('Comment') + ':' + comment + '
'; - if (autorec_caption) - content += '
' + _('Autorec') + ':' + autorec_caption + '
'; - if (timerec_caption) - content += '
' + _('Time Scheduler') + ':' + timerec_caption + '
'; - if (chicon) + + content += tvheadend.getDisplayCredits(event.credits); + if (event.keyword) + content += tvheadend.sortAndAddArray(event.keyword, _('Keywords')); + if (event.category) + content += tvheadend.sortAndAddArray(event.category, _('Categories')); + if (event.rating_icon) + content += ''; + if (event.age_rating) + content += '
' + _('Age Rating') + ':' + event.age_rating + '
'; + if (event.rating_label) + content += '
' + _('Parental Rating') + ':' + event.rating_label + '
'; + if (event.status) + content += '
' + _('Status') + ':' + event.status + '
'; + if (event.filesize) + content += '
' + _('File size') + ':' + parseInt(event.filesize / 1000000) + ' MB
'; + if (event.filename && (tvheadend.uiviewlevel ? tvheadend.uiviewlevel : tvheadend.uilevel) !== 'basic') // Only show for 'advanced' and 'expert' levels. + content += '
' + _('File name') + ':' + event.filename + '
'; + if (event.comment) + content += '
' + _('Comment') + ':' + event.comment + '
'; + if (event.autorec_caption) + content += '
' + _('Autorec') + ':' + event.autorec_caption + '
'; + if (event.timerec_caption) + content += '
' + _('Time Scheduler') + ':' + event.timerec_caption + '
'; + if (event.channel_icon) content += '
'; /* x-epg-bottom */ content += '
'; //dialog content return content