mathisgauthey / obsidian-workflow-template

This is an Obsidian vault template from my Workflow with Tasks and Project Management, Journaling, Media Tracking, Offline Read-it-later and Bookmark Management, Note-taking and Note-sharing on Your Own Website
MIT License
242 stars 36 forks source link

Todoist Import scripts error #12

Closed lena-py closed 2 months ago

lena-py commented 3 months ago

Thank you for the fabulous setup - I believe the simplicity of the setup along with the advanced functionality that I can explore over time will be perfect for me. I also appreciate the exercise app recommendations - still using Gymstro?!

I've successfully installed the Todoist plugin - the features that come with that plugin are all functional. However, when attempting to import Todoist tasks via the provided scripts, I receive the following error below. This error occurs on all syncs: passion / project / etc.

I hope this is an easy fix but also hope I am not wasting your time with an EBCAK issue!!

Screenshot 2024-07-04 at 8 42 09 AM
lena-py commented 3 months ago

Also, just wanted to add that I have read through both your documentation as well as the Todoist plugin before raising this issue.

mathisgauthey commented 2 months ago

Hey here ! Sorry for the late reply, I was drowning in stuff lately !

I'm now using Hevy, I paid for the development and the ability to have a web app. Plus there is a lifetime pricing, hence I did not care much and won't be changing apps anytime soon !

Concerning your issue, I'm quite sorry, but I just cloned the repo and can't seem to reproduce. (As seen below)

24_07_16-19_11_50-firefox

Anyway, here is the source of the script, you might find valuable things in here. I'm sorry but I'm no longer working on this project and won't be able to debug this further 😶

I guess it's related to the upgrade to Todoist API v2 : https://jamiebrynes7.github.io/obsidian-todoist-plugin/docs/changelog#v1100-2022-10-17

Changed can be found here if anyone want to look for a fix in the script : https://github.com/jamiebrynes7/obsidian-todoist-plugin/compare/1.10.1...1.11.1

mathisgauthey commented 2 months ago

I found a fix !

In _Scripts/tasksync.js (and the other ones) change :

Here is the corrected version that works with the latest todoist-sync-plugin (1.13.0) and quickadd (1.10.0) :

module.exports = {
  SelectFromAllTasks: SelectFromAllTasks,
  GetAllTasksFromProject: GetAllTasksFromProject,
  GetAllTasksFromSection: GetAllTasksFromSection,
};

const getTodoistPluginApi = (t) =>
  t.plugins.plugins["todoist-sync-plugin"].services.todoist.api.value;

async function SelectFromAllTasks(t) {
  const s = await getAllTasks(t);
  if (0 === s.length) return void new Notice("No tasks.");
  const e = await selectTasks(t, s);
  return await closeSelectedTasks(t.app, e), formatTasksToTasksPluginTask(e);
}
async function GetAllTasksFromProject(t) {
  const [s, e] = await Promise.all([getAllTasks(t), getProjects(t.app)]),
    a = await t.quickAddApi.suggester(
      (t) => (
        (t.tasks = s.filter((s) => s.projectID === t.id)),
        `${t.name} (${t.tasks.length})`
      ),
      e
    );
  if (a) {
    if (0 !== a.tasks.length)
      return (
        new Notice(`Added ${a.tasks.length} tasks from '${a.name}'.`),
        await closeSelectedTasks(t.app, a.tasks),
        formatTasksToTasksPluginTask(a.tasks)
      );
    new Notice(`No tasks in '${a.name}'.`);
  }
}
async function GetAllTasksFromSection(t) {
  const [s, e, a] = await Promise.all([
      getProjects(t.app),
      getSections(t.app),
      getAllTasks(t),
    ]),
    n = await t.quickAddApi.suggester((t) => {
      const e = s.find((s) => s.id === t.project_id);
      return (
        (t.tasks = a.filter((s) => s.sectionID === t.id)),
        `${e.name} > ${t.name} (${t.tasks.length})`
      );
    }, e);
  if (0 !== n.tasks.length)
    return (
      new Notice(`Added ${n.tasks.length} tasks from '${n.name}'.`),
      await closeSelectedTasks(n.tasks),
      formatTasksToTasksPluginTask(n.tasks)
    );
  new Notice(`No tasks in '${n.name}'.`);
}
async function getAllTasks(t) {
  const s = getTodoistPluginApi(t.app);
  e = await s.getTasks();
  return e;
}
async function selectTasks(t, s) {
  const e = await t.quickAddApi.checkboxPrompt(s.map((t) => t.content));
  return s.filter((t) => e.some((s) => s.contains(t.content)));
}
async function closeSelectedTasks(t, s) {
  const e = getTodoistPluginApi(t);
  s.forEach(async (t) => await e.closeTask(t.id));
}
function formatTasksToTasksPluginTask(t) {
  const todayDate = new Date().toISOString().split("T")[0]; // Get today's date in YYYY-MM-DD format
  return (
    t
      .map(
        (t) =>
          (t = t.rawDatetime
            ? `- [ ] ${
                t.content
              } \u2795 ${todayDate} \ud83d\udcc5 ${t.rawDatetime.format(
                "YYYY-MM-DD"
              )}`
            : `- [ ] ${t.content} \u2795 ${todayDate}`)
      )
      .join("\n") + "\n"
  );
}
async function getTasksGroupedByProject(t) {
  const s = getTodoistPluginApi(t),
    { ok: e } = await s.getTasksGroupedByProject();
  return e;
}
async function getProjects(t) {
  const s = getTodoistPluginApi(t),
    { ok: e } = await s.getProjects();
  return e;
}
async function getSections(t) {
  const s = getTodoistPluginApi(t),
    { ok: e } = await s.getSections();
  return e;
}
github-actions[bot] commented 2 months ago

:tada: This issue has been resolved in version 1.0.6 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

lena-py commented 2 months ago

Hey - no big deal on the delay! I’m not sure if you saw my other email - so in case not I wanted to say that the effort you made to put this into the world has had an extremely positive impact on me. Just over a year ago, I experienced a catastrophic flood in my house. Needless to say, all of my productivity efforts went into putting my house back together, so my personal productivity energy was completely sapped.

A year later, and the desire to get back to keeping track of the projects I want to accomplish has returned. I found yours and the fact you took the time to write documentation about your template, detailing why it works, gave me the confidence that it was the right one to dive into. Your comments about the ability to use it even when you cannot focus on the details, and that it eliminates the “let’s make a cool dashboard” angle is what convinced me. The simplicity of it means it won’t break down, but the potential to further customize is also there!

Furthermore, the integration with ToDoIst (which worked well enough for me to see it rendered in the DailyNote) was also a vital piece so I can jot things down in the moment.

So anyway, thank you VERY MUCH for your fix, I’m not surprised you were tempted to fix it even though this isn’t an active project any longer. 😀

Best of luck on your productivity journey and whatever other aspirations are holding your attention currently.

—Lena

On Jul 16, 2024, at 12:16 PM, Mathis Gauthey @.***> wrote:

Hey here ! Sorry for the late reply, I was drowning in stuff lately !

I'm now using Hevy, I paid for the development and the ability to have a web app. Plus there is a lifetime pricing, hence I did not care much and won't be changing apps anytime soon !

Concerning your issue, I'm quite sorry, but I just cloned the repo and can't seem to reproduce. (As seen below)

24_07_16-19_11_50-firefox.gif (view on web) https://github.com/user-attachments/assets/55ffd91a-0289-434d-aea1-4345d62829aa Maybe it is related to the obsidian-todoist plugin that got updated and the script needs to be rewritten or at least adapted to match. Maybe Todoist APIs changed and the script doesn't work anymore Anyway, here https://quickadd.obsidian.guide/docs/Examples/Capture_FetchTasksFromTodoist is the source of the script, you might find valuable things in here. I'm sorry but I'm no longer working on this project and won't be able to debug this further 😶

— Reply to this email directly, view it on GitHub https://github.com/mathisgauthey/obsidian-workflow-template/issues/12#issuecomment-2231431479, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC5RK6PTKDZDLE4RZD56553ZMVINLAVCNFSM6AAAAABKLTKDYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZRGQZTCNBXHE. You are receiving this because you authored the thread.

mathisgauthey commented 2 months ago

Hi Lena, thank you very much for your kind words, it means a lot. Indeed, I did not check my mails lately but just found out about your double dose of gratefulness, so I'm going to answer to both.

I do this for fun, but it sure is rewarding to hear feedbacks and gratitude from kind strangers around the world appreciating my work. It really motivates me to keep going and to get back on my feet when things don't go too well.

Keep some gratitude for you, as your bug report will surely allow other users to benefit from it as we approach the 200 stars (just checked out, this is huge, last I watched there was like 40 or something).

So thanks again, it reached me warmly !