jgauth / MMM-GoogleTasks

21 stars 26 forks source link

Subtasks appear above parent task #9

Open klearlab opened 4 years ago

klearlab commented 4 years ago

When you create a sub task it appears above the parent task

gubbsjuk commented 4 years ago

Added a pull request from my fork to master on a quick and dirty sorting of items.

z0mb13k1ll commented 2 years ago

This is still an issue

altany commented 2 years ago

If anyone is interested, I have fixed this with the code below and I am happy to send a PR soon.

  if (this.config.ordering === "myorder") {
      let titleWrapper, dateWrapper, noteWrapper, item;
      let orderedTasks = [];
      let parentTasks = this.tasks.filter((task) => !task.parent);
      parentTasks.forEach((parentTask) => {
        orderedTasks.push(parentTask);
        const childrenTasks = this.tasks.filter(
          (childTask) => childTask.parent === parentTask.id
        );
        orderedTasks.push(...childrenTasks);
      });

      //this.tasks.forEach((item, index) => {
      for (let i = 0; i < numTasks; i++) {
        item = orderedTasks[i];
        titleWrapper = document.createElement("div");
        titleWrapper.className = "item title";
        titleWrapper.innerHTML =
          '<i class="fa fa-circle-thin" ></i>' + item.title;

        // If item is completed change icon to checkmark
        if (item.status === "completed") {
          titleWrapper.innerHTML = '<i class="fa fa-check" ></i>' + item.title;
        }

        if (item.parent) {
          titleWrapper.className = "item child";
        }

        if (item.notes) {
          noteWrapper = document.createElement("div");
          noteWrapper.className = "item notes light";
          noteWrapper.innerHTML = item.notes.replace(/\n/g, "<br>");
          titleWrapper.appendChild(noteWrapper);
        }

        dateWrapper = document.createElement("div");
        dateWrapper.className = "item date light";

        if (item.due) {
          var date = moment(item.due);
          dateWrapper.innerHTML = date.utc().format(this.config.dateFormat);
        }

        // Create borders between parent items
        if (i < numTasks - 1 && !orderedTasks[i + 1].parent) {
          titleWrapper.style.borderBottom = "1px solid #666";
          dateWrapper.style.borderBottom = "1px solid #666";
        }

        wrapper.appendChild(titleWrapper);
        wrapper.appendChild(dateWrapper);
      }

      return wrapper;
    }

This needs to replace the rendering code in modules/MMM-GoogleTasks/MMM-GoogleTasks.js lines 92-147

jbarkhuizen commented 2 years ago

Hi, I added this code, but then the Task Module don't show Maybe share conpleted file