Skip to content

Commit f87a8f9

Browse files
authored
Merge pull request #7 from blopa/hotfix/splice_arr
Hotfix/splice arr
2 parents d793ff1 + 21708ba commit f87a8f9

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

README.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ First of all you need to create a Google Spreadsheet following the same rules as
4040
- **square-list**: A list with a square before it
4141
- **depends**: Put the identification (id) of the row that this row must belong
4242
- **mandatory**: Make the row mandatory, meaning it will not ask to be added to the contract
43+
- **disabled**: Disable row
4344

4445
So whenever you want a part of the contract to be only available when certain other part is on the contract, you should use the ``depends`` field. One row can depend of another row that also depends on another and so on. Use your creativity.
4546

@@ -54,6 +55,7 @@ You can create complex tree decisions using the field ``depends``. The following
5455
"type": "title",
5556
"depends": "",
5657
"mandatory": "TRUE",
58+
"disabled": "",
5759
"used": false,
5860
"childs": []
5961
},
@@ -64,6 +66,7 @@ You can create complex tree decisions using the field ``depends``. The following
6466
"type": "paragraph",
6567
"depends": "",
6668
"mandatory": "FALSE",
69+
"disabled": "",
6770
"used": false,
6871
"childs": []
6972
},
@@ -74,6 +77,7 @@ You can create complex tree decisions using the field ``depends``. The following
7477
"type": "numeric-list",
7578
"depends": "",
7679
"mandatory": "FALSE",
80+
"disabled": "TRUE",
7781
"used": false,
7882
"childs": []
7983
},
@@ -84,6 +88,7 @@ You can create complex tree decisions using the field ``depends``. The following
8488
"type": "numeric-list",
8589
"depends": "",
8690
"mandatory": "FALSE",
91+
"disabled": "",
8792
"used": false,
8893
"childs": [
8994
{
@@ -93,6 +98,7 @@ You can create complex tree decisions using the field ``depends``. The following
9398
"type": "circle-list",
9499
"depends": "sample_4",
95100
"mandatory": "FALSE",
101+
"disabled": "",
96102
"used": false,
97103
"childs": []
98104
},
@@ -103,6 +109,7 @@ You can create complex tree decisions using the field ``depends``. The following
103109
"type": "numeric-list",
104110
"depends": "sample_4",
105111
"mandatory": "FALSE",
112+
"disabled": "",
106113
"used": false,
107114
"childs": []
108115
},
@@ -113,6 +120,7 @@ You can create complex tree decisions using the field ``depends``. The following
113120
"type": "numeric-list",
114121
"depends": "sample_4",
115122
"mandatory": "FALSE",
123+
"disabled": "",
116124
"used": false,
117125
"childs": [
118126
{
@@ -122,6 +130,7 @@ You can create complex tree decisions using the field ``depends``. The following
122130
"type": "numeric-list",
123131
"depends": "sample_8",
124132
"mandatory": "FALSE",
133+
"disabled": "",
125134
"used": false,
126135
"childs": [
127136
{
@@ -131,6 +140,7 @@ You can create complex tree decisions using the field ``depends``. The following
131140
"type": "circle-list",
132141
"depends": "sample_9",
133142
"mandatory": "FALSE",
143+
"disabled": "",
134144
"used": false,
135145
"childs": [
136146
{
@@ -140,6 +150,7 @@ You can create complex tree decisions using the field ``depends``. The following
140150
"type": "circle-list",
141151
"depends": "sample_11",
142152
"mandatory": "TRUE",
153+
"disabled": "",
143154
"used": false,
144155
"childs": []
145156
},
@@ -150,6 +161,7 @@ You can create complex tree decisions using the field ``depends``. The following
150161
"type": "circle-list",
151162
"depends": "sample_11",
152163
"mandatory": "TRUE",
164+
"disabled": "",
153165
"used": false,
154166
"childs": [
155167
{
@@ -159,6 +171,7 @@ You can create complex tree decisions using the field ``depends``. The following
159171
"type": "square-list",
160172
"depends": "sample_13",
161173
"mandatory": "FALSE",
174+
"disabled": "",
162175
"used": false,
163176
"childs": [
164177
{
@@ -168,6 +181,7 @@ You can create complex tree decisions using the field ``depends``. The following
168181
"type": "square-list",
169182
"depends": "sample_17",
170183
"mandatory": "FALSE",
184+
"disabled": "",
171185
"used": false,
172186
"childs": []
173187
}
@@ -182,6 +196,7 @@ You can create complex tree decisions using the field ``depends``. The following
182196
"type": "circle-list",
183197
"depends": "sample_11",
184198
"mandatory": "TRUE",
199+
"disabled": "",
185200
"used": false,
186201
"childs": []
187202
},
@@ -192,6 +207,7 @@ You can create complex tree decisions using the field ``depends``. The following
192207
"type": "circle-list",
193208
"depends": "sample_11",
194209
"mandatory": "TRUE",
210+
"disabled": "",
195211
"used": false,
196212
"childs": []
197213
}
@@ -210,6 +226,7 @@ You can create complex tree decisions using the field ``depends``. The following
210226
"type": "numeric-list",
211227
"depends": "",
212228
"mandatory": "TRUE",
229+
"disabled": "",
213230
"used": false,
214231
"childs": []
215232
},
@@ -220,6 +237,7 @@ You can create complex tree decisions using the field ``depends``. The following
220237
"type": "paragraph",
221238
"depends": "",
222239
"mandatory": "TRUE",
240+
"disabled": "",
223241
"used": false,
224242
"childs": []
225243
},
@@ -230,6 +248,7 @@ You can create complex tree decisions using the field ``depends``. The following
230248
"type": "square-list",
231249
"depends": "",
232250
"mandatory": "FALSE",
251+
"disabled": "",
233252
"used": false,
234253
"childs": []
235254
},
@@ -250,6 +269,7 @@ You can create complex tree decisions using the field ``depends``. The following
250269
"type": "paragraph",
251270
"depends": "",
252271
"mandatory": "TRUE",
272+
"disabled": "",
253273
"used": false,
254274
"childs": []
255275
}
@@ -268,8 +288,9 @@ You can create complex tree decisions using the field ``depends``. The following
268288

269289
## Release Notes
270290
- **v0.0.2:**
271-
- Fix mandatory children glitch
272-
- Fix sheetId always equals to 0
291+
- [Feature] Add option to disable row in the Spreadsheet
292+
- [Bugfix] Fix mandatory children glitch
293+
- [Bugfix] Fix sheetId always equals to 0
273294
- **v0.0.1:**
274295
- First working version
275296

js/contract-generator.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ var sheetCallback = function (error, options, response) {
6161
var typeIndex = response.rows[0].labels.indexOf('type');
6262
var dependsIndex = response.rows[0].labels.indexOf('depends');
6363
var mandatoryIndex = response.rows[0].labels.indexOf('mandatory');
64+
var disabledIndex = response.rows[0].labels.indexOf('disabled');
65+
//debugger;
6466

65-
//collection = response.rows.slice(1, response.rows.length); // remove labels
66-
collection = response.rows; // remove labels
67+
if (arraysEqual(response.rows[0].cellsArray, response.rows[0].labels))
68+
collection = response.rows.slice(1, response.rows.length); // remove labels
69+
else
70+
collection = response.rows; // remove labels
6771
collection.filter(function(item){ // get all objects that has no dependency
6872
if (item.cellsArray[dependsIndex] === "")
6973
{
@@ -74,15 +78,19 @@ var sheetCallback = function (error, options, response) {
7478
tempObject.type = item.cellsArray[typeIndex];
7579
tempObject.depends = item.cellsArray[dependsIndex];
7680
tempObject.mandatory = item.cellsArray[mandatoryIndex];
81+
tempObject.disabled = item.cellsArray[disabledIndex];
7782
tempObject.used = false;
7883
tempObject.childs = [];
84+
if (tempObject.disabled.toLowerCase() === "false") // ignore disabled rows
85+
return;
7986

8087
docObject.push(tempObject);
8188
}
8289
});
8390
collDependency = collection.filter(function(item){ // get all objects that has dependency
84-
return (item.cellsArray[dependsIndex] !== "");
91+
return ((item.cellsArray[dependsIndex] !== "") && (item.cellsArray[disabledIndex].toLowerCase() !== "false"));
8592
});
93+
//debugger;
8694
// TODO add while to deep decision tree
8795
var tempColl = [];
8896
var i = 0;
@@ -101,6 +109,7 @@ var sheetCallback = function (error, options, response) {
101109
tempObject.type = this.cellsArray[typeIndex];
102110
tempObject.depends = this.cellsArray[dependsIndex];
103111
tempObject.mandatory = this.cellsArray[mandatoryIndex];
112+
tempObject.disabled = this.cellsArray[disabledIndex];
104113
tempObject.used = false;
105114
tempObject.childs = [];
106115

@@ -164,6 +173,16 @@ else{
164173
}
165174

166175
// FUNCTIONS
176+
function arraysEqual(arr1, arr2) {
177+
if(arr1.length !== arr2.length)
178+
return false;
179+
for(var i = arr1.length; i--;) {
180+
if(arr1[i] !== arr2[i])
181+
return false;
182+
}
183+
return true;
184+
}
185+
167186
function parseSpreadsheet()
168187
{
169188
//debugger;

0 commit comments

Comments
 (0)