Skip to content

Commit

Permalink
UI - New "Search List" icon and functionality (#1580)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtlmoon committed May 18, 2023
1 parent e9057cb commit 06ddf03
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 34 deletions.
16 changes: 13 additions & 3 deletions changedetectionio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ def index():

# Sort by last_changed and add the uuid which is usually the key..
sorted_watches = []
search_q = request.args.get('q').strip().lower() if request.args.get('q') else False
for uuid, watch in datastore.data['watching'].items():

if limit_tag != None:
Expand All @@ -413,16 +414,24 @@ def index():
tag_in_watch = tag_in_watch.strip()
if tag_in_watch == limit_tag:
watch['uuid'] = uuid
sorted_watches.append(watch)
if search_q:
if (watch.get('title') and search_q in watch.get('title')) or search_q in watch.get('url', '').lower():
sorted_watches.append(watch)
else:
sorted_watches.append(watch)

else:
watch['uuid'] = uuid
sorted_watches.append(watch)
if search_q:
if (watch.get('title') and search_q in watch.get('title')) or search_q in watch.get('url', '').lower():
sorted_watches.append(watch)
else:
sorted_watches.append(watch)

existing_tags = datastore.get_all_tags()
form = forms.quickWatchForm(request.form)
page = request.args.get(get_page_parameter(), type=int, default=1)
total_count = len(sorted_watches) if sorted_watches else len(datastore.data['watching'])
total_count = len(sorted_watches)
pagination = Pagination(page=page, total=total_count, per_page=int(os.getenv('pagination_per_page', 50)), css_framework = "semantic")

output = render_template(
Expand All @@ -437,6 +446,7 @@ def index():
hosted_sticky=os.getenv("SALTED_PASS", False) == False,
pagination=pagination,
queued_uuids=[q_uuid.item['uuid'] for q_uuid in update_q.queue],
search_q=request.args.get('q','').strip(),
sort_attribute=request.args.get('sort') if request.args.get('sort') else request.cookies.get('sort'),
sort_order=request.args.get('order') if request.args.get('order') else request.cookies.get('order'),
system_default_fetcher=datastore.data['settings']['application'].get('fetch_backend'),
Expand Down
31 changes: 30 additions & 1 deletion changedetectionio/static/js/toggle-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Toggles theme between light and dark mode.
*/
$(document).ready(function () {
const button = document.getElementsByClassName("toggle-theme")[0];
const button = document.getElementById("toggle-light-mode");

button.onclick = () => {
const htmlElement = document.getElementsByTagName("html");
Expand All @@ -21,4 +21,33 @@ $(document).ready(function () {
const setCookieValue = (value) => {
document.cookie = `css_dark_mode=${value};max-age=31536000;path=/`
}

// Search input box behaviour
const toggle_search = document.getElementById("toggle-search");
const search_q = document.getElementById("search-q");
window.addEventListener('keydown', function (e) {

if (e.altKey == true && e.keyCode == 83)
search_q.classList.toggle('expanded');
search_q.focus();
});


search_q.onkeydown = (e) => {
var key = e.keyCode || e.which;
if (key === 13) {
document.searchForm.submit();
}
};
toggle_search.onclick = () => {
// Could be that they want to search something once text is in there
if (search_q.value.length) {
document.searchForm.submit();
} else {
// If not..
search_q.classList.toggle('expanded');
search_q.focus();
}
};

});
55 changes: 41 additions & 14 deletions changedetectionio/static/styles/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,47 @@ a.github-link {
}
}

button.toggle-theme {
width: 4rem;
#toggle-light-mode {
width: 3rem;
.icon-dark {
display: none;
}

&.dark {
.icon-light {
display: none;
}

.icon-dark {
display: block;
}
}
}

#toggle-search {
width: 2rem;
}

#search-q {
opacity: 0;
-webkit-transition: all .9s ease;
-moz-transition: all .9s ease;
transition: all .9s ease;
width: 0;
display: none;
&.expanded {
width: auto;
display: inline-block;

opacity: 1;
}
}
#search-result-info {
color: #fff;
}

button.toggle-button {
vertical-align: middle;
background: transparent;
border: none;
cursor: pointer;
Expand All @@ -74,19 +113,7 @@ button.toggle-theme {
display: block;
}

.icon-dark {
display: none;
}

&.dark {
.icon-light {
display: none;
}

.icon-dark {
display: block;
}
}
}

.pure-menu-horizontal {
Expand Down
43 changes: 32 additions & 11 deletions changedetectionio/static/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -331,23 +331,44 @@ a.github-link {
a.github-link:hover {
color: var(--color-icon-github-hover); }

button.toggle-theme {
width: 4rem;
#toggle-light-mode {
width: 3rem; }
#toggle-light-mode .icon-dark {
display: none; }
#toggle-light-mode.dark .icon-light {
display: none; }
#toggle-light-mode.dark .icon-dark {
display: block; }

#toggle-search {
width: 2rem; }

#search-q {
opacity: 0;
-webkit-transition: all .9s ease;
-moz-transition: all .9s ease;
transition: all .9s ease;
width: 0;
display: none; }
#search-q.expanded {
width: auto;
display: inline-block;
opacity: 1; }

#search-result-info {
color: #fff; }

