From 973adc227fb739100de75f4f452b13126205281f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 13 May 2015 11:39:07 -0400 Subject: [PATCH] update reports --- dashboard-ui/ReportManager.html | 259 --- dashboard-ui/reports.html | 335 ++-- dashboard-ui/scripts/librarymenu.js | 2 +- dashboard-ui/scripts/reportmanager.js | 1030 ------------ dashboard-ui/scripts/reports.js | 1435 +++++++++-------- .../thirdparty/jquery.unveil-custom.js | 2 - 6 files changed, 1015 insertions(+), 2048 deletions(-) delete mode 100644 dashboard-ui/ReportManager.html delete mode 100644 dashboard-ui/scripts/reportmanager.js diff --git a/dashboard-ui/ReportManager.html b/dashboard-ui/ReportManager.html deleted file mode 100644 index 3387bd135b..0000000000 --- a/dashboard-ui/ReportManager.html +++ /dev/null @@ -1,259 +0,0 @@ - - - - Emby - - -
-
-
-
- ${LabelReport} -
- -
-
- -
- -
-
-
-
-
-
- -
-
- -
-
- - -
-
- - -
-
- - - -
-
- - - -
-
-
- -
-

${OptionReportColumns}

- -
-
-
-
-
- -
-
- - ${HeaderFilters} - - - - - - - - - - - - - - - - - - -
-
- -
-

${LabelManagement}

-
- - - - - - - - - - - - - - -
-
-
- - ${HeaderStatus} - - - - - -
- -
-

${HeaderAirDays}

- -
- - - - - - - - - - - - - - -
-
-
-

${HeaderEpisodes}

-
- - - - - -
-
-
-

${HeaderFeatures}

- -
- - - - - - - - - - - - - - - -
-
- -
-

${HeaderGenres}

- -
-
-
- -
-

${HeaderParentalRatings}

- -
-
-
- -
-

${HeaderTags}

- -
-
-
- -
-

${HeaderVideoTypes}

- -
- - - - - - - - - - - - - - - - - - -
-
- -
-

${HeaderYears}

- -
-
-
- -
- -
-
- -
-
- - diff --git a/dashboard-ui/reports.html b/dashboard-ui/reports.html index 693f8682dc..85be72b9b5 100644 --- a/dashboard-ui/reports.html +++ b/dashboard-ui/reports.html @@ -4,11 +4,17 @@ Emby -
+
${LabelReport} +
+ +
-

-
+
+ +
+
+ + +
+
+ + +
+
+ + + +
+
+ + + +
+
+
+ +
+

${HeaderColumns}

+ +
+
+
+
+
+ +
+
+ + ${HeaderFilters} + + + + + + + + + + + + + + + + + + +
+
+ +
+

${LabelManagement}

+
+ + + + + + + + + + + + + + +
+
+
+ + ${HeaderStatus} + + + + + +
+ +
+

${HeaderAirDays}

+ +
+ + + + + + + + + + + + + + +
+
+
+

${HeaderEpisodes}

+
+ + + + + +
+
+
+

${HeaderFeatures}

+ +
+ + + + + + + + + + + + + + + +
+
+ +
+

${HeaderGenres}

+ +
+
+
+ +
+

${HeaderParentalRatings}

+ +
+
+
+ +
+

${HeaderTags}

+ +
+
+
+ +
+

${HeaderVideoTypes}

+ +
+ + + + + + + + + + + + + + + + + + +
+
+ +
+

${HeaderYears}

