This commit is contained in:
UKDTOM 2021-02-21 02:15:35 +01:00
parent ded3d78bd5
commit e1ae1b159c
6 changed files with 352 additions and 23 deletions

View file

@ -174,7 +174,20 @@
"curSetting": "Current Setting",
"defSetting": "Default Setting",
"newSettingValueTXT": "<Enter new value>",
"varning": "Change at your own risk. Any change can lead to malfunction of your plex server"
"varning": "Change at your own risk. Any change can lead to malfunction of your plex server",
"ExportAllSettings": "Export all settings to CSV",
"ExportGroupSettings": "Export selected group settings to CSV"
},
"Export":{
"Items":{
"Category": "Category",
"Name": "Name",
"Label":"Label",
"Summary":"Summary",
"Type": "Type",
"Default": "Default",
"Value": "Value"
}
}
},
"ET": {

View file

@ -0,0 +1,157 @@
// Helper file for PMS Settings module
const log = require('electron-log');
console.log = log.log;
import {wtconfig, wtutils} from '../../../General/wtutils';
import i18n from '../../../../../i18n';
import store from '../../../../../store';
i18n, wtconfig, wtutils, store
const pmssettings = new class PMSSettings {
constructor() {
this.header = [
i18n.t('Modules.PMS.Export.Items.Category'),
i18n.t('Modules.PMS.Export.Items.Name'),
i18n.t('Modules.PMS.Export.Items.Label'),
i18n.t('Modules.PMS.Export.Items.Summary'),
i18n.t('Modules.PMS.Export.Items.Type'),
i18n.t('Modules.PMS.Export.Items.Default'),
i18n.t('Modules.PMS.Export.Items.Value')
]
this.itemfields = [
"label",
"summary",
"type",
"default",
"value"
],
this.separator = wtconfig.get('ET.ColumnSep')
}
async exportSettings({ Module, Grp, Data }){
/*
Will export selected user to a file
*/
let strTmp = i18n.t('Modules.PMS.Export.Items.Category');
console.log('Ged Export Group', Grp)
// Open a file stream
const tmpFile = await this.getFileName({Type: 'tmp', Module: Module, Grp: Grp});
var fs = require('fs');
var stream = fs.createWriteStream(tmpFile, {flags:'a'});
// Add the header
this.header.forEach(function (item) {
strTmp += item + pmssettings.separator;
}
);
// Remove last separator and add CR
strTmp = strTmp.slice(0,-1) + "\n";
// Write header to tmp file
stream.write( strTmp );
// Add Data
if ( Grp === "All"){
console.log('Ged all')
Object.keys(Data).forEach(function(key) {
strTmp = '';
pmssettings.fields.forEach(function (item) {
let result = Data[key][item];
if (result == null){
result = wtconfig.get('ET.NotAvail');
}
strTmp += result + pmssettings.separator;
}
);
// Remove last separator and add CR
strTmp = strTmp.slice(0,-1) + "\n";
// Write to tmp file
stream.write( strTmp );
})
}
else {
console.log('Ged Single Group', Grp)
Data[Grp].forEach(function (item) {
Object.keys(item).forEach(function(key) {
strTmp = i18n.t('Modules.PMS.Export.Items.Category');
pmssettings.itemfields.forEach(function (field) {
console.log('Ged Item Field', field, item[key][field])
let result = item[key][field];
if (result == null){
result = wtconfig.get('ET.NotAvail');
}
strTmp += result + pmssettings.separator;
});
// Remove last separator and add CR
strTmp = strTmp.slice(0,-1) + "\n";
// Write to tmp file
stream.write( strTmp );
console.log('Ged ******** New line ********')
});
});
}
/*
else {
strTmp = '';
// Add each field
this.fields.forEach(function (item) {
let result = Data[item];
if (result == null){
result = wtconfig.get('ET.NotAvail');
}
strTmp += result + pmssettings.separator;
//strTmp += Data[item] + plextv.separator;
}
);
// Remove last separator and add CR
strTmp = strTmp.slice(0,-1) + "\n";
// Write to tmp file
stream.write( strTmp );
}
*/
// Close tmp file
stream.end();
// Rename to real file name
var newFile = tmpFile.replace('.tmp', '.csv');
fs.renameSync(tmpFile, newFile);
console.log('renamed complete');
}
async getFileName({ Type, Module, Grp }){
/*
Will create the output directory if it doesn't exists
Will return a string with the filename to use
*/
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 = Grp + '_';
outFile += timeStamp + '.' + Type;
const targetDir = path.join(
OutDir, wtutils.AppName, Module);
const outFileWithPath = path.join(
targetDir, outFile);
// Make sure target dir exists
const fs = require('fs')
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
log.info(`OutFile is ${outFileWithPath}`)
return outFileWithPath;
}
}
export {pmssettings};

View file

@ -94,15 +94,29 @@
<template #table-caption>{{ $t('Modules.PMS.Settings.tblCaption') }}</template>
</b-table>
</div>
<br>
<div class="buttons">
<!-- Buttons -->
<div id="buttons" class="text-center">
<b-button-group >
<b-button variant="success" class="mr-1" :disabled="this.selSection == ''" @click="exportSettings"> {{ $t('Modules.PMS.Settings.ExportGroupSettings') }} </b-button>
<b-button variant="success" class="mr-1" @click="exportAllSettings">{{ $t('Modules.PMS.Settings.ExportAllSettings') }}</b-button>
</b-button-group>
</div>
</div>
<br>
<p class="text-center">{{ $t('Modules.PlexTV.Settings') }}</p>
{{ this.selSection }}
</b-container>
</template>
<script>
const log = require("electron-log");
const {JSONPath} = require('jsonpath-plus');
import {wtconfig} from '../../General/wtutils';
import {wtconfig} from './../../General/wtutils';
import i18n from '../../../../i18n';
import store from '../../../../store';
import { pmssettings } from "./scripts/settings";
export default {
data() {
return {
@ -145,6 +159,19 @@
}
},
methods: {
exportSettings: async function(){
log.info(`Export Group Settings: ${this.selSection}`);
const path = require('path');
const dirPath = path.join(i18n.t("Modules.PMS.Name"), i18n.t("Modules.PMS.Settings.Settings"));
await pmssettings.exportSettings({Module: dirPath, Grp: this.selSection, Data: this.$store.getters.getPMSSettings});
},
exportAllSettings: async function(){
log.info(`Export All Settings: ${this.selSection}`);
await pmssettings.exportSettings({Module: i18n.t("Modules.PMS.Name"), Grp: 'All', Data: this.$store.getters.getPMSSettings});
},
async saveNewSetting() {
log.debug(`Saving setting ${this.newSettingValue} for setting ${this.edtSettingKey}`);
// Save setting
@ -205,20 +232,6 @@
getGroupSelectedItem: function(myarg) {
log.debug(`Group changed to: ${myarg}`);
this.updateTbl(myarg);
/* // Update the data table with new settings
const filteredResult = JSONPath({path: `$.${myarg}`, json: this.$store.getters.getPMSSettings})[0];
log.verbose(`filtered settings: ${JSON.stringify(filteredResult)}`);
this.settingsItems = [];
for (var i = 0; i < filteredResult.length; i++) {
var entry = {};
entry['name'] = JSONPath({path: `$.*~`, json: filteredResult[i]})[0];
entry['label'] = JSONPath({path: `$..label`, json: filteredResult[i]})[0];
entry['summary'] = JSONPath({path: `$..summary`, json: filteredResult[i]})[0];
entry['type'] = JSONPath({path: `$..type`, json: filteredResult[i]})[0];
entry['default'] = JSONPath({path: `$..default`, json: filteredResult[i]})[0];
entry['value'] = JSONPath({path: `$..value`, json: filteredResult[i]})[0];
this.settingsItems.push(entry);
} */
},
async serverSelected() {
let serverCheck = this.$store.getters.getSelectedServer;

File diff suppressed because one or more lines are too long

View file

@ -110,8 +110,7 @@
exportUsr: async function(){
log.info(`Export Plex.TV User: ${this.usrName}`);
let Data = this.selUserDetails;
const filename = await plextv.exportUsr({Module: i18n.t("Modules.PlexTV.Name"), Usr: this.usrID, Data: Data});
filename
await plextv.exportUsr({Module: i18n.t("Modules.PlexTV.Name"), Usr: this.usrID, Data: Data});
},
exportAllUsr: async function(){
log.info(`Export All Plex.TV Users`)

View file

@ -118,7 +118,7 @@ const plextv = new class PlexTV {
// Make sure target dir exists
const fs = require('fs')
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
fs.mkdirSync(targetDir, { recursive: true });
}
log.info(`OutFile is ${outFileWithPath}`)
return outFileWithPath;