Skip to content

Commit

Permalink
Supplemental work on adapt-it#507
Browse files Browse the repository at this point in the history
Getting search results back now. Still need to figure out paging mechanism for larger data sets.
  • Loading branch information
eb1 committed Oct 31, 2023
1 parent d50ccdb commit 7309232
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 54 deletions.
109 changes: 62 additions & 47 deletions www/js/views/SearchViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// - TUView: View/edit individual target unit
// - NewTUView: Create new target unit
// - LookupView: Browse / search chapters and books, with links to AdaptView (adapt a selected passage)
// - ChapterResultsView: List chapters matching a search criteria

define(function (require) {

Expand Down Expand Up @@ -35,6 +34,7 @@ define(function (require) {
caseSource = [],
caseTarget = [],
refstrings = [],
PAGE_SIZE = 100, // arbitrary # of search results to display at once

////////
// STATIC METHODS
Expand Down Expand Up @@ -163,23 +163,6 @@ define(function (require) {
// end STATIC METHODS
////////


NoChildrenView = Marionette.ItemView.extend({
template: Handlebars.compile("<div id=\"nochildren\"></div>")
}),

ChapterItemView = Marionette.ItemView.extend({
template: Handlebars.compile(tplChapterList)
}),

ChapterResultsView = Marionette.CollectionView.extend({
childView: ChapterItemView,
emptyView: NoChildrenView,
initialize: function () {
this.collection.on("reset", this.render, this);
}
}),

TUListView = Marionette.ItemView.extend({
template: Handlebars.compile(tplTUList),
initialize: function () {
Expand Down Expand Up @@ -211,47 +194,63 @@ define(function (require) {
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;
var key = $('#search').val().trim();
console.log("searching KB for: " + key);
// filter based on search text
$("#lstTU").html("");
var self = this,
lstTU = "",
rs = null;
this.TUList.fetch({data: {source: key}}).done( function() {
console.log("fetch returns - element count: " + self.TUList.length);
self.TUList.comparator = 'source';
self.TUList.sort();
self.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>";
}
});
if (self.TUList.length === 0) {
$("#lblTotals").html(i18next.t("view.lblNoEntries"));
$("#SearchPrev").prop("disabled", true);
$("#SearchNext").prop("disabled", true);
} else {
$("#lblTotals").html(i18next.t("view.lblRange", {pgStart: 1, pgEnd: 100, total: self.TUList.length}));
$("#SearchPrev").prop("disabled", true);
if (self.TUList.length > PAGE_SIZE) {
// more than 1 page of results - enable next button
$("#SearchNext").prop("disabled", false);
} else {
// no translations (shouldn't happen)
lstTU += i18next.t("view.ttlNoTranslations");
$("#SearchNext").prop("disabled", true);
}
lstTU += "</span><span class=\"chevron\"></span></a></li>";
$("#SearchNext").prop("disabled", true);
}
$("#lstTU").html(lstTU);

});
$("#lstTU").html(lstTU);
},
onShow: function () {
var lstTU = "";
var rs = null;
var strInfo = "";
// first item in list -- create a new TU
// lstTU += "<li class=\"topcoat-list__item\"><a class=\"big-link\" id=\"btnNewTU\"><span class=\"btn-plus\"></span>" + i18next.t("view.lblProjectSettings") + "<span class=\"chevron\"></span></a></li>";
this.TUList = window.Application.kbList;
// this.TUList.fetch({reset: true, data: {projectid: this.model.get('projectid')}});
console.log("onShow: this.TUList.length = " + this.TUList.length);
// initial sort - name
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) {
Expand All @@ -273,7 +272,24 @@ define(function (require) {
$("#lstTU").html(lstTU);
strInfo = i18next.t("view.ttlProjectName", {name: window.Application.currentProject.get("name")}) + "<br>" + i18next.t("view.ttlTotalEntries", {total: this.TUList.length});
$("#lblProjInfo").html(strInfo);
// if there's no data, show the empty view
// are there any entries in the KB?
if (this.TUList.length === 0) {
// KB is empty - tell the user and disable the prev/next buttons
$("#lblTotals").html(i18next.t("view.lblNoEntries"));
$("#SearchPrev").prop("disabled", true);
$("#SearchNext").prop("disabled", true);
} else {
// some items to display -- give totals and enable UI
$("#lblTotals").html(i18next.t("view.lblRange", {pgStart: 1, pgEnd: PAGE_SIZE, total: this.TUList.length}));
$("#SearchPrev").prop("disabled", true);
if (this.TUList.length > PAGE_SIZE) {
// more than 1 page of results - enable next button
$("#SearchNext").prop("disabled", false);
} else {
$("#SearchNext").prop("disabled", true);
}
$("#SearchNext").prop("disabled", true);
}
}
}),

Expand Down Expand Up @@ -1214,6 +1230,5 @@ define(function (require) {
TUView: TUView,
NewTUView: NewTUView,
LookupView: LookupView,
ChapterResultsView: ChapterResultsView
};
});
2 changes: 2 additions & 0 deletions www/locales/dev/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
"lblNewRS": "Add Translation...",
"dscNewSP": "Enter a word or phrase in language \"__src__\", and a translation in language \"__tgt__\". You can add more translations by clicking on the \"Add Translation...\" button.",
"dscNewRS": "Enter a translation for \"__source__\".",
"lblRange": "__pgStart__-__pgEnd__ of __total__",
"lblNoEntries": "No entries found.",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
2 changes: 2 additions & 0 deletions www/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
"lblNewRS": "Add Translation...",
"dscNewSP": "Enter a word or phrase in language \"__src__\", and a translation in language \"__tgt__\". You can add more translations by clicking on the \"Add Translation...\" button.",
"dscNewRS": "Enter a translation for \"__source__\".",
"lblRange": "__pgStart__-__pgEnd__ of __total__",
"lblNoEntries": "No entries found.",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
2 changes: 2 additions & 0 deletions www/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
"lblNewRS": "Nueva Traducción...",
"dscNewSP": "Escriba una palabra o frase en el idioma \"__src__\" y una traducción en el idioma \"__tgt__\". Puede agregar más traducciones haciendo clic en el botón \"Nueva traducción...\".",
"dscNewRS": "Escriba una traducción para \"__source__\".",
"lblRange": "__pgStart__-__pgEnd__ de __total__",
"lblNoEntries": "No se encontraron elementos.",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
2 changes: 2 additions & 0 deletions www/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
"lblNewRS": "Nouvelle traduction...",
"dscNewSP": "Entrez un mot ou une expression dans la langue \"__src__\" et une traduction dans la langue \"__tgt__\". Vous pouvez ajouter plus de traductions en cliquant sur le bouton \"Nouvelle traduction...\".",
"dscNewRS": "Entrez une traduction pour \"__source__\".",
"lblRange": "__pgStart__-__pgEnd__ sur __total__",
"lblNoEntries": "Aucune entrée trouvée.",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
2 changes: 2 additions & 0 deletions www/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
"lblNewRS": "Nova tradução...",
"dscNewSP": "Digite uma palavra ou frase no idioma \"__src__\" e uma tradução no idioma \"__tgt__\". Você pode adicionar mais traduções clicando no botão \"Nova Tradução...\".",
"dscNewRS": "Digite uma tradução para \"__source__\".",
"lblRange": "__pgStart__-__pgEnd__ de __total__",
"lblNoEntries": "Nenhuma iten encontrada.",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
2 changes: 2 additions & 0 deletions www/locales/tpi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
"lblNewRS": "Nupela trenslesen...",
"dscNewSP": "Enter a word or phrase in language \"__lang__\".",
"dscNewRS": "Enter a translation for \"__source__\".",
"lblRange": "__pgStart__-__pgEnd__ of __total__",
"lblNoEntries": "No entries found.",
"_comment" : "****Add new strings BEFORE this line!****"
},
"help": {
Expand Down
11 changes: 10 additions & 1 deletion www/res/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ header h3 {
}
.search-bar {
display: none;
background-color: rgb(215,220,220);
background-color: rgb(214,218,220);
border-top: 1px solid #1f7ba5;
flex-direction: row;
justify-content: flex-end;
Expand All @@ -387,6 +387,15 @@ header h3 {
.search-label {
padding: 6px;
}
.relative-search-bar {
background-color: rgb(207,214,218);
flex-direction: row;
justify-content: flex-end;
display: flex;
height: 32px;
width: 100%;
padding: 0px 1px;
}
#SearchRS {
flex-grow: 1;
font-weight: bold;
Expand Down
14 changes: 8 additions & 6 deletions www/tpl/TargetUnitList.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
<div id="kbSearch" class="scroller-notb">
<div class="control-group">
<div class="control-row"><span id="lblProjInfo"></span></div>
<!-- <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'}}" 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>
<ul class="topcoat-list__container chapter-list" id="lstNewTU"><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>{{ t 'view.lblNewTU' }} </div></div></li></ul>
<div class="relative-search-bar" id="SearchBar">
<span class="search-label" id="SearchRS"></span>
<span class="search-label" id="lblTotals"></span>
<button class="search light-grey" id="SearchPrev"><span class="img-left-small"></span></button>
<button class="search light-grey" id="SearchNext"><span class="img-right-small"></span></button>
</div>
</div>
<ul class="chapter-list topcoat-list__container" id="lstTU"></ul>
<!-- <div class="topcoat-list__header" id="lblResults"><span class="right">1-100 of 2000 <button class="search light-grey" id="SearchPrev"><span class="img-left-small"></span></button><button class="search light-grey" id="SearchNext"><span class="img-right-small"></span></button></span></div> -->
<ul class="topcoat-list__container chapter-list" id="lstTU"></ul>
</div>
</div>
<div class="bottom-tb hide" id="tbBottom">
Expand Down

0 comments on commit 7309232

Please sign in to comment.