mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Merge branch 'add-search' into dev
Conflicts: resources/report/js/filters.js
This commit is contained in:
@@ -60,6 +60,10 @@ loot-clear-metadata
|
||||
:host(:not([data-edits])) #hasUserEdits {
|
||||
display: none;
|
||||
}
|
||||
:host(.search-result) #front,
|
||||
:host(.search-result) #editor {
|
||||
box-shadow: inset 4px 0 #3F51B5;
|
||||
}
|
||||
#front {
|
||||
display: block;
|
||||
transform: translateZ(1px);
|
||||
@@ -219,6 +223,7 @@ loot-clear-metadata
|
||||
'data.tags': 'onTagsChange',
|
||||
'data.computed.messages': 'onMessagesChange',
|
||||
'data.userlist': 'onUserlistChange',
|
||||
'data.isSearchResult' : 'onSearchResultChange',
|
||||
'data.isMenuOpen': 'onMenuToggle'
|
||||
},
|
||||
|
||||
@@ -261,6 +266,9 @@ loot-clear-metadata
|
||||
/* Also set highlight if the conflict filter is active. */
|
||||
this.classList.toggle('highlight', newValue.isConflictFilterChecked);
|
||||
|
||||
/* Set highlight if the plugin is a search result. */
|
||||
this.onSearchResultChange(oldValue.isSearchResult, newValue.isSearchResult);
|
||||
|
||||
/* Update tooltip positions. */
|
||||
var tooltips = this.shadowRoot.querySelectorAll('core-tooltip');
|
||||
for (var i = 0; i < tooltips.length; ++i) {
|
||||
@@ -301,6 +309,10 @@ loot-clear-metadata
|
||||
}
|
||||
},
|
||||
|
||||
onSearchResultChange: function(oldValue, newValue) {
|
||||
this.classList.toggle('search-result', newValue);
|
||||
},
|
||||
|
||||
onMenuToggle: function(oldValue, newValue) {
|
||||
if (newValue) {
|
||||
this.style.marginBottom = '190px';
|
||||
|
||||
@@ -91,8 +91,11 @@ loot-editor-close
|
||||
}
|
||||
|
||||
/* Misc Styling. */
|
||||
core-toolbar.medium-tall {
|
||||
:host {
|
||||
background: #CFD4E9;
|
||||
}
|
||||
core-toolbar.medium-tall {
|
||||
background: transparent;
|
||||
height: 104px;
|
||||
}
|
||||
core-toolbar > div {
|
||||
@@ -105,8 +108,9 @@ loot-editor-close
|
||||
vertical-align: inherit !important;
|
||||
}
|
||||
core-selector > * {
|
||||
border: 4px solid #CFD4E9;
|
||||
border-top: none;
|
||||
border-bottom: 4px solid #CFD4E9;
|
||||
background: white;
|
||||
margin: 0 4px 4px 4px;
|
||||
}
|
||||
#main {
|
||||
padding: 16px;
|
||||
|
||||
@@ -17,6 +17,9 @@ searchTarget is the ID of the core-list element to search the elements of.
|
||||
core-toolbar > * {
|
||||
top: -3px;
|
||||
}
|
||||
paper-input {
|
||||
position: relative;
|
||||
}
|
||||
paper-input /deep/ paper-input-decorator::shadow .label-text,
|
||||
paper-input /deep/ input::-webkit-input-placeholder {
|
||||
color: rgba(255, 255, 255, 0.3) !important;
|
||||
@@ -31,11 +34,9 @@ searchTarget is the ID of the core-list element to search the elements of.
|
||||
}
|
||||
</style>
|
||||
<core-toolbar>
|
||||
<core-tooltip label="Press Enter to search." position="bottom" noarrow flex layout horizontal center>
|
||||
<paper-input id="search" label="Search" flex></paper-input>
|
||||
</core-tooltip>
|
||||
<paper-input id="search" label="Search Cards" flex></paper-input>
|
||||
<div id="count" class="caption hidden">
|
||||
{{currentResult}}/{{numResults}}
|
||||
{{currentResult + 1}}/{{numResults}}
|
||||
</div>
|
||||
<paper-icon-button id="prev" icon="expand-less" disabled></paper-icon-button>
|
||||
<paper-icon-button id="next" icon="expand-more" disabled></paper-icon-button>
|
||||
@@ -44,20 +45,13 @@ searchTarget is the ID of the core-list element to search the elements of.
|
||||
</template>
|
||||
<script>
|
||||
Polymer({
|
||||
currentResult: 0,
|
||||
currentResult: -1,
|
||||
results: [],
|
||||
numResults: 0,
|
||||
searchTarget: undefined,
|
||||
|
||||
resultsChanged: function(oldValue, newValue) {
|
||||
this.numResults = newValue.length;
|
||||
if (newValue.length == 0) {
|
||||
this.shadowRoot.getElementById('prev').setAttribute('disabled', '');
|
||||
this.shadowRoot.getElementById('next').setAttribute('disabled', '');
|
||||
} else {
|
||||
this.shadowRoot.getElementById('prev').removeAttribute('disabled');
|
||||
this.shadowRoot.getElementById('next').removeAttribute('disabled');
|
||||
}
|
||||
},
|
||||
|
||||
currentResultChanged: function(oldValue, newValue) {
|
||||
@@ -65,10 +59,10 @@ searchTarget is the ID of the core-list element to search the elements of.
|
||||
if (this.results.length == 1) {
|
||||
this.shadowRoot.getElementById('prev').setAttribute('disabled', '');
|
||||
this.shadowRoot.getElementById('next').setAttribute('disabled', '');
|
||||
} else if (newValue == 1) {
|
||||
} else if (newValue == 0) {
|
||||
this.shadowRoot.getElementById('prev').setAttribute('disabled', '');
|
||||
this.shadowRoot.getElementById('next').removeAttribute('disabled');
|
||||
} else if (newValue == this.results.length) {
|
||||
} else if (newValue == this.results.length - 1) {
|
||||
this.shadowRoot.getElementById('prev').removeAttribute('disabled');
|
||||
this.shadowRoot.getElementById('next').setAttribute('disabled', '');
|
||||
} else {
|
||||
@@ -79,76 +73,119 @@ searchTarget is the ID of the core-list element to search the elements of.
|
||||
},
|
||||
|
||||
attached: function() {
|
||||
this.shadowRoot.getElementById('search').addEventListener('change', this.onSearch, false);
|
||||
this.shadowRoot.getElementById('search').addEventListener('input', this.onSearch, false);
|
||||
this.shadowRoot.getElementById('search').addEventListener('keyup', this.onEnter, false);
|
||||
this.shadowRoot.getElementById('prev').addEventListener('click', this.onPrev, false);
|
||||
this.shadowRoot.getElementById('next').addEventListener('click', this.onNext, false);
|
||||
this.shadowRoot.getElementById('close').addEventListener('click', this.onClose, false);
|
||||
},
|
||||
|
||||
detached: function() {
|
||||
this.shadowRoot.getElementById('search').removeEventListener('change', this.onSearch, false);
|
||||
this.shadowRoot.getElementById('search').removeEventListener('input', this.onSearch, false);
|
||||
this.shadowRoot.getElementById('search').removeEventListener('keyup', this.onEnter, false);
|
||||
this.shadowRoot.getElementById('prev').removeEventListener('click', this.onPrev, false);
|
||||
this.shadowRoot.getElementById('next').removeEventListener('click', this.onNext, false);
|
||||
this.shadowRoot.getElementById('close').removeEventListener('change', this.onClose, false);
|
||||
},
|
||||
|
||||
resetResults: function() {
|
||||
loot.game.plugins.forEach(function(plugin){
|
||||
plugin.isSearchResult = false;
|
||||
});
|
||||
this.results = [];
|
||||
this.currentResult = -1;
|
||||
this.shadowRoot.getElementById('prev').setAttribute('disabled', '');
|
||||
this.shadowRoot.getElementById('next').setAttribute('disabled', '');
|
||||
},
|
||||
|
||||
onEnter: function(evt) {
|
||||
var host = evt.target.parentElement.parentNode.host;
|
||||
if (evt.keyCode != 13 || host.results.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (host.currentResult == host.results.length - 1) {
|
||||
host.currentResult = 0;
|
||||
} else {
|
||||
++host.currentResult;
|
||||
}
|
||||
document.getElementById(host.searchTarget).scrollToItem(host.results[host.currentResult]);
|
||||
},
|
||||
|
||||
focusInput: function() {
|
||||
this.shadowRoot.getElementById('search').focus();
|
||||
},
|
||||
|
||||
search: function() {
|
||||
this.shadowRoot.getElementById('search').dispatchEvent(new Event('input'));
|
||||
},
|
||||
|
||||
onSearch: function(evt) {
|
||||
var needle = evt.target.value.toLowerCase();
|
||||
var host = evt.target.parentElement.parentElement.parentNode.host;
|
||||
host.currentResult = 0;
|
||||
host.results = [];
|
||||
var host = evt.target.parentElement.parentNode.host;
|
||||
|
||||
host.resetResults();
|
||||
host.shadowRoot.getElementById('count').classList.toggle('hidden', !evt.target.value);
|
||||
|
||||
if (!evt.target.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
var versionHidden = document.getElementById('hideVersionNumbers').checked;
|
||||
var crcHidden = document.getElementById('hideCRCs').checked;
|
||||
var bashTagHidden = document.getElementById('hideBashTags').checked;
|
||||
document.getElementById(host.searchTarget).data.forEach(function(plugin, index){
|
||||
if (plugin.name.toLowerCase().indexOf(needle) != -1
|
||||
|| plugin.getCrcString().toLowerCase().indexOf(needle) != -1
|
||||
|| plugin.version.toLowerCase().indexOf(needle) != -1) {
|
||||
|| (!versionHidden && plugin.version.toLowerCase().indexOf(needle) != -1)
|
||||
|| (!crcHidden && plugin.getCrcString().toLowerCase().indexOf(needle) != -1)) {
|
||||
|
||||
host.results.push(index);
|
||||
plugin.isSearchResult = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var tags = plugin.getTagStrings();
|
||||
if (tags.added.toLowerCase().indexOf(needle) != -1
|
||||
|| tags.removed.toLowerCase().indexOf(needle) != -1) {
|
||||
if (!bashTagHidden) {
|
||||
var tags = plugin.getTagStrings();
|
||||
if (tags.added.toLowerCase().indexOf(needle) != -1
|
||||
|| tags.removed.toLowerCase().indexOf(needle) != -1) {
|
||||
|
||||
host.results.push(index);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < plugin.messages.length; ++i) {
|
||||
if (plugin.messages[i].content[0].str.toLowerCase().indexOf(needle) != -1) {
|
||||
host.results.push(index);
|
||||
plugin.isSearchResult = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < plugin.computed.messages.length; ++i) {
|
||||
if (plugin.computed.messages[i].textContent.toLowerCase().indexOf(needle) != -1) {
|
||||
host.results.push(index);
|
||||
plugin.isSearchResult = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (host.results.length > 0) {
|
||||
host.currentResult = 1;
|
||||
document.getElementById(host.searchTarget).scrollToItem(host.results[host.currentResult - 1]);
|
||||
host.currentResult = 0;
|
||||
// For some reason change watcher doesn't run, call it manually.
|
||||
host.currentResultChanged(-1, 0);
|
||||
document.getElementById(host.searchTarget).scrollToItem(host.results[host.currentResult]);
|
||||
}
|
||||
},
|
||||
|
||||
onPrev: function(evt) {
|
||||
var host = evt.target.parentElement.parentNode.host;
|
||||
--host.currentResult;
|
||||
document.getElementById(host.searchTarget).scrollToItem(host.results[host.currentResult - 1]);
|
||||
document.getElementById(host.searchTarget).scrollToItem(host.results[host.currentResult]);
|
||||
},
|
||||
|
||||
onNext: function(evt) {
|
||||
var host = evt.target.parentElement.parentNode.host;
|
||||
++host.currentResult;
|
||||
document.getElementById(host.searchTarget).scrollToItem(host.results[host.currentResult - 1]);
|
||||
document.getElementById(host.searchTarget).scrollToItem(host.results[host.currentResult]);
|
||||
},
|
||||
|
||||
onClose: function(evt) {
|
||||
evt.target.parentElement.parentNode.host.currentResult = 0;
|
||||
evt.target.parentElement.parentNode.host.results = [];
|
||||
evt.target.parentElement.parentNode.host.resetResults();
|
||||
evt.target.parentElement.parentNode.getElementById('search').value = '';
|
||||
evt.target.parentElement.parentNode.getElementById('count').classList.toggle('hidden', true);
|
||||
evt.target.dispatchEvent(new CustomEvent('loot-search-close'));
|
||||
|
||||
@@ -15,10 +15,19 @@ function onToggleDisplayCSS(evt) {
|
||||
} else {
|
||||
document.getElementById('main').removeAttribute(attr);
|
||||
}
|
||||
|
||||
if (evt.target.id != 'hideBashTags') {
|
||||
/* Now perform search again. If there is no current search, this won't
|
||||
do anything. */
|
||||
document.getElementById('searchBar').search();
|
||||
}
|
||||
}
|
||||
function onToggleBashTags(evt) {
|
||||
onToggleDisplayCSS(evt);
|
||||
document.getElementById('main').lastElementChild.updateSize();
|
||||
/* Now perform search again. If there is no current search, this won't
|
||||
do anything. */
|
||||
document.getElementById('searchBar').search();
|
||||
}
|
||||
function onOpenLogLocation(evt) {
|
||||
loot.query('openLogLocation').catch(processCefError);
|
||||
@@ -447,6 +456,10 @@ function onEditorClose(evt) {
|
||||
|
||||
evt.target.data.userlist = edits.userlist;
|
||||
delete evt.target.data.editor;
|
||||
|
||||
/* Now perform search again. If there is no current search, this won't
|
||||
do anything. */
|
||||
document.getElementById('searchBar').search();
|
||||
}
|
||||
}).catch(processCefError);
|
||||
} else {
|
||||
@@ -549,6 +562,9 @@ function onClearMetadata(evt) {
|
||||
}
|
||||
}
|
||||
toast(l10n.jed.translate('The user-added metadata for "%s" has been cleared.').fetch(evt.target.getName()));
|
||||
/* Now perform search again. If there is no current search, this won't
|
||||
do anything. */
|
||||
document.getElementById('searchBar').search();
|
||||
}
|
||||
}).catch(processCefError);
|
||||
}
|
||||
@@ -648,6 +664,7 @@ function onContentRefresh(evt) {
|
||||
}
|
||||
function onSearchOpen(evt) {
|
||||
document.getElementById('mainToolbar').classList.add('search');
|
||||
document.getElementById('searchBar').focusInput();
|
||||
}
|
||||
function onSearchClose(evt) {
|
||||
document.getElementById('mainToolbar').classList.remove('search');
|
||||
|
||||
@@ -206,6 +206,10 @@ function setFilteredUIData() {
|
||||
filtered.forEach(function(plugin){
|
||||
plugin.computed.messages = plugin.getUIMessages();
|
||||
});
|
||||
|
||||
/* Now perform search again. If there is no current search, this won't
|
||||
do anything. */
|
||||
document.getElementById('searchBar').search();
|
||||
});
|
||||
}
|
||||
function restoreFilterStates() {
|
||||
|
||||
@@ -45,6 +45,7 @@ function Plugin(obj) {
|
||||
this.isMenuOpen = false;
|
||||
this.isEditorOpen = false;
|
||||
this.isConflictFilterChecked = false;
|
||||
this.isSearchResult = false;
|
||||
|
||||
/* Converts between the LOOT metadata object for tags, and their
|
||||
editor row representation. */
|
||||
|
||||
Reference in New Issue
Block a user