Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Side by Side Diff: chrome/browser/resources/snippets_internals.js

Issue 2223073002: Add per-section clearing and dismissed suggestions to snippets-internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix non-Debug builds Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('chrome.SnippetsInternals', function() { 5 cr.define('chrome.SnippetsInternals', function() {
6 'use strict'; 6 'use strict';
7 7
8 // Stores the list of snippets we received in receiveSnippets. 8 // Stores the list of suggestions we received in receiveContentSuggestions.
9 var lastSnippets = []; 9 var lastSuggestions = [];
10 10
11 function initialize() { 11 function initialize() {
12 $('submit-download').addEventListener('click', function(event) { 12 $('submit-download').addEventListener('click', function(event) {
13 chrome.send('download', [$('hosts-input').value]); 13 chrome.send('download', [$('hosts-input').value]);
14 event.preventDefault(); 14 event.preventDefault();
15 }); 15 });
16 16
17 $('submit-clear').addEventListener('click', function(event) {
18 chrome.send('clear');
19 event.preventDefault();
20 });
21
22 $('submit-dump').addEventListener('click', function(event) { 17 $('submit-dump').addEventListener('click', function(event) {
23 downloadJson(JSON.stringify(lastSnippets)); 18 downloadJson(JSON.stringify(lastSuggestions));
24 event.preventDefault(); 19 event.preventDefault();
25 }); 20 });
26 21
27 $('last-json-button').addEventListener('click', function(event) { 22 $('last-json-button').addEventListener('click', function(event) {
28 $('last-json-container').classList.toggle('hidden'); 23 $('last-json-container').classList.toggle('hidden');
29 }); 24 });
30 25
31 $('last-json-dump').addEventListener('click', function(event) { 26 $('last-json-dump').addEventListener('click', function(event) {
32 downloadJson($('last-json-text').innerText); 27 downloadJson($('last-json-text').innerText);
33 event.preventDefault(); 28 event.preventDefault();
34 }); 29 });
35 30
36 $('dismissed-snippets-clear').addEventListener('click', function(event) {
37 chrome.send('clearDismissed');
38 event.preventDefault();
39 });
40
41 $('submit-clear-cached-suggestions')
42 .addEventListener('click', function(event) {
43 chrome.send('clearCachedSuggestions');
44 event.preventDefault();
45 });
46
47 $('submit-clear-dismissed-suggestions')
48 .addEventListener('click', function(event) {
49 chrome.send('clearDismissedSuggestions');
50 event.preventDefault();
51 });
52
53 window.addEventListener('focus', refreshContent); 31 window.addEventListener('focus', refreshContent);
54 window.setInterval(refreshContent, 1000); 32 window.setInterval(refreshContent, 1000);
55 33
56 refreshContent(); 34 refreshContent();
57 } 35 }
58 36
59 function setHostRestricted(restricted) { 37 function setHostRestricted(restricted) {
60 receiveProperty('switch-restrict-to-hosts', restricted ? 'True' : 'False'); 38 receiveProperty('switch-restrict-to-hosts', restricted ? 'True' : 'False');
61 if (!restricted) { 39 if (!restricted) {
62 $('hosts-restrict').classList.add('hidden'); 40 $('hosts-restrict').classList.add('hidden');
63 } 41 }
64 } 42 }
65 43
66 function receiveProperty(propertyId, value) { 44 function receiveProperty(propertyId, value) {
67 $(propertyId).textContent = value; 45 $(propertyId).textContent = value;
68 } 46 }
69 47
70 function receiveHosts(hosts) { 48 function receiveHosts(hosts) {
71 displayList(hosts, 'hosts'); 49 displayList(hosts, 'hosts');
72 50
73 $('hosts-input').value = hosts.list.map( 51 $('hosts-input').value = hosts.list.map(
74 function(host) { return host.url;}).join(' '); 52 function(host) { return host.url;}).join(' ');
75 } 53 }
76 54
77 function receiveSnippets(snippets) { 55 function receiveContentSuggestions(categoriesList) {
78 lastSnippets = snippets; 56 lastSuggestions = categoriesList;
79 displayList(snippets, 'snippets', 'snippet-title'); 57 displayList(categoriesList, 'content-suggestions',
58 'hidden-toggler');
59
60 var clearCachedButtons =
61 document.getElementsByClassName('submit-clear-cached-suggestions');
62 for (var button of clearCachedButtons) {
63 button.addEventListener('click', onClearCachedButtonClicked);
64 }
65
66 var clearDismissedButtons =
67 document.getElementsByClassName('submit-clear-dismissed-suggestions');
68 for (var button of clearDismissedButtons) {
69 button.addEventListener('click', onClearDismissedButtonClicked);
70 }
80 } 71 }
81 72
82 function receiveDismissedSnippets(dismissedSnippets) { 73 function onClearCachedButtonClicked(event) {
83 displayList(dismissedSnippets, 'dismissed-snippets', 74 event.preventDefault();
84 'dismissed-snippet-title'); 75 var id = parseInt(event.currentTarget.getAttribute('category-id'), 10);
76 chrome.send('clearCachedSuggestions', [id]);
85 } 77 }
86 78
87 function receiveContentSuggestions(categoriesList) { 79 function onClearDismissedButtonClicked(event) {
88 displayList(categoriesList, 'content-suggestions', 80 event.preventDefault();
89 'content-suggestion-title'); 81 var id = parseInt(event.currentTarget.getAttribute('category-id'), 10);
82 chrome.send('clearDismissedSuggestions', [id]);
90 } 83 }
91 84
92 function receiveJson(json) { 85 function receiveJson(json) {
93 var trimmed = json.trim(); 86 var trimmed = json.trim();
94 var hasContent = (trimmed && trimmed != '{}'); 87 var hasContent = (trimmed && trimmed != '{}');
95 88
96 if (hasContent) { 89 if (hasContent) {
97 receiveProperty('last-json-text', trimmed); 90 receiveProperty('last-json-text', trimmed);
98 $('last-json').classList.remove('hidden'); 91 $('last-json').classList.remove('hidden');
99 } else { 92 } else {
(...skipping 13 matching lines...) Expand all
113 106
114 function refreshContent() { 107 function refreshContent() {
115 chrome.send('refreshContent'); 108 chrome.send('refreshContent');
116 } 109 }
117 110
118 function toggleHidden(event) { 111 function toggleHidden(event) {
119 var id = event.currentTarget.getAttribute('hidden-id'); 112 var id = event.currentTarget.getAttribute('hidden-id');
120 $(id).classList.toggle('hidden'); 113 $(id).classList.toggle('hidden');
121 } 114 }
122 115
123 function displayList(object, domId, titleClass) { 116 function displayList(object, domId, toggleClass) {
124 jstProcess(new JsEvalContext(object), $(domId)); 117 jstProcess(new JsEvalContext(object), $(domId));
125 118
126 var text; 119 var text;
127 var display; 120 var display;
128 121
129 if (object.list.length > 0) { 122 if (object.list.length > 0) {
130 text = ''; 123 text = '';
131 display = 'inline'; 124 display = 'inline';
132 } else { 125 } else {
133 text = 'The list is empty.'; 126 text = 'The list is empty.';
134 display = 'none'; 127 display = 'none';
135 } 128 }
136 129
137 if ($(domId + '-empty')) $(domId + '-empty').textContent = text; 130 if ($(domId + '-empty')) $(domId + '-empty').textContent = text;
138 if ($(domId + '-clear')) $(domId + '-clear').style.display = display; 131 if ($(domId + '-clear')) $(domId + '-clear').style.display = display;
139 132
140 var links = document.getElementsByClassName(titleClass); 133 var links = document.getElementsByClassName(toggleClass);
141 for (var link of links) { 134 for (var link of links) {
142 link.addEventListener('click', toggleHidden); 135 link.addEventListener('click', toggleHidden);
143 } 136 }
144 } 137 }
145 138
146 // Return an object with all of the exports. 139 // Return an object with all of the exports.
147 return { 140 return {
148 initialize: initialize, 141 initialize: initialize,
149 setHostRestricted: setHostRestricted, 142 setHostRestricted: setHostRestricted,
150 receiveProperty: receiveProperty, 143 receiveProperty: receiveProperty,
151 receiveHosts: receiveHosts, 144 receiveHosts: receiveHosts,
152 receiveSnippets: receiveSnippets,
153 receiveDismissedSnippets: receiveDismissedSnippets,
154 receiveContentSuggestions: receiveContentSuggestions, 145 receiveContentSuggestions: receiveContentSuggestions,
155 receiveJson: receiveJson, 146 receiveJson: receiveJson,
156 }; 147 };
157 }); 148 });
158 149
159 document.addEventListener('DOMContentLoaded', 150 document.addEventListener('DOMContentLoaded',
160 chrome.SnippetsInternals.initialize); 151 chrome.SnippetsInternals.initialize);
OLDNEW
« no previous file with comments | « chrome/browser/resources/snippets_internals.html ('k') | chrome/browser/ui/webui/snippets_internals_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698