What I am trying to do is to make the dataview tables editable in my vault using the metadata menu plugin but after searching I realised that I can only do this if I rewrite these tables again in dataviewjs but unfortunately I don’t have much experience in JavaScript but I did manage to do this but I have a query that I couldn’t convert which is:
TABLE WITHOUT ID
regexreplace(regexreplace(regexreplace(regexreplace(regexreplace(Tasks.text, "\d{2}:\d{2}\s*", ""), "[APap][Mm]", ""), "\[.*$", ""), "\-",""),"\*","") as task,
meta(Tasks.section).subpath as "Status",
file.link as "Board",
Tasks.Scheduled As "Scheduled", Tasks.donw As "Duration"
from #Task-Board
FLATTEN file.tasks As Tasks
WHERE contains(Tasks.text, "<% moment(tp.file.title,'YYYY-[W]ww').format("YYYY-MM-DD")%>") OR
contains(Tasks.text, "<% moment(tp.file.title,'YYYY-[W]ww').add(+1, 'day').format("YYYY-MM-DD")%>") OR
contains(Tasks.text, "<% moment(tp.file.title,'YYYY-[W]ww').add(+2, 'day').format("YYYY-MM-DD")%>") OR
contains(Tasks.text, "<% moment(tp.file.title,'YYYY-[W]ww').add(+3, 'day').format("YYYY-MM-DD")%>") OR
contains(Tasks.text, "<% moment(tp.file.title,'YYYY-[W]ww').add(+4, 'day').format("YYYY-MM-DD")%>") OR
contains(Tasks.text, "<% moment(tp.file.title,'YYYY-[W]ww').add(+5, 'day').format("YYYY-MM-DD")%>") OR
contains(Tasks.text, "<% moment(tp.file.title,'YYYY-[W]ww').add(+6, 'day').format("YYYY-MM-DD")%>")
SORT date(Tasks.due.file.name)
I am using this query to view tasks from kanban boards so can you help me rewrite this query in dataviewjs?
I had this idea in my mind before, but I didn’t think that AI would be able to do it, but I asked
ChatGPT 4o after your comment and it gave me this query
// Function to format the task text by removing time and other details using regex
function formatTaskText(taskText) {
return taskText
.replace(/\d{2}:\d{2}\s*/, "")
.replace(/\d{2}:\d{2}\s*/, "")
.replace(/\[.*$/, "")
.replace(/[APap][Mm]/, "")
.replace(/[APap][Mm]/, "")
.replace("-", "")
.replace("*", "")
.replace("*", "")
.replace(" ", "")
;
}
// Fetch tasks from pages marked with the tag "#Task-Board"
const pages = dv.pages("#Task-Board");
// Flatten tasks and map with necessary data
const tasks = [];
pages.values.forEach(page => {
if (page.file.tasks) {
page.file.tasks.forEach(task => {
const titleDate = moment(dv.current().file.name, 'YYYY-[W]ww');
const taskDateTexts = Array.from({ length: 7 }, (_, i) => titleDate.clone().add(i, 'days').format('YYYY-MM-DD'));
if (taskDateTexts.some(dateText => task.text.includes(dateText))) {
tasks.push({
task: formatTaskText(task.text),
Status: task.section.subpath, // Imitating meta(Tasks.section).subpath
Board: dv.fileLink(page.file.path),
Scheduled: task.Scheduled,
Duration: task.Duration,
});
}
});
}
});
// Sort tasks by date
tasks.sort((a, b) => new Date(a.Scheduled) - new Date(b.Scheduled));
// Display the table
dv.table(["Task", "Status", "Board", "Scheduled", "Duration"], tasks.map(t => [t.task, t.Status, t.Board, t.Scheduled, t.Duration]));
, which after testing it gave me a great result and I was able to make the table editable using the metadata menu plugin, thank you very much skasper .