DBR as Checkbox


#1

Hi,

I would be a handy feature if DBRs pointing to numeric cells could be visualized as a checkbox (checked: 1, not checked: 0).

Cheers,

Marius


#2

Quick and dirty solution:

<tm1-ui-dbr-checkbox tm1-instance="dev" tm1-cube="Cube1" tm1-elements="'A','1','Value'" ng-model="value"></tm1-ui-dbr-checkbox>

app.directive('tm1UiDbrCheckbox', ['$tm1Ui', function ($tm1Ui) {
    return {
        restrict: 'E',
        replace: true,
        template: '<input class="form-control" type="checkbox">',
        scope: {
            'tm1Instance': '@',
            'tm1Cube': '@',
            'tm1Elements': '@',
            'ngModel': '='
        },
        require: 'ngModel',
        link: function ($scope, elem, attr) {
            var f = '$tm1Ui.cellGet($scope.tm1Instance, $scope.tm1Cube,' + $scope.tm1Elements + ');';
            var getValue = eval(f);
            getValue.then(function (d) {
                if (d.Value == '1') $scope.ngModel = true;
                if (d.Value == '0') $scope.ngModel = false;
            });
            $scope.$watch('ngModel', function () {
                var v;
                if ($scope.ngModel) v = 1;
                if (!$scope.ngModel) v = 0;
                var f = '$tm1Ui.cellPut(v, $scope.tm1Instance, $scope.tm1Cube, ' + $scope.tm1Elements + ');';
                var sendValue = eval(f);
                sendValue.then(function () {
                    $tm1Ui.dataRefresh();
                });
            });
        }
    };
}]);

#3

Thanks again, Andrey. Works really well for a quick and dirty solution :slight_smile:


#4

The $tm1Ui.dataRefresh(); should be removed to avoid the whole page refreshing.