Skip to content

Commit

Permalink
Supplemental work on adapt-it#507
Browse files Browse the repository at this point in the history
Grr... forgot to add search functionality. Partially working now.
  • Loading branch information
eb1 committed Oct 27, 2023
1 parent 353be7b commit d50ccdb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
12 changes: 6 additions & 6 deletions www/js/models/sql/targetunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ define(function (require) {
options.success(data);
});
} else if (options.data.hasOwnProperty('projectid')) {
projectid = options.data.projectid;
projectid = options.data.projectid;
results = targetunits.filter(function (element) {
return element.attributes.projectid === projectid.toLowerCase();
});
Expand Down Expand Up @@ -308,11 +308,6 @@ define(function (require) {
return deferred.promise();
} else if (options.data.hasOwnProperty('source')) {
var source = options.data.source;
// special case -- empty source query ==> reset local copy so we force a retrieve
// from the database
if (source === "") {
targetunits.length = 0;
}
results = targetunits.filter(function (element) {
return element.attributes.source.toLowerCase().indexOf(source.toLowerCase()) > -1;
});
Expand Down Expand Up @@ -351,6 +346,11 @@ define(function (require) {
}
// return the promise
return deferred.promise();
} else {
results = targetunits;
// results already in collection -- return them
options.success(results);
deferred.resolve(results);
}
} else if (method === "delete") {
if (options.data.hasOwnProperty('projectid')) {
Expand Down
3 changes: 2 additions & 1 deletion www/js/views/DocumentViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -6499,8 +6499,9 @@ define(function (require) {
caseTarget.push(elt.t);
});
// fetch the KB in case we import an AI XML document (we'll populate the KB if that happens)
window.Application.kbList.clearLocal(); // clear out the kbList so it gets rebuilt
kblist = window.Application.kbList;
kblist.fetch({reset: true, data: {source: ""}});
kblist.fetch({reset: true, data: {projectid: window.Application.currentProject.get("projectid")}});
// reset the isKB flag
isKB = false;
isGlossKB = false;
Expand Down
37 changes: 37 additions & 0 deletions www/js/views/SearchViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ define(function (require) {
this.render();
},
events: {
"input #search": "search",
"click .big-link": "onClickTU",
"click #btnNewTU": "onClickNewTU"
},
Expand All @@ -202,6 +203,42 @@ define(function (require) {
console.log("onClickNewTU - entry");
window.Application.router.navigate("tu", {trigger: true});
},

search: function (event) {
var lstTU = "";
var rs = null;
if (event.keycode === 13) { // enter key pressed
event.preventDefault();
}
this.TUList = window.Application.kbList;
var key = $('#search').val();
if (key.length > 0) {
// filter based on search text
this.TUList.fetch({data: {source: key}});
}
this.TUList.comparator = 'source';
this.TUList.sort();
lstTU += "<li class=\"topcoat-list__item li-tu\"><div class=\"big-link\" id=\"btnNewTU\"><div class=\"chap-list__item emphasized refstring-list__item filter-burnt-orange\"><span class=\"img-plus-small\" style=\"padding-right: 16px;\"></span>" + i18next.t("view.lblNewTU") + "</div></div></li>";
this.TUList.each(function (model, index) {
// TODO: what to do with placeholder text? Currently filtered out here
if (model.get("source").length > 0) {
lstTU += "<li class=\"topcoat-list__item li-tu\"><a class=\"big-link\" id=\"" + model.get("tuid") + "\"><span class=\"chap-list__item emphasized\">" + model.get("source") + "</span><br><span class=\"sectionStatus\">";
rs = model.get("refstring");
if (rs.length > 1) {
// multiple translations - give a count
lstTU += i18next.t("view.ttlTotalTranslations", {total: rs.length});
} else if (rs.length === 1) {
// exactly 1 translation - just display it
lstTU += rs[0].target;
} else {
// no translations (shouldn't happen)
lstTU += i18next.t("view.ttlNoTranslations");
}
lstTU += "</span><span class=\"chevron\"></span></a></li>";
}
});
$("#lstTU").html(lstTU);
},
onShow: function () {
var lstTU = "";
var rs = null;
Expand Down
2 changes: 1 addition & 1 deletion www/tpl/TargetUnitList.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<!-- <div class="control-row"><button class="topcoat-button" id="btnNewTU"><span class="img-plus-small"></span> {{t 'view.lblNewTU'}}</button></div> -->
</div>
<div id="grpSearch">
<div class="doc-search-bar"><input id="search" type="search" placeholder="{{ t 'view.dscSearch'}}" class="topcoat-search-input doc-search-key"></div>
<div class="doc-search-bar"><input id="search" type="search" placeholder="{{ t 'view.dscSearch'}}" autocapitalize="off" class="topcoat-search-input doc-search-key"></div>
<div class="topcoat-list hide" style="overflow:hidden" id="lstSearch">
<h3 class="topcoat-list__header" id="lblSearchResults" style="display:none">{{t 'view.lblSearchResults'}}</h3>
<ul class="topcoat-list__container chapter-list" id="lstSearchResults"></ul>
Expand Down

0 comments on commit d50ccdb

Please sign in to comment.