From 73092320190ffb16a90bf9fc53033b2f2cec3a16 Mon Sep 17 00:00:00 2001 From: Erik Brommers Date: Tue, 31 Oct 2023 15:23:40 -0700 Subject: [PATCH] Supplemental work on #507 Getting search results back now. Still need to figure out paging mechanism for larger data sets. --- www/js/views/SearchViews.js | 109 ++++++++++++++++++------------- www/locales/dev/translation.json | 2 + www/locales/en/translation.json | 2 + www/locales/es/translation.json | 2 + www/locales/fr/translation.json | 2 + www/locales/pt/translation.json | 2 + www/locales/tpi/translation.json | 2 + www/res/css/styles.css | 11 +++- www/tpl/TargetUnitList.html | 14 ++-- 9 files changed, 92 insertions(+), 54 deletions(-) diff --git a/www/js/views/SearchViews.js b/www/js/views/SearchViews.js index 5b00b79b..057ef381 100644 --- a/www/js/views/SearchViews.js +++ b/www/js/views/SearchViews.js @@ -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) { @@ -35,6 +34,7 @@ define(function (require) { caseSource = [], caseTarget = [], refstrings = [], + PAGE_SIZE = 100, // arbitrary # of search results to display at once //////// // STATIC METHODS @@ -163,23 +163,6 @@ define(function (require) { // end STATIC METHODS //////// - - NoChildrenView = Marionette.ItemView.extend({ - template: Handlebars.compile("
") - }), - - 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 () { @@ -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 += "
  • " + i18next.t("view.lblNewTU") + "
  • "; - this.TUList.each(function (model, index) { - // TODO: what to do with placeholder text? Currently filtered out here - if (model.get("source").length > 0) { - lstTU += "
  • " + model.get("source") + "
    "; - 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 += "
  • " + model.get("source") + "
    "; + 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 += "
  • "; + } + }); + 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 += ""; + $("#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 += "
  • " + i18next.t("view.lblProjectSettings") + "
  • "; 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 += "
  • " + i18next.t("view.lblNewTU") + "
  • "; this.TUList.each(function (model, index) { // TODO: what to do with placeholder text? Currently filtered out here if (model.get("source").length > 0) { @@ -273,7 +272,24 @@ define(function (require) { $("#lstTU").html(lstTU); strInfo = i18next.t("view.ttlProjectName", {name: window.Application.currentProject.get("name")}) + "
    " + 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); + } } }), @@ -1214,6 +1230,5 @@ define(function (require) { TUView: TUView, NewTUView: NewTUView, LookupView: LookupView, - ChapterResultsView: ChapterResultsView }; }); \ No newline at end of file diff --git a/www/locales/dev/translation.json b/www/locales/dev/translation.json index e6b01f02..ab846ae6 100644 --- a/www/locales/dev/translation.json +++ b/www/locales/dev/translation.json @@ -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": { diff --git a/www/locales/en/translation.json b/www/locales/en/translation.json index 0abdc33a..67e52fca 100644 --- a/www/locales/en/translation.json +++ b/www/locales/en/translation.json @@ -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": { diff --git a/www/locales/es/translation.json b/www/locales/es/translation.json index b7386952..ebc0d14f 100644 --- a/www/locales/es/translation.json +++ b/www/locales/es/translation.json @@ -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": { diff --git a/www/locales/fr/translation.json b/www/locales/fr/translation.json index f31e020e..9ba3e4ac 100644 --- a/www/locales/fr/translation.json +++ b/www/locales/fr/translation.json @@ -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": { diff --git a/www/locales/pt/translation.json b/www/locales/pt/translation.json index ffea0f72..e863fdab 100644 --- a/www/locales/pt/translation.json +++ b/www/locales/pt/translation.json @@ -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": { diff --git a/www/locales/tpi/translation.json b/www/locales/tpi/translation.json index 3191635b..6452d2d5 100644 --- a/www/locales/tpi/translation.json +++ b/www/locales/tpi/translation.json @@ -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": { diff --git a/www/res/css/styles.css b/www/res/css/styles.css index fefaba5a..0e6f0932 100755 --- a/www/res/css/styles.css +++ b/www/res/css/styles.css @@ -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; @@ -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; diff --git a/www/tpl/TargetUnitList.html b/www/tpl/TargetUnitList.html index 747321cb..db137a21 100644 --- a/www/tpl/TargetUnitList.html +++ b/www/tpl/TargetUnitList.html @@ -16,16 +16,18 @@
    -
    -
    - -
      +
      + -
      -
        + +