button.toggle-button {
vertical-align: middle;
background: transparent;
border: none;
cursor: pointer;
color: var(--color-icon-github); }
button.toggle-theme:hover {
button.toggle-button:hover {
color: var(--color-icon-github-hover); }
button.toggle-theme svg {
button.toggle-button svg {
fill: currentColor; }
button.toggle-theme .icon-light {
display: block; }
button.toggle-theme .icon-dark {
display: none; }
button.toggle-theme.dark .icon-light {
display: none; }
button.toggle-theme.dark .icon-dark {
button.toggle-button .icon-light {
display: block; }

.pure-menu-horizontal {
Expand Down
6 changes: 4 additions & 2 deletions changedetectionio/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,21 @@ def save_screenshot(self, watch_uuid, screenshot: bytes, as_error=False):
def save_error_text(self, watch_uuid, contents):
if not self.data['watching'].get(watch_uuid):
return
target_path = os.path.join(self.datastore_path, watch_uuid, "last-error.txt")

self.data['watching'][watch_uuid].ensure_data_dir_exists()
target_path = os.path.join(self.datastore_path, watch_uuid, "last-error.txt")
with open(target_path, 'w') as f:
f.write(contents)

def save_xpath_data(self, watch_uuid, data, as_error=False):

if not self.data['watching'].get(watch_uuid):
return
if as_error:
target_path = os.path.join(self.datastore_path, watch_uuid, "elements-error.json")
else:
target_path = os.path.join(self.datastore_path, watch_uuid, "elements.json")

self.data['watching'][watch_uuid].ensure_data_dir_exists()
with open(target_path, 'w') as f:
f.write(json.dumps(data))
f.close()
Expand Down
2 changes: 1 addition & 1 deletion changedetectionio/templates/_common_fields.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
URLs generated by changedetection.io (such as <code>{{ '{{diff_url}}' }}</code>) require the <code>BASE_URL</code> environment variable set.<br>
Your <code>BASE_URL</code> var is currently "{{settings_application['current_base_url']}}"
<br>
Warning: Contents of <code>{{ '{{diff}}' }}</code>, <code>{{ '{{diff_removed}}' }}</code>, and <code>{{ '{{diff_added}}' }}</code> depend on how the difference algorithm perceives the change. For example, an addition or removal could be perceived as a change in some cases. <a target="_new" href="https://github.com/dgtlmoon/changedetection.io/wiki/Using-the-%7B%7Bdiff%7D%7D,-%7B%7Bdiff_added%7D%7D,-and-%7B%7Bdiff_removal%7D%7D-notification-tokens">More Here</a> <br>
Warning: Contents of <code>{{ '{{diff}}' }}</code>, <code>{{ '{{diff_removed}}' }}</code>, and <code>{{ '{{diff_added}}' }}</code> depend on how the difference algorithm perceives the change. For example, an addition or removal could be perceived as a change in some cases. <a target="_new" href="https://github.com/dgtlmoon/changedetection.io/wiki/Using-the-%7B%7Bdiff%7D%7D,-%7B%7Bdiff_added%7D%7D,-and-%7B%7Bdiff_removed%7D%7D-notification-tokens">More Here</a> <br>
</div>
</div>
</div>
Expand Down
12 changes: 11 additions & 1 deletion changedetectionio/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,21 @@
<a href="{{url_for('logout')}}" class="pure-menu-link">LOG OUT</a>
</li>
{% endif %}
<li class="pure-menu-item pure-form" id="search-menu-item">
<!-- We use GET here so it offers people a chance to set bookmarks etc -->
<form name="searchForm" action="/" method="GET">
<input id="search-q" class="" name="q" placeholder="URL or Title {% if active_tag %}in '{{ active_tag }}'{% endif %}" required="" type="text" value="">
<input name="tag" type="hidden" value="{% if active_tag %}{{active_tag}}{% endif %}">
<button class="toggle-button " id="toggle-search" type="button" title="Search, or Use Alt+S Key" >
{% include "svgs/search-icon.svg" %}
</button>
</form>
</li>
<li class="pure-menu-item">
{% if dark_mode %}
{% set darkClass = 'dark' %}
{% endif %}
<button class="toggle-theme {{darkClass}}" type="button" title="Toggle Light/Dark Mode">
<button class="toggle-button {{darkClass}}" id ="toggle-light-mode" type="button" title="Toggle Light/Dark Mode">
<span class="visually-hidden">Toggle light/dark mode</span>
<span class="icon-light">
{% include "svgs/light-mode-toggle-icon.svg" %}
Expand Down
1 change: 1 addition & 0 deletions changedetectionio/templates/svgs/search-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion changedetectionio/templates/watch-overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
{% if watches|length >= pagination.per_page %}
{{ pagination.info }}
{% endif %}
{% if search_q %}<div id="search-result-info">Searching "<strong><i>{{search_q}}</i></strong>"</div>{% endif %}
<div>
<a href="{{url_for('index')}}" class="pure-button button-tag {{'active' if not active_tag }}">All</a>
{% for tag in tags %}
Expand Down Expand Up @@ -73,7 +74,11 @@
</tr>
</thead>
<tbody>

{% if not watches|length %}
<tr>
<td colspan="6">No website watches configured, please add a URL in the box above, or <a href="{{ url_for('import_page')}}" >import a list</a>.</td>
</tr>
{% endif %}
{% for watch in (watches|sort(attribute=sort_attribute, reverse=sort_order == 'asc'))[pagination.skip:pagination.skip+pagination.per_page] %}
<tr id="{{ watch.uuid }}"
class="{{ loop.cycle('pure-table-odd', 'pure-table-even') }} processor-{{ watch['processor'] }}
Expand Down

0 comments on commit 06ddf03

Please sign in to comment.