Permalink
Browse files

Draft share expiration

Also reactivates drafts in history.
#40
  • Loading branch information...
Manuel-777 committed Oct 16, 2018
1 parent ffe3720 commit dece7f3aa72910e8bc36a43542c7282e1965a056
Showing with 74 additions and 11 deletions.
  1. BIN images/sets/MED.png
  2. +8 −0 main.js
  3. +1 −1 shared/database.js
  4. +19 −1 window_background/background.js
  5. +46 −9 window_main/renderer.js
BIN +5.09 KB images/sets/MED.png
Binary file not shown.
@@ -49,6 +49,10 @@ app.on('ready', () => {
break;
// to renderer
case 'set_draft_link':
mainWindow.webContents.send("set_draft_link", arg);
break;
case 'set_settings':
//console.log("set settings: ", arg);
saveSettings(arg);
@@ -158,6 +162,10 @@ app.on('ready', () => {
break;
// to background
case 'request_draft_link':
background.webContents.send("request_draft_link", arg);
break;
case 'get_deck_changes':
background.webContents.send("get_deck_changes", arg);
break;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -177,6 +177,7 @@ ipc.on('set_renderer_state', function (event, arg) {
ipc.on('login', function (event, arg) {
if (arg.password == "********") {
tokenAuth = rstore.get("token");
playerUsername = arg.username;
httpAuth(arg.username, arg.password);
}
else if (arg.username == '' && arg.password == '') {
@@ -192,6 +193,11 @@ ipc.on('login', function (event, arg) {
});
//
ipc.on('request_draft_link', function (event, obj) {
httpDraftShareLink(obj.id, obj.expire);
});
//
ipc.on('windowBounds', function (event, obj) {
@@ -366,7 +372,6 @@ function loadPlayerConfig(playerId) {
for (let i=0; i<drafts.matches.length; i++) {
ipc_send("popup", {"text": "Reading drafts: "+i+" / "+drafts.matches.length, "time": 0});
var id = drafts.matches[i];
console.log("Read draft: ", entireConfig[id]);
if (id != null) {
var item = entireConfig[id];
@@ -1894,6 +1899,9 @@ function httpBasic() {
if (_headers.method == 'get_course') {
ipc_send("open_course_deck", parsedResult.result);
}
if (_headers.method == 'share_draft') {
ipc_send("set_draft_link", parsedResult.url);
}
if (_headers.method == 'get_database') {
cardsDb.set(parsedResult);
resetLogLoop(1);
@@ -1902,6 +1910,9 @@ function httpBasic() {
ipc_send("set_db", parsedResult);
}
}
else if (parsedResult.ok == false) {
// errors here
}
if (_headers.method == 'auth') {
ipc_send("auth", parsedResult);
}
@@ -2006,6 +2017,13 @@ function htttpGetStatus() {
httpAsync.push({'reqId': _id, 'method': 'get_status', 'uid': playerId});
}
function httpDraftShareLink(did, exp) {
var _id = makeId(6);
httpAsync.push({'reqId': _id, 'method': 'share_draft', 'uid': playerId, 'id': did, 'expire': exp});
}
//
function parseWotcTime(str) {
let datePart = str.split(" ")[0];
@@ -651,10 +651,12 @@ function setHistory(loadMore) {
var match = matchesHistory[match_id];
if (match == undefined) continue;
if (match.opponent == undefined) continue;
if (match.opponent.userid.indexOf("Familiar") !== -1) continue;
console.log("Load match: ", match_id, match);
console.log("Match: ", loadHistory, match.type, match);
if (match.type == "match") {
if (match.opponent == undefined) continue;
if (match.opponent.userid.indexOf("Familiar") !== -1) continue;
}
//console.log("Load match: ", match_id, match);
//console.log("Match: ", loadHistory, match.type, match);
var div = document.createElement("div");
div.classList.add(match.id);
@@ -758,7 +760,6 @@ function setHistory(loadMore) {
}
}
else {
//console.log("DRAFT: ", match)
var tileGrpid = setsList[match.set].tile;
var tile = document.createElement("div");
@@ -813,9 +814,11 @@ function setHistory(loadMore) {
loadHistory = loadEnd;
}
var currentId = null;
//
function addShare(_match) {
$('.'+_match.id+'dr').on('click', function(e) {
currentId = _match.id;
e.stopPropagation();
$('.share_dialog_wrapper').css('opacity', 1);
$('.share_dialog_wrapper').css('pointer-events', 'all');
@@ -849,20 +852,54 @@ function addShare(_match) {
cont.append('<div class="share_title">Link For sharing:</div>');
var icd = $('<div class="share_input_container"></div>');
var but = $('<div class="button_simple">Copy</div>');
var sin = $('<input id="share_input" onClick="this.setSelectionRange(0, this.value.length)" autofocus autocomplete="off" value="https://mtgatool.com/draft/'+_match.id+'" />');
var sin = $('<input id="share_input" onClick="this.setSelectionRange(0, this.value.length)" autofocus autocomplete="off" value="" />');
sin.appendTo(icd);
but.appendTo(icd);
icd.appendTo(cont);
cont.append('<div class="share_subtitle"><i>This link will never expire</i></div>');
cont.append('<div class="share_subtitle"><i>Expires in: </i></div>');
cont.appendTo(dialog);
var select = $('<select id="expire_select">'+sortingAlgorithm+'</select>');
var sortby = ['One day', 'One week', 'One month', 'Never'];
for (var i=0; i < sortby.length; i++) {
select.append('<option value="'+sortby[i]+'">'+sortby[i]+'</option>');
}
select.appendTo(cont);
selectAdd(select, draftShareLink);
but.click(function () {
ipc_send('set_clipboard', "https://mtgatool.com/draft/"+_match.id);
ipc_send('set_clipboard', document.getElementById("share_input").value);
});
});
}
//
function draftShareLink() {
var shareExpire = document.getElementById("expire_select").value;
var expire = 0;
switch (shareExpire) {
case 'One day': expire = 0; break;
case 'One week': expire = 1; break;
case 'One month': expire = 2; break;
case 'Never': expire = -1; break;
default: expire = 0; break;
}
obj = {
expire: expire,
id: currentId
}
ipc_send('request_draft_link', obj);
}
//
ipc.on('set_draft_link', function (event, arg) {
document.getElementById("share_input").value = arg;
});
//
function addHover(_match, tileGrpid) {
$('.'+_match.id).on('mouseenter', function(e) {
@@ -1807,7 +1844,7 @@ function open_draft(id, tileGrpid, set) {
top.append(flr);
if (cardsDb.get(tileGrpid)) {
change_background("https://img.scryfall.com/cards"+cardsDb.get(grpId).images["art_crop"]);
change_background("https://img.scryfall.com/cards"+cardsDb.get(tileGrpid).images["art_crop"]);
}
var cont = $('<div class="flex_item" style="flex-direction: column;"></div>');

0 comments on commit dece7f3

Please sign in to comment.