From 9dbb3767e28cd45fcd5c9ad2227ff0cbdb3ee313 Mon Sep 17 00:00:00 2001 From: Gijs van Dam Date: Fri, 1 Feb 2019 13:27:42 +0800 Subject: [PATCH] Extract tag parsing in separate function --- src/diagrams/gantt/ganttDb.js | 79 ++++++++++++++--------------------- 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index 3f4328c1c..adf8304a6 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -158,30 +158,8 @@ const compileData = function (prevTask, dataStr) { const task = {} // Get tags like active, done, crit and milestone - let matchFound = true - while (matchFound) { - matchFound = false - if (data[0].match(/^\s*active\s*$/)) { - task.active = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*done\s*$/)) { - task.done = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*crit\s*$/)) { - task.crit = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*milestone\s*$/)) { - task.milestone = true - data.shift(1) - matchFound = true - } - } + getTaskTags(data, task) + for (let i = 0; i < data.length; i++) { data[i] = data[i].trim() } @@ -221,30 +199,8 @@ const parseData = function (prevTaskId, dataStr) { const task = {} // Get tags like active, done, crit and milestone - let matchFound = true - while (matchFound) { - matchFound = false - if (data[0].match(/^\s*active\s*$/)) { - task.active = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*done\s*$/)) { - task.done = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*crit\s*$/)) { - task.crit = true - data.shift(1) - matchFound = true - } - if (data[0].match(/^\s*milestone\s*$/)) { - task.milestone = true - data.shift(1) - matchFound = true - } - } + getTaskTags(data, task) + for (let i = 0; i < data.length; i++) { data[i] = data[i].trim() } @@ -373,3 +329,30 @@ export default { findTaskById, addTaskOrg } + +function getTaskTags (data, task) { + let matchFound = true + while (matchFound) { + matchFound = false + if (data[0].match(/^\s*active\s*$/)) { + task.active = true + data.shift(1) + matchFound = true + } + if (data[0].match(/^\s*done\s*$/)) { + task.done = true + data.shift(1) + matchFound = true + } + if (data[0].match(/^\s*crit\s*$/)) { + task.crit = true + data.shift(1) + matchFound = true + } + if (data[0].match(/^\s*milestone\s*$/)) { + task.milestone = true + data.shift(1) + matchFound = true + } + } +}