Merge pull request #274 from WebTools-NG/#271-Export-Filename-missing-type

Fixed #271
This commit is contained in:
Tommy Mikkelsen 2021-03-07 23:50:02 +01:00 committed by GitHub
commit daddc57464
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 40 deletions

View file

@ -6,6 +6,7 @@
* [#269 Levelcount broken for Custom levels](https://github.com/WebTools-NG/WebTools-NG/issues/269)
* [#107 Allow export of Artist](https://github.com/WebTools-NG/WebTools-NG/issues/107)
* [#271 Export Filename missing type](https://github.com/WebTools-NG/WebTools-NG/issues/271)
## V0.1.16

View file

@ -515,13 +515,14 @@ const excel2 = new class Excel {
return true;
}
async getFileName({ Library, Level, Type, Module }){
async getFileName({ Library, Level, Type, Module, exType }){
const dateFormat = require('dateformat');
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 += exType + '_';
outFile += Level + '_';
outFile += timeStamp + '.' + Type;
const targetDir = path.join(
@ -533,18 +534,18 @@ const excel2 = new class Excel {
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
}
log.info(`OutFile is ${outFileWithPath}`)
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, Module: i18n.t('Modules.ET.Name') })
log.info('Saving output file as: ' + name)
async SaveWorkbook({ Workbook, Library, Level, Type, exType } ) {
const fs = require('fs');
const name = await this.getFileName( { Library: Library, Level: Level, Type: Type, Module: i18n.t('Modules.ET.Name'), exType: exType });
log.info('Saving output file as: ' + name);
// Save Excel on Hard Disk
Workbook.xlsx.writeBuffer()
.then(buffer => fs.writeFileSync(name, buffer))
return true
return true;
}
async postProcess( {name, val, title=""} ){
@ -918,15 +919,15 @@ const excel2 = new class Excel {
}
async createXLSXFile( {csvFile, level, libType, libName} )
async createXLSXFile( {csvFile, level, libType, libName, exType} )
{
// This will loop thru a csv file, and create xlsx file
// First create a WorkBook
const workBook = await excel2.NewExcelWorkBook()
const workBook = await excel2.NewExcelWorkBook();
// Create Sheet
let sheet = await excel2.NewSheet(workBook, libName, level)
let sheet = await excel2.NewSheet(workBook, libName, level);
// Add the header to the sheet
await excel2.AddHeader(sheet, level, libType)
await excel2.AddHeader(sheet, level, libType);
/*
autoFilter sadly doesn't work :(
@ -980,19 +981,19 @@ const excel2 = new class Excel {
});
log.info('Setting xlsx column width ended')
}
await excel2.SaveWorkbook(workBook, libName, level, "xlsx")
await excel2.SaveWorkbook( { Workbook: workBook, Library: libName, Level: level, Type: "xlsx", exType: exType});
});
}
async createOutFile( {libName, level, libType, baseURL, accessToken} )
async createOutFile( {libName, level, libType, baseURL, accessToken, exType} )
{
const header = excel2.GetHeader(level, libType)
const header = excel2.GetHeader(level, libType);
log.debug(`header: ${header}`);
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);
// Open a file stream
const tmpFile = await excel2.getFileName({ Library: libName, Level: level, Type: 'tmp', Module: i18n.t('Modules.ET.Name') });
const tmpFile = await excel2.getFileName({ Library: libName, Level: level, Type: 'tmp', Module: i18n.t('Modules.ET.Name'), exType: exType });
var fs = require('fs');
var stream = fs.createWriteStream(tmpFile, {flags:'a'});
// Add the header
@ -1039,12 +1040,11 @@ const excel2 = new class Excel {
// Rename to real file name
var newFile = tmpFile.replace('.tmp', '.csv')
fs.renameSync(tmpFile, newFile);
console.log('renamed complete');
// Need to export to xlsx as well?
if (wtconfig.get('ET.ExpExcel')){
log.info('We need to create an xlsx file as well')
store.commit("UPDATE_EXPORTSTATUS", i18n.t('Modules.ET.Status.CreateExlsFile'))
await excel2.createXLSXFile( {csvFile: newFile, level: level, libType: libType, libName: libName})
log.info('We need to create an xlsx file as well');
store.commit("UPDATE_EXPORTSTATUS", i18n.t('Modules.ET.Status.CreateExlsFile'));
await excel2.createXLSXFile( {csvFile: newFile, level: level, libType: libType, libName: libName, exType: exType});
}
store.commit("UPDATE_EXPORTSTATUS", `Export finished. File:"${newFile}" created`);
}

View file

@ -46,10 +46,10 @@ const actions = {
commit('UPDATE_SECTIONS', await et.getSections(baseURL, accessToken))
},
exportMedias({ getters }) {
var baseURL = getters.getSelectedServerAddress
var accessToken = getters.getSelectedServerToken
var libType = getters.getLibType
var baseURL = getters.getSelectedServerAddress;
var accessToken = getters.getSelectedServerToken;
var libType = getters.getLibType;
var exType = getters.getLibType;
var levelName = et.getLevelDisplayName(getters.getSelectedExportLevel, libType);
var libName = et.getLibDisplayName(getters.getSelectedSection, getters.getPmsSections);
excel2.createOutFile( {
@ -57,7 +57,8 @@ const actions = {
level: levelName,
libType: libType,
baseURL: baseURL,
accessToken: accessToken
accessToken: accessToken,
exType: exType
} );
}
}