mirror of
https://github.com/WebTools-NG/WebTools-NG
synced 2024-11-23 11:33:14 +00:00
Fixed #287
This commit is contained in:
parent
a654486101
commit
96b2374db8
2 changed files with 75 additions and 73 deletions
|
@ -1,27 +1,27 @@
|
|||
<template>
|
||||
<template>
|
||||
<div class="col-lg-10 col-md-12 col-xs-12">
|
||||
<h3>{{ $t("Modules.PlexTV.Name") }} <br>
|
||||
</h3>
|
||||
<h3>{{ $t("Modules.PlexTV.Name") }} <br>
|
||||
</h3>
|
||||
{{ $t("Modules.PlexTV.Description") }}
|
||||
|
||||
<br>
|
||||
<br>
|
||||
<!-- Select User -->
|
||||
<div class="d-flex align-items-center">
|
||||
<b-form-group id="plexTVUsers" v-bind:label="$t('Modules.PlexTV.SelUsr')" label-size="lg" label-class="font-weight-bold pt-0">
|
||||
<b-form-group id="plexTVUsers" v-bind:label="$t('Modules.PlexTV.SelUsr')" label-size="lg" label-class="font-weight-bold pt-0">
|
||||
<div ref="libSpinner" id="libSpinner" :hidden="selUserWait">
|
||||
<b-spinner id="libLoad" class="ml-auto text-danger"></b-spinner>
|
||||
</div>
|
||||
<b-tooltip target="plexTVUsers" triggers="hover">
|
||||
{{ $t('Modules.PlexTV.TT-User') }}
|
||||
</b-tooltip>
|
||||
<b-form-select
|
||||
v-model="selUser"
|
||||
<b-form-select
|
||||
v-model="selUser"
|
||||
id="selUser"
|
||||
:options="selUserOptions"
|
||||
name="selLibrary">
|
||||
name="selLibrary">
|
||||
</b-form-select>
|
||||
</b-form-group>
|
||||
</b-form-group>
|
||||
</div>
|
||||
<b-input-group id="UserIDGrp" :prepend="$t('Modules.PlexTV.UsrID')" class="mt-3">
|
||||
<b-form-input id="usrID" name="usrID" type="text" class="form-control" v-model="usrID" :disabled=true></b-form-input>
|
||||
|
@ -33,44 +33,44 @@
|
|||
<b-form-input id="usrEmail" name="usrEmail" type="text" class="form-control" v-model="usrEmail" :disabled=true></b-form-input>
|
||||
</b-input-group>
|
||||
<b-input-group id="UserRestrictedGrp" :prepend="$t('Modules.PlexTV.UsrRestricted')" class="mt-3">
|
||||
<b-form-input id="usrRestricted" name="usrRestricted" type="text" class="form-control" v-model="usrRestricted" :disabled=true></b-form-input>
|
||||
<b-form-input id="usrRestricted" name="usrRestricted" class="form-control" v-model="usrRestricted" :disabled=true></b-form-input>
|
||||
</b-input-group>
|
||||
<b-input-group id="UserThumbGrp" :prepend="$t('Modules.PlexTV.UsrThumb')" class="mt-3">
|
||||
<b-form-input id="usrThumb" name="usrThumb" type="text" class="form-control" v-model="usrThumb" :disabled=true></b-form-input>
|
||||
</b-input-group>
|
||||
<b-input-group id="UserHomeGrp" :prepend="$t('Modules.PlexTV.UsrHome')" class="mt-3">
|
||||
<b-form-input id="usrHome" name="usrHome" type="text" class="form-control" v-model="usrHome" :disabled=true></b-form-input>
|
||||
<b-form-input id="usrHome" name="usrHome" class="form-control" v-model="usrHome" :disabled=true></b-form-input>
|
||||
</b-input-group>
|
||||
<b-input-group id="UserStatusGrp" :prepend="$t('Modules.PlexTV.UsrStatus')" class="mt-3">
|
||||
<b-form-input id="usrStatus" name="usrStatus" type="text" class="form-control" v-model="usrStatus" :disabled=true></b-form-input>
|
||||
</b-input-group>
|
||||
<br>
|
||||
<div class="buttons">
|
||||
<div class="buttons">
|
||||
<br>
|
||||
<!-- Buttons -->
|
||||
<div id="buttons" class="text-center">
|
||||
<b-button-group >
|
||||
<b-button-group >
|
||||
<b-button variant="success" class="mr-1" :disabled="this.selUser == ''" @click="exportUsr"> {{ $t('Modules.PlexTV.ExportUsr') }} </b-button>
|
||||
<b-button variant="success" class="mr-1" @click="exportAllUsr">{{ $t('Modules.PlexTV.ExportAllUsr') }}</b-button>
|
||||
</b-button-group>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<p class="text-center">{{ $t('Modules.PlexTV.Settings') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script>
|
||||
import store from '../../../store';
|
||||
import { plextv } from "./scripts/plextv";
|
||||
import { plextv } from "./scripts/plextv";
|
||||
import i18n from '../../../i18n';
|
||||
import { wtconfig } from '../General/wtutils';
|
||||
import { wtconfig } from '../General/wtutils';
|
||||
|
||||
const log = require("electron-log");
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
selUserWait: false,
|
||||
selUserWait: false,
|
||||
selUser: "",
|
||||
selUserOptions: [],
|
||||
selUserDetails: {},
|
||||
|
@ -82,26 +82,26 @@
|
|||
usrHome: "",
|
||||
usrStatus: ""
|
||||
};
|
||||
},
|
||||
},
|
||||
async created() {
|
||||
log.info("PlexTV Created");
|
||||
// Get users from plex.tv
|
||||
// Get users from plex.tv
|
||||
await store.dispatch('fetchUsers');
|
||||
this.getUsers();
|
||||
this.getUsers();
|
||||
},
|
||||
watch: {
|
||||
// Watch for when selecting a user
|
||||
selUser: async function(){
|
||||
// Changed, so we need to update the libraries
|
||||
var userLst = this.$store.getters.getUsers;
|
||||
log.verbose(`Watch detected a user was selected as ${JSON.stringify(userLst[this.selUser])}`);
|
||||
log.verbose(`Watch detected a user was selected as ${JSON.stringify(userLst[this.selUser])}`);
|
||||
this.selUserDetails = userLst[this.selUser];
|
||||
this.usrEmail = userLst[this.selUser]['email'];
|
||||
this.usrID = userLst[this.selUser]['id'];
|
||||
this.usrName = userLst[this.selUser]['title'];
|
||||
this.usrRestricted = userLst[this.selUser]['restricted'];
|
||||
this.usrRestricted = userLst[this.selUser]['restricted'].toString();
|
||||
this.usrThumb = userLst[this.selUser]['thumb'];
|
||||
this.usrHome = userLst[this.selUser]['home'];
|
||||
this.usrHome = userLst[this.selUser]['home'].toString();
|
||||
this.usrStatus = userLst[this.selUser]['status'];
|
||||
}
|
||||
},
|
||||
|
@ -109,56 +109,57 @@
|
|||
exportUsr: async function(){
|
||||
if (wtconfig.get('General.ExportPath', "") == "")
|
||||
{
|
||||
log.info('ET: No output dir defined')
|
||||
log.info('ET: No output dir defined')
|
||||
this.$bvToast.toast(this.$t("Common.ErrorNoOutDirMsg"), {
|
||||
title: this.$t("Common.ErrorNoOutDirTitle"),
|
||||
autoHideDelay: 3000,
|
||||
autoHideDelay: 3000,
|
||||
solid: true,
|
||||
variant: 'primary',
|
||||
toaster: 'b-toaster-bottom-right'
|
||||
})
|
||||
toaster: 'b-toaster-bottom-right'
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
log.info(`Export Plex.TV User: ${this.usrName}`);
|
||||
let Data = this.selUserDetails;
|
||||
const outFile = await plextv.exportUsr({Module: i18n.t("Modules.PlexTV.Name"), Usr: this.usrID, Data: Data});
|
||||
const bodyStr = i18n.t("Modules.PMS.ExportDoneBody", [outFile]);
|
||||
this.$bvToast.toast(bodyStr, {
|
||||
let Data = this.selUserDetails;
|
||||
const outFile = await plextv.exportUsr({Module: i18n.t("Modules.PlexTV.Name"), Usr: this.usrID, Data: Data});
|
||||
const bodyStr = i18n.t("Modules.PMS.ExportDoneBody", [outFile]);
|
||||
this.$bvToast.toast(bodyStr, {
|
||||
title: this.$t("Modules.PMS.ExportDoneTitle"),
|
||||
autoHideDelay: 400000,
|
||||
autoHideDelay: 400000,
|
||||
solid: true,
|
||||
variant: 'primary',
|
||||
toaster: 'b-toaster-bottom-right'
|
||||
toaster: 'b-toaster-bottom-right'
|
||||
});
|
||||
},
|
||||
exportAllUsr: async function(){
|
||||
if (wtconfig.get('General.ExportPath', "") == "")
|
||||
{
|
||||
log.info('ET: No output dir defined')
|
||||
log.info('ET: No output dir defined')
|
||||
this.$bvToast.toast(this.$t("Common.ErrorNoOutDirMsg"), {
|
||||
title: this.$t("Common.ErrorNoOutDirTitle"),
|
||||
autoHideDelay: 3000,
|
||||
autoHideDelay: 3000,
|
||||
solid: true,
|
||||
variant: 'primary',
|
||||
toaster: 'b-toaster-bottom-right'
|
||||
})
|
||||
toaster: 'b-toaster-bottom-right'
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
log.info(`Export All Plex.TV Users`)
|
||||
let Data = this.$store.getters.getUsers;
|
||||
const outFile = await plextv.exportUsr({Module: i18n.t("Modules.PlexTV.Name"), Usr: 'All', Data: Data});
|
||||
const bodyStr = i18n.t("Modules.PMS.ExportDoneBody", [outFile]);
|
||||
this.$bvToast.toast(bodyStr, {
|
||||
const bodyStr = i18n.t("Modules.PMS.ExportDoneBody", [outFile]);
|
||||
this.$bvToast.toast(bodyStr, {
|
||||
title: this.$t("Modules.PMS.ExportDoneTitle"),
|
||||
autoHideDelay: 400000,
|
||||
autoHideDelay: 400000,
|
||||
solid: true,
|
||||
variant: 'primary',
|
||||
toaster: 'b-toaster-bottom-right'
|
||||
toaster: 'b-toaster-bottom-right'
|
||||
});
|
||||
},
|
||||
getUsers: async function(){
|
||||
console.log('Ged77')
|
||||
this.selUserWait = false;
|
||||
var userLst = this.$store.getters.getUsers;
|
||||
var userLst = this.$store.getters.getUsers;
|
||||
// Output store
|
||||
const result = [];
|
||||
// Temp Store, in order to sort the list, case insensitive
|
||||
|
@ -174,7 +175,8 @@
|
|||
result.push(Object.assign({}, item));
|
||||
}
|
||||
this.selUserOptions = result;
|
||||
this.selUserWait = true;
|
||||
this.selUserWait = true;
|
||||
console.log('Ged77-2')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,11 +13,11 @@ i18n, wtconfig, wtutils, store
|
|||
const plextv = new class PlexTV {
|
||||
constructor() {
|
||||
this.header = [
|
||||
i18n.t('Modules.PlexTV.UsrID'),
|
||||
i18n.t('Modules.PlexTV.UsrID'),
|
||||
i18n.t('Modules.PlexTV.UsrTitle'),
|
||||
i18n.t('Modules.PlexTV.UsrName'),
|
||||
i18n.t('Modules.PlexTV.UsrEMail'),
|
||||
i18n.t('Modules.PlexTV.UsrRestricted'),
|
||||
i18n.t('Modules.PlexTV.UsrRestricted'),
|
||||
i18n.t('Modules.PlexTV.UsrThumb'),
|
||||
i18n.t('Modules.PlexTV.UsrHome'),
|
||||
i18n.t('Modules.PlexTV.UsrStatus')]
|
||||
|
@ -33,24 +33,24 @@ const plextv = new class PlexTV {
|
|||
],
|
||||
this.separator = wtconfig.get('ET.ColumnSep')
|
||||
}
|
||||
|
||||
|
||||
async exportUsr({ Module, Usr, Data }){
|
||||
/*
|
||||
Will export selected user to a file
|
||||
*/
|
||||
Will export selected user to a file
|
||||
*/
|
||||
let strTmp = '';
|
||||
// Set result file to users title
|
||||
let fName = 'All';
|
||||
let fName = 'All';
|
||||
if ( typeof(Usr) === "number"){
|
||||
fName = Data['title'];
|
||||
}
|
||||
// Open a file stream
|
||||
const tmpFile = await this.getFileName({Type: 'tmp', Module: Module, Usr: fName});
|
||||
var fs = require('fs');
|
||||
var fs = require('fs');
|
||||
var stream = fs.createWriteStream(tmpFile, {flags:'a'});
|
||||
// Add the header
|
||||
this.header.forEach(function (item) {
|
||||
strTmp += item + plextv.separator;
|
||||
strTmp += item + plextv.separator;
|
||||
}
|
||||
);
|
||||
// Remove last separator and add CR
|
||||
|
@ -58,70 +58,70 @@ const plextv = new class PlexTV {
|
|||
// Write header to tmp file
|
||||
stream.write( strTmp );
|
||||
// Add Data
|
||||
if ( typeof(Usr) === "string"){
|
||||
if ( typeof(Usr) === "string"){
|
||||
Object.keys(Data).forEach(function(key) {
|
||||
strTmp = '';
|
||||
plextv.fields.forEach(function (item) {
|
||||
let result = Data[key][item];
|
||||
if (result == null){
|
||||
result = wtconfig.get('ET.NotAvail');
|
||||
result = wtconfig.get('ET.NotAvail');
|
||||
}
|
||||
strTmp += result + plextv.separator;
|
||||
strTmp += result + plextv.separator;
|
||||
}
|
||||
);
|
||||
// Remove last separator and add CR
|
||||
strTmp = strTmp.slice(0,-1) + "\n";
|
||||
// Write to tmp file
|
||||
stream.write( strTmp );
|
||||
stream.write( strTmp );
|
||||
})
|
||||
}
|
||||
else {
|
||||
else {
|
||||
strTmp = '';
|
||||
// Add each field
|
||||
// Add each field
|
||||
this.fields.forEach(function (item) {
|
||||
let result = Data[item];
|
||||
if (result == null){
|
||||
result = wtconfig.get('ET.NotAvail');
|
||||
result = wtconfig.get('ET.NotAvail');
|
||||
}
|
||||
strTmp += result + plextv.separator;
|
||||
//strTmp += Data[item] + plextv.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 );
|
||||
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');
|
||||
fs.renameSync(tmpFile, newFile);
|
||||
log.info('renamed complete');
|
||||
return newFile;
|
||||
}
|
||||
|
||||
async getFileName({ Type, Module, Usr }){
|
||||
/*
|
||||
Will create the output directory if it doesn't exists
|
||||
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 timeStamp=dateFormat(new Date(), "yyyy.mm.dd_h.MM.ss");
|
||||
const path = require('path');
|
||||
let outFile = Usr + '_';
|
||||
let outFile = Usr + '_';
|
||||
outFile += timeStamp + '.' + Type;
|
||||
const targetDir = path.join(
|
||||
OutDir, wtutils.AppName, Module);
|
||||
const outFileWithPath = path.join(
|
||||
targetDir, outFile);
|
||||
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}`)
|
||||
}
|
||||
log.info(`OutFile is ${outFileWithPath}`)
|
||||
return outFileWithPath;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue