* Integrates brick view elements inside pipe structure. * @return {PipeView} Fluent interface
()
| 131 | * @return {PipeView} Fluent interface |
| 132 | */ |
| 133 | update () { |
| 134 | // Gather brick views in order |
| 135 | const bricks = this.getModel().getBricks() |
| 136 | const brickViews = bricks.map(brick => brick.getView()) |
| 137 | |
| 138 | this.getElement() |
| 139 | const $content = this._$content |
| 140 | |
| 141 | // Detach each brick subview element without breaking it (emptying parent |
| 142 | // via innerHTML does not work in IE11) |
| 143 | brickViews.forEach(brickView => { |
| 144 | const $element = brickView.getElement() |
| 145 | $element.parentNode && $element.parentNode.removeChild($element) |
| 146 | }) |
| 147 | |
| 148 | // Empty content element |
| 149 | $content.innerHTML = '' |
| 150 | |
| 151 | // Store reference and index for each pipe part |
| 152 | this._$pipeParts = [] |
| 153 | this._pipePartIndex = [] |
| 154 | |
| 155 | // Compose pipe |
| 156 | let $pipePart |
| 157 | let cowards = [] |
| 158 | for (let i = 0; i < bricks.length; i++) { |
| 159 | if (!bricks[i].isHidden()) { |
| 160 | // Append brick |
| 161 | $pipePart = this._createPipePart(i) |
| 162 | this._$pipeParts.push($pipePart) |
| 163 | this._pipePartIndex.push(i) |
| 164 | |
| 165 | $content.appendChild($pipePart) |
| 166 | $content.appendChild(this._createBrickPart(brickViews[i])) |
| 167 | } else { |
| 168 | // Collect cowards |
| 169 | cowards.push(bricks[i]) |
| 170 | |
| 171 | // Append cowards group if this is the last coward in the group |
| 172 | if (i + 1 === bricks.length || !bricks[i + 1].isHidden()) { |
| 173 | const index = i - cowards.length + 1 |
| 174 | $pipePart = this._createPipePart(index) |
| 175 | this._$pipeParts.push($pipePart) |
| 176 | this._pipePartIndex.push(index) |
| 177 | $content.appendChild($pipePart) |
| 178 | $content.appendChild(this._createCollapsedPart(cowards)) |
| 179 | cowards = [] |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // Add end part |
| 185 | $pipePart = this._createPipePart(brickViews.length) |
| 186 | this._$pipeParts.push($pipePart) |
| 187 | this._pipePartIndex.push(brickViews.length) |
| 188 | $content.appendChild($pipePart) |
| 189 | |
| 190 | this.layout() |
no test coverage detected