Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: desktop-options.js

Issue 29674584: Issue 5549 - Implement missing error handlings for custom filter lists (Closed)
Patch Set: fixed linting typos Created Jan. 23, 2018, 10:46 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 if (returnElement) 540 if (returnElement)
541 return element; 541 return element;
542 return element.getAttribute("data-" + dataName); 542 return element.getAttribute("data-" + dataName);
543 } 543 }
544 544
545 element = element.parentElement; 545 element = element.parentElement;
546 } 546 }
547 return null; 547 return null;
548 } 548 }
549 549
550 function sendMessageHandleErrors(message, onSuccess) 550 function sendMessageHandleErrors(message, onMessage)
saroyanm 2018/01/23 15:26:06 Suggestion/detail: seems like onMessage is used fo
551 { 551 {
552 browser.runtime.sendMessage(message, (errors) => 552 browser.runtime.sendMessage(message, (errors) =>
553 { 553 {
554 if (errors.length > 0) 554 if (onMessage)
555 alert(errors.join("\n")); 555 {
556 else if (onSuccess) 556 if (errors.length > 0)
557 onSuccess(); 557 onMessage(errors);
558 else
559 onMessage();
560 }
558 }); 561 });
559 } 562 }
560 563
561 function switchTab(id) 564 function switchTab(id)
562 { 565 {
563 location.hash = id; 566 location.hash = id;
564 } 567 }
565 568
566 function execAction(action, element) 569 function execAction(action, element)
567 { 570 {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 text: findParentData(element, "access", false) 644 text: findParentData(element, "access", false)
642 }); 645 });
643 break; 646 break;
644 case "remove-subscription": 647 case "remove-subscription":
645 browser.runtime.sendMessage({ 648 browser.runtime.sendMessage({
646 type: "subscriptions.remove", 649 type: "subscriptions.remove",
647 url: findParentData(element, "access", false) 650 url: findParentData(element, "access", false)
648 }); 651 });
649 break; 652 break;
650 case "save-custom-filters": 653 case "save-custom-filters":
654 const filters = E("custom-filters-raw");
651 sendMessageHandleErrors({ 655 sendMessageHandleErrors({
652 type: "filters.importRaw", 656 type: "filters.importRaw",
653 text: E("custom-filters-raw").value, 657 text: filters.value,
654 removeExisting: true 658 removeExisting: true
655 }, 659 },
656 () => 660 (errors) =>
657 { 661 {
658 setCustomFiltersView("read"); 662 if (errors)
663 {
664 filters.classList.add("warning");
665 E("custom-filters-edit-error").classList.add("warning");
saroyanm 2018/01/23 15:26:06 Suggestion: I think we can use "custom-filters" in
666 E("link-filters-on-edit-error").classList.add("visible");
saroyanm 2018/01/23 15:26:06 Note: If we agree on making this message persisten
667 const lines = filters.value.split(/\n+/);
668 const info = errors.map(error => lines[error.lineno - 1]);
saroyanm 2018/01/23 15:26:05 Note: As soon we introduce a new functionality whi
saroyanm 2018/01/23 15:26:06 I think would be great if we could return the filt
a.giammarchi 2018/01/23 15:43:18 yup, that's the "there's surely still stuff to do
a.giammarchi 2018/01/23 15:59:23 about this ... the error object doesn't offer much
saroyanm 2018/01/24 09:05:49 I think I couldn't well describe what I meant: sen
669 const editFilters = E("custom-filters-edit-filters");
670 editFilters.textContent = info.join("\n");
saroyanm 2018/01/23 15:26:05 Adding all the elements as a textContent to div ma
a.giammarchi 2018/01/23 15:43:18 I either follow UI or I don't ... this comment is
saroyanm 2018/01/23 17:37:18 I missed that, I didn't review the CSS, my fault.
671 if (errors.length > 5)
672 editFilters.classList.add("many");
673 }
674 else
675 {
676 setCustomFiltersView("read");
677 }
659 }); 678 });
660 break; 679 break;
661 case "show-more-filters-section": 680 case "show-more-filters-section":
662 E("more-filters").setAttribute("aria-hidden", false); 681 E("more-filters").setAttribute("aria-hidden", false);
663 break; 682 break;
664 case "switch-acceptable-ads": 683 case "switch-acceptable-ads":
665 let value = element.value || element.dataset.value; 684 let value = element.value || element.dataset.value;
666 // User check the checkbox 685 // User check the checkbox
667 let shouldCheck = element.getAttribute("aria-checked") != "true"; 686 let shouldCheck = element.getAttribute("aria-checked") != "true";
668 let installAcceptableAds = false; 687 let installAcceptableAds = false;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 break; 767 break;
749 } 768 }
750 } 769 }
751 770
752 function setCustomFiltersView(mode) 771 function setCustomFiltersView(mode)
753 { 772 {
754 let customFiltersElement = E("custom-filters-raw"); 773 let customFiltersElement = E("custom-filters-raw");
755 updateCustomFiltersUi(); 774 updateCustomFiltersUi();
756 if (mode == "read") 775 if (mode == "read")
757 { 776 {
777 E("custom-filters-raw").classList.remove("warning");
saroyanm 2018/01/23 15:26:06 Note: As mentioned above we don't need to remove t
778 E("custom-filters-edit-error").classList.remove("warning");
779 E("link-filters-on-edit-error").classList.remove("visible");
780 const editFilters = E("custom-filters-edit-filters");
781 editFilters.textContent = "";
782 editFilters.classList.remove("many");
758 customFiltersElement.disabled = true; 783 customFiltersElement.disabled = true;
759 if (!customFiltersElement.value) 784 if (!customFiltersElement.value)
760 { 785 {
761 setCustomFiltersView("empty"); 786 setCustomFiltersView("empty");
762 return; 787 return;
763 } 788 }
764 } 789 }
765 else if (mode == "write") 790 else if (mode == "write")
766 { 791 {
767 customFiltersElement.disabled = false; 792 customFiltersElement.disabled = false;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 936
912 // General tab 937 // General tab
913 getDocLink("contribute", (link) => 938 getDocLink("contribute", (link) =>
914 { 939 {
915 E("contribute").href = link; 940 E("contribute").href = link;
916 }); 941 });
917 getDocLink("acceptable_ads_criteria", (link) => 942 getDocLink("acceptable_ads_criteria", (link) =>
918 { 943 {
919 setLinks("enable-acceptable-ads-description", link); 944 setLinks("enable-acceptable-ads-description", link);
920 }); 945 });
921 setElementText(E("tracking-warning-1"), "options_tracking_warning_1", 946 setElementText(E("tracking-warning-1"), "options_tracking_warning_1",
922 [getMessage("common_feature_privacy_title"), 947 [getMessage("common_feature_privacy_title"),
923 getMessage("options_acceptableAds_ads_label")]); 948 getMessage("options_acceptableAds_ads_label")]);
924 setElementText(E("tracking-warning-3"), "options_tracking_warning_3", 949 setElementText(E("tracking-warning-3"), "options_tracking_warning_3",
925 [getMessage("options_acceptableAds_privacy_label")]); 950 [getMessage("options_acceptableAds_privacy_label")]);
926 951
927 getDocLink("privacy_friendly_ads", (link) => 952 getDocLink("privacy_friendly_ads", (link) =>
928 { 953 {
929 E("enable-acceptable-ads-privacy-description").href = link; 954 E("enable-acceptable-ads-privacy-description").href = link;
930 }); 955 });
931 getDocLink("adblock_plus_{browser}_dnt", url => 956 getDocLink("adblock_plus_{browser}_dnt", url =>
932 { 957 {
933 setLinks("dnt", url); 958 setLinks("dnt", url);
934 }); 959 });
(...skipping 22 matching lines...) Expand all
957 what: "features" 982 what: "features"
958 }, 983 },
959 (features) => 984 (features) =>
960 { 985 {
961 hidePref("show_devtools_panel", !features.devToolsPanel); 986 hidePref("show_devtools_panel", !features.devToolsPanel);
962 }); 987 });
963 988
964 getDocLink("filterdoc", (link) => 989 getDocLink("filterdoc", (link) =>
965 { 990 {
966 E("link-filters").setAttribute("href", link); 991 E("link-filters").setAttribute("href", link);
992 E("link-filters-on-edit-error").setAttribute("href", link);
967 }); 993 });
968 994
969 getDocLink("subscriptions", (link) => 995 getDocLink("subscriptions", (link) =>
970 { 996 {
971 E("filter-lists-learn-more").setAttribute("href", link); 997 E("filter-lists-learn-more").setAttribute("href", link);
972 }); 998 });
973 999
974 E("custom-filters-raw").setAttribute("placeholder", 1000 E("custom-filters-raw").setAttribute("placeholder",
975 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"])); 1001 getMessage("options_customFilters_edit_placeholder", ["/ads/track/*"]));
976 1002
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 setPrivacyConflict(); 1314 setPrivacyConflict();
1289 break; 1315 break;
1290 case "downloading": 1316 case "downloading":
1291 case "downloadStatus": 1317 case "downloadStatus":
1292 case "homepage": 1318 case "homepage":
1293 case "lastDownload": 1319 case "lastDownload":
1294 case "title": 1320 case "title":
1295 updateSubscription(subscription); 1321 updateSubscription(subscription);
1296 break; 1322 break;
1297 case "added": 1323 case "added":
1298 let {url, recommended} = subscription; 1324 let {url} = subscription;
1299 // Handle custom subscription 1325 // Handle custom subscription
1300 if (/^~user/.test(url)) 1326 if (/^~user/.test(url))
1301 { 1327 {
1302 loadCustomFilters(subscription.filters); 1328 loadCustomFilters(subscription.filters);
1303 return; 1329 return;
1304 } 1330 }
1305 else if (url in subscriptionsMap) 1331 else if (url in subscriptionsMap)
1306 updateSubscription(subscription); 1332 updateSubscription(subscription);
1307 else 1333 else
1308 addSubscription(subscription); 1334 addSubscription(subscription);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 }); 1495 });
1470 browser.runtime.sendMessage({ 1496 browser.runtime.sendMessage({
1471 type: "subscriptions.listen", 1497 type: "subscriptions.listen",
1472 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1498 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1473 "title", "downloadStatus", "downloading"] 1499 "title", "downloadStatus", "downloading"]
1474 }); 1500 });
1475 1501
1476 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1502 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1477 window.addEventListener("hashchange", onHashChange, false); 1503 window.addEventListener("hashchange", onHashChange, false);
1478 } 1504 }
OLDNEW

Powered by Google App Engine
This is Rietveld