Skip to content

Commit

Permalink
Add variables list view to options page
Browse files Browse the repository at this point in the history
  • Loading branch information
gyng committed Jul 26, 2018
1 parent 38d469d commit 86f358b
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"CLICK_TYPES": false,

"BROWSERS": false,
"CURRENT_BROWSER": false
"CURRENT_BROWSER": false,

"addClickToCopy": false
}
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 3.0.0

* Fix Chrome rules matching against `_`, now matches against special characters instead
* Add variables view to last download in options
* Fix routing failing in some cases (regression) (#80)
* Fix last used access key not working at all (Chrome)

Expand Down
8 changes: 8 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@
"message": "Capture groups"
},

"o_lRoutingVariables": {
"message": "Variables"
},

"o_lRoutingVariablesClickToSee": {
"message": "Click to reveal"
},

"o_lRoutingLastDownloadHelp": {
"message": "Test your current rules, applied to the last downloaded file"
},
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "2.7.4",
"version": "3.0.0",
"default_locale": "en",

"applications": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "save-in",
"version": "2.7.4",
"version": "3.0.0",
"license": "MIT",
"scripts": {
"build": "env -u WEB_EXT_API_KEY -u WEB_EXT_API_SECRET web-ext build --overwrite-dest -i test docs yarn.lock yarn-error.log",
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ window.init = () => {
}

if (options.enableLastLocation) {
const lastUsedTitle = lastUsedPath || browser.i18n.getMessage("contextMenuLastUsed");
const lastUsedTitle =
lastUsedPath || browser.i18n.getMessage("contextMenuLastUsed");
const lastUsedMenuOptions = {
id: `save-in-_-_-last-used`,
title: setAccesskey(lastUsedTitle, options.keyLastUsed),
Expand Down
25 changes: 20 additions & 5 deletions src/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,30 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
});
break;
case MESSAGE_TYPES.CHECK_ROUTES:
const lastState =
(request.body && request.body.state) ||
(window.lastDownloadState != null && window.lastDownloadState);

const interpolatedVariables = lastState
? Object.keys(Variable.transformers).reduce(
(acc, val) =>
Object.assign(acc, {
[val]: Variable.applyVariables(
new Path.Path(val),
lastState.info
).finalize()
}),
{}
)
: null;

sendResponse({
type: MESSAGE_TYPES.CHECK_ROUTES_RESPONSE,
body: {
optionErrors: window.optionErrors,
routeInfo: OptionsManagement.checkRoutes(
(request.body && request.body.state) ||
(window.lastDownloadState != null && window.lastDownloadState)
),
lastDownload: window.lastDownloadState
routeInfo: OptionsManagement.checkRoutes(lastState),
lastDownload: window.lastDownloadState,
interpolatedVariables
}
});
break;
Expand Down
15 changes: 14 additions & 1 deletion src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,27 @@ <h4>Moving downloads into different directories</h4>
</td>
<td style="font-family: monospace; text-overflow: hidden; overflow: hidden; white-space: nowrap; max-width: 80%;" id="last-dl-url">__MSG_o_lRoutingLastDownloadEmpty__</td>
</tr>
<tr class="hi2de" id="rules-applied-row">
<tr id="rules-applied-row">
<td style="font-weight: 600; padding: 0; text-align: left;">__MSG_o_lRoutingRenamedTo__</td>
<td style="font-family: monospace; word-break: break-all;" id="last-dl-match">__MSG_o_lRoutingNoMatches__</td>
</tr>
<tr class="hide" id="capture-group-rows">
<td style="font-weight: 600; padding: 0;">__MSG_o_lRoutingCaptureGroups__</td>
<td style="font-family: monospace; word-break: break-all;" id="last-dl-capture"></td>
</tr>
<tr class="hide" id="variables-table-row">
<td style="font-weight: 600; padding: 0;">
__MSG_o_lRoutingVariables__
</td>
<td>
<div class="button" id="see-variables-btn">__MSG_o_lRoutingVariablesClickToSee__</div>
<table id="variables-table">
<tbody class="hide" id="variables-body">
</tbody>
</table>
</td>
</tr>
</tr>
</tbody>
</table>
</div>
Expand Down
38 changes: 38 additions & 0 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,42 @@ const updateErrors = () => {
lastDlMatch.textContent = body.routeInfo.path;
}

// Variables
if (hasLastDownload) {
document
.querySelector("#variables-table-row")
.classList.toggle("hide", !hasLastDownload);
}
document
.querySelector("#see-variables-btn")
.addEventListener("click", () => {
if (body.interpolatedVariables) {
const tableBody = document.querySelector("#variables-body");
tableBody.classList.toggle("hide");
tableBody.innerHTML = "";

Object.keys(body.interpolatedVariables).forEach(key => {
const val = body.interpolatedVariables[key];

const variableRow = document.createElement("tr");

const nameEl = document.createElement("td");
nameEl.textContent = key;
nameEl.classList.add("click-to-copy");
nameEl.classList.add("code");
addClickToCopy(nameEl);

const interpolatedEl = document.createElement("td");
interpolatedEl.style.fontFamily = "monospace";
interpolatedEl.textContent = val;

variableRow.appendChild(nameEl);
variableRow.appendChild(interpolatedEl);
tableBody.appendChild(variableRow);
});
}
});

// Capture groups
const hasCaptureMatches =
body.routeInfo && Array.isArray(body.routeInfo.captures);
Expand All @@ -83,6 +119,8 @@ const updateErrors = () => {

const code = document.createElement("code");
code.innerText = `:$${i + 1}:`;
code.classList.add("click-to-copy");
addClickToCopy(code);
div.appendChild(code);

const value = document.createElement("div");
Expand Down
2 changes: 2 additions & 0 deletions src/options/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ html {
min-height: 1%; /* Firefox options page height hack */
}

.code,
code,
pre {
font-family: monospace;
Expand All @@ -70,6 +71,7 @@ pre {
overflow-x: auto;
}

.code,
code {
padding: 4px;
}
Expand Down

0 comments on commit 86f358b

Please sign in to comment.