let {sourcetype, dateadded, language, author, publicationd, theme, readingd} = input; let page = dv.pages() .filter(p => {return !p.file.path.contains('00.01') && p.DocType !== undefined && p.DocType !== null && p.DocType.contains('Source') && p.Source.Type !== undefined && p.Source.Type !== null && p.Source.Type.contains(`${sourcetype}`)}) function DataCheck(arg1, arg2) { var iarg1 = arg1 if (moment(iarg1).isValid()) {iarg1 = arg1.toString()} var iarg2 = arg2 if (moment(iarg2).isValid()) {iarg2 = arg2.toString()} if (!Array.isArray(iarg2)) { var result = iarg1.contains(iarg2) } else if (!Array.isArray(iarg1)) { var result = iarg2.contains(iarg1) } else { let count = iarg2.length let tempresult = false for (let i = 0; i < count; i++) { tempresult = tempresult || iarg1.contains(iarg2[i]) } var result = tempresult } return result } function IsInSearch(book) { if (Boolean(theme)) { var result_tag = DataCheck(book.Tag, theme) } else {var result_tag = true} if (Boolean(dateadded)) { var result_date = DataCheck(book.Date, dateadded) } else {var result_date = true} if (Boolean(language)) { var result_lang = DataCheck(book.Source.Language, language) } else {var result_lang = true} if (Boolean(author)) { var result_auth = DataCheck(book.Source.Author, author) } else {var result_auth = true} if (Boolean(publicationd)) { var result_pub = DataCheck(book.Source.Published, publicationd) } else {var result_pub = true} if (readingd !== undefined && readingd !== null) { if (readingd == true) { var result_read = Boolean(book.Source.Read) } else if (!Boolean(readingd)) { var result_read = !Boolean(book.Source.Read) } else { if (Boolean(book.Source.Read)) { var result_read = DataCheck(book.Source.Read, readingd) } else { var result_read = false} } } else {var result_read = true} var result = result_tag && result_date && result_lang && result_auth && result_pub && result_read return result } if (page.length > 0) { dv.table(["Title", "Author", "Published date", "Language", "Themes", "Date read"], page .where(p => p && IsInSearch(p)) .sort(p => p.file.name, `asc`) .map(p => [p.file.link, p.Source.Author, p.Source.Published, p.Source.Language, p.Tag, p.Source.Read])); } else { return '"No result matching your query"'}