Permalink
Browse files

Custom export formats for collection

Fixes #28
  • Loading branch information...
Manuel-777 committed Oct 17, 2018
1 parent dece7f3 commit 47225e778c52eadd469ef60dd6b2f12164c13514
Showing with 68 additions and 13 deletions.
  1. +21 −0 main.js
  2. +19 −9 shared/util.js
  3. +5 −0 window_background/background.js
  4. +23 −4 window_main/renderer.js
21 main.js
@@ -320,6 +320,27 @@ app.on('ready', () => {
}
});
case 'export_csvtxt':
dialog.showSaveDialog({
filters: [{
name: 'csv',
extensions: ['csv']
},{
name: 'txt',
extensions: ['txt']
}],
defaultPath: '~/'+arg.name+'.csv'
}, function(file_path) {
if (file_path) {
fs.writeFile(file_path, arg.str, function(err) {
if (err) {
dialog.showErrorBox('Error', err);
return;
}
});
}
});
break;
default:
@@ -536,18 +536,28 @@ function collectionSortCmc(a, b) {
//
function get_collection_export() {
var str = "";
var list = "";
Object.keys(cards).forEach(function(key) {
let quantity = cards[key];
let name = cardsDb.get(key).name;
name = replaceAll(name, '///', '//');
str += quantity+" "+name+"\r\n";
var add = settings.export_format+"";
var card = cardsDb.get(key);
if (card) {
let name = card.name;
name = replaceAll(name, '///', '//');
add = add.replace('$Name', name);
add = add.replace('$Count', cards[key]);
add = add.replace('$SetName', card.set);
add = add.replace('$SetCode', setsList[card.set].code);
add = add.replace('$Collector', card.cid);
add = add.replace('$Rarity', card.rarity);
add = add.replace('$Type', card.type);
add = add.replace('$Cmc', card.cmc);
list += add+"\r\n";
}
});
return str;
return list;
}
//
@@ -32,6 +32,7 @@ const defaultCfg = {
overlay_deck: true,
overlay_clock: true,
overlay_ontop: true,
export_format: "$Name,$Count,$Rarity,$SetName,$Collector",
back_color: "rgba(0,0,0,0.3)",
back_url: ''
},
@@ -409,6 +410,10 @@ function updateSettings(_settings, relay) {
ipc_send("overlay_set_ontop", _settings.overlay_ontop);
if (_settings.export_format == undefined) {
_settings.export_format = "$Name,$Count,$Rarity,$SetName,$Collector";
}
if (_settings.show_overlay == false) {
ipc_send("overlay_close", 1);
}
@@ -2260,7 +2260,7 @@ function open_cards() {
select.appendTo(flex);
selectAdd(select, sortCollection);
var exp = $('<div class="button_simple button_thin" onClick="exportCollection()">Copy to Clipboard</div>');
var exp = $('<div class="button_simple button_thin" onClick="exportCollection()">Export Collection</div>');
exp.appendTo(flex);
var reset = $('<div class="button_simple button_thin" onClick="resetFilters()">Reset</div>');
reset.appendTo(flex);
@@ -2442,8 +2442,8 @@ function resetFilters() {
//
function exportCollection() {
var str = get_collection_export();
ipc_send('set_clipboard', str);
var list = get_collection_export();
ipc_send('export_csvtxt', {str: list, name: "collection"});
}
//
@@ -2854,7 +2854,17 @@ function open_settings(openSection) {
add_checkbox(section, 'Close to tray', 'settings_closetotray', settings.close_to_tray);
add_checkbox(section, 'Sound when priority changes', 'settings_soundpriority', settings.sound_priority);
//
var label = $('<label class="but_container_label">Export Format:</label>');
label.appendTo(section);
var icd = $('<div class="input_container"></div>');
var export_input = $('<input type="search" id="settings_export_format" autocomplete="off" value="'+settings.export_format+'" />');
export_input.appendTo(icd);
icd.appendTo(label);
section.append('<label style="color: rgba(250, 229, 210, 0.75); font-size: 14px; margin-left: 16px;"><i>Possible variables: $Name, $Count, $SetName, $SetCode, $Collector, $Rarity, $Type, $Cmc</i></label>');
section = $('<div class="settings_section ss2"></div>');
section.appendTo(div);
section.append('<div class="settings_title">Overlay</div>');
@@ -3036,6 +3046,12 @@ function open_settings(openSection) {
}
});
export_input.on('keyup', function (e) {
if (e.keyCode == 13) {
updateSettings();
}
});
$(".sliderA").off();
$(".sliderA").on('click mousemove', function() {
@@ -3150,6 +3166,8 @@ function updateSettings() {
var overlayClock = document.getElementById("settings_overlay_clock").checked;
var overlaySideboard = document.getElementById("settings_overlay_sideboard").checked;
var exportFormat = document.getElementById("settings_export_format").value;
settings = {
sound_priority: soundPriority,
show_overlay: showOverlay,
@@ -3170,6 +3188,7 @@ function updateSettings() {
anon_explore: anonExplore,
back_color: backColor,
back_url: backUrl,
export_format: exportFormat
};
cardSize = 100+(cardSizePos*10);
ipc_send('save_settings', settings);

0 comments on commit 47225e7

Please sign in to comment.