You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.3 KiB

3 years ago
let {sourcetype, dateadded, language, author, publicationd, theme, readingd} = input;
let page = dv.pages()
3 years ago
.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++) {
3 years ago
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"'}