jakob1111 / dokuwiki-plugin-flowcharts

Add flowcharts and diagrams to Dokuwiki with an incredibly simple syntax
GNU General Public License v2.0
7 stars 8 forks source link

Multiple after statements mermaid feature request 552 #12

Open itprdev opened 4 years ago

itprdev commented 4 years ago

Feature request: https://github.com/mermaid-js/mermaid/issues/552

Usage: gantt apple :a, 2017-07-20, 1w banana :crit, b, 2017-07-23, 1d cherry :active, c, after b a, 1d

Sepparated by space

const getStartDate = function(prevTime, dateFormat, str) {
  str = str.trim();

  // Test for after
  const re = /^after\s+([\d\w- ]+)/;
  const afterStatement = re.exec(str.trim());

  if (afterStatement !== null) {
    // check all after ids and take the latest
    let latestEndingTask = null;
    afterStatement[1].split(' ').forEach(function(id) {
      let task = findTaskById(id);
      if (typeof task !== 'undefined') {
        if (!latestEndingTask) {
          latestEndingTask = task;
        } else {
          if (task.endTime > latestEndingTask.endTime) {
            latestEndingTask = task;
          }
        }
      }
    });

    if (!latestEndingTask) {
      const dt = new Date();
      dt.setHours(0, 0, 0, 0);
      return dt;
    } else {
      return latestEndingTask.endTime;
    }
  }

  // Check for actual date set
  let mDate = moment(str, dateFormat.trim(), true);
  if (mDate.isValid()) {
    return mDate.toDate();
  } else {
    logger.debug('Invalid date:' + str);
    logger.debug('With date format:' + dateFormat.trim());
  }

  // Default date - now
  return new Date();
};

This change has also been submitted to mermaid.