+ +
+
+
+ +
+ +
+
+
- -
-
- -
- ${HeaderFilters} - - - - -
-
-
- - ${LabelVideoType} - - - - - - - - - - - - - - - - - - - - - -
-
-
- - ${HeaderEpisodes} - - - - - - - -
-
- - - -
-
-
diff --git a/dashboard-ui/scripts/librarymenu.js b/dashboard-ui/scripts/librarymenu.js index e90001366e..f41efca273 100644 --- a/dashboard-ui/scripts/librarymenu.js +++ b/dashboard-ui/scripts/librarymenu.js @@ -129,7 +129,7 @@ html += '' + Globalize.translate('ButtonDashboard') + ''; html += '' + Globalize.translate('ButtonMetadataManager') + ''; - html += '' + Globalize.translate('ButtonReports') + ''; + html += '' + Globalize.translate('ButtonReports') + ''; html += '
'; html += '' + Globalize.translate('ButtonSync') + ''; diff --git a/dashboard-ui/scripts/reportmanager.js b/dashboard-ui/scripts/reportmanager.js deleted file mode 100644 index 09a0c021e1..0000000000 --- a/dashboard-ui/scripts/reportmanager.js +++ /dev/null @@ -1,1030 +0,0 @@ -(function ($, document) { - var defaultSortBy = "SortName"; - var SelectedReportView = "ReportData"; - var topItems = 5; - - var query = { - StartIndex: 0, - Limit: 100, - IncludeItemTypes: "Movie", - HasQueryLimit: true, - GroupBy: "None" - }; - - function getTable(result) { - var html = ''; - //Report table - html += ''; - html += ''; - - //Report headers - result.Headers.map(function (header) { - var cellHtml = ''; - html += cellHtml; - }); - - html += ''; - //Report body - html += ''; - if (result.IsGrouped === false) { - - result.Rows.map(function (row) { - html += getRow(result.Headers, row); - }); - } - else { - - result.Groups.map(function (group) { - html += ''; - html += ''; - html += ''; - group.Rows.map(function (row) { - html += getRow(result.Headers, row); - }); - html += ''; - html += ''; - html += ''; - }); - } - - html += ''; - html += '
'; - - if (header.SortField) { - cellHtml += ''; - } - - cellHtml += (header.Name || ' '); - if (header.SortField) { - cellHtml += ''; - if (header.SortField === defaultSortBy) { - - if (query.SortOrder === "Descending") { - cellHtml += ''; - } else { - cellHtml += ''; - } - } - } - cellHtml += '
' + (group.Name || ' ') + '
' + ' ' + '
'; - return html; - } - - function getRow(rHeaders, rRow) { - var html = ''; - html += ''; - - for (var j = 0; j < rHeaders.length; j++) { - var rHeader = rHeaders[j]; - var rItem = rRow.Columns[j]; - html += getItem(rHeader, rRow, rItem); - } - html += ''; - return html; - } - - function getItem(rHeader, rRow, rItem) { - var html = ''; - html += ''; - switch (rHeader.ItemViewType) { - case "None": - html += rItem.Name; - break; - case "Detail": - var id = rRow.Id; - if (rItem.Id) - id = rItem.Id; - html += '' + rItem.Name + ''; - break; - case "Edit": - html += '' + rItem.Name + ''; - break; - case "List": - html += '' + rItem.Name + ''; - break; - case "ItemByNameDetails": - html += '' + rItem.Name + ''; - break; - case "EmbeddedImage": - if (rRow.HasEmbeddedImage) { - html += '
'; - } - break; - case "SubtitleImage": - if (rRow.HasSubtitles) { - html += '
'; - } - break; - case "TrailersImage": - if (rRow.HasLocalTrailer) { - html += '
'; - } - break; - case "SpecialsImage": - if (rRow.HasSpecials) { - html += '
'; - } - break; - case "StatusImage": - if (rRow.HasLockData) { - html += ''; - } - if (rRow.IsUnidentified) { - html += '
'; - } - - if (!rRow.HasLocalTrailer && rRow.RowType === "Movie") { - html += ''; - } - - if (!rRow.HasImageTagsPrimary) { - html += ''; - } - - if (!rRow.HasImageTagsBackdrop) { - if (rRow.RowType !== "Episode" && rRow.RowType !== "Season" && rRow.MediaType !== "Audio" && rRow.RowType !== "TvChannel" && rRow.RowType !== "MusicAlbum") { - html += ''; - } - } - - if (!rRow.HasImageTagsLogo) { - if (rRow.RowType === "Movie" || rRow.RowType === "Trailer" || rRow.RowType === "Series" || rRow.RowType === "MusicArtist" || rRow.RowType === "BoxSet") { - html += ''; - } - } - break; - default: - html += rItem.Name; - } - html += ''; - return html; - } - - function getStats(result) { - var html = ''; - html += '
'; - //html += '
If you like Africa Fever II, check these out...
'; - html += '
'; - result.Groups.map(function (group) { - //html += '
'; - //html += '
'; - //html += '
'; - html += '
'; - //html += '
'; - html += '
'; - html += '
'; - - html += '
' - html += '
'; - html += '' + group.Header + ' ' + ''; - html += '
'; - - html += '
'; - html += '
'; - html += ''; - html += '
'; - html += '
'; - html += '
'; - - html += '
'; - html += '
'; - html += '
'; - - }); - - - html += '
'; - //html += '
'; - html += '
'; - return html; - } - - function ExportReport(page, e) { - - query.UserId = Dashboard.getCurrentUserId(); - query.HasQueryLimit = false; - var url = ApiClient.getUrl("Reports/Items/Download", query); - - if (url) { - e.preventDefault(); //stop the browser from following - window.location.href = url; - } - } - - function loadGroupByFilters(page) { - - query.UserId = Dashboard.getCurrentUserId(); - var url = ""; - - url = ApiClient.getUrl("Reports/Headers", query); - ApiClient.getJSON(url).done(function (result) { - var selected = "None"; - - $('#selectReportGroup', page).find('option').remove().end(); - $('#selectReportGroup', page).append(''); - - result.map(function (header) { - if (header.Visible && header.CanGroup) { - if (header.FieldName.length > 0) { - var option = ''; - $('#selectReportGroup', page).append(option); - if (query.GroupBy === header.FieldName) - selected = header.FieldName; - } - } - }); - $('#selectPageSize', page).val(selected).selectmenu('refresh'); - - }); - } - - function renderItems(page, result) { - - $(document).scrollTop(0); - var html = ''; - - if (SelectedReportView === "ReportData") { - $('.listTopPaging', page).html(LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, [], false)).trigger('create'); - $('.listTopPaging', page).show(); - - $('.listBottomPaging', page).html(LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, [], false)).trigger('create'); - $('.listBottomPaging', page).show(); - - $('.btnNextPage', page).on('click', function () { - query.StartIndex += query.Limit; - reloadItems(page); - }); - $('.btnNextPage', page).show(); - - $('.btnPreviousPage', page).on('click', function () { - query.StartIndex -= query.Limit; - reloadItems(page); - }); - $('.btnPreviousPage', page).show(); - - $('#btnReportExport', page).show(); - $('#selectPageSizeBox', page).show(); - $('#selectReportGroupingBox', page).show(); - $('#grpReportsColumns', page).show(); - - html += getTable(result); - - $('.reporContainer', page).html(html).trigger('create'); - - $('.lnkColumnSort', page).on('click', function () { - - var order = this.getAttribute('data-sortfield'); - - if (query.SortBy === order) { - - if (query.SortOrder === "Descending") { - - query.SortOrder = "Ascending"; - query.SortBy = defaultSortBy; - - } else { - - query.SortOrder = "Descending"; - query.SortBy = order; - } - - } else { - - query.SortOrder = "Ascending"; - query.SortBy = order; - } - - query.StartIndex = 0; - - reloadItems(page); - }); - } - else { - $('.listTopPaging', page).hide(); - $('.listBottomPaging', page).hide(); - $('.btnNextPage', page).hide(); - $('.btnPreviousPage', page).hide(); - - $('#btnReportExport', page).hide(); - $('#selectPageSizeBox', page).hide(); - $('#selectReportGroupingBox', page).hide(); - $('#grpReportsColumns', page).hide(); - - html += getStats(result); - $('.reporContainer', page).html(html).trigger('create'); - } - - $('#GroupStatus', page).hide(); - $('#GroupAirDays', page).hide(); - $('#GroupEpisodes', page).hide(); - switch (query.IncludeItemTypes) { - case "Series": - case "Season": - $('#GroupStatus', page).show(); - $('#GroupAirDays', page).show(); - break; - case "Episode": - $('#GroupStatus', page).show(); - $('#GroupAirDays', page).show(); - $('#GroupEpisodes', page).show(); - break; - } - - } - - function reloadItems(page) { - Dashboard.showLoadingMsg(); - - query.UserId = Dashboard.getCurrentUserId(); - var url = ""; - - switch (SelectedReportView) { - case "ReportData": - query.HasQueryLimit = true; - url = ApiClient.getUrl("Reports/Items", query); - break; - case "ReportStatistic": - query.TopItems = topItems; - query.HasQueryLimit = false; - url = ApiClient.getUrl("Reports/Statistics", query); - break; - } - - ApiClient.getJSON(url).done(function (result) { - updateFilterControls(page); - renderItems(page, result); - }); - - - Dashboard.hideLoadingMsg(); - } - - function updateFilterControls(page) { - - - - $('.chkStandardFilter', page).each(function () { - - var filters = "," + (query.Filters || ""); - var filterName = this.getAttribute('data-filter'); - - this.checked = filters.indexOf(',' + filterName) != -1; - - }).checkboxradio('refresh'); - - - $('.chkVideoTypeFilter', page).each(function () { - - var filters = "," + (query.VideoTypes || ""); - var filterName = this.getAttribute('data-filter'); - - this.checked = filters.indexOf(',' + filterName) != -1; - - }).checkboxradio('refresh'); - - $('.chkStatus', page).each(function () { - - var filters = "," + (query.SeriesStatus || ""); - var filterName = this.getAttribute('data-filter'); - - this.checked = filters.indexOf(',' + filterName) != -1; - - }).checkboxradio('refresh'); - - $('.chkAirDays', page).each(function () { - - var filters = "," + (query.AirDays || ""); - var filterName = this.getAttribute('data-filter'); - - this.checked = filters.indexOf(',' + filterName) != -1; - - }).checkboxradio('refresh'); - - $('#chk3D', page).checked(query.Is3D == true).checkboxradio('refresh'); - $('#chkHD', page).checked(query.IsHD == true).checkboxradio('refresh'); - $('#chkSD', page).checked(query.IsHD == false).checkboxradio('refresh'); - - $('#chkSubtitle', page).checked(query.HasSubtitles == true).checkboxradio('refresh'); - $('#chkTrailer', page).checked(query.HasTrailer == true).checkboxradio('refresh'); - $('#chkSpecialFeature', page).checked(query.HasSpecialFeature == true).checkboxradio('refresh'); - $('#chkThemeSong', page).checked(query.HasThemeSong == true).checkboxradio('refresh'); - $('#chkThemeVideo', page).checked(query.HasThemeVideo == true).checkboxradio('refresh'); - - $('#selectPageSize', page).val(query.Limit).selectmenu('refresh'); - - //Management - $('#chkMissingRating', page).checked(query.HasOfficialRating == false).checkboxradio('refresh'); - $('#chkMissingOverview', page).checked(query.HasOverview == false).checkboxradio('refresh'); - $('#chkYearMismatch', page).checked(query.IsYearMismatched == true).checkboxradio('refresh'); - - $('#chkIsUnidentified', page).checked(query.IsUnidentified == true).checkboxradio('refresh'); - $('#chkIsLocked', page).checked(query.IsLocked == true).checkboxradio('refresh'); - - //Episodes - $('#chkSpecialEpisode', page).checked(query.ParentIndexNumber == 0).checkboxradio('refresh'); - $('#chkMissingEpisode', page).checked(query.IsMissing == true).checkboxradio('refresh'); - $('#chkFutureEpisode', page).checked(query.IsUnaired == true).checkboxradio('refresh'); - - $('#selectView').val(query.IncludeItemTypes).selectmenu('refresh'); - } - - var filtersLoaded; - function reloadFiltersIfNeeded(page) { - - if (!filtersLoaded) { - - filtersLoaded = true; - - QueryReportFilters.loadFilters(page, Dashboard.getCurrentUserId(), query, function () { - - reloadItems(page); - }); - - QueryReportColumns.loadColumns(page, Dashboard.getCurrentUserId(), query, function () { - - reloadItems(page); - }); - } - - } - - $(document).on('pageinit', "#libraryReportManagerPage", function () { - - var page = this; - - $('#selectView', page).on('change', function () { - - query.StartIndex = 0; - SelectedReportView = $('#selectReportType', page).val(); - query.IncludeItemTypes = this.value; - query.SortOrder = "Ascending"; - query.ReportColumns = null; - $('.btnReportExport', page).hide(); - filtersLoaded = false; - loadGroupByFilters(page); - reloadFiltersIfNeeded(page); - reloadItems(page); - - - }); - - $('#selectReportType', page).on('change', function () { - - query.StartIndex = 0; - query.IncludeItemTypes = $('#selectView', page).val(); - SelectedReportView = this.value; - query.SortOrder = "Ascending"; - filtersLoaded = false; - loadGroupByFilters(page); - reloadFiltersIfNeeded(page); - reloadItems(page); - - - }); - - $('#selectReportGroup', page).on('change', function () { - query.GroupBy = this.value; - query.StartIndex = 0; - reloadItems(page); - }); - - $('#btnReportExportCsv', page).on('click', function (e) { - - query.ExportType = "CSV" - ExportReport(page, e); - }); - - $('#btnReportExportExcel', page).on('click', function (e) { - - query.ExportType = "Excel" - ExportReport(page, e); - }); - - $('#btnResetReportColumns', page).on('click', function (e) { - - query.ReportColumns = null - query.StartIndex = 0; - filtersLoaded = false; - reloadFiltersIfNeeded(page); - reloadItems(page); - }); - - $('#filterPanel', page).on('panelopen', function () { - - reloadFiltersIfNeeded(page); - }); - - $('#selectPageSize', page).on('change', function () { - query.Limit = parseInt(this.value); - query.StartIndex = 0; - reloadItems(page); - }); - - $('.chkStandardFilter', this).on('change', function () { - - var filterName = this.getAttribute('data-filter'); - var filters = query.Filters || ""; - - filters = (',' + filters).replace(',' + filterName, '').substring(1); - - if (this.checked) { - filters = filters ? (filters + ',' + filterName) : filterName; - } - - query.StartIndex = 0; - query.Filters = filters; - - reloadItems(page); - }); - - $('.chkVideoTypeFilter', this).on('change', function () { - - var filterName = this.getAttribute('data-filter'); - var filters = query.VideoTypes || ""; - - filters = (',' + filters).replace(',' + filterName, '').substring(1); - - if (this.checked) { - filters = filters ? (filters + ',' + filterName) : filterName; - } - - query.StartIndex = 0; - query.VideoTypes = filters; - - reloadItems(page); - }); - - $('#chk3D', this).on('change', function () { - - query.StartIndex = 0; - query.Is3D = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkHD', this).on('change', function () { - - query.StartIndex = 0; - query.IsHD = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkSD', this).on('change', function () { - - query.StartIndex = 0; - query.IsHD = this.checked ? false : null; - - reloadItems(page); - }); - - $('#chkSubtitle', this).on('change', function () { - - query.StartIndex = 0; - query.HasSubtitles = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkTrailer', this).on('change', function () { - - query.StartIndex = 0; - query.HasTrailer = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkSpecialFeature', this).on('change', function () { - - query.StartIndex = 0; - query.HasSpecialFeature = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkThemeSong', this).on('change', function () { - - query.StartIndex = 0; - query.HasThemeSong = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkThemeVideo', this).on('change', function () { - - query.StartIndex = 0; - query.HasThemeVideo = this.checked ? true : null; - - reloadItems(page); - }); - - $('#radioBasicFilters', this).on('change', function () { - - if (this.checked) { - $('.basicFilters', page).show(); - $('.advancedFilters', page).hide(); - } else { - $('.basicFilters', page).hide(); - } - }); - - $('#radioAdvancedFilters', this).on('change', function () { - - if (this.checked) { - $('.advancedFilters', page).show(); - $('.basicFilters', page).hide(); - } else { - $('.advancedFilters', page).hide(); - } - }); - - //Management - $('#chkIsLocked', page).on('change', function () { - - query.StartIndex = 0; - query.IsLocked = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkMissingOverview', page).on('change', function () { - - query.StartIndex = 0; - query.HasOverview = this.checked ? false : null; - - reloadItems(page); - }); - - $('#chkMissingEpisode', page).on('change', function () { - - query.StartIndex = 0; - query.IsMissing = this.checked ? true : false; - - reloadItems(page); - }); - - $('#chkMissingRating', page).on('change', function () { - - query.StartIndex = 0; - query.HasOfficialRating = this.checked ? false : null; - - reloadItems(page); - }); - - $('#chkYearMismatch', page).on('change', function () { - - query.StartIndex = 0; - query.IsYearMismatched = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkIsUnidentified', page).on('change', function () { - - query.StartIndex = 0; - query.IsUnidentified = this.checked ? true : null; - - reloadItems(page); - }); - - //Episodes - $('#chkMissingEpisode', page).on('change', function () { - - query.StartIndex = 0; - query.IsMissing = this.checked ? true : false; - - reloadItems(page); - }); - - $('#chkFutureEpisode', page).on('change', function () { - - query.StartIndex = 0; - - if (this.checked) { - query.IsUnaired = true; - query.IsVirtualUnaired = null; - } else { - query.IsUnaired = null; - query.IsVirtualUnaired = false; - } - - - reloadItems(page); - }); - - $('#chkSpecialEpisode', page).on('change', function () { - - query.ParentIndexNumber = this.checked ? 0 : null; - - reloadItems(page); - }); - - $('.chkAirDays', this).on('change', function () { - - var filterName = this.getAttribute('data-filter'); - var filters = query.AirDays || ""; - - filters = (',' + filters).replace(',' + filterName, '').substring(1); - - if (this.checked) { - filters = filters ? (filters + ',' + filterName) : filterName; - } - - query.AirDays = filters; - query.StartIndex = 0; - reloadItems(page); - }); - - $('.chkStatus', this).on('change', function () { - - var filterName = this.getAttribute('data-filter'); - var filters = query.SeriesStatus || ""; - - filters = (',' + filters).replace(',' + filterName, '').substring(1); - - if (this.checked) { - filters = filters ? (filters + ',' + filterName) : filterName; - } - - query.SeriesStatus = filters; - query.StartIndex = 0; - reloadItems(page); - }); - }) - .on('pagebeforeshow', "#libraryReportManagerPage", function () { - - query.UserId = Dashboard.getCurrentUserId(); - var page = this; - query.SortOrder = "Ascending"; - - QueryFilters.onPageShow(page, query); - - $('#selectView', page).val(query.IncludeItemTypes).selectmenu('refresh').trigger('change'); - - }) - .on('pageshow', "#libraryReportManagerPage", function () { - - var page = this; - - updateFilterControls(page); - - filtersLoaded = false; - updateFilterControls(this); - }); - -})(jQuery, document); - -(function (window) { - - function renderOptions(page, selector, cssClass, items) { - - var elem; - - if (items.length) { - - elem = $(selector, page).show(); - - } else { - elem = $(selector, page).hide(); - } - - var html = ''; - - // style="margin: -.2em -.8em;" - html += '
'; - - var index = 0; - var idPrefix = 'chk' + selector.substring(1); - - html += items.map(function (filter) { - - var itemHtml = ''; - - var id = idPrefix + index; - var label = filter; - var value = filter; - var checked = false; - if (filter.FieldName) { - label = filter.Name; - value = filter.FieldName; - checked = filter.Visible; - } - itemHtml += ''; - itemHtml += '' + LibraryBrowser.getPosterViewDisplayName(item, false, false) + ''; - } - break; - } - - case 'Name': - { - html += '' + LibraryBrowser.getPosterViewDisplayName(item, false, false) + ''; - break; - } - case 'Community Rating': - { - html += item.CommunityRating || ' '; - break; - } - case 'Parental Rating': - { - html += item.OfficialRating || ' '; - break; - } - - case 'Year': - case 'Release Date': - { - if (item.PremiereDate && item.Type != "Series") { - try { - var date = parseISO8601Date(item.PremiereDate, { toLocal: true }); - - html += date.toLocaleDateString(); - } - catch (e) { - html += ' '; - } - } - else if (item.ProductionYear) { - html += item.ProductionYear; - - if (item.Status == "Continuing") { - html += "-Present"; - } - else if (item.EndDate) { - - try { - - var endYear = parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear(); - - if (endYear != item.ProductionYear) { - html += "-" + parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear(); - } - - } - catch (e) { - console.log("Error parsing date: " + item.EndDate); - } - } - - } else { - html += ' '; - } - break; - } - case 'Date Added': - { - if (item.DateCreated) { - try { - html += parseISO8601Date(item.DateCreated, { toLocal: true }).toLocaleDateString(); - } - catch (e) { - html += ' '; - } - } - break; - } - default: - { - if (item.LockData) { - html += ''; - } - if (item.IsUnidentified) { - html += '
'; - } - - if (!item.LocalTrailerCount && item.Type == "Movie") { - html += ''; - } - - if (!item.ImageTags || !item.ImageTags.Primary) { - html += ''; - } - - if (!item.BackdropImageTags || !item.BackdropImageTags.length) { - if (item.Type !== "Episode" && item.Type !== "Season" && item.MediaType !== "Audio" && item.Type !== "TvChannel" && item.Type !== "MusicAlbum") { - html += ''; - } - } - - if (!item.ImageTags || !item.ImageTags.Logo) { - if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "Series" || item.Type == "MusicArtist" || item.Type == "BoxSet") { - html += ''; - } - } - - break; - } - } - - html += ''; - return html; - - }).join(''); - } - - function getReportHtml(items, reportType, currentSortField, currentSortDirection) { - + function getTable(result) { var html = ''; - + //Report table html += ''; - html += ''; - html += ''; - var cells = getHeaderCells(reportType); + //Report headers + result.Headers.map(function (header) { + var cellHtml = ''; + html += cellHtml; + }); - return cellHtml; - - }).join(''); - - html += ''; html += ''; - + //Report body html += ''; + if (result.IsGrouped === false) { - for (var i = 0, length = items.length; i < length; i++) { + result.Rows.map(function (row) { + html += getRow(result.Headers, row); + }); + } + else { - var item = items[i]; - - html += ''; - html += getItemCellsHtml(item, cells); - html += ''; + result.Groups.map(function (group) { + html += ''; + html += ''; + html += ''; + group.Rows.map(function (row) { + html += getRow(result.Headers, row); + }); + html += ''; + html += ''; + html += ''; + }); } html += ''; - html += '
'; - html += cells.map(function (c) { - - var cellHtml = ''; - - if (c.sortField) { - cellHtml += ''; + if (header.SortField) { + cellHtml += ''; } - cellHtml += (c.name || ' '); - - if (c.sortField) { - + cellHtml += (header.Name || ' '); + if (header.SortField) { cellHtml += ''; + if (header.SortField === defaultSortBy) { - if (c.sortField == currentSortField) { - - if (currentSortDirection == "Descending") { + if (query.SortOrder === "Descending") { cellHtml += ''; } else { cellHtml += ''; } } } - cellHtml += '
' + (group.Name || ' ') + '
' + ' ' + '
'; - return html; } - function renderItems(page, result, reportType) { + function getRow(rHeaders, rRow) { + var html = ''; + html += ''; - // Scroll back up so they can see the results from the beginning - $(document).scrollTop(0); + for (var j = 0; j < rHeaders.length; j++) { + var rHeader = rHeaders[j]; + var rItem = rRow.Columns[j]; + html += getItem(rHeader, rRow, rItem); + } + html += ''; + return html; + } - $('.listTopPaging', page).html(LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, [], false)).trigger('create'); - - updateFilterControls(page); - - $('.listBottomPaging', page).html(LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, [], false)).trigger('create'); - - $('.reportContainer', page).html(getReportHtml(result.Items, reportType, query.SortBy, query.SortOrder)).trigger('create'); - - $('.btnNextPage', page).on('click', function () { - query.StartIndex += query.Limit; - reloadItems(page); - }); - - $('.btnPreviousPage', page).on('click', function () { - query.StartIndex -= query.Limit; - reloadItems(page); - }); - - $('.lnkColumnSort', page).on('click', function () { - - var order = this.getAttribute('data-sortfield'); - - if (query.SortBy == order) { - - if (query.SortOrder == "Descending") { - - query.SortOrder = "Ascending"; - query.SortBy = defaultSortBy; - - } else { - - query.SortOrder = "Descending"; - query.SortBy = order; + function getItem(rHeader, rRow, rItem) { + var html = ''; + html += ''; + switch (rHeader.ItemViewType) { + case "None": + html += rItem.Name; + break; + case "Detail": + var id = rRow.Id; + if (rItem.Id) + id = rItem.Id; + html += '' + rItem.Name + ''; + break; + case "Edit": + html += '' + rItem.Name + ''; + break; + case "List": + html += '' + rItem.Name + ''; + break; + case "ItemByNameDetails": + html += '' + rItem.Name + ''; + break; + case "EmbeddedImage": + if (rRow.HasEmbeddedImage) { + html += '
'; + } + break; + case "SubtitleImage": + if (rRow.HasSubtitles) { + html += '
'; + } + break; + case "TrailersImage": + if (rRow.HasLocalTrailer) { + html += '
'; + } + break; + case "SpecialsImage": + if (rRow.HasSpecials) { + html += '
'; + } + break; + case "StatusImage": + if (rRow.HasLockData) { + html += ''; + } + if (rRow.IsUnidentified) { + html += '
'; } - } else { + if (!rRow.HasLocalTrailer && rRow.RowType === "Movie") { + html += ''; + } + + if (!rRow.HasImageTagsPrimary) { + html += ''; + } + + if (!rRow.HasImageTagsBackdrop) { + if (rRow.RowType !== "Episode" && rRow.RowType !== "Season" && rRow.MediaType !== "Audio" && rRow.RowType !== "TvChannel" && rRow.RowType !== "MusicAlbum") { + html += ''; + } + } + + if (!rRow.HasImageTagsLogo) { + if (rRow.RowType === "Movie" || rRow.RowType === "Trailer" || rRow.RowType === "Series" || rRow.RowType === "MusicArtist" || rRow.RowType === "BoxSet") { + html += ''; + } + } + break; + default: + html += rItem.Name; + } + html += ''; + return html; + } + + function getStats(result) { + var html = ''; + html += '
'; + //html += '
If you like Africa Fever II, check these out...
'; + html += '
'; + result.Groups.map(function (group) { + //html += '
'; + //html += '
'; + //html += '
'; + html += '
'; + //html += '
'; + html += '
'; + html += '
'; + + html += '
' + html += '
'; + html += '' + group.Header + ' ' + ''; + html += '
'; + + html += '
'; + html += '
'; + html += ''; + html += '
'; + html += '
'; + html += '
'; - query.StartIndex = 0; + html += '
'; + html += '
'; + html += '
'; + + }); + + + html += '
'; + //html += '
'; + html += '
'; + return html; + } + + function ExportReport(page, e) { + + query.UserId = Dashboard.getCurrentUserId(); + query.HasQueryLimit = false; + var url = ApiClient.getUrl("Reports/Items/Download", query); + + if (url) { + e.preventDefault(); //stop the browser from following + window.location.href = url; + } + } + + function loadGroupByFilters(page) { + + query.UserId = Dashboard.getCurrentUserId(); + var url = ""; + + url = ApiClient.getUrl("Reports/Headers", query); + ApiClient.getJSON(url).done(function (result) { + var selected = "None"; + + $('#selectReportGroup', page).find('option').remove().end(); + $('#selectReportGroup', page).append(''); + + result.map(function (header) { + if (header.Visible && header.CanGroup) { + if (header.FieldName.length > 0) { + var option = ''; + $('#selectReportGroup', page).append(option); + if (query.GroupBy === header.FieldName) + selected = header.FieldName; + } + } + }); + $('#selectPageSize', page).val(selected).selectmenu('refresh'); - reloadItems(page); }); } - function reloadItems(page) { + function renderItems(page, result) { - var url = ApiClient.getUrl("Items", query); - var reportType = $('#selectView', page).val(); + $(document).scrollTop(0); + var html = ''; + + if (SelectedReportView === "ReportData") { + + var pagingHtml = LibraryBrowser.getQueryPagingHtml({ + startIndex: query.StartIndex, + limit: query.Limit, + totalRecordCount: result.TotalRecordCount, + updatePageSizeSetting: false, + viewButton: true, + showLimit: false + }); + + $('.listTopPaging', page).html(pagingHtml).trigger('create'); + $('.listTopPaging', page).show(); + + $('.listBottomPaging', page).html(pagingHtml).trigger('create'); + $('.listBottomPaging', page).show(); + + $('.btnNextPage', page).on('click', function () { + query.StartIndex += query.Limit; + reloadItems(page); + }); + $('.btnNextPage', page).show(); + + $('.btnPreviousPage', page).on('click', function () { + query.StartIndex -= query.Limit; + reloadItems(page); + }); + $('.btnPreviousPage', page).show(); + + $('#btnReportExport', page).show(); + $('#selectPageSizeBox', page).show(); + $('#selectReportGroupingBox', page).show(); + $('#grpReportsColumns', page).show(); + + html += getTable(result); + + $('.reporContainer', page).html(html).trigger('create'); + + $('.lnkColumnSort', page).on('click', function () { + + var order = this.getAttribute('data-sortfield'); + + if (query.SortBy === order) { + + if (query.SortOrder === "Descending") { + + query.SortOrder = "Ascending"; + query.SortBy = defaultSortBy; + + } else { + + query.SortOrder = "Descending"; + query.SortBy = order; + } + + } else { + + query.SortOrder = "Ascending"; + query.SortBy = order; + } + + query.StartIndex = 0; + + reloadItems(page); + }); + } + else { + $('.listTopPaging', page).hide(); + $('.listBottomPaging', page).hide(); + $('.btnNextPage', page).hide(); + $('.btnPreviousPage', page).hide(); + + $('#btnReportExport', page).hide(); + $('#selectPageSizeBox', page).hide(); + $('#selectReportGroupingBox', page).hide(); + $('#grpReportsColumns', page).hide(); + + html += getStats(result); + $('.reporContainer', page).html(html).trigger('create'); + } + + $('#GroupStatus', page).hide(); + $('#GroupAirDays', page).hide(); + $('#GroupEpisodes', page).hide(); + switch (query.IncludeItemTypes) { + case "Series": + case "Season": + $('#GroupStatus', page).show(); + $('#GroupAirDays', page).show(); + break; + case "Episode": + $('#GroupStatus', page).show(); + $('#GroupAirDays', page).show(); + $('#GroupEpisodes', page).show(); + break; + } + + } + + function reloadItems(page) { + Dashboard.showLoadingMsg(); + + query.UserId = Dashboard.getCurrentUserId(); + var url = ""; + + switch (SelectedReportView) { + case "ReportData": + query.HasQueryLimit = true; + url = ApiClient.getUrl("Reports/Items", query); + break; + case "ReportStatistic": + query.TopItems = topItems; + query.HasQueryLimit = false; + url = ApiClient.getUrl("Reports/Statistics", query); + break; + } ApiClient.getJSON(url).done(function (result) { - - renderItems(page, result, reportType); - + updateFilterControls(page); + renderItems(page, result); }); + + + Dashboard.hideLoadingMsg(); } function updateFilterControls(page) { - $('#selectView').val(query.IncludeItemTypes).selectmenu('refresh'); + + + $('.chkStandardFilter', page).each(function () { + + var filters = "," + (query.Filters || ""); + var filterName = this.getAttribute('data-filter'); + + this.checked = filters.indexOf(',' + filterName) != -1; + + }).checkboxradio('refresh'); + $('.chkVideoTypeFilter', page).each(function () { @@ -597,21 +412,37 @@ }).checkboxradio('refresh'); + $('.chkStatus', page).each(function () { + + var filters = "," + (query.SeriesStatus || ""); + var filterName = this.getAttribute('data-filter'); + + this.checked = filters.indexOf(',' + filterName) != -1; + + }).checkboxradio('refresh'); + + $('.chkAirDays', page).each(function () { + + var filters = "," + (query.AirDays || ""); + var filterName = this.getAttribute('data-filter'); + + this.checked = filters.indexOf(',' + filterName) != -1; + + }).checkboxradio('refresh'); + $('#chk3D', page).checked(query.Is3D == true).checkboxradio('refresh'); $('#chkHD', page).checked(query.IsHD == true).checkboxradio('refresh'); $('#chkSD', page).checked(query.IsHD == false).checkboxradio('refresh'); $('#chkSubtitle', page).checked(query.HasSubtitles == true).checkboxradio('refresh'); - $('#chkNoSubtitle', page).checked(query.HasSubtitles === false).checkboxradio('refresh'); $('#chkTrailer', page).checked(query.HasTrailer == true).checkboxradio('refresh'); - $('#chkNoTrailer', page).checked(query.HasTrailer == false).checkboxradio('refresh'); $('#chkSpecialFeature', page).checked(query.HasSpecialFeature == true).checkboxradio('refresh'); $('#chkThemeSong', page).checked(query.HasThemeSong == true).checkboxradio('refresh'); - $('#chkNoThemeSong', page).checked(query.HasThemeSong == false).checkboxradio('refresh'); $('#chkThemeVideo', page).checked(query.HasThemeVideo == true).checkboxradio('refresh'); - $('#chkNoThemeVideo', page).checked(query.HasThemeVideo == false).checkboxradio('refresh'); - $('#chkIsPlaceHolder', page).checked(query.IsPlaceHolder == true).checkboxradio('refresh'); + $('#selectPageSize', page).val(query.Limit).selectmenu('refresh'); + + //Management $('#chkMissingRating', page).checked(query.HasOfficialRating == false).checkboxradio('refresh'); $('#chkMissingOverview', page).checked(query.HasOverview == false).checkboxradio('refresh'); $('#chkYearMismatch', page).checked(query.IsYearMismatched == true).checkboxradio('refresh'); @@ -619,47 +450,124 @@ $('#chkIsUnidentified', page).checked(query.IsUnidentified == true).checkboxradio('refresh'); $('#chkIsLocked', page).checked(query.IsLocked == true).checkboxradio('refresh'); + //Episodes $('#chkSpecialEpisode', page).checked(query.ParentIndexNumber == 0).checkboxradio('refresh'); $('#chkMissingEpisode', page).checked(query.IsMissing == true).checkboxradio('refresh'); $('#chkFutureEpisode', page).checked(query.IsUnaired == true).checkboxradio('refresh'); + + $('#selectView').val(query.IncludeItemTypes).selectmenu('refresh'); } - $(document).on('pageinit', "#libraryReportPage", function () { + var filtersLoaded; + function reloadFiltersIfNeeded(page) { + + if (!filtersLoaded) { + + filtersLoaded = true; + + QueryReportFilters.loadFilters(page, Dashboard.getCurrentUserId(), query, function () { + + reloadItems(page); + }); + + QueryReportColumns.loadColumns(page, Dashboard.getCurrentUserId(), query, function () { + + reloadItems(page); + }); + } + + } + + $(document).on('pageinit', "#libraryReportManagerPage", function () { var page = this; - $('#radioBasicFilters', page).on('change', function () { - - if (this.checked) { - $('.basicFilters', page).show(); - $('.advancedFilters', page).hide(); - } else { - $('.basicFilters', page).hide(); - } - }); - - $('#radioAdvancedFilters', page).on('change', function () { - - if (this.checked) { - $('.advancedFilters', page).show(); - $('.basicFilters', page).hide(); - } else { - $('.advancedFilters', page).hide(); - } - }); - $('#selectView', page).on('change', function () { query.StartIndex = 0; + SelectedReportView = $('#selectReportType', page).val(); query.IncludeItemTypes = this.value; - - query.SortBy = getDefaultSortOrder(this.value); query.SortOrder = "Ascending"; + query.ReportColumns = null; + $('.btnReportExport', page).hide(); + filtersLoaded = false; + loadGroupByFilters(page); + reloadFiltersIfNeeded(page); + reloadItems(page); + + + }); + + $('#selectReportType', page).on('change', function () { + + query.StartIndex = 0; + query.IncludeItemTypes = $('#selectView', page).val(); + SelectedReportView = this.value; + query.SortOrder = "Ascending"; + filtersLoaded = false; + loadGroupByFilters(page); + reloadFiltersIfNeeded(page); + reloadItems(page); + + + }); + + $('#selectReportGroup', page).on('change', function () { + query.GroupBy = this.value; + query.StartIndex = 0; + reloadItems(page); + }); + + $('#btnReportExportCsv', page).on('click', function (e) { + + query.ExportType = "CSV"; + ExportReport(page, e); + }); + + $('#btnReportExportExcel', page).on('click', function (e) { + + query.ExportType = "Excel"; + ExportReport(page, e); + }); + + $('#btnResetReportColumns', page).on('click', function (e) { + + query.ReportColumns = null; + query.StartIndex = 0; + filtersLoaded = false; + reloadFiltersIfNeeded(page); + reloadItems(page); + }); + + $('.viewPanel', page).on('panelopen', function () { + + reloadFiltersIfNeeded(page); + }); + + $('#selectPageSize', page).on('change', function () { + query.Limit = parseInt(this.value); + query.StartIndex = 0; + reloadItems(page); + }); + + $('.chkStandardFilter', this).on('change', function () { + + var filterName = this.getAttribute('data-filter'); + var filters = query.Filters || ""; + + filters = (',' + filters).replace(',' + filterName, '').substring(1); + + if (this.checked) { + filters = filters ? (filters + ',' + filterName) : filterName; + } + + query.StartIndex = 0; + query.Filters = filters; reloadItems(page); }); - $('.chkVideoTypeFilter', page).on('change', function () { + $('.chkVideoTypeFilter', this).on('change', function () { var filterName = this.getAttribute('data-filter'); var filters = query.VideoTypes || ""; @@ -676,7 +584,7 @@ reloadItems(page); }); - $('#chk3D', page).on('change', function () { + $('#chk3D', this).on('change', function () { query.StartIndex = 0; query.Is3D = this.checked ? true : null; @@ -684,7 +592,7 @@ reloadItems(page); }); - $('#chkHD', page).on('change', function () { + $('#chkHD', this).on('change', function () { query.StartIndex = 0; query.IsHD = this.checked ? true : null; @@ -692,7 +600,7 @@ reloadItems(page); }); - $('#chkSD', page).on('change', function () { + $('#chkSD', this).on('change', function () { query.StartIndex = 0; query.IsHD = this.checked ? false : null; @@ -700,47 +608,23 @@ reloadItems(page); }); - $('#chkSubtitle', page).on('change', function () { + $('#chkSubtitle', this).on('change', function () { query.StartIndex = 0; query.HasSubtitles = this.checked ? true : null; - $('#chkNoSubtitle', page).checked(false).checkboxradio('refresh'); - reloadItems(page); }); - $('#chkNoSubtitle', page).on('change', function () { - - query.StartIndex = 0; - query.HasSubtitles = this.checked ? false : null; - - $('#chkSubtitle', page).checked(false).checkboxradio('refresh'); - - reloadItems(page); - }); - - $('#chkTrailer', page).on('change', function () { + $('#chkTrailer', this).on('change', function () { query.StartIndex = 0; query.HasTrailer = this.checked ? true : null; - $('#chkNoTrailer', page).checked(false).checkboxradio('refresh'); - reloadItems(page); }); - $('#chkNoTrailer', page).on('change', function () { - - query.StartIndex = 0; - query.HasTrailer = this.checked ? false : null; - - $('#chkTrailer', page).checked(false).checkboxradio('refresh'); - - reloadItems(page); - }); - - $('#chkSpecialFeature', page).on('change', function () { + $('#chkSpecialFeature', this).on('change', function () { query.StartIndex = 0; query.HasSpecialFeature = this.checked ? true : null; @@ -748,50 +632,47 @@ reloadItems(page); }); - $('#chkIsPlaceHolder', page).on('change', function () { - - query.StartIndex = 0; - query.IsPlaceHolder = this.checked ? true : null; - - reloadItems(page); - }); - - $('#chkThemeSong', page).on('change', function () { + $('#chkThemeSong', this).on('change', function () { query.StartIndex = 0; query.HasThemeSong = this.checked ? true : null; - $('#chkNoThemeSong', page).checked(false).checkboxradio('refresh'); - reloadItems(page); }); - $('#chkNoThemeSong', page).on('change', function () { - - query.StartIndex = 0; - query.HasThemeSong = this.checked ? false : null; - - $('#chkThemeSong', page).checked(false).checkboxradio('refresh'); - - reloadItems(page); - }); - - $('#chkThemeVideo', page).on('change', function () { + $('#chkThemeVideo', this).on('change', function () { query.StartIndex = 0; query.HasThemeVideo = this.checked ? true : null; - - $('#chkNoThemeVideo', page).checked(false).checkboxradio('refresh'); reloadItems(page); }); - - $('#chkNoThemeVideo', page).on('change', function () { + + $('#radioBasicFilters', this).on('change', function () { + + if (this.checked) { + $('.basicFilters', page).show(); + $('.advancedFilters', page).hide(); + } else { + $('.basicFilters', page).hide(); + } + }); + + $('#radioAdvancedFilters', this).on('change', function () { + + if (this.checked) { + $('.advancedFilters', page).show(); + $('.basicFilters', page).hide(); + } else { + $('.advancedFilters', page).hide(); + } + }); + + //Management + $('#chkIsLocked', page).on('change', function () { query.StartIndex = 0; - query.HasThemeVideo = this.checked ? false : null; - - $('#chkThemeVideo', page).checked(false).checkboxradio('refresh'); + query.IsLocked = this.checked ? true : null; reloadItems(page); }); @@ -804,6 +685,14 @@ reloadItems(page); }); + $('#chkMissingEpisode', page).on('change', function () { + + query.StartIndex = 0; + query.IsMissing = this.checked ? true : false; + + reloadItems(page); + }); + $('#chkMissingRating', page).on('change', function () { query.StartIndex = 0; @@ -828,14 +717,7 @@ reloadItems(page); }); - $('#chkIsLocked', page).on('change', function () { - - query.StartIndex = 0; - query.IsLocked = this.checked ? true : null; - - reloadItems(page); - }); - + //Episodes $('#chkMissingEpisode', page).on('change', function () { query.StartIndex = 0; @@ -867,19 +749,292 @@ reloadItems(page); }); - }).on('pagebeforeshow', "#libraryReportPage", function () { + $('.chkAirDays', this).on('change', function () { - var page = this; + var filterName = this.getAttribute('data-filter'); + var filters = query.AirDays || ""; - query.SortBy = getDefaultSortOrder($('#selectView', page).val()); - query.SortOrder = "Ascending"; + filters = (',' + filters).replace(',' + filterName, '').substring(1); - $('#selectView', page).val(query.IncludeItemTypes).selectmenu('refresh').trigger('change'); + if (this.checked) { + filters = filters ? (filters + ',' + filterName) : filterName; + } - }).on('pageshow', "#libraryReportPage", function () { + query.AirDays = filters; + query.StartIndex = 0; + reloadItems(page); + }); - updateFilterControls(this); - }); + $('.chkStatus', this).on('change', function () { -})(jQuery, document, window); + var filterName = this.getAttribute('data-filter'); + var filters = query.SeriesStatus || ""; + filters = (',' + filters).replace(',' + filterName, '').substring(1); + + if (this.checked) { + filters = filters ? (filters + ',' + filterName) : filterName; + } + + query.SeriesStatus = filters; + query.StartIndex = 0; + reloadItems(page); + }); + }) + .on('pagebeforeshow', "#libraryReportManagerPage", function () { + + query.UserId = Dashboard.getCurrentUserId(); + var page = this; + query.SortOrder = "Ascending"; + + QueryFilters.onPageShow(page, query); + + $('#selectView', page).val(query.IncludeItemTypes).selectmenu('refresh').trigger('change'); + + }) + .on('pageshow', "#libraryReportManagerPage", function () { + + var page = this; + + updateFilterControls(page); + + filtersLoaded = false; + updateFilterControls(this); + }); + +})(jQuery, document); + +(function (window) { + + function renderOptions(page, selector, cssClass, items) { + + var elem; + + if (items.length) { + + elem = $(selector, page).show(); + + } else { + elem = $(selector, page).hide(); + } + + var html = ''; + + // style="margin: -.2em -.8em;" + html += '
'; + + var index = 0; + var idPrefix = 'chk' + selector.substring(1); + + html += items.map(function (filter) { + + var itemHtml = ''; + + var id = idPrefix + index; + var label = filter; + var value = filter; + var checked = false; + if (filter.FieldName) { + label = filter.Name; + value = filter.FieldName; + checked = filter.Visible; + } + itemHtml += ''; + itemHtml += '