From a6b664511e67bc740377c3509c217bb8eddd425c Mon Sep 17 00:00:00 2001 From: Matt Brooks Date: Wed, 26 Jun 2024 15:46:44 -0400 Subject: [PATCH 1/7] Set report start date to 1 year ago and update blacklist --- springshare-libinsight-dataset-downloader.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/springshare-libinsight-dataset-downloader.js b/springshare-libinsight-dataset-downloader.js index 01bc4b0..fabdff8 100644 --- a/springshare-libinsight-dataset-downloader.js +++ b/springshare-libinsight-dataset-downloader.js @@ -18,20 +18,14 @@ // Set this array to strings of the dataset IDs you do not want to download. const blacklist = [ - // '4698', - // '4878', + '4698', + '4878', // '5011', - '7927', - '22125', - '22124', - '22126', - '22123', - '22122' + '7927' ]; let datasetsRows; let datasetCounts = []; - // Process dataset ids and counts. Add menu item to download reports. if(datasetsRows = document.querySelectorAll('#all-datasets tr')) { let dataRows = [].slice.call(datasetsRows, 2); @@ -53,6 +47,10 @@ downloadLink.text = 'Download All Reports'; let adminMenu = document.querySelector('#li-admin-navbar-manage').parentNode.querySelector('div'); adminMenu.appendChild(downloadLink); + let startDate = new Date(new Date().setFullYear(new Date().getFullYear() - 1)); + let startDateFormatted = startDate.toLocaleDateString('en-us', { month: 'short' }); + startDateFormatted += ' ' + startDate.toLocaleDateString('en-us', { day: '2-digit' }); + startDateFormatted += ' ' + startDate.toLocaleDateString('en-us', { year: 'numeric' }); // Download reports. @@ -68,7 +66,7 @@ '&dataset_type=1' + '&user_level=1' + '&total_count=' + dataset.count + - '&from=Jan 01 0000' + + '&from=' + startDateFormatted + '&to=Dec 31 9999' + '&filters[day_limit]=21' + '&filters[hr_start]=0' + From eaf68ec0e8f92e2b857cb084d2c3732a4d0a7500 Mon Sep 17 00:00:00 2001 From: Vivian Le Date: Tue, 13 Aug 2024 12:20:19 -0400 Subject: [PATCH 2/7] Updates script to download/queue dataset --- springshare-libinsight-dataset-downloader.js | 154 ++++++++++++------- 1 file changed, 100 insertions(+), 54 deletions(-) diff --git a/springshare-libinsight-dataset-downloader.js b/springshare-libinsight-dataset-downloader.js index fabdff8..c0f3df6 100644 --- a/springshare-libinsight-dataset-downloader.js +++ b/springshare-libinsight-dataset-downloader.js @@ -14,74 +14,120 @@ // ==/UserScript== (() => { - 'use strict'; + "use strict"; // Set this array to strings of the dataset IDs you do not want to download. const blacklist = [ - '4698', - '4878', - // '5011', - '7927' + // '4698', + // '4878', + // '5011', + '7927', + "22125", + "22124", + "22126", + "22123", + "22122", ]; + const maxRecords = 10000; let datasetsRows; let datasetCounts = []; // Process dataset ids and counts. Add menu item to download reports. - if(datasetsRows = document.querySelectorAll('#all-datasets tr')) { - let dataRows = [].slice.call(datasetsRows, 2); + if ((datasetsRows = document.querySelectorAll("#all-datasets tr"))) { + let dataRows = [].slice.call(datasetsRows, 2); - dataRows.forEach(row => { - datasetCounts.push({ - id: row.childNodes[1].textContent, - count: row.childNodes[7].textContent.replace(',', '') - }); - }); + dataRows.forEach((row) => { + datasetCounts.push({ + id: row.childNodes[1].textContent, + count: row.childNodes[7].textContent.replace(",", ""), + }); + }); - datasetCounts = datasetCounts.filter(dataset => !blacklist.includes(dataset.id)); + datasetCounts = datasetCounts.filter( + (dataset) => !blacklist.includes(dataset.id) + ); + // Create menu item. + let downloadLink = document.createElement("a"); + downloadLink.setAttribute("class", "dropdown-item"); + downloadLink.setAttribute("href", "#"); + downloadLink.text = "Download All Reports"; + let adminMenu = document + .querySelector("#li-admin-navbar-manage") + .parentNode.querySelector("div"); + adminMenu.appendChild(downloadLink); - // Create menu item. - let downloadLink = document.createElement('a'); - downloadLink.setAttribute('class', 'dropdown-item'); - downloadLink.setAttribute('href', '#'); - downloadLink.text = 'Download All Reports'; - let adminMenu = document.querySelector('#li-admin-navbar-manage').parentNode.querySelector('div'); - adminMenu.appendChild(downloadLink); - let startDate = new Date(new Date().setFullYear(new Date().getFullYear() - 1)); - let startDateFormatted = startDate.toLocaleDateString('en-us', { month: 'short' }); - startDateFormatted += ' ' + startDate.toLocaleDateString('en-us', { day: '2-digit' }); - startDateFormatted += ' ' + startDate.toLocaleDateString('en-us', { year: 'numeric' }); + // Download reports. + downloadLink.onclick = (e) => { + e.preventDefault(); + e.stopPropagation(); + datasetCounts.forEach((dataset) => { + // Download report if number of records less than max records + if (dataset.count < maxRecords) { + downloadReport(dataset); + } + else // Queue report if number of records more than max records + { + queueReport(dataset); + } + }); + }; + } + + function downloadReport(dataset) + { + let url = 'https://gsu.libinsight.com/admin/custom-dataset/' + dataset.id + '/export' + + '?filters[page]=1' + + '&iid=294' + + '&dataset_id=' + dataset.id + + '&dataset_type=1' + + '&user_level=1' + + '&total_count=' + dataset.count + + '&from=Jan 01 0000' + + '&to=Dec 31 9999' + + '&filters[day_limit]=21' + + '&filters[hr_start]=0' + + '&filters[hr_end]=24' + + '&filters[sort]=date-desc'; + + setTimeout(() => { + let a = document.createElement('a'); + a.href = url; + document.body.appendChild(a); + a.setAttribute('target', '_blank'); + a.click(); + a.remove(); + }, 100); + } + + function queueReport(dataset) + { + let url = "https://gsu.libinsight.com/admin/reports/" + dataset.id + "/add"; + let form = new FormData(); + form.set("name", "Dataset-" + dataset.id + "-" + new Date().toISOString()); + form.set("dataset_type", 1); + form.set("record_count", dataset.count); + form.set("date_range", "Custom Date Range"); - // Download reports. - downloadLink.onclick = e => { - e.preventDefault(); - e.stopPropagation(); + let options = '?filters[page]=1' + + '&iid=294' + + '&dataset_id=' + dataset.id + + '&dataset_type=1' + + '&user_level=1' + + '&total_count=' + dataset.count + + '&from=Jan 01 0000' + + '&to=Dec 31 9999' + + '&filters[day_limit]=21' + + '&filters[hr_start]=0' + + '&filters[hr_end]=24' + + '&filters[sort]=date-desc' - datasetCounts.forEach(dataset => { - let url = 'https://gsu.libinsight.com/admin/custom-dataset/' + dataset.id + '/export' + - '?filters[page]=1' + - '&iid=294' + - '&dataset_id=' + dataset.id + - '&dataset_type=1' + - '&user_level=1' + - '&total_count=' + dataset.count + - '&from=' + startDateFormatted + - '&to=Dec 31 9999' + - '&filters[day_limit]=21' + - '&filters[hr_start]=0' + - '&filters[hr_end]=24' + - '&filters[sort]=date-desc'; + form.set("options", options); - setTimeout(() => { - let a = document.createElement('a'); - a.href = url; - document.body.appendChild(a); - a.setAttribute('target', '_blank'); - a.click(); - a.remove(); - }, 100); - }); - } + fetch(url, { + method: "POST", + body: form, + }); } -})(); +})(); \ No newline at end of file From 42f81a378582fb89e14e2cdb8521f3bf778c4839 Mon Sep 17 00:00:00 2001 From: Vivian Le Date: Tue, 13 Aug 2024 12:21:35 -0400 Subject: [PATCH 3/7] Update read me and changelog --- CHANGELOG.md | 5 +++++ README.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06b13ca..6f9cb4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [4.0.0] - 2024-08-13 +### Springshare LibInsight Dataset Downloader +- Update script to download dataset if less then 10000 records. +- Add script to queue the export if more than 10000 records. + ## [3.0.0] - 2022-12-14 ### SharePoint Permission Link - Add userscript that adds a site permission link on the right ribbon of SharePoint sites. diff --git a/README.md b/README.md index 41ca6c2..33f5a7c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Code Repository: https://github.com/gsu-library/userscripts Author: Matt Brooks Date Created: 2021-05-19 License: [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html) -Version: 3.0.0 +Version: 4.0.0 ## Description UserScripts used by GSU Library. From 05ad235ebe8498000adbbeea61e0ee551f730bf5 Mon Sep 17 00:00:00 2001 From: Vivian Le Date: Tue, 13 Aug 2024 12:22:36 -0400 Subject: [PATCH 4/7] Update script to download/queue dataset --- springshare-libinsight-dataset-downloader.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/springshare-libinsight-dataset-downloader.js b/springshare-libinsight-dataset-downloader.js index c0f3df6..e373f2c 100644 --- a/springshare-libinsight-dataset-downloader.js +++ b/springshare-libinsight-dataset-downloader.js @@ -121,8 +121,7 @@ '&filters[day_limit]=21' + '&filters[hr_start]=0' + '&filters[hr_end]=24' + - '&filters[sort]=date-desc' - + '&filters[sort]=date-desc'; form.set("options", options); fetch(url, { From d3c56cbdd45c61c0ce56e9329d02c05a01710142 Mon Sep 17 00:00:00 2001 From: Vivian Le Date: Tue, 13 Aug 2024 15:26:05 -0400 Subject: [PATCH 5/7] Update report blacklist --- springshare-libinsight-dataset-downloader.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/springshare-libinsight-dataset-downloader.js b/springshare-libinsight-dataset-downloader.js index e373f2c..90241bc 100644 --- a/springshare-libinsight-dataset-downloader.js +++ b/springshare-libinsight-dataset-downloader.js @@ -18,15 +18,10 @@ // Set this array to strings of the dataset IDs you do not want to download. const blacklist = [ - // '4698', - // '4878', + '4698', + '4878', // '5011', '7927', - "22125", - "22124", - "22126", - "22123", - "22122", ]; const maxRecords = 10000; let datasetsRows; From 97a7015b13668fd2d1fb0e35721be7503bff5100 Mon Sep 17 00:00:00 2001 From: Vivian Le Date: Tue, 13 Aug 2024 15:39:22 -0400 Subject: [PATCH 6/7] Update readme and changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f9cb4d..8a51ad7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Springshare LibInsight Dataset Downloader - Update script to download dataset if less then 10000 records. - Add script to queue the export if more than 10000 records. +- Update blacklist. ## [3.0.0] - 2022-12-14 ### SharePoint Permission Link From 14440788c92e86373dd32c68d5be5d04517ac67e Mon Sep 17 00:00:00 2001 From: Vivian Le Date: Tue, 13 Aug 2024 15:55:14 -0400 Subject: [PATCH 7/7] Increase the version in dataset downloader header --- springshare-libinsight-dataset-downloader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/springshare-libinsight-dataset-downloader.js b/springshare-libinsight-dataset-downloader.js index 90241bc..8991c30 100644 --- a/springshare-libinsight-dataset-downloader.js +++ b/springshare-libinsight-dataset-downloader.js @@ -3,7 +3,7 @@ // @namespace https://github.com/gsu-library/ // @author mbrooks34@gsu.edu // @license GPLv3 -// @version 2.0.0 +// @version 3.0.0 // @description Adds a download all reports item to the admin menu on the datasets page in LibInsight Lite. // @match https://gsu.libinsight.com/admin/all // @grant none