jonshaffer/angular-data-table

View on GitHub
src/components/body/CellDirective.js

Summary

Maintainability
B
5 hrs
Test Coverage
import CellController from './CellController';
 
Function `CellDirective` has 69 lines of code (exceeds 25 allowed). Consider refactoring.
export default function CellDirective($rootScope, $compile) {
return {
restrict: 'E',
controller: CellController,
scope: true,
controllerAs: 'cell',
Similar blocks of code found in 2 locations. Consider refactoring.
bindToController: {
options: '=',
value: '=',
selected: '=',
column: '=',
row: '=',
expanded: '=',
hasChildren: '=',
onTreeToggle: '&',
onCheckboxChange: '&',
},
template:
`<div class="dt-cell"
data-title="{{::cell.column.name}}"
ng-style="cell.styles()"
ng-class="cell.cellClass()">
<label ng-if="cell.column.isCheckboxColumn" class="dt-checkbox">
<input type="checkbox"
ng-checked="cell.selected"
ng-click="cell.onCheckboxChanged($event)" />
</label>
<span ng-if="cell.column.isTreeColumn && cell.hasChildren"
ng-class="cell.treeClass()"
ng-click="cell.onTreeToggled($event)"></span>
<span class="dt-cell-content"></span>
</div>`,
replace: true,
Function `compile` has 34 lines of code (exceeds 25 allowed). Consider refactoring.
compile() {
return {
Function `pre` has 30 lines of code (exceeds 25 allowed). Consider refactoring.
pre($scope, $elm, $attrs, ctrl) {
const content = angular.element($elm[0].querySelector('.dt-cell-content'));
 
let cellScope;
 
// extend the outer scope onto our new cell scope
if (ctrl.column.template || ctrl.column.cellRenderer) {
createCellScope();
}
 
$scope.$watch('cell.row', () => {
if (cellScope) {
cellScope.$destroy();
 
createCellScope();
 
cellScope.$cell = ctrl.value;
cellScope.$row = ctrl.row;
cellScope.$column = ctrl.column;
cellScope.$$watchers = null;
}
 
if (ctrl.column.template) {
content.empty();
const elm = angular.element(`<span>${ctrl.column.template.trim()}</span>`);
content.append($compile(elm)(cellScope));
} else if (ctrl.column.cellRenderer) {
content.empty();
const elm = angular.element(ctrl.column.cellRenderer(cellScope, content));
content.append($compile(elm)(cellScope));
} else {
content[0].innerHTML = ctrl.getValue();
}
}, true);
 
function createCellScope() {
cellScope = ctrl.options.$outer.$new(false);
cellScope.getValue = ctrl.getValue;
}
},
};
},
};
}