/
journeyDb.js
139 lines (117 loc) · 2.72 KB
/
journeyDb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import mermaidAPI from '../../mermaidAPI';
import * as configApi from '../../config';
import common from '../common/common';
import {
setAccTitle,
getTitle,
getAccDescription,
setAccDescription,
clear as commonClear,
} from '../../commonDb';
const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig());
let title = '';
let description = '';
let currentSection = '';
const sections = [];
const tasks = [];
const rawTasks = [];
export const parseDirective = function (statement, context, type) {
mermaidAPI.parseDirective(this, statement, context, type);
};
export const clear = function () {
sections.length = 0;
tasks.length = 0;
currentSection = '';
title = '';
description = '';
rawTasks.length = 0;
commonClear();
};
export const addSection = function (txt) {
currentSection = txt;
sections.push(txt);
};
export const getSections = function () {
return sections;
};
export const getTasks = function () {
let allItemsProcessed = compileTasks();
const maxDepth = 100;
let iterationCount = 0;
while (!allItemsProcessed && iterationCount < maxDepth) {
allItemsProcessed = compileTasks();
iterationCount++;
}
tasks.push(...rawTasks);
return tasks;
};
const updateActors = function () {
const tempActors = [];
tasks.forEach((task) => {
if (task.people) {
tempActors.push(...task.people);
}
});
const unique = new Set(tempActors);
return [...unique].sort();
};
export const addTask = function (descr, taskData) {
const pieces = taskData.substr(1).split(':');
let score = 0;
let peeps = [];
if (pieces.length === 1) {
score = Number(pieces[0]);
peeps = [];
} else {
score = Number(pieces[0]);
peeps = pieces[1].split(',');
}
const peopleList = peeps.map((s) => s.trim());
const rawTask = {
section: currentSection,
type: currentSection,
people: peopleList,
task: descr,
score,
};
rawTasks.push(rawTask);
};
export const addTaskOrg = function (descr) {
const newTask = {
section: currentSection,
type: currentSection,
description: descr,
task: descr,
classes: [],
};
tasks.push(newTask);
};
const compileTasks = function () {
const compileTask = function (pos) {
return rawTasks[pos].processed;
};
let allProcessed = true;
for (let i = 0; i < rawTasks.length; i++) {
compileTask(i);
allProcessed = allProcessed && rawTasks[i].processed;
}
return allProcessed;
};
const getActors = function () {
return updateActors();
};
export default {
parseDirective,
getConfig: () => configApi.getConfig().journey,
clear,
setAccTitle,
getTitle,
setAccDescription,
getAccDescription,
addSection,
getSections,
getTasks,
addTask,
addTaskOrg,
getActors,
};