From 89d20f3042a8ac55981ffd3e253bdc9846aa272f Mon Sep 17 00:00:00 2001 From: UKDTOM Date: Sun, 14 Feb 2021 01:53:16 +0100 Subject: [PATCH 1/3] #239 closer to a blobal export path --- public/locales/en.json | 14 +++---- src/components/modules/ExportTools/Export.vue | 6 +-- .../modules/ExportTools/Settings/settings.vue | 24 +----------- .../modules/ExportTools/scripts/et.js | 6 ++- src/components/modules/General/wtutils.js | 39 +++++++++++++++++-- .../modules/Main/GlobalSettings.vue | 35 ++++++++++++++++- src/components/modules/Main/Home.vue | 25 ++++++++++-- 7 files changed, 106 insertions(+), 43 deletions(-) diff --git a/public/locales/en.json b/public/locales/en.json index 4829694..1987373 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -121,7 +121,11 @@ "Body": "{0} was released on Github on: {1}.", "Body2": "Click here for more info", "Skip": "Don't show notification for this version anymore" - } + }, + "ExportDir": "Select Export Directory", + "Browse": "Browse", + "ErrorNoOutDirMsg": "You need to define an output directory in the global settings page first", + "ErrorNoOutDirTitle": "No output directory defined" }, "Modules": { "PlexTV": { @@ -207,9 +211,7 @@ "ErrorNoServerSelectedMsg": "You need to select a server to extract from", "Settings": { "Settings": "Settings", - "Description": "Here you can define the settings for @:Modules.ET.Name", - "Browse": "Browse", - "SelectOutDir": "Select Output Directory", + "Description": "Here you can define the settings for @:Modules.ET.Name", "ArraySep": "Delimiter for multiple info in same field", "ColumnSep": "Delimiter between columns in CSV file (Use 9 for TAB)", "TimeOut": "Timeout when requesting info from PMS in sec (Global setting)", @@ -238,9 +240,7 @@ "CreateExlsFile": "Creating Excel file", "ProcessItem": "Processing item {count} of {total}", "GetSectionItems": "Fetching items {idx} in chunks of {chunck} with a total of {totalSize}" - }, - "ErrorNoOutDirTitle": "No output directory defined", - "ErrorNoOutDirMsg": "You need to define an output directory in the settings page first", + }, "ErrorBadSepTitle": "Column separator issue", "ErrorBadSep": "Column separator can only be one character" }, diff --git a/src/components/modules/ExportTools/Export.vue b/src/components/modules/ExportTools/Export.vue index 539767a..38b95c3 100644 --- a/src/components/modules/ExportTools/Export.vue +++ b/src/components/modules/ExportTools/Export.vue @@ -241,11 +241,11 @@ }, getMedia() { log.info("getMedia Called"); - if (wtconfig.get('ET.OutPath', "") == "") + if (wtconfig.get('General.ExportPath', "") == "") { log.info('ET: No output dir defined') - this.$bvToast.toast(this.$t("Modules.ET.ErrorNoOutDirMsg"), { - title: this.$t("Modules.ET.ErrorNoOutDirTitle"), + this.$bvToast.toast(this.$t("Common.ErrorNoOutDirMsg"), { + title: this.$t("Common.ErrorNoOutDirTitle"), autoHideDelay: 3000, solid: true, variant: 'primary', diff --git a/src/components/modules/ExportTools/Settings/settings.vue b/src/components/modules/ExportTools/Settings/settings.vue index fbf7d73..be2da6e 100644 --- a/src/components/modules/ExportTools/Settings/settings.vue +++ b/src/components/modules/ExportTools/Settings/settings.vue @@ -2,15 +2,7 @@

{{ $t("Modules.ET.Settings.Settings") }}

-

{{ $t("Modules.ET.Settings.Description") }}

-
- - - - {{ $t("Modules.ET.Settings.Browse") }} - - -
+

{{ $t("Modules.ET.Settings.Description") }}

