• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

compassinformatics / cpsi-mapview / 15022980938

14 May 2025 02:11PM UTC coverage: 26.333% (+0.04%) from 26.29%
15022980938

push

github

geographika
Move describe to test globals

492 of 2344 branches covered (20.99%)

Branch coverage included in aggregate %.

1464 of 5084 relevant lines covered (28.8%)

1.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

1.41
/app/plugin/TreeColumnStyleSwitcher.js
1
/**
2
 * A plugin for Ext.grid.column.Column that extends the internal cellTpl to
3
 * add a radio group to switch the style for a layer
4
 * (CpsiMapview.view.layer.StyleSwitcherRadioGroup).
5
 */
6
Ext.define('CpsiMapview.plugin.TreeColumnStyleSwitcher', {
1✔
7
    extend: 'Ext.plugin.Abstract',
8
    alias: 'plugin.cmv_tree_column_style_switcher',
9
    pluginId: 'cmv_tree_column_style_switcher',
10

11
    requires: ['CpsiMapview.view.layer.StyleSwitcherRadioGroup'],
12

13
    statics: {
14
        /**
15
         * Returns a valid HTML element ID from the given UUID (e.g. the ID of
16
         * a layer record).
17
         *
18
         * @param  {String} uuid The UUID to transform to a HTML ID
19
         * @return {String}      The HTML ID derived from the UUID
20
         */
21
        getDomId: function (uuid) {
22
            return 'cmv-tss-' + uuid;
×
23
        }
24
    },
25

26
    /**
27
     * List of currently rendered instances of
28
     * CpsiMapview.view.layer.StyleSwitcherRadioGroup. Used to cleanup.
29
     *
30
     * @property {CpsiMapview.view.layer.StyleSwitcherRadioGroup[]}
31
     * @readonly
32
     * @private
33
     */
34
    radioGroups: [],
35

36
    /**
37
     * @private
38
     */
39
    init: function (treeColumn) {
40
        const me = this;
×
41
        if (!(treeColumn instanceof Ext.grid.column.Column)) {
×
42
            Ext.log.warn(
×
43
                'Plugin shall only be applied to instances of' +
44
                    ' Ext.grid.column.Column'
45
            );
46
            return;
×
47
        }
48
        const THIS_CLS = CpsiMapview.plugin.TreeColumnStyleSwitcher;
×
49

50
        // add a DIV as placeholder for each layer needing a style switcher
51
        const tplArr = [
×
52
            '<tpl if="this.needsStyleSwitcher(values.record)">',
53
            // DIV placeholder for radio group (layer record ID as connector)
54
            '<div id="{[this.getRecId(values.record)]}" style="">',
55
            '</div>',
56
            '</tpl>'
57
        ];
58

59
        // helper function to get a DOM ID from layer record ID in XTemplate
60
        const getRecId = function (rec) {
×
61
            return THIS_CLS.getDomId(rec.getId());
×
62
        };
63
        // helper function if a DIV placeholder for style switcher is needed
64
        const needsStyleSwitcher = function (rec) {
×
65
            const olLayer = rec.getOlLayer();
×
66
            return (
×
67
                !rec.get('isLayerGroup') &&
×
68
                olLayer &&
69
                Ext.isArray(olLayer.get('styles'))
70
            );
71
        };
72

73
        if (treeColumn.cellTpl.length === 2) {
×
74
            // The cellTpl of this column is modeled as a single string
75
            // (as done in plugin.cmv_basic_tree_column_legend).
76
            // So the cellTpl is an array with 2 entries (0 => XTemplate string,
77
            // 1 => context object with template functions)
78

79
            // inject template code (string) to existing one
80
            const origCellTpl = treeColumn.cellTpl[0];
×
81
            treeColumn.cellTpl[0] = origCellTpl.replace(
×
82
                '</span></tpl>',
83
                '</span>' + tplArr.join('') + '</tpl>'
84
            );
85
            // set context function for XTemplate
86
            treeColumn.cellTpl[1].getRecId = getRecId;
×
87
            treeColumn.cellTpl[1].needsStyleSwitcher = needsStyleSwitcher;
×
88
        } else {
89
            // The case that the XTemplate is modeled as array (default)
90
            // 0-(n-1) => XTemplate strings, n => context object with template
91
            // functions
92

93
            // inject template code (array) to existing one
94
            Ext.Array.insert(
×
95
                treeColumn.cellTpl,
96
                treeColumn.cellTpl.length - 1,
97
                tplArr
98
            );
99
            // set context function for XTemplate
100
            treeColumn.cellTpl.push({
×
101
                getRecId: getRecId,
102
                needsStyleSwitcher: needsStyleSwitcher
103
            });
104
        }
105

106
        me.callParent();
×
107

108
        // wait until all layers are loaded to the map
109
        const layerTree = treeColumn.up('treepanel');
×
110
        layerTree.on('cmv-init-layertree', function () {
×
111
            // render radio groups on initialisation
112
            me.cleanupAllRadioGroups();
×
113
            me.renderRadioGroups();
×
114

115
            // ensure the radio groups are re-rendered every time the tree view
116
            // changes (e.g.) layer visibility is changed
117
            layerTree.getView().on('refresh', function () {
×
118
                Ext.defer(function () {
×
119
                    me.cleanupAllRadioGroups();
×
120
                    me.renderRadioGroups();
×
121
                }, 1);
122
            });
123
        });
124

125
        // ensure that the radio groups are rendered after a node has been
126
        // dragged and dropped
127
        treeColumn.up('treepanel').on('drop', function (node, data) {
×
128
            Ext.defer(function () {
×
129
                me.cleanupAllRadioGroups();
×
130
                // updates the whole node for the layer and forces the
131
                // me.renderRadioGroups via 'itemupdate' event
132
                // directly executing me.renderRadioGroups leaves some artifacts
133
                if (
×
134
                    data.records &&
×
135
                    data.records.length > 0 &&
136
                    data.records[0].getOlLayer()
137
                ) {
138
                    const layer = data.records[0].getOlLayer();
×
139
                    treeColumn.up('treepanel').updateLayerNodeUi(layer);
×
140
                }
141
            }, 1);
142
        });
143
    },
144

145
    /**
146
     * Renders the radio groups for each layer having connected styles.
147
     * The radio group instance is injected into the DIV placeholder created in
148
     * the cellTpl of this tree column (see #init fucntion of this plugin).
149
     * Connection of placeholder and layer is done by the layer record ID.
150
     */
151
    renderRadioGroups: function () {
152
        const me = this;
×
153
        const THIS_CLS = CpsiMapview.plugin.TreeColumnStyleSwitcher;
×
154
        const treePanel = me.cmp.up('treepanel');
×
155

156
        treePanel.getRootNode().cascadeBy(function (node) {
×
157
            // skip group layers (folders) and the root node
158
            if (!node.get('isLayerGroup') && node.get('text') !== 'root') {
×
159
                const lyrRecId = node.get('id');
×
160
                const placeholderDomId = THIS_CLS.getDomId(lyrRecId);
×
161
                // use fly to avoid Ext element cache which raises error
162
                const placeholderDiv = Ext.fly(placeholderDomId);
×
163
                const olLayer = node.getOlLayer();
×
164

165
                if (placeholderDiv && olLayer.get('styles')) {
×
166
                    const radioGroup = Ext.create(
×
167
                        'CpsiMapview.view.layer.StyleSwitcherRadioGroup',
168
                        {
169
                            layer: olLayer,
170
                            containerId: placeholderDiv.id,
171
                            renderTo: placeholderDiv
172
                        }
173
                    );
174

175
                    me.radioGroups.push(radioGroup);
×
176
                }
177
            }
178
        });
179
    },
180

181
    /**
182
     * Removes all currently rendered radio groups.
183
     */
184
    cleanupAllRadioGroups: function () {
185
        const me = this;
×
186

187
        Ext.each(me.radioGroups, function (rg) {
×
188
            rg.destroy();
×
189
        });
190

191
        me.radioGroups = [];
×
192
    }
193
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc