class globalFunc {
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) && !Array.isArray(iarg1)) {
var resultdc = this.compareData(iarg1, iarg2)
} else if (!Array.isArray(iarg1)) {
let tempresult = false
for (let i = 0; i < iarg2.length; i++) {
tempresult = tempresult || this.compareData(iarg1, iarg2[i])
}
var resultdc = tempresult
} else if (!Array.isArray(iarg2)) {
let tempresult = false
for (let i = 0; i < iarg1.length; i++) {
tempresult = tempresult || this.compareData(iarg1[i], iarg2)
}
var resultdc = tempresult
} else {
let tempresult = false
for (let i = 0; i < arg2.length; i++) {
for (let j = 0; j < arg1.length; j++) {
tempresult = tempresult || this.compareData(iarg1[j], iarg2[i])
}
}
var resultdc = tempresult
}
return resultdc
}
compareData(arg1, arg2) {
let tempresult = false;
if (arg2.length > 1 && this.hasOperator(arg2)) {
switch(this.getOperator(arg2)) {
case '<':
tempresult = (parseFloat(arg1) < parseFloat(arg2.replace(this.getOperator(arg2), "")))
break;
case '<=':
tempresult = (parseFloat(arg1) <= parseFloat(arg2.replace(this.getOperator(arg2), "")))
break;
case '>':
tempresult = (parseFloat(arg1) > parseFloat(arg2.replace(this.getOperator(arg2), "")))
break;
case '>=':
tempresult = (parseFloat(arg1) >= parseFloat(arg2.replace(this.getOperator(arg2), "")))
break;
case '!':
if (isNaN(arg2.replace("!", ""))) {
tempresult = !(arg1.search(new RegExp(arg2, "i")) > -1)
} else {tempresult = (parseFloat(arg1) != parseFloat(arg2.replace(this.getOperator(arg2), "")))}
break;
}
} else {tempresult = (arg1.search(new RegExp(arg2, "i")) > -1)}
return tempresult
}
hasOperator(arg1) {
let tempresult = false;
switch(arg1.charAt(0)) {
case '<':
case '>':
case '!':
tempresult = true
break;
}
return tempresult
}
getOperator(arg1) {
let tempresult = arg1.charAt(0);
if (this.hasOperator(arg1.charAt(1))) {
tempresult = tempresult + arg1.charAt(1)
}
return tempresult
}
BuildList(arg1, construct) {
let TempS = ""
for (let i = 0; i < arg1.length; i++) {
if (Boolean(arg1[i])) {
if (TempS == "") {
TempS = arg1[i]
} else {
TempS = TempS + construct + arg1[i]
}
}
}
return TempS
}
buildToPrint(arg1, arg2, construct) {
let TempS = ""
if (Array.isArray(arg2)) {
for (let i = 0; i < arg1.length; i++) {
if (Boolean(arg1[i])) {
if (TempS == "") {
TempS = arg2[i] + ": " + "" + arg1[i] + ""
} else {
TempS = TempS + construct + arg2[i] + ": " + "" + arg1[i] + ""
}
if (arg2[i].search(new RegExp("time", "i")) > -1) {
TempS = TempS + " min"
}
}
}
} else {
for (let i = 0; i < arg1.length; i++) {
if (Boolean(arg1[i])) {
if (TempS == "") {
TempS = "" + arg1[i] + ""
} else {
TempS = TempS + construct + "" + arg1[i] + ""
}
}
}
}
return TempS
}
Get1stArg(arg3) {
if (!Array.isArray(arg3)) {
return arg3
} else {
return arg3[0]
}
}
topLevelFilter(pobj, DocType, subType) {
let result = true
let folderExcl = (DocType == 'Source') ? '00.01' : '00.';
result = !pobj.file.path.contains(folderExcl) && this.GetPoint(pobj, "main", "type") !== undefined && this.GetPoint(pobj, "main", "type") !== null && this.GetPoint(pobj, "main", "type").contains(DocType)
if (Boolean(subType)) {
result = result && this.GetPoint(pobj, DocType, "type") !== undefined && this.GetPoint(pobj, DocType, "type") !== null && this.GetPoint(pobj, DocType, "type").contains(subType)
}
return result
}
IsInSearch(pobj, DocType, darray, iarray) {
let ilength = iarray.length;
let result = true
for (let i = 0; i < iarray.length; i++) {
if (iarray[i] == undefined || darray[i] == undefined) {result = result && true} else {
switch(darray[i]) {
case 'readingd':
if (iarray[i] == true || iarray[i] == false) {result = result && (Boolean(this.GetpProp(pobj, DocType, darray[i])) == iarray[i])} else {
if (Boolean(iarray[i])) {
let pProp = this.GetpProp(pobj, DocType, darray[i])
if (!Boolean(pProp)) { result = result && false } else {
result = result && this.DataCheck(pProp, iarray[i])
}
} else {result = result && true}
}
break;
default:
if (Boolean(iarray[i])) {
let pProp = this.GetpProp(pobj, DocType, darray[i])
if (!Boolean(pProp)) { result = result && false } else {
result = result && this.DataCheck(pProp, iarray[i])
}
} else {result = result && true}
break;
}
}
}
return result
}
getTable(dv, DocType, darray, iarray, tabletype) {
let page = dv.pages()
.filter(p => p && this.topLevelFilter(p, DocType, 0))
.where(p => p && this.IsInSearch(p, DocType, darray, iarray))
if (typeof page == 'undefined' || typeof page == 'null' || page.length === 0) {
return this.EmptyQueryMessage()
}
dv.table(this.GetTableHeaders(DocType, tabletype), page
.sort(p => p.file.name, `asc`)
.map(p => this.GetTableMap(DocType, tabletype,p)));
}
EmptyQueryMessage() {
return dv.el('b', '⚠️ Warning:\nNo result matching your query!')
}
GetTableHeaders(DataT, TableT) {
let TempData = ["Name"]
switch(DataT) {
case 'Investment':
switch(TableT) {
case 'overview':
TempData = ["Name", "Currency", "Style", "Stage", "Themes"]
break;
case 'trading':
TempData = ["Name", "Currency", "Trading date", "Trading price"]
break;
}
break;
case 'Source':
TempData = ["Title", "Author", "Published date", "Language", "Themes", "Date read"]
break;
case 'Place':
switch(TableT) {
case 'Restaurant':
case 'Brunch':
TempData = ["Name", "Style", "Cuisine", "Phone", "Email", "Website"]
break;
case 'Hotel':
case 'Bar':
TempData = ["Name", "Type", "Influence", "Phone", "Email", "Website"]
break;
case 'Sport':
TempData = ["Name", "Phone", "Email", "Website"]
break;
case 'Café':
TempData = ["Name", "Style", "Phone", "Email", "Website"]
break;
}
break;
case 'Product':
TempData = ["Name", "Category", "Link", "Value", "Themes"]
break;
case 'Server':
switch(TableT) {
case 'overview':
TempData = ["Name", "Provider", "Service", "Location", "IP Address"]
break;
case 'technical':
TempData = ["Name", "OS", "CPU", "RAM", "Disk size", "Disk type", "Bandwidth", "Speed"]
break;
case 'usage':
TempData = ["Name", "Disk size", "Used space", "Date updated"]
break;
}
break;
case 'Recipe':
switch(TableT) {
case 0:
TempData = ["Name", "Category", "Cuisine", "Cooking time", "Rating (1-5)"]
break;
case 'extended':
TempData = ["Name", "Course", "Category", "Cuisine", "Cooking time", "Rating (1-5)", "Favourite"]
break;
}
break;
}
return TempData
}
GetTableMap(DataT, TableT, p) {
let TempData = [p.file.link]
switch(DataT) {
case 'Investment':
switch(TableT) {
case 'overview':
TempData = [p.file.link, this.GetPoint(p, DataT, "ccy"), this.GetPoint(p, DataT, "style"), this.GetPoint(p, DataT, "stage"), this.GetPoint(p, "main", "tag")]
break;
case 'trading':
TempData = [p.file.link, this.GetPoint(p, DataT, "ccy"), this.GetPoint(p, DataT, "tradingd"), this.GetPoint(p, DataT, "tradingp")]
break;
}
break;
case 'Source':
TempData = [p.file.link, this.GetPoint(p, DataT, "author"), this.GetPoint(p, DataT, "published"), this.GetPoint(p, DataT, "lang"), this.GetPoint(p, "main", "tag"), this.GetPoint(p, DataT, "read")]
break;
case 'Place':
switch(TableT) {
case 'Restaurant':
case 'Brunch':
case 'Hotel':
case 'Bar':
TempData = [p.file.link, this.GetPoint(p, DataT, "subtype"), this.toEmoji(this.GetPoint(p, DataT, "style")), this.GetPoint(p, DataT, "phone"), this.GetPoint(p, DataT, "email"), this.GetPoint(p, DataT, "website")]
break;
case 'Sport':
TempData = [p.file.link, this.GetPoint(p, DataT, "phone"), this.GetPoint(p, DataT, "email"), this.GetPoint(p, DataT, "website")]
break;
case 'Café':
TempData = [p.file.link, this.GetPoint(p, DataT, "subtype"), this.GetPoint(p, DataT, "phone"), this.GetPoint(p, DataT, "email"), this.GetPoint(p, DataT, "website")]
break;
}
break;
case 'Product':
TempData = [p.file.link, this.GetPoint(p, DataT, "type"), this.GetPoint(p, DataT, "link"), this.GetPoint(p, DataT, "value"), this.GetPoint(p, "main", "tag")]
break;
case 'Server':
switch(TableT) {
case 'overview':
TempData = [p.file.link, this.GetPoint(p, DataT, "host"), this.GetPoint(p, DataT, "subdomain"), this.GetPoint(p, DataT, "dom"), this.GetPoint(p, DataT, "ipv4")]
break;
case 'technical':
TempData = [p.file.link, this.GetPoint(p, DataT, "os"), this.GetPoint(p, DataT, "cpu"), this.GetPoint(p, DataT, "ram"), this.GetPoint(p, DataT, "capa"), this.GetPoint(p, DataT, "type"), this.GetPoint(p, DataT, "bw"), this.GetPoint(p, DataT, "speed")]
break;
case 'usage':
TempData = [p.file.link, this.GetPoint(p, DataT, "capa"), this.GetPoint(p, DataT, "usedspace"), this.GetPoint(p, DataT, "timestamp")]
break;
}
break;
case 'Recipe':
switch(TableT) {
default:
TempData = [p.file.link, this.GetPoint(p, DataT, "category"), this.toEmoji(this.GetPoint(p, DataT, "collection")), this.GetPoint(p, DataT, "cooking") + " min", this.GetPoint(p, DataT, "rating")]
break;
case 'extended':
TempData = [p.file.link, this.GetPoint(p, DataT, "course"), this.GetPoint(p, DataT, "category"), this.toEmoji(this.GetPoint(p, DataT, "collection")), this.GetPoint(p, DataT, "cooking") + " min", this.GetPoint(p, DataT, "rating"), this.toEmoji(Boolean(this.GetPoint(p, DataT, "isfavourite")))]
break;
}
break;
}
return TempData
}
toEmoji(label) {
let tempresult = ""
if (Array.isArray(label)) {
for (let i = 0; i < label.length; i++) {
if (tempresult == '') {
tempresult = this.getEmoji(label[i]);
} else {tempresult = tempresult + " / " + this.getEmoji(label[i]);}
}
} else {tempresult = this.getEmoji(label)}
return tempresult
}
getEmoji(label) {
let tempresult = ""
switch(label) {
case 'French':
tempresult = "🇫🇷"
break;
case 'Italian':
tempresult = "🇮🇹"
break;
case 'British':
tempresult = "🇬🇧"
break;
case 'American':
case 'US':
tempresult = "🇺🇸"
break;
case 'Indian':
tempresult = "🇮🇳"
break;
case 'Mexican':
tempresult = "🇲🇽"
break;
case 'Asian':
case 'Asian Fusion':
tempresult = "⛩"
break;
case 'Modern':
tempresult = "💠"
break;
case 'Peruvian':
tempresult = "🇵🇪"
break;
case 'Spanish':
tempresult = "🇪🇸"
break;
case 'Greek':
tempresult = "🇬🇷"
break;
case 'Japanese':
tempresult = "🇯🇵"
break;
case 'Argentine':
tempresult = "🇦🇷"
break;
case 'Chinese':
tempresult = "🇨🇳"
break;
case 'Taiwanese':
tempresult = "🇹🇼"
break;
case 'Egg':
tempresult = "🥚"
break;
case 'Middle Eastern':
tempresult = "☪️"
break;
case 'European':
tempresult = "🇪🇺"
break;
case 'North African':
case 'North African Fusion':
tempresult = "🇲🇦"
break;
case 'Swedish':
case 'Nordics':
tempresult = "🇸🇪"
break;
case 'Pub':
tempresult = "🍺"
break;
case true:
tempresult = "✅"
break;
case false:
tempresult = "❌"
break;
case 'Fish':
tempresult = "🐠"
break;
default:
tempresult = label
}
return tempresult
}
GetpProp(pobj, DocType, dPoint) {
let result = null
switch(dPoint) {
case 'dateadded':
result = this.GetPoint(pobj, "main", "date")
break;
case 'theme':
result = this.GetPoint(pobj, "main", "tag")
break;
case 'invtype':
case 'sourcetype':
case 'placetype':
case 'prodtype':
case 'disktype':
result = this.GetPoint(pobj, DocType, "type")
break;
case 'style':
result = this.GetPoint(pobj, DocType, "style")
break;
case 'stage':
result = this.GetPoint(pobj, DocType, "stage")
break;
case 'ccy':
result = this.GetPoint(pobj, DocType, "ccy")
break;
case 'tradingd':
result = this.GetPoint(pobj, DocType, "tradingd")
break;
case 'tradingp':
result = this.GetPoint(pobj, DocType, "tradingp")
break;
case 'language':
result = this.GetPoint(pobj, DocType, "lang")
break;
case 'author':
result = this.GetPoint(pobj, DocType, "author")
break;
case 'publicationd':
result = this.GetPoint(pobj, DocType, "published")
break;
case 'readingd':
result = this.GetPoint(pobj, DocType, "read")
break;
case 'country':
result = this.GetPoint(pobj, DocType, "country")
break;
case 'area':
result = this.GetPoint(pobj, DocType, "location")
break;
case 'ambiance':
result = this.GetPoint(pobj, DocType, "subtype")
break;
case 'status':
result = this.GetPoint(pobj, DocType, "status")
break;
case 'prodvalue':
result = this.GetPoint(pobj, DocType, "value")
break;
case 'host':
result = this.GetPoint(pobj, DocType, "host")
break;
case 'subdomain':
result = this.GetPoint(pobj, DocType, "subdomain")
break;
case 'OS':
result = this.GetPoint(pobj, DocType, "os")
break;
case 'CPU':
result = this.GetPoint(pobj, DocType, "cpu")
break;
case 'RAM':
result = this.GetPoint(pobj, DocType, "ram")
break;
case 'Capa':
result = this.GetPoint(pobj, DocType, "capa")
break;
case 'BW':
result = this.GetPoint(pobj, DocType, "bw")
break;
case 'speed':
result = this.GetPoint(pobj, DocType, "speed")
break;
case 'dom':
result = this.GetPoint(pobj, DocType, "dom")
break;
case 'course':
result = this.GetPoint(pobj, DocType, "course")
break;
case 'category':
result = this.GetPoint(pobj, DocType, "category")
break;
case 'cuisine':
result = this.GetPoint(pobj, DocType, "collection")
break;
case 'ingredient':
result = this.GetPoint(pobj, DocType, "ingredient")
break;
case 'isfavourite':
result = this.GetPoint(pobj, DocType, "isfavourite")
break;
case 'rating':
result = this.GetPoint(pobj, DocType, "rating")
break;
case 'cookingtime':
result = this.GetPoint(pobj, DocType, "cooking")
break;
}
return result
}
GetPoint(pobj, fstline, dPoint) {
let result = null
switch(fstline) {
case 'main':
switch(dPoint) {
case 'alias':
result = pobj.Alias
break;
case 'tag':
result = pobj.Tag
break;
case 'date':
result = pobj.Date
break;
case 'type':
result = pobj.DocType
break;
case 'hierarchy':
result = pobj.Hierarchy
break;
case 'location':
result = pobj.location
break;
case 'meatatable':
result = pobj.CollapseMetaTable
break;
case 'timestamp':
result = pobj.TimeStamp
break;
}
break;
case 'Investment':
switch(dPoint) {
case 'style':
result = pobj.Investment.Style
break;
case 'stage':
result = pobj.Investment.Stage
break;
case 'ccy':
result = pobj.Investment.Ccy
break;
case 'type':
result = pobj.Investment.Type
break;
case 'tradingd':
result = pobj.Trading.PDate
break;
case 'tradingp':
result = pobj.Trading.PPrice
break;
}
break;
case 'Place':
switch(dPoint) {
case 'style':
result = pobj.Place.Style
break;
case 'subtype':
result = pobj.Place.SubType
break;
case 'location':
result = pobj.Place.Location
break;
case 'type':
result = pobj.Place.Type
break;
case 'country':
result = pobj.Place.Country
break;
case 'status':
result = pobj.Place.Status
break;
case 'phone':
result = pobj.Phone
break;
case 'email':
result = pobj.Email
break;
case 'website':
result = pobj.Website
break;
}
break;
case 'Source':
switch(dPoint) {
case 'author':
result = pobj.Source.Author
break;
case 'lang':
result = pobj.Source.Language
break;
case 'published':
result = pobj.Source.Published
break;
case 'type':
result = pobj.Source.Type
break;
case 'link':
result = pobj.Source.Link
break;
case 'read':
result = pobj.Source.Read
break;
}
break;
case 'Product':
switch(dPoint) {
case 'value':
result = pobj.Product.Value
break;
case 'type':
result = pobj.Product.Type
break;
case 'link':
result = pobj.Product.Link
break;
}
break;
case 'Server':
switch(dPoint) {
case 'cpu':
result = pobj.Performance.CPU
break;
case 'ram':
result = pobj.Performance.RAM
break;
case 'bw':
result = pobj.Performance.Bandwidth
break;
case 'speed':
result = pobj.Performance.Speed
break;
case 'os':
result = pobj.Characteristics.OS
break;
case 'dom':
result = pobj.Characteristics.Domiciliation
break;
case 'ipv4':
result = pobj.Characteristics.IPv4
break;
case 'hostname':
result = pobj.Characteristics.Hostname
break;
case 'host':
result = pobj.Characteristics.Host
break;
case 'subdomain':
result = pobj.Characteristics.SubDomain
break;
case 'capa':
result = pobj.Disk.Capa
break;
case 'type':
result = pobj.Disk.Type
break;
case 'usedspace':
result = pobj.Disk.UsedSpace
break;
case 'timestamp':
result = pobj.Disk.TimeStamp
break;
}
break;
case 'Task':
switch(dPoint) {
case 'priority':
result = pobj.Task.Priority
break;
case 'status':
result = pobj.Task.Status
break;
case 'startdate':
result = pobj.Task.StartDate
break;
case 'duedate':
result = pobj.Task.DueDate
break;
case 'nextreviewdate':
result = pobj.Task.NextReviewDate
break;
}
break;
case 'Travel':
switch(dPoint) {
case 'country':
result = pobj.Travel.Country
break;
case 'duration':
result = pobj.Travel.Duration
break;
case 'budget':
result = pobj.Travel.Budget
break;
case 'type':
result = pobj.Travel.Type
break;
case 'lbestseason':
result = pobj.Travel.BestSeason
break;
case 'departuredate':
result = pobj.Travel.DepartureDate
break;
}
break;
case 'Recipe':
switch(dPoint) {
case 'course':
result = pobj.Recipe.Courses
break;
case 'category':
result = pobj.Recipe.Categories
break;
case 'collection':
result = pobj.Recipe.Collections
break;
case 'source':
result = pobj.Recipe.Source
break;
case 'preparation':
result = pobj.Recipe.PreparationTime
break;
case 'cooking':
result = pobj.Recipe.CookingTime
break;
case 'ingredient':
result = pobj.Ingredients
break;
case 'isfavourite':
result = pobj.Meta.IsFavourite
break;
case 'rating':
result = pobj.Meta.Rating
break;
}
break;
}
return result
}
}