@@ -57,8 +49,7 @@ } }, data() { - return { - outDirVal: wtconfig.get('ET.OutPath', i18n.t('Modules.ET.Settings.SelectOutDir')), + return { ArraySep: wtconfig.get('ET.ArraySep'), TextQualifierCSV: wtconfig.get('ET.TextQualifierCSV', '"'), NotAvailIndicator: wtconfig.get('ET.NotAvail', 'N/A'), @@ -89,17 +80,6 @@ wtconfig.set("ET." + cbItem, (this.cbSelected.includes(cbItem))) } }, - browse: function(){ - log.debug('Start browsing for Output Directory'); - const outDir = dialog.OpenDirectory( i18n.t("Modules.ET.Settings.SelectOutDir"), i18n.t("Common.Ok")); - //const outDir = dialog.OpenDirectory('Title', 'OK'); - if (outDir) - { - wtconfig.set('ET.OutPath', outDir[0]); - this.outDirVal = outDir[0]; - log.debug(`Selected Directory is ${outDir}`); - } - }, setColumnSep(val){ if (val.length > 1) { diff --git a/src/components/modules/ExportTools/scripts/et.js b/src/components/modules/ExportTools/scripts/et.js index 20e372d..79bf31a 100644 --- a/src/components/modules/ExportTools/scripts/et.js +++ b/src/components/modules/ExportTools/scripts/et.js @@ -484,15 +484,17 @@ const excel2 = new class Excel { async getFileName({ Library, Level, Type }){ const dateFormat = require('dateformat'); - const OutDir = wtconfig.get('ET.OutPath', wtutils.UserHomeDir) + const OutDir = wtconfig.get('General.ExportPath'); const timeStamp=dateFormat(new Date(), "yyyy.mm.dd_h.MM.ss"); const path = require('path'); let outFile = store.getters.getSelectedServer.name + '_'; outFile += Library + '_'; outFile += Level + '_'; outFile += timeStamp + '.' + Type; + console.log('Ged22', OutDir,wtutils.AppName, i18n.t('Modules.ET.Name'), outFile) const outFileWithPath = path.join( - OutDir, outFile); + OutDir, wtutils.AppName, i18n.t('Modules.ET.Name'), outFile); + console.log('Ged ExportFile', outFileWithPath) return outFileWithPath; } diff --git a/src/components/modules/General/wtutils.js b/src/components/modules/General/wtutils.js index de862bd..59c6bc1 100644 --- a/src/components/modules/General/wtutils.js +++ b/src/components/modules/General/wtutils.js @@ -23,6 +23,42 @@ const wtutils = new class WTUtils { return configFileName; } + get ExportDirPresent(){ + + + log.info('Checking ExportPath') + const ExportPath = wtconfig.get('General.ExportPath', 'N/A'); + if ( ExportPath == 'N/A' ){ + log.error('ExportPath not defined'); + return false; + } + const fs = require("fs"); + if (fs.existsSync(ExportPath)) { + const path = require('path'); + const appExportDir = path.join(ExportPath, wtutils.AppName); + if (!fs.existsSync(appExportDir)) + { + log.debug('Export dir existed, but AppDir didnt') + fs.mkdirSync(appExportDir) + if (fs.existsSync(appExportDir)) + { + return true; + } + else + { + return false; + } + } + else + { + return true; + } + } + return false; + + + } + get RunningOS(){ return process.platform; } @@ -245,9 +281,6 @@ const wtutils = new class WTUtils { if ( wtconfig.get('ET.ColumnSep', 'N/A') == 'N/A' ){ wtconfig.set('ET.ColumnSep', ',') } - if ( wtconfig.get('ET.OutPath', 'N/A') == 'N/A' ){ - wtconfig.set('ET.OutPath', '') - } if ( wtconfig.get('ET.NotAvail', 'N/A') == 'N/A' ){ wtconfig.set('ET.NotAvail', 'N/A') } diff --git a/src/components/modules/Main/GlobalSettings.vue b/src/components/modules/Main/GlobalSettings.vue index b8fb07c..ae6ac73 100644 --- a/src/components/modules/Main/GlobalSettings.vue +++ b/src/components/modules/Main/GlobalSettings.vue @@ -3,7 +3,18 @@

{{ $t("Modules.GlobalSettings.Title") }}

{{ $t("Modules.GlobalSettings.Description") }}

+
+ + + + {{ $t("Common.Browse") }} + + +
+ + + @@ -57,9 +68,10 @@ wtutils, dialog, i18n - export default { + export default { data() { return { + ExportDirVal: wtconfig.get('General.ExportPath', i18n.t('Common.ExportDir')), TimeOut: wtconfig.get('PMS.TimeOut'), LogLevel: wtconfig.get('Log.fileLevel'), LogLevelConsole: wtconfig.get('Log.consoleLevel'), @@ -69,6 +81,25 @@ } }, methods: { + browse: function(){ + log.debug('Start browsing for Export Directory'); + const exportDir = dialog.OpenDirectory( i18n.t("Common.ExportDir"), i18n.t("Common.Ok")); + if (exportDir) + { + wtconfig.set('General.ExportPath', exportDir[0]); + this.ExportDirVal = exportDir[0]; + log.debug(`Selected Directory is ${exportDir}`); + if (!wtutils.ExportDirPresent) + { + console.log('ged1 globalsetting dir error') + this.ExportDirVal = '*** ERROR ***'; + } + else + { + console.log('ged123 globalsetting dir ok') + } + } + }, factoryReset() { // Doing a factory reset log.warn('Doing a factory reset'); @@ -167,7 +198,7 @@ } }, - computed: { + computed: { logLevels: function() { const options = ['error', 'warn', 'info', 'verbose', 'debug', 'silly']; return options; diff --git a/src/components/modules/Main/Home.vue b/src/components/modules/Main/Home.vue index ee2d99f..a6835dd 100644 --- a/src/components/modules/Main/Home.vue +++ b/src/components/modules/Main/Home.vue @@ -68,7 +68,8 @@ export default { mounted() { log.info("Home Created"); this.checkLangUpdates(); - this.UpdatePresent(); + this.UpdatePresent(); + this.CheckExportDir(); }, methods: { // Visit GitHub release page @@ -152,11 +153,27 @@ export default { } } } + selLang, wtutils, selLangUpdated + }, + async CheckExportDir() { + if ( wtutils.ExportDirPresent ) + { + console.log('Ged1 Home ExportDir OK') + } + else + { + console.log('Ged2 Home ExportDir ERROR') + const bodyStr = i18n.t("Common.ErrorNoOutDirMsg"); + this.$bvToast.toast(bodyStr, { + title: this.$t("Common.ErrorNoOutDirTitle"), + autoHideDelay: 400000, + solid: true, + variant: 'primary', + toaster: 'b-toaster-bottom-right' + }); - - - selLang, i18n, wtutils, selLangUpdated + } } } } From e43cae4dbc7f1f14efc6114574935f6af777fc5a Mon Sep 17 00:00:00 2001 From: UKDTOM Date: Mon, 15 Feb 2021 01:08:16 +0100 Subject: [PATCH 2/3] #239 fixed --- .../modules/ExportTools/scripts/et.js | 17 +++++++++++------ src/components/modules/Main/GlobalSettings.vue | 5 ----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/modules/ExportTools/scripts/et.js b/src/components/modules/ExportTools/scripts/et.js index 79bf31a..366930d 100644 --- a/src/components/modules/ExportTools/scripts/et.js +++ b/src/components/modules/ExportTools/scripts/et.js @@ -482,7 +482,7 @@ const excel2 = new class Excel { return true; } - async getFileName({ Library, Level, Type }){ + async getFileName({ Library, Level, Type, Module }){ const dateFormat = require('dateformat'); const OutDir = wtconfig.get('General.ExportPath'); const timeStamp=dateFormat(new Date(), "yyyy.mm.dd_h.MM.ss"); @@ -491,16 +491,20 @@ const excel2 = new class Excel { outFile += Library + '_'; outFile += Level + '_'; outFile += timeStamp + '.' + Type; - console.log('Ged22', OutDir,wtutils.AppName, i18n.t('Modules.ET.Name'), outFile) + const targetDir = path.join( + OutDir, wtutils.AppName, Module); const outFileWithPath = path.join( - OutDir, wtutils.AppName, i18n.t('Modules.ET.Name'), outFile); - console.log('Ged ExportFile', outFileWithPath) + targetDir, outFile); + // Make sure target dir exists + const fs = require('fs') + fs.mkdirSync(targetDir); + log.info(`OutFile is ${outFileWithPath}`) return outFileWithPath; } async SaveWorkbook(Workbook, Library, Level, Type) { const fs = require('fs') - const name = await this.getFileName( { Library: Library, Level: Level, Type: Type }) + const name = await this.getFileName( { Library: Library, Level: Level, Type: Type, Module: i18n.t('Modules.ET.Name') }) log.info('Saving output file as: ' + name) // Save Excel on Hard Disk Workbook.xlsx.writeBuffer() @@ -831,7 +835,8 @@ const excel2 = new class Excel { // Now we need to find out how many calls to make const call = await et.getLevelCall(libType, level) // Open a file stream - const tmpFile = await excel2.getFileName({ Library: libName, Level: level, Type: 'tmp' }) + const tmpFile = await excel2.getFileName({ Library: libName, Level: level, Type: 'tmp', Module: i18n.t('Modules.ET.Name') }) + console.log('Ged 5 et tmpFile', tmpFile) var fs = require('fs'); var stream = fs.createWriteStream(tmpFile, {flags:'a'}); // Add the header diff --git a/src/components/modules/Main/GlobalSettings.vue b/src/components/modules/Main/GlobalSettings.vue index ae6ac73..2f945e4 100644 --- a/src/components/modules/Main/GlobalSettings.vue +++ b/src/components/modules/Main/GlobalSettings.vue @@ -91,13 +91,8 @@ log.debug(`Selected Directory is ${exportDir}`); if (!wtutils.ExportDirPresent) { - console.log('ged1 globalsetting dir error') this.ExportDirVal = '*** ERROR ***'; } - else - { - console.log('ged123 globalsetting dir ok') - } } }, factoryReset() { From 3f3084ca608bfb84fe0d1a136e382b7bbcb5a446 Mon Sep 17 00:00:00 2001 From: UKDTOM Date: Mon, 15 Feb 2021 01:25:33 +0100 Subject: [PATCH 3/3] #239 Fixed now with Changelog --- CHANGELOG.md | 1 + src/components/modules/ExportTools/scripts/et.js | 11 ++++++----- src/components/modules/Main/Home.vue | 5 ++--- src/components/modules/PMS/Settings/settings.vue | 1 - 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d77aa6..e1112df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * [#233 Electron errors after updating](https://github.com/WebTools-NG/WebTools-NG/pull/233) * [#234 Editing a custom level](https://github.com/WebTools-NG/WebTools-NG/pull/234) * [#238 We need a Text qualifier](https://github.com/WebTools-NG/WebTools-NG/pull/238) +* [#239 Does not output if the output folder does NOT exist](https://github.com/WebTools-NG/WebTools-NG/pull/239) ## V0.1.13 diff --git a/src/components/modules/ExportTools/scripts/et.js b/src/components/modules/ExportTools/scripts/et.js index 366930d..e0091ff 100644 --- a/src/components/modules/ExportTools/scripts/et.js +++ b/src/components/modules/ExportTools/scripts/et.js @@ -497,7 +497,9 @@ const excel2 = new class Excel { targetDir, outFile); // Make sure target dir exists const fs = require('fs') - fs.mkdirSync(targetDir); + if (!fs.existsSync(targetDir)) { + fs.mkdirSync(targetDir); + } log.info(`OutFile is ${outFileWithPath}`) return outFileWithPath; } @@ -831,12 +833,11 @@ const excel2 = new class Excel { { const header = excel2.GetHeader(level, libType) log.debug(`header: ${header}`); - const strHeader = header.join(wtconfig.get('ET.ColumnSep', ',')) + const strHeader = header.join(wtconfig.get('ET.ColumnSep', ',')); // Now we need to find out how many calls to make - const call = await et.getLevelCall(libType, level) + const call = await et.getLevelCall(libType, level); // Open a file stream - const tmpFile = await excel2.getFileName({ Library: libName, Level: level, Type: 'tmp', Module: i18n.t('Modules.ET.Name') }) - console.log('Ged 5 et tmpFile', tmpFile) + const tmpFile = await excel2.getFileName({ Library: libName, Level: level, Type: 'tmp', Module: i18n.t('Modules.ET.Name') }); var fs = require('fs'); var stream = fs.createWriteStream(tmpFile, {flags:'a'}); // Add the header diff --git a/src/components/modules/Main/Home.vue b/src/components/modules/Main/Home.vue index a6835dd..7ba5f4a 100644 --- a/src/components/modules/Main/Home.vue +++ b/src/components/modules/Main/Home.vue @@ -158,12 +158,11 @@ export default { async CheckExportDir() { if ( wtutils.ExportDirPresent ) { - console.log('Ged1 Home ExportDir OK') - + log.info('ExportDir OK'); } else { - console.log('Ged2 Home ExportDir ERROR') + log.error('ExportDir missing'); const bodyStr = i18n.t("Common.ErrorNoOutDirMsg"); this.$bvToast.toast(bodyStr, { title: this.$t("Common.ErrorNoOutDirTitle"), diff --git a/src/components/modules/PMS/Settings/settings.vue b/src/components/modules/PMS/Settings/settings.vue index 3039c8b..4bbb999 100644 --- a/src/components/modules/PMS/Settings/settings.vue +++ b/src/components/modules/PMS/Settings/settings.vue @@ -249,7 +249,6 @@ this.updateTbl(this.selSection); }, getFilterSettings() { - console.log('Ged get filter settings') this.selFilterSetting = wtconfig.get('PMS.FilterSetting', 'AllSettings'); } }