1var articles = { 2 created: function () { 3 var self = this; 4 /*bus.$on('sourcesLoaded', function () { 5 setTimeout(() => self.fetchArticlesData(), 1000); 6 });*/ 7 bus.$on('updateFilteredArticles', function () { 8 self.updateFilteredArticles(); 9 }); 10 }, 11 data: { 12 articles: [], 13 articlesFilter: "", 14 loadedSourceCount: 0, 15 sourcesCount: 1, 16 allArticlesYears: [], 17 showAbstracts: false, 18 modalChapter: {}, 19 modalTextFilter: "", 20 modalChapterDescription: "", 21 modalYear: 0, 22 modalAudioAutoplay: false, 23 modalIssue: 0, 24 modalShowAbstracts: "", 25 modalArticlesFilter: "", 26 showModalDialog: false, 27 wholeWordSearch: false, 28 filterScope: "title", 29 filteredArticles: [], 30 filteredArticleItems: [], 31 displayedArticlesCount: 0, 32 showedArticlesCount: 0, 33 selectedArticlesYears: [], 34 modalFilteredArticles: [], 35 maxArticlesListLength: 2000, 36 modalFilteredArticlesCount: -1 37 }, 38 computed: {}, 39 methods: { 40 getSearchText: function (article) { 41 if (this.filterScope === "authors") { 42 return article.authorsList; 43 } else if (this.filterScope === "abstract") { 44 return article.title + " " + article.authorsList + " " + article.quoteAbstract; 45 } else if (this.filterScope === "year") { 46 return "" + article.year; 47 } 48 49 return article.title; 50 }, 51 updateFilteredArticles: function () { 52 var result = []; 53 var self = this; 54 55 if (this.articlesFilter != null && this.articlesFilter.length > 0) { 56 var terms = this.articlesFilter.toLowerCase().split(";"); 57 this.articles.filter(function (a) { 58 return a.source.selected; 59 }
59).forEach(function (article) { 60 var added = null; 61 terms.forEach(function (term) { 62 var searchText = self.getSearchText(article); 63 if (!searchText) return; 64 searchText = searchText.toLowerCase(); 65 term = term.trim(); 66 var wholeWordSearchText = " " 67 + searchText.replace(/\,|\:|\)|\(|\.|\[|\]|\}|\{|\"/, " ") + " "; 68 if (added === null && term.length > 0) { 69 if (self.wholeWordSearch 70 && (wholeWordSearchText.includes(" " + term + " ") 71 || wholeWordSearchText.includes(" " + term + "'"))) { 72 added = true; 73 } else if (!self.wholeWordSearch && searchText.includes(term)) { 74 added = true; 75 } 76 } else if (term.startsWith("-") && searchText.includes(term.substr(1))) { 77 added = false; 78 return; 79 } 80 }); 81 82 if (added) { 83 result.push(article); 84 } 85 }); 86 } else { 87 result = this.articles; 88 } 89 90 result.forEach(function (article) { 91 article.showAbstract = false; 92 }); 93 94 var sortedResults = result.sort(function (a, b) { 95 var indexA = self.sources.indexOf(a.source); 96 var indexB = self.sources.indexOf(b.source); 97 return (indexA + b.year * 100) - (indexB + a.year * 100); 98 }); 99 100 this.filteredArticlesCount = sortedResults.length; 101 102 if (sortedResults.length > this.maxArticlesListLength) { 103 this.filteredArticles = sortedResults.slice(0, this.maxArticlesListLength); 104 } else { 105 this.filteredArticles = sortedResults; 106 } 107 108 this.displayedArticlesCount = this.filteredArticles.length; 109 110 this.filteredArticleItems = []; 111 this.filteredArticles.forEach(function (article) { 112 self.filteredArticleItems.push({ 113 article: article, 114 source: article.source, 115 year: article.year 116 }); 117 }); 118 }, 119 fetchArticlesData: function () { 120 let self = this; 121 self.articles = []; 122 self.sourcesCount = this.sources.length; 123 self.loadedSourceCount = 0; 124 this.sources.forEach(function (source) { 125 source.numberOfArticles = 0; 126 // source.firstYear = 0; 127 self.loadedSourceCount += 3; 128 }); 129 }, 130 flipShowAbstract: function (article) { 131 article.showAbstract = !article.showAbstract; 132 }, 133 getLinkText: function () { 134 if (this.about.linkText === undefined) { 135 this.about.linkText = "Read Full Article"; 136 } 137 return this.about.linkText; 138 }, 139 openModalDialog: function () { 140 this.showModalDialog = true; 141 }, 142 closeModalDialog: function () { 143 this.showModalDialog = false; 144 }, 145 showArticles: function (chapter, audioAutoPlay) { 146 this.modalFilteredArticlesCount = -1; 147 this.modalChapter = chapter; 148 this.modalChapterDescription = chapter.description; 149 this.modalYear = chapter.year; 150 this.modalIssue = chapter.number; 151 this.modalAudioAutoplay = audioAutoPlay ? true : false; 152 this.modalShowAbstracts = false; 153 this.modalArticlesFilter = chapter.year + " (issue " + chapter.issue + ")"; 154 this.openModalDialog(); 155 const self = this; 156 self.modalFilteredArticles = []; 157 let url = 'https://obren359.s3-accelerate.amazonaws.com/'
158 + chapter.source.id + '/issues/' 159 + chapter.year + '-' 160 + chapter.number + '.json'; 161 162 console.log(url); 163 164 $.get(url, function (data) { 165 let issueArticles = JSON.parse(data); 166 issueArticles.forEach(function (article) { 167 article.source = chapter.source 168 }); 169 170 issueArticles.forEach(function (article) { 171 article.showAbstract = false; 172 }); 173 174 issueArticles = issueArticles.sort(function (a, b) { 175 return (a.page ? a.page : 0) - (b.page ? b.page : 0); 176 }); 177 issueArticles = issueArticles.sort(function (a, b) { 178 return a.year - b.year; 179 }); 180 181 self.modalFilteredArticles = issueArticles; 182 self.modalFilteredArticlesCount = self.modalFilteredArticles.length; 183 }); 184 185 }, 186 filteredModalArticles: function () { 187 const self = this; 188 let filter = self.modalTextFilter.toLowerCase(); 189 return self.modalFilteredArticles.filter(function (article) { 190 return filter.length === 0 || (article.title + '').toLowerCase().includes(filter); 191 }); 192 }, 193 getSourceById: function (id) { 194 return this.sources.filter(function (s) { 195 return s.id === id; 196 })[0]; 197 }, 198 getArticles: function (year, issue, maxArticles) { 199 var selectedArticles = []; 200 var count = 0; 201 this.articles.forEach(function (article) { 202 if (count < maxArticles) { 203 if (article.year === year && article.number === issue) { 204 count++; 205 selectedArticles.push(article); 206 } 207 } 208 }); 209 210 return selectedArticles; 211 }, 212 filterArticles: function (filter) { 213 var result = []; 214 var self = this; 215 this.articles.forEach(function (article) { 216 if (article.searchText.indexOf(filter.toLowerCase()) >= 0) { 217 result.push(article); 218 } 219 }); 220 221 result.forEach(function (article) { 222 article.showAbstract = false; 223 }); 224 225 return result.sort(function (a, b) { 226 return a.year - b.year; 227 }); 228 }, 229 downloadArticles: function (url, articlesSource) { 230 const self = this; 231 $.ajaxSetup({ 232 timeout:5000 // in milliseconds 233 }); 234 $.get(url, function (data) { 235 let parsedData = JSON.parse(data); 236 if (parsedData.articles) { 237 parsedData.articles.forEach(function (article) { 238 article.source = articlesSource; 239 }); 240 241 parsedData.articles = parsedData.articles.sort(function (a, b) { 242 return (a.year - b.year) * 100 - (a.number - b.number); 243 }); 244 245 self.filteredArticles = self.filteredArticles.concat(parsedData.articles); 246 self.filteredArticlesCount += parsedData.count; 247 self.filteredArticles.forEach(function (article) { 248 self.filteredArticleItems.push({ 249 article: article, 250 source: articlesSource, 251 year: article.year 252 }); 253 }); 254 self.filteredArticles = self.filteredArticles.sort(function (a, b) { 255 var indexA = self.sources.indexOf(a.source); 256 var indexB = self.sources.indexOf(b.source); 257 return (indexA + b.year * 100) - (indexB + a.year * 100); 258 }); 259 self.filteredArticleItems = self.filteredArticleItems.sort(function (a, b) { 260 var indexA = self.sources.indexOf(a.article.source); 261 var indexB = self.sources.indexOf(b.article.source); 262 return (indexA + b.article.year * 100) - (indexB + a.article.year * 100); 263 }); 264 self.articles = self.filteredArticles; 265 self.extractAllArticlesYears(); 266 self.extractSelectedArticlesYears(); 267 } 268 }).complete(function (data) { 269 self.progressCount++; 270 }); 271 }, 272 doArticlesFiltering: function () { 273 const self = this; 274 this.articlesFilter = document.getElementById('filter').value; 275 this.filteredArticlesCount = 0; 276 self.filteredArticleItems = []; 277 self.filteredArticles = []; 278 self.progressCount = 0; 279 self.progressGoal = this.sources.length; 280
281 this.sources.forEach(function (articlesSource) { 282 articlesSource.numberOfArticles = 0; 283 articlesSource.firstYear = 0; 284 if (articlesSource.selected) { 285 let url = "/.netlify/functions/search" 286 + "?source=" + articlesSource.id 287 + "&q=" + self.articlesFilter 288 + "&scope=" + self.filterScope 289 + "&word=" + self.wholeWordSearch; 290 self.downloadArticles(url, articlesSource); 291 } else { 292 self.progressCount++; 293 } 294 }); 295 }, 296 extractAllArticlesYears: function () { 297 let max = new Date().getUTCFullYear(); 298 let min = max; 299 for (var item in this.articles) { 300 let year = parseInt(this.articles[item].year + ""); 301 if (year > 1800 && year < 2200) { 302 min = Math.min(min, year); 303 } 304 } 305 306 let years = []; 307 308 for (let year = max; year >= min; year--) { 309 years.push(year); 310 } 311 312 this.allArticlesYears = years; 313 314 return years; 315 }, 316 extractSelectedArticlesYears: function () { 317 var years = []; 318 for (var item in this.filteredArticles) { 319 let year = parseInt(this.filteredArticles[item].year + ""); 320 if (year > 1900 && years.indexOf(year) == -1) { 321 years.push(year); 322 } 323 } 324 325 this.selectedArticlesYears = years; 326 } 327 } 328}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.