-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport_tables.js
More file actions
156 lines (123 loc) · 4.45 KB
/
report_tables.js
File metadata and controls
156 lines (123 loc) · 4.45 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
function addTableScenario(para, jsonDetails, sample) {
// default parameters
sample = sample | false;
// declare local variables
var steps = jsonDetails['scenario']['steps'];
// build the table header
var header = ['', 'Description', 'Action', 'Target', 'Actuator', 'Modifier']
var cells = [ header ];
// add the table
var paraNext = pubcode.addPara(para);
var tbl = pubcode.addTable(para, cells);
// add multicell header
var row = tbl.getRow(0);
var cell = row.getCell(3);
cell.appendHorizontalRule();
cell.appendParagraph('Target-Specifier');
cell = row.getCell(4);
cell.appendHorizontalRule();
cell.appendParagraph('Actuator-Specifier');
for (var i = 0; i < steps.length; i++) {
var step = steps[i];
if ((sample && (parseStepValue(step['notes']).indexOf('<sample/>') != -1 || parseStepValue(step['notes']).indexOf('#sample') != -1)) || !sample) {
row = tbl.appendTableRow();
cell = row.appendTableCell(parseStepValue(step['step']));
cell = row.appendTableCell(parseStepValue(step['description']));
pubcode.formatMarkdown(cell);
var action = parseStepValue(step['action']);
cell = row.appendTableCell(action != '' ? '#' + action : '');
pubcode.formatMarkdown(cell);
//pubcode.formatActionText(cell);
cell = row.appendTableCell(parseStepValue(step['target']));
cell.appendHorizontalRule();
cell.appendParagraph(parseStepValue(step['target-specifier']));
cell = row.appendTableCell(parseStepValue(step['actuator']));
cell.appendHorizontalRule();
cell.appendParagraph(parseStepValue(step['actuator-specifier']));
cell = row.appendTableCell(parseStepValue(step['modifier']));
}
}
// format table
pubcode.formatTableScenario(tbl);
return paraNext;
}
function parseStepValue(value) {
var rvalue = '';
if (value != null) {
rvalue = value;
}
return rvalue;
}
function addFigureUseCase(para, jsonDetails, imagePath, imageExt, sample) {
// default parameters
sample = sample | false;
// set styles
var styleNormal = {};
styleNormal[DocumentApp.Attribute.FONT_FAMILY] = 'Open Sans';
styleNormal[DocumentApp.Attribute.FONT_SIZE] = 10;
var styleDesc = {};
styleDesc[DocumentApp.Attribute.FONT_FAMILY] = 'Open Sans';
styleDesc[DocumentApp.Attribute.FONT_SIZE] = 8;
var styleCode = {};
styleCode[DocumentApp.Attribute.FONT_FAMILY] = 'Source Code Pro';
// set image style
var width = 605;
var height = width * 74 / 722;
// declare local variables
var steps = jsonDetails['scenario']['steps'];
// build the table header
var header = ['', 'Description', '']
var cells = [ header ];
// add the table
var paraNext = pubcode.addPara(para);
var tbl = pubcode.addTable(para, cells);
// set the styles to the header
tbl.setAttributes(styleNormal);
// add the swimlanes image
var cell = tbl.getCell(0, 2);
// set the image cell
var imageUrl = imagePath + 'swimlanes' + imageExt;
cell.setPaddingTop(0);
cell.setPaddingBottom(0);
cell.setPaddingLeft(0);
cell.setPaddingRight(0);
// Retrieve an image from the web.
var resp = UrlFetchApp.fetch(imageUrl);
// insert the image
var img = cell.insertImage(0, resp.getBlob());
img.setWidth(width);
img.setHeight(height);
cell.setText('');
for (var i = 0; i < steps.length; i++) {
// debug
if (i > 4) {
break;
}
var step = steps[i];
if ((sample && (parseStepValue(step['notes']).indexOf('<sample/>') != -1 || parseStepValue(step['notes']).indexOf('#sample') != -1)) || !sample) {
row = tbl.appendTableRow();
cell = row.appendTableCell(parseStepValue(step['step']));
cell.setAttributes(styleNormal);
cell = row.appendTableCell(parseStepValue(step['description']));
cell.setAttributes(styleDesc);
pubcode.formatMarkdown(cell);
// set the image cell
var imageUrl = imagePath + parseStepValue(step['image']) + imageExt;
cell = row.appendTableCell();
cell.setPaddingTop(0);
cell.setPaddingBottom(0);
cell.setPaddingLeft(0);
cell.setPaddingRight(0);
// Retrieve an image from the web.
var resp = UrlFetchApp.fetch(imageUrl);
// insert the image
var img = cell.insertImage(0, resp.getBlob());
img.setWidth(width);
img.setHeight(height);
cell.setText('');
}
}
// format table
formatFigureUseCase(tbl);
return paraNext;
}