pict-section-form 1.3.17 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/source/providers/dynamictemplates/Pict-DynamicTemplates-DefaultFormTemplates.js +1 -1
- package/source/providers/layouts/Pict-Layout-Record.js +57 -2
- package/source/providers/layouts/Pict-Layout-Tabular.js +65 -0
- package/test/Pict-Layout-Record-Width_tests.js +110 -0
- package/test/PictSectionForm-Tabular-Features_tests.js +135 -0
package/package.json
CHANGED
|
@@ -260,7 +260,7 @@ Glug glug glug Oo... -->
|
|
|
260
260
|
"DefaultInputExtensions": ["Pict-Input-Chart"],
|
|
261
261
|
"Template": /*HTML*/`
|
|
262
262
|
<!-- InputType Chart {~D:Record.Hash~} {~D:Record.DataType~} -->
|
|
263
|
-
<div style="width:{~DWAF:Record.PictForm.QuantizedWidth:100~}%; display:inline-block;">
|
|
263
|
+
<div style="width:{~DWAF:Record.PictForm.QuantizedWidth:100~}%; margin-left:{~DWAF:Record.PictForm.QuantizedWidthOffset:0~}%; display:inline-block;">
|
|
264
264
|
<input type="hidden" id="CONFIG-FOR-{~D:Record.Macro.RawHTMLID~}" value="">
|
|
265
265
|
<h3><span>{~D:Record.Name~}:</span></h3>
|
|
266
266
|
<!-- ChartHeight (pixels) sets the plot area. It is min-height rather than height so the
|
|
@@ -12,6 +12,40 @@ class RecordLayout extends libPictSectionGroupLayout
|
|
|
12
12
|
this.fable;
|
|
13
13
|
/** @type {any} */
|
|
14
14
|
this.log;
|
|
15
|
+
|
|
16
|
+
/** @type {Array<(pInput: any) => boolean>} */
|
|
17
|
+
this.layoutExcludedInputChecks = [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Register a check that marks an input as taking no width in its row. An excluded
|
|
22
|
+
* input gets `PictForm.LayoutExcluded = true` and a QuantizedWidth of 0, and the
|
|
23
|
+
* other inputs in the row share its space.
|
|
24
|
+
*
|
|
25
|
+
* @param {(pInput: any) => boolean} fCheck - returns true when the input takes no width
|
|
26
|
+
*/
|
|
27
|
+
registerLayoutExcludedInputCheck(fCheck)
|
|
28
|
+
{
|
|
29
|
+
if ((typeof fCheck === 'function') && !this.layoutExcludedInputChecks.includes(fCheck))
|
|
30
|
+
{
|
|
31
|
+
this.layoutExcludedInputChecks.push(fCheck);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {any} pInput
|
|
37
|
+
* @returns {boolean} - true when any registered check excludes the input from row width
|
|
38
|
+
*/
|
|
39
|
+
isLayoutExcludedInput(pInput)
|
|
40
|
+
{
|
|
41
|
+
for (let i = 0; i < this.layoutExcludedInputChecks.length; i++)
|
|
42
|
+
{
|
|
43
|
+
if (this.layoutExcludedInputChecks[i](pInput))
|
|
44
|
+
{
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
15
49
|
}
|
|
16
50
|
|
|
17
51
|
/**
|
|
@@ -76,8 +110,20 @@ class RecordLayout extends libPictSectionGroupLayout
|
|
|
76
110
|
{
|
|
77
111
|
tmpInputWidth = 1;
|
|
78
112
|
}
|
|
113
|
+
let tmpInputWidthOffset = Math.abs(parseFloat(tmpInput.PictForm.WidthOffset));
|
|
114
|
+
if (!tmpInputWidthOffset || isNaN(tmpInputWidthOffset))
|
|
115
|
+
{
|
|
116
|
+
tmpInputWidthOffset = 0;
|
|
117
|
+
}
|
|
118
|
+
tmpInput.PictForm.LayoutExcluded = this.isLayoutExcludedInput(tmpInput);
|
|
119
|
+
if (tmpInput.PictForm.LayoutExcluded)
|
|
120
|
+
{
|
|
121
|
+
tmpInputWidth = 0;
|
|
122
|
+
tmpInputWidthOffset = 0;
|
|
123
|
+
}
|
|
79
124
|
tmpInput.PictForm.RawWidth = tmpInputWidth;
|
|
80
|
-
|
|
125
|
+
tmpInput.PictForm.RawWidthOffset = tmpInputWidthOffset;
|
|
126
|
+
tmpRow.WidthTotalRaw += tmpInputWidth + tmpInputWidthOffset;
|
|
81
127
|
|
|
82
128
|
//tmpTemplate += tmpMetatemplateGenerator.getInputMetatemplateTemplateReference(pView, tmpInput.DataType, tmpInput.PictForm.InputType, `getInput("${pGroup.GroupIndex}","${j}","${k}")`);
|
|
83
129
|
}
|
|
@@ -107,7 +153,16 @@ class RecordLayout extends libPictSectionGroupLayout
|
|
|
107
153
|
for (let k = 0; k < tmpRow.Inputs.length; k++)
|
|
108
154
|
{
|
|
109
155
|
let tmpInput = tmpRow.Inputs[k];
|
|
110
|
-
|
|
156
|
+
if (tmpRow.WidthTotalRaw > 0)
|
|
157
|
+
{
|
|
158
|
+
tmpInput.PictForm.QuantizedWidth = Math.round((tmpInput.PictForm.RawWidth / tmpRow.WidthTotalRaw) * tmpGroupQuantizedWidth);
|
|
159
|
+
tmpInput.PictForm.QuantizedWidthOffset = Math.round((tmpInput.PictForm.RawWidthOffset / tmpRow.WidthTotalRaw) * tmpGroupQuantizedWidth);
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
{
|
|
163
|
+
tmpInput.PictForm.QuantizedWidth = 0;
|
|
164
|
+
tmpInput.PictForm.QuantizedWidthOffset = 0;
|
|
165
|
+
}
|
|
111
166
|
//this.fable.log.trace(`Quantized input width for Group ${pGroup.GroupIndex} Row ${j} Input ${k} (${tmpInput.Name}) to ${tmpInput.PictForm.QuantizedWidth} (Raw: ${tmpInput.PictForm.RawWidth} / Total Raw: ${tmpRow.WidthTotalRaw} / Group Quantization: ${tmpGroupQuantizedWidth})`);
|
|
112
167
|
|
|
113
168
|
tmpTemplate += tmpMetatemplateGenerator.getInputMetatemplateTemplateReference(pView, tmpInput.DataType, tmpInput.PictForm.InputType, `getInput("${pGroup.GroupIndex}","${j}","${k}")`);
|
|
@@ -1577,6 +1577,68 @@ class TabularLayout extends libPictSectionGroupLayout
|
|
|
1577
1577
|
return true;
|
|
1578
1578
|
}
|
|
1579
1579
|
|
|
1580
|
+
/**
|
|
1581
|
+
* A `<colgroup>` sizing the visible data columns as percentages of the table,
|
|
1582
|
+
* in proportion to each descriptor's `PictForm.Width` (missing, zero or
|
|
1583
|
+
* unparseable counts as 1, as in the Record layout). Leading non-data columns
|
|
1584
|
+
* get an unsized `<col>` so the data widths line up.
|
|
1585
|
+
*
|
|
1586
|
+
* Returns an empty string when no visible column carries a positive Width, so
|
|
1587
|
+
* tables without widths keep the browser's automatic column sizing.
|
|
1588
|
+
*
|
|
1589
|
+
* @param {Object} pGroup
|
|
1590
|
+
* @param {Set<string>|null} pChooserHiddenSet - columns hidden by the ColumnChooser
|
|
1591
|
+
* @param {number} pLeadingColumnCount - row-select, row label and left editing-control columns
|
|
1592
|
+
* @returns {string}
|
|
1593
|
+
*/
|
|
1594
|
+
_buildTabularColGroupHTML(pGroup, pChooserHiddenSet, pLeadingColumnCount)
|
|
1595
|
+
{
|
|
1596
|
+
let tmpRawWidths = [];
|
|
1597
|
+
let tmpAnyWidth = false;
|
|
1598
|
+
for (let k = 0; k < pGroup.supportingManifest.elementAddresses.length; k++)
|
|
1599
|
+
{
|
|
1600
|
+
let tmpHash = pGroup.supportingManifest.elementAddresses[k];
|
|
1601
|
+
let tmpDescriptor = pGroup.supportingManifest.elementDescriptors[tmpHash];
|
|
1602
|
+
if (!tmpDescriptor || (tmpDescriptor.PictForm && tmpDescriptor.PictForm.TabularHidden))
|
|
1603
|
+
{
|
|
1604
|
+
continue;
|
|
1605
|
+
}
|
|
1606
|
+
if (pChooserHiddenSet && pChooserHiddenSet.has(String(tmpHash)))
|
|
1607
|
+
{
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
let tmpWidth = Math.abs(parseFloat(tmpDescriptor.PictForm ? tmpDescriptor.PictForm.Width : undefined));
|
|
1611
|
+
if (!tmpWidth || isNaN(tmpWidth))
|
|
1612
|
+
{
|
|
1613
|
+
tmpWidth = 1;
|
|
1614
|
+
}
|
|
1615
|
+
else
|
|
1616
|
+
{
|
|
1617
|
+
tmpAnyWidth = true;
|
|
1618
|
+
}
|
|
1619
|
+
tmpRawWidths.push(tmpWidth);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
if (!tmpAnyWidth)
|
|
1623
|
+
{
|
|
1624
|
+
return '';
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
let tmpTotal = tmpRawWidths.reduce((pSum, pWidth) => pSum + pWidth, 0);
|
|
1628
|
+
let tmpColGroup = '<colgroup class="pict-tabular-colgroup">';
|
|
1629
|
+
for (let l = 0; l < pLeadingColumnCount; l++)
|
|
1630
|
+
{
|
|
1631
|
+
tmpColGroup += '<col>';
|
|
1632
|
+
}
|
|
1633
|
+
for (let c = 0; c < tmpRawWidths.length; c++)
|
|
1634
|
+
{
|
|
1635
|
+
let tmpPercent = Math.round((tmpRawWidths[c] / tmpTotal) * 10000) / 100;
|
|
1636
|
+
tmpColGroup += `<col style="width:${tmpPercent}%">`;
|
|
1637
|
+
}
|
|
1638
|
+
tmpColGroup += '</colgroup>';
|
|
1639
|
+
return tmpColGroup;
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1580
1642
|
/**
|
|
1581
1643
|
* Generate a group layout template for a single-record dynamically generated group view.
|
|
1582
1644
|
*
|
|
@@ -1663,6 +1725,9 @@ class TabularLayout extends libPictSectionGroupLayout
|
|
|
1663
1725
|
|
|
1664
1726
|
tmpTemplate += tmpMetatemplateGenerator.getMetatemplateTemplateReference(pView, `-TabularTemplate-Group-Prefix`, `getGroup("${pGroup.GroupIndex}")`);
|
|
1665
1727
|
|
|
1728
|
+
// Group-Prefix ends with the <table> open tag and RowHeader-Prefix starts with <thead>.
|
|
1729
|
+
tmpTemplate += this._buildTabularColGroupHTML(pGroup, tmpChooserHiddenSet, tmpLeadingColumnCount);
|
|
1730
|
+
|
|
1666
1731
|
// Header section
|
|
1667
1732
|
tmpTemplate += tmpMetatemplateGenerator.getMetatemplateTemplateReference(pView, `-TabularTemplate-RowHeader-Prefix`, `getGroup("${pGroup.GroupIndex}")`);
|
|
1668
1733
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Unit tests for the Record layout's row width math: PictForm.Width / WidthOffset quantized to
|
|
3
|
+
QuantizedWidth / QuantizedWidthOffset, and inputs excluded from row width by a registered check.
|
|
4
|
+
Exercised against a stub `this` so we don't need to mount a full form.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const Chai = require('chai');
|
|
8
|
+
const Expect = Chai.expect;
|
|
9
|
+
|
|
10
|
+
const libRecordLayout = require('../source/providers/layouts/Pict-Layout-Record.js');
|
|
11
|
+
|
|
12
|
+
function buildLayout()
|
|
13
|
+
{
|
|
14
|
+
const tmpLayout = Object.create(libRecordLayout.prototype);
|
|
15
|
+
tmpLayout.layoutExcludedInputChecks = [];
|
|
16
|
+
tmpLayout.pict =
|
|
17
|
+
{
|
|
18
|
+
PictApplication: { options: {} },
|
|
19
|
+
providers:
|
|
20
|
+
{
|
|
21
|
+
MetatemplateGenerator:
|
|
22
|
+
{
|
|
23
|
+
getMetatemplateTemplateReference: () => '',
|
|
24
|
+
getInputMetatemplateTemplateReference: () => ''
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
return tmpLayout;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function buildGroup(pInputs, pWidthQuantization)
|
|
32
|
+
{
|
|
33
|
+
const tmpGroup = { GroupIndex: 0, Rows: [ { Hash: 'Row_1', RowNumber: 1, Inputs: pInputs } ] };
|
|
34
|
+
if (pWidthQuantization)
|
|
35
|
+
{
|
|
36
|
+
tmpGroup.WidthQuantization = pWidthQuantization;
|
|
37
|
+
}
|
|
38
|
+
return tmpGroup;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function input(pHash, pPictForm)
|
|
42
|
+
{
|
|
43
|
+
return { Hash: pHash, DataType: 'String', PictForm: Object.assign({}, pPictForm) };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function widths(pGroup)
|
|
47
|
+
{
|
|
48
|
+
return pGroup.Rows[0].Inputs.map((pInput) => [ pInput.PictForm.QuantizedWidth, pInput.PictForm.QuantizedWidthOffset ]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
suite('Record layout row widths', () =>
|
|
52
|
+
{
|
|
53
|
+
test('widths without offsets quantize as before (default 95)', () =>
|
|
54
|
+
{
|
|
55
|
+
const tmpGroup = buildGroup([ input('A', { Width: 1 }), input('B', { Width: 3 }) ]);
|
|
56
|
+
buildLayout().generateGroupLayoutTemplate({}, tmpGroup);
|
|
57
|
+
Expect(widths(tmpGroup)).to.deep.equal([ [ 24, 0 ], [ 71, 0 ] ]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('offsets count toward the row total and quantize to QuantizedWidthOffset', () =>
|
|
61
|
+
{
|
|
62
|
+
const tmpGroup = buildGroup([ input('A', { Width: 2, WidthOffset: 1 }), input('B', { Width: 3 }) ], 100);
|
|
63
|
+
buildLayout().generateGroupLayoutTemplate({}, tmpGroup);
|
|
64
|
+
Expect(widths(tmpGroup)).to.deep.equal([ [ 33, 17 ], [ 50, 0 ] ]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('a row authored to 12 with offsets keeps its proportions', () =>
|
|
68
|
+
{
|
|
69
|
+
const tmpGroup = buildGroup([ input('A', { Width: 3, WidthOffset: 3 }), input('B', { Width: '6' }) ], 100);
|
|
70
|
+
buildLayout().generateGroupLayoutTemplate({}, tmpGroup);
|
|
71
|
+
Expect(widths(tmpGroup)).to.deep.equal([ [ 25, 25 ], [ 50, 0 ] ]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('zero, missing and unparseable widths count as 1; bad offsets count as 0', () =>
|
|
75
|
+
{
|
|
76
|
+
const tmpGroup = buildGroup([ input('A', { Width: 0 }), input('B', {}), input('C', { Width: 'wide', WidthOffset: 'x' }), input('D', { Width: 1 }) ], 100);
|
|
77
|
+
buildLayout().generateGroupLayoutTemplate({}, tmpGroup);
|
|
78
|
+
Expect(widths(tmpGroup)).to.deep.equal([ [ 25, 0 ], [ 25, 0 ], [ 25, 0 ], [ 25, 0 ] ]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('an input excluded by a registered check takes no width and the rest share the row', () =>
|
|
82
|
+
{
|
|
83
|
+
const tmpLayout = buildLayout();
|
|
84
|
+
tmpLayout.registerLayoutExcludedInputCheck((pInput) => pInput.PictForm.InputType === 'Invisible');
|
|
85
|
+
const tmpGroup = buildGroup([ input('A', { Width: 6, WidthOffset: 2, InputType: 'Invisible' }), input('B', { Width: 1 }), input('C', { Width: 1 }) ], 100);
|
|
86
|
+
tmpLayout.generateGroupLayoutTemplate({}, tmpGroup);
|
|
87
|
+
Expect(widths(tmpGroup)).to.deep.equal([ [ 0, 0 ], [ 50, 0 ], [ 50, 0 ] ]);
|
|
88
|
+
Expect(tmpGroup.Rows[0].Inputs.map((pInput) => pInput.PictForm.LayoutExcluded)).to.deep.equal([ true, false, false ]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('a row where every input is excluded gets zero widths, not NaN', () =>
|
|
92
|
+
{
|
|
93
|
+
const tmpLayout = buildLayout();
|
|
94
|
+
tmpLayout.registerLayoutExcludedInputCheck(() => true);
|
|
95
|
+
const tmpGroup = buildGroup([ input('A', { Width: 2 }), input('B', {}) ], 100);
|
|
96
|
+
tmpLayout.generateGroupLayoutTemplate({}, tmpGroup);
|
|
97
|
+
Expect(widths(tmpGroup)).to.deep.equal([ [ 0, 0 ], [ 0, 0 ] ]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('registering ignores non-functions and the same check twice', () =>
|
|
101
|
+
{
|
|
102
|
+
const tmpLayout = buildLayout();
|
|
103
|
+
const fCheck = () => false;
|
|
104
|
+
tmpLayout.registerLayoutExcludedInputCheck(fCheck);
|
|
105
|
+
tmpLayout.registerLayoutExcludedInputCheck(fCheck);
|
|
106
|
+
tmpLayout.registerLayoutExcludedInputCheck('not a function');
|
|
107
|
+
Expect(tmpLayout.layoutExcludedInputChecks).to.have.length(1);
|
|
108
|
+
Expect(tmpLayout.isLayoutExcludedInput(input('A', {}))).to.equal(false);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -39,6 +39,27 @@ const _ReferenceManifests =
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
+
SizedStudentEditor:
|
|
43
|
+
{
|
|
44
|
+
Scope: 'SizedStudentEditor',
|
|
45
|
+
Descriptors:
|
|
46
|
+
{
|
|
47
|
+
Section:
|
|
48
|
+
{
|
|
49
|
+
Name: 'Section',
|
|
50
|
+
Hash: 'Section',
|
|
51
|
+
DataType: 'String',
|
|
52
|
+
PictForm: { Section: 'Class', Group: 'Students', Width: 1 }
|
|
53
|
+
},
|
|
54
|
+
StudentName:
|
|
55
|
+
{
|
|
56
|
+
Name: 'Student',
|
|
57
|
+
Hash: 'StudentName',
|
|
58
|
+
DataType: 'String',
|
|
59
|
+
PictForm: { Section: 'Class', Group: 'Students', Width: 3 }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
42
63
|
GradeRowEditor:
|
|
43
64
|
{
|
|
44
65
|
Scope: 'GradeRowEditor',
|
|
@@ -2034,4 +2055,118 @@ suite('PictSectionForm Tabular Features', () =>
|
|
|
2034
2055
|
}, fDone);
|
|
2035
2056
|
});
|
|
2036
2057
|
});
|
|
2058
|
+
|
|
2059
|
+
suite('Tabular column widths (PictForm.Width)', () =>
|
|
2060
|
+
{
|
|
2061
|
+
function makeGroup(pDescriptors)
|
|
2062
|
+
{
|
|
2063
|
+
return { supportingManifest: { elementAddresses: Object.keys(pDescriptors), elementDescriptors: pDescriptors } };
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
test('No colgroup when no column carries a Width', (fDone) =>
|
|
2067
|
+
{
|
|
2068
|
+
let App = makeApplication({
|
|
2069
|
+
Hash: 'Students',
|
|
2070
|
+
Layout: 'Tabular',
|
|
2071
|
+
RecordSetAddress: 'Students',
|
|
2072
|
+
RecordManifest: 'StudentEditor'
|
|
2073
|
+
});
|
|
2074
|
+
bootstrap(App, (_Pict) =>
|
|
2075
|
+
{
|
|
2076
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
2077
|
+
let tmpGroup = tmpView.sectionDefinition.Groups[0];
|
|
2078
|
+
let tmpTemplate = _Pict.providers['Pict-Layout-Tabular'].generateGroupLayoutTemplate(tmpView, tmpGroup);
|
|
2079
|
+
Expect(tmpTemplate).to.not.contain('<colgroup', 'tables without widths keep automatic sizing');
|
|
2080
|
+
}, fDone);
|
|
2081
|
+
});
|
|
2082
|
+
|
|
2083
|
+
test('Widths become percentages in a colgroup between the table open and the header', (fDone) =>
|
|
2084
|
+
{
|
|
2085
|
+
let App = makeApplication({
|
|
2086
|
+
Hash: 'Students',
|
|
2087
|
+
Layout: 'Tabular',
|
|
2088
|
+
RecordSetAddress: 'Students',
|
|
2089
|
+
RecordManifest: 'SizedStudentEditor'
|
|
2090
|
+
});
|
|
2091
|
+
bootstrap(App, (_Pict) =>
|
|
2092
|
+
{
|
|
2093
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
2094
|
+
let tmpGroup = tmpView.sectionDefinition.Groups[0];
|
|
2095
|
+
let tmpTemplate = _Pict.providers['Pict-Layout-Tabular'].generateGroupLayoutTemplate(tmpView, tmpGroup);
|
|
2096
|
+
Expect(tmpTemplate).to.contain('<colgroup class="pict-tabular-colgroup"><col style="width:25%"><col style="width:75%"></colgroup>');
|
|
2097
|
+
let tmpColGroupAt = tmpTemplate.indexOf('<colgroup');
|
|
2098
|
+
Expect(tmpColGroupAt).to.be.greaterThan(tmpTemplate.indexOf('-TabularTemplate-Group-Prefix'), 'after the table open');
|
|
2099
|
+
Expect(tmpColGroupAt).to.be.lessThan(tmpTemplate.indexOf('-TabularTemplate-RowHeader-Prefix'), 'before the header');
|
|
2100
|
+
}, fDone);
|
|
2101
|
+
});
|
|
2102
|
+
|
|
2103
|
+
test('Columns without a usable Width count as 1; zero is not hidden', (fDone) =>
|
|
2104
|
+
{
|
|
2105
|
+
let App = makeApplication({
|
|
2106
|
+
Hash: 'Students',
|
|
2107
|
+
Layout: 'Tabular',
|
|
2108
|
+
RecordSetAddress: 'Students',
|
|
2109
|
+
RecordManifest: 'StudentEditor'
|
|
2110
|
+
});
|
|
2111
|
+
bootstrap(App, (_Pict) =>
|
|
2112
|
+
{
|
|
2113
|
+
let tmpLayout = _Pict.providers['Pict-Layout-Tabular'];
|
|
2114
|
+
let tmpHTML = tmpLayout._buildTabularColGroupHTML(makeGroup(
|
|
2115
|
+
{
|
|
2116
|
+
A: { Hash: 'A', PictForm: { Width: 2 } },
|
|
2117
|
+
B: { Hash: 'B', PictForm: { Width: 0 } },
|
|
2118
|
+
C: { Hash: 'C', PictForm: { Width: 'wide' } },
|
|
2119
|
+
D: { Hash: 'D' }
|
|
2120
|
+
}), null, 0);
|
|
2121
|
+
Expect(tmpHTML).to.equal('<colgroup class="pict-tabular-colgroup"><col style="width:40%"><col style="width:20%"><col style="width:20%"><col style="width:20%"></colgroup>');
|
|
2122
|
+
let tmpZeroHTML = tmpLayout._buildTabularColGroupHTML(makeGroup(
|
|
2123
|
+
{
|
|
2124
|
+
A: { Hash: 'A', PictForm: { Width: 0 } },
|
|
2125
|
+
B: { Hash: 'B', PictForm: { Width: 0 } }
|
|
2126
|
+
}), null, 0);
|
|
2127
|
+
Expect(tmpZeroHTML).to.equal('', 'all-zero widths size nothing');
|
|
2128
|
+
}, fDone);
|
|
2129
|
+
});
|
|
2130
|
+
|
|
2131
|
+
test('Hidden columns are skipped and leading columns get unsized cols', (fDone) =>
|
|
2132
|
+
{
|
|
2133
|
+
let App = makeApplication({
|
|
2134
|
+
Hash: 'Students',
|
|
2135
|
+
Layout: 'Tabular',
|
|
2136
|
+
RecordSetAddress: 'Students',
|
|
2137
|
+
RecordManifest: 'StudentEditor'
|
|
2138
|
+
});
|
|
2139
|
+
bootstrap(App, (_Pict) =>
|
|
2140
|
+
{
|
|
2141
|
+
let tmpLayout = _Pict.providers['Pict-Layout-Tabular'];
|
|
2142
|
+
let tmpHTML = tmpLayout._buildTabularColGroupHTML(makeGroup(
|
|
2143
|
+
{
|
|
2144
|
+
A: { Hash: 'A', PictForm: { Width: 1 } },
|
|
2145
|
+
Secret: { Hash: 'Secret', PictForm: { Width: 50, TabularHidden: true } },
|
|
2146
|
+
Chosen: { Hash: 'Chosen', PictForm: { Width: 50 } },
|
|
2147
|
+
B: { Hash: 'B', PictForm: { Width: 2 } }
|
|
2148
|
+
}), new Set([ 'Chosen' ]), 2);
|
|
2149
|
+
Expect(tmpHTML).to.equal('<colgroup class="pict-tabular-colgroup"><col><col><col style="width:33.33%"><col style="width:66.67%"></colgroup>');
|
|
2150
|
+
}, fDone);
|
|
2151
|
+
});
|
|
2152
|
+
|
|
2153
|
+
test('Chooser-hidden columns drop out of the baked colgroup', (fDone) =>
|
|
2154
|
+
{
|
|
2155
|
+
let App = makeApplication({
|
|
2156
|
+
Hash: 'Students',
|
|
2157
|
+
Layout: 'Tabular',
|
|
2158
|
+
RecordSetAddress: 'Students',
|
|
2159
|
+
RecordManifest: 'SizedStudentEditor',
|
|
2160
|
+
ColumnChooser: true,
|
|
2161
|
+
RowSelection: true
|
|
2162
|
+
}, { Students_HiddenColumns: [ 'StudentName' ] });
|
|
2163
|
+
bootstrap(App, (_Pict) =>
|
|
2164
|
+
{
|
|
2165
|
+
let tmpView = _Pict.views['PictSectionForm-Class'];
|
|
2166
|
+
let tmpGroup = tmpView.sectionDefinition.Groups[0];
|
|
2167
|
+
let tmpTemplate = _Pict.providers['Pict-Layout-Tabular'].generateGroupLayoutTemplate(tmpView, tmpGroup);
|
|
2168
|
+
Expect(tmpTemplate).to.contain('<colgroup class="pict-tabular-colgroup"><col><col style="width:100%"></colgroup>', 'row-select col, then the one visible column');
|
|
2169
|
+
}, fDone);
|
|
2170
|
+
});
|
|
2171
|
+
});
|
|
2037
2172
|
});
|