diff --git a/source/file_size_metrics/.editorconfig b/source/file_size_metrics/.editorconfig new file mode 100644 index 000000000..778e78303 --- /dev/null +++ b/source/file_size_metrics/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[{info.json,*.py}] +indent_size = 4 diff --git a/source/file_size_metrics/changelog.md b/source/file_size_metrics/changelog.md index 0db16e637..7775d4a6c 100644 --- a/source/file_size_metrics/changelog.md +++ b/source/file_size_metrics/changelog.md @@ -1,3 +1,6 @@ +**0.1.1** +- When viewing on mobile, show individual file metrics in a dialog popup + **0.1.0** - New layout to try and make better use of space diff --git a/source/file_size_metrics/info.json b/source/file_size_metrics/info.json index eb839d827..3b1a95751 100644 --- a/source/file_size_metrics/info.json +++ b/source/file_size_metrics/info.json @@ -1,15 +1,15 @@ { - "author": "Josh.5, EspadaV8", - "compatibility": [1, 2], - "description": "Aggregate changes in file size metrics for processed files and add a data panel for displaying the results.", - "icon": "https://raw.githubusercontent.com/Josh5/unmanic.plugin.file_size_metrics/master/icon.png", - "id": "file_size_metrics", - "name": "File Size Metrics Data Panel", - "platform": ["all"], - "priorities": { - "on_worker_process": 1, - "on_postprocessor_task_results": 0 - }, - "tags": "data panel", - "version": "0.1.0" + "author": "Josh.5, EspadaV8", + "compatibility": [1, 2], + "description": "Aggregate changes in file size metrics for processed files and add a data panel for displaying the results.", + "icon": "https://raw.githubusercontent.com/Josh5/unmanic.plugin.file_size_metrics/master/icon.png", + "id": "file_size_metrics", + "name": "File Size Metrics Data Panel", + "platform": ["all"], + "priorities": { + "on_worker_process": 1, + "on_postprocessor_task_results": 0 + }, + "tags": "data panel", + "version": "0.1.1" } diff --git a/source/file_size_metrics/plugin.py b/source/file_size_metrics/plugin.py index dec06ec74..f53a6e29f 100644 --- a/source/file_size_metrics/plugin.py +++ b/source/file_size_metrics/plugin.py @@ -317,12 +317,12 @@ def prepare_filtered_historic_tasks(self, request_dict): self.db_stop() return return_data - def save_source_item(self, abspath, size, task_success=False): + def save_source_item(self, abspath, size, start_time=None, task_success=False): self.db_start() basename = os.path.basename(abspath) task_label = basename - start_time = datetime.datetime.now() + start_time = start_time if start_time is not None else datetime.datetime.now() finish_time = None try: new_historic_task = HistoricTasks.create( @@ -412,10 +412,10 @@ def get_total_size_change_data_details(data): return json.dumps(results, indent=2) -def save_source_size(abspath, size): +def save_source_details(abspath, size, start_time=None): # Return a list of historical tasks based on the request JSON body data = Data() - task_id = data.save_source_item(abspath, size) + task_id = data.save_source_item(abspath, size, start_time) return task_id @@ -458,7 +458,10 @@ def on_worker_process(data): with open(plugin_data_file, 'w') as f: required_data = { + 'file_in': data.get('file_in'), + 'original_file_path': data.get('original_file_path'), 'source_size': source_size, + 'start_time': datetime.datetime.now().isoformat(), } json.dump(required_data, f, indent=4) @@ -491,11 +494,15 @@ def on_postprocessor_task_results(data): # Get the file out and store (if it exists) src_file_hash = hashlib.md5(original_source_path.encode('utf8')).hexdigest() plugin_data_file = os.path.join(profile_directory, '{}.json'.format(src_file_hash)) + start_time = None + if os.path.exists(plugin_data_file): # The store exists with open(plugin_data_file) as infile: task_metadata = json.load(infile) + source_size = task_metadata.get('source_size') + start_time = datetime.datetime.fromisoformat(task_metadata.get('start_time')) if 'start_time' in task_metadata else datetime.datetime.now() else: # The store did not exist, resort to fetching the data from the original source file (hopefully unchanged) logger.warning("Plugin data file is missing. Fetching source size direct from source path.") @@ -504,7 +511,9 @@ def on_postprocessor_task_results(data): if not source_size: logger.error("Plugin data file is missing 'source_size'.") return data - task_id = save_source_size(original_source_path, source_size) + + task_id = save_source_details(original_source_path, source_size, start_time) + if task_id is None: logger.error("Failed to create source size entry for this file") return data diff --git a/source/file_size_metrics/static/css/style.css b/source/file_size_metrics/static/css/style.css index d7904f690..dddcf0b55 100644 --- a/source/file_size_metrics/static/css/style.css +++ b/source/file_size_metrics/static/css/style.css @@ -85,9 +85,8 @@ html { background-color: var(--q-card-head-hover); } -.content { +.card-content { background-color: var(--q-card); - display: none; overflow: hidden; padding: 0 18px; } @@ -126,7 +125,10 @@ html { } #individual_file_size_chart { + display: block; order: 2; + overflow: hidden; + padding: 0 3px; } #individual_file_size_chart .card { @@ -195,6 +197,7 @@ html { #individual_file_size_chart { order: 1; + display: none; } #individual_file_size_chart .card { @@ -210,3 +213,35 @@ html { padding-top: 20px; } } + +dialog { + color: var(--q-text); + border: none; + background-color: var(--q-card); + width: 100%; + padding: 0; +} + +dialog::backdrop { + background-color: var(--q-card-head); + opacity: 0.85; +} + +dialog .card-content { + padding: 0 10px; +} + +dialog .card-footer { + padding: 0 0 10px 0; +} + +dialog .q-btn { + background: var(--q-primary); + border: 0; + color: #fff; + font-size: 14px; + font-weight: 500; + outline: 0; + padding: 8px 20px; + text-transform: uppercase; +} diff --git a/source/file_size_metrics/static/index.html b/source/file_size_metrics/static/index.html index 4ad873642..7347036e6 100644 --- a/source/file_size_metrics/static/index.html +++ b/source/file_size_metrics/static/index.html @@ -51,6 +51,12 @@ +
@@ -91,27 +97,36 @@
Individual File Size Change
-
- - -
-
- There was an issue showing this chart -
+
+
+ There was an issue showing this chart
+
+ +
+
+
+
-
- (Select a task from the table) + +
+
Individual File Size Change
+
+
+
+ There was an issue showing this chart
+ +
+
+
-
+
diff --git a/source/file_size_metrics/static/js/filesizechart.js b/source/file_size_metrics/static/js/filesizechart.js index 00188c92c..4a7acc0bf 100644 --- a/source/file_size_metrics/static/js/filesizechart.js +++ b/source/file_size_metrics/static/js/filesizechart.js @@ -40,7 +40,7 @@ const CompletedTasksFileSizeDiffChart = (function () { let source_total_size = 0; let destination_total_size = 0; - const individualChart = Highcharts.chart("file_size_chart", { + Highcharts.setOptions({ chart: { backgroundColor: chart_background, height: chartHeight, @@ -58,6 +58,9 @@ const CompletedTasksFileSizeDiffChart = (function () { }, }, colors: [default_bar_colour, positive_bar_colour], + legend: { + enabled: false, + }, xAxis: { type: "category", labels: { @@ -74,62 +77,33 @@ const CompletedTasksFileSizeDiffChart = (function () { }, }, title: { - text: "Sizes", + text: "Size", style: { color: subtext_colour, }, }, }, - legend: { - enabled: false, - }, series: [], }); - const totalChart = Highcharts.chart("total_size_chart", { + const individualChart = new Highcharts.Chart({ chart: { - backgroundColor: chart_background, - height: chartHeight, + renderTo: "file_size_chart", }, - title: { - text: "", - style: { - color: text_colour, - }, + }); + const individualChart2 = new Highcharts.Chart({ + chart: { + renderTo: "file_size_chart_dialog", + }, + }); + + const totalChart = new Highcharts.Chart({ + chart: { + renderTo: "total_size_chart", }, subtitle: { text: "Displaying the total file size changed on disk by Unmanic processing files", - style: { - color: subtext_colour, - }, - }, - colors: [default_bar_colour, positive_bar_colour], - xAxis: { - type: "category", - labels: { - style: { - color: text_colour, - }, - }, - lineColor: text_colour, - }, - yAxis: { - labels: { - style: { - color: text_colour, - }, - }, - title: { - text: "Sizes", - style: { - color: subtext_colour, - }, - }, }, - legend: { - enabled: false, - }, - series: [], }); const updateIndividualChart = function () { @@ -149,7 +123,7 @@ const CompletedTasksFileSizeDiffChart = (function () { source_file_size = Number(source_file_size); destination_file_size = Number(destination_file_size); - individualChart.update({ + const options = { chart: { backgroundColor: chart_background, type: "bar", @@ -173,7 +147,10 @@ const CompletedTasksFileSizeDiffChart = (function () { File Size: ${formatBytes(Math.abs(this.point.y))}`; }, }, - }); + }; + + individualChart.update(options); + individualChart2.update(options); const newSeriesData = { borderWidth: 0, @@ -193,10 +170,14 @@ const CompletedTasksFileSizeDiffChart = (function () { for (let i = individualChart.series.length - 1; i >= 0; i--) { individualChart.series[i].remove(false); + individualChart2.series[i].remove(false); } individualChart.addSeries(newSeriesData, false); + individualChart2.addSeries(newSeriesData, false); + individualChart.redraw(); + individualChart2.redraw(); }; const updateTotalChart = function () { @@ -303,7 +284,7 @@ const CompletedTasksFileSizeDiffChart = (function () {

`; } - $("#selected_task_name").html(html); + $(".selected_task_name").html(html); }); }; diff --git a/source/file_size_metrics/static/js/table.js b/source/file_size_metrics/static/js/table.js index ead7356be..baf5d5124 100644 --- a/source/file_size_metrics/static/js/table.js +++ b/source/file_size_metrics/static/js/table.js @@ -3,6 +3,8 @@ const viewConversionDetails = (jobId) => { }; const CompletedTasksDatatable = (function () { + const modal = document.querySelector("[data-modal]"); + const recordName = (basename, type, { task_success } = row) => { if (task_success) { return ` ${basename}`; @@ -69,6 +71,10 @@ const CompletedTasksDatatable = (function () { viewConversionDetails(data.id); } + + if ($("#individual_file_size_chart").is(":visible") === false) { + modal.showModal(); + } }); };