<commit_before>﻿(function (ng, app) {
    app.controller('object.EditAdviceCtrl', ['$', '$scope', '$http', '$state', '$stateParams', '$timeout', 'notify', '$uibModal', 'Roles', 'object', 'users', 'type', 'advicename', 'hasWriteAccess',
        function ($, $scope, $http, $state, $stateParams, $timeout, notify, $modal, roles, object, users, type, advicename, hasWriteAccess) {
            $scope.type = type;
            $scope.object = object;
            $scope.hasWriteAccess = hasWriteAccess;
            $scope.advicename = advicename;

            $scope.mainGridOptions = {
                dataSource: {
                    type: "odata-v4",
                    transport: {
                        read: {
                            url: `/Odata/advice?$filter=type eq '` + type + `' and RelationId eq ` + object.id + `&$expand=Reciepients, Advicesent`,
                            dataType: "json"
                        },
                    },
                    pageSize: 10,
                    serverPaging: true,
                    serverFiltering: true,
                },
                selectable: true,
                change: onChange,
                columns: [{
                    field: "Name",
                    title: "Navn",
                    attributes: { "class": "might-overflow" }
                },
                {
                            field: "SentDate",
                            title: "Sidst sendt",
                            template: x => {
                                if (x.SentDate != null) {
                                    return kendo.toString(new Date(x.SentDate), "d");
                                }
                                return "";
                            },
                            attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "Id",
                            hidden: true
                        },
                        
                        {
                            field: "AlarmDate",
                            title: "Start dato",
                            template: x => {
                                if (x.AlarmDate != null) {
                                    return kendo.toString(new Date(x.AlarmDate), "d");
                                }
                                return "";
                            },
                            attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "StopDate",
                            title: "Slut dato",
                            template: x => {
                                if (x.StopDate != null) {
                                    return kendo.toString(new Date(x.StopDate), "d");
                                }
                                return "";
                            },
                            attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "Reciepients.Name", title: "Modtager",
                            template: () =>
                                `<span data-ng-model="dataItem.Reciepients" value="cc.Name" ng-repeat="cc in dataItem.Reciepients | filter: { RecieverType: 'RECIEVER'}"> {{cc.Name}}{{$last ? '' : ', '}}</span>`,
                            attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "Reciepients.Name",
                            title: "CC",
                            template: () =>
                                `<span data-ng-model="dataItem.Reciepients" value="cc.Name" ng-repeat="cc in dataItem.Reciepients | filter: { RecieverType: 'CC'}"> {{cc.Name}}{{$last ? '' : ', '}}</span>`,
                                    attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "Subject",
                            title: "Emne"
                        },
                        {
                            template: (dataItem) => {
                                var isActive = (kendo.toString(new Date(dataItem.StopDate), "d") < kendo.toString(new Date(), "d") || dataItem.Scheduling === 'Immediate');
                                console.log(dataItem);
                                var canDelete = dataItem.AdviceSent.length === 0;
                                if (hasWriteAccess) {
                                    return `<button class="btn-link" ng-disabled="${isActive}" data-ng-click="newAdvice('PATCH',${dataItem.Id})"><i class="glyphicon glyphicon-pencil"></i></button>
                                            <button class="btn-link" ng-disabled="${!canDelete}" data-ng-click="deleteAdvice(${dataItem.Id})"><i class="glyphicon glyphicon-trash"></i></button>`;
                                } else {
                                    return 'Ingen rettigheder';
                                }
                            }<commit_msg>OS2KITOS-956 - fixed code, OS2KITOS-954 -fixed sql script<commit_after>﻿(function (ng, app) {
    app.controller('object.EditAdviceCtrl', ['$', '$scope', '$http', '$state', '$stateParams', '$timeout', 'notify', '$uibModal', 'Roles', 'object', 'users', 'type', 'advicename', 'hasWriteAccess',
        function ($, $scope, $http, $state, $stateParams, $timeout, notify, $modal, roles, object, users, type, advicename, hasWriteAccess) {
            $scope.type = type;
            $scope.object = object;
            $scope.hasWriteAccess = hasWriteAccess;
            $scope.advicename = advicename;

            $scope.mainGridOptions = {
                dataSource: {
                    type: "odata-v4",
                    transport: {
                        read: {
                            url: `/Odata/advice?$filter=type eq '` + type + `' and RelationId eq ` + object.id + `&$expand=Reciepients, Advicesent`,
                            dataType: "json"
                        },
                    },
                    pageSize: 10,
                    serverPaging: true,
                    serverFiltering: true,
                },
                selectable: true,
                change: onChange,
                columns: [{
                    field: "Name",
                    title: "Navn",
                    attributes: { "class": "might-overflow" }
                },
                {
                            field: "SentDate",
                            title: "Sidst sendt",
                            template: x => {
                                if (x.SentDate != null) {
                                    return kendo.toString(new Date(x.SentDate), "d");
                                }
                                return "";
                            },
                            attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "Id",
                            hidden: true
                        },
                        
                        {
                            field: "AlarmDate",
                            title: "Start dato",
                            template: x => {
                                if (x.AlarmDate != null) {
                                    return kendo.toString(new Date(x.AlarmDate), "d");
                                }
                                return "";
                            },
                            attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "StopDate",
                            title: "Slut dato",
                            template: x => {
                                if (x.StopDate != null) {
                                    return kendo.toString(new Date(x.StopDate), "d");
                                }
                                return "";
                            },
                            attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "Reciepients.Name", title: "Modtager",
                            template: () =>
                                `<span data-ng-model="dataItem.Reciepients" value="cc.Name" ng-repeat="cc in dataItem.Reciepients | filter: { RecieverType: 'RECIEVER'}"> {{cc.Name}}{{$last ? '' : ', '}}</span>`,
                            attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "Reciepients.Name",
                            title: "CC",
                            template: () =>
                                `<span data-ng-model="dataItem.Reciepients" value="cc.Name" ng-repeat="cc in dataItem.Reciepients | filter: { RecieverType: 'CC'}"> {{cc.Name}}{{$last ? '' : ', '}}</span>`,
                                    attributes: { "class": "might-overflow" }
                        },
                        {
                            field: "Subject",
                            title: "Emne"
                        },
                        {
                            template: (dataItem) => {
                                var isActive = moment().isAfter(moment(dataItem.StopDate)) || dataItem.Scheduling === 'Immediate';
                                var canDelete = dataItem.AdviceSent.length === 0;
                                if (hasWriteAccess) {
                                    return `<button class="btn-link" ng-disabled="${isActive}" data-ng-click="newAdvice('PATCH',${dataItem.Id})"><i class="glyphicon glyphicon-pencil"></i></button>
                                            <button class="btn-link" ng-disabled="${!canDelete}" data-ng-click="deleteAdvice(${dataItem.Id})"><i class="glyphicon glyphicon-trash"></i></button>`;
                                } else {
                                    return 'Ingen rettigheder';
                                }
                            }
{'fraction_non_alphanumeric': 0.12095984329089128, 'fraction_numerical': 0.0015670910871694416, 'mean_word_length': 0.8535124341985841, 'pattern_counts': {'":': 12, '<': 28, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3955935', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2281, 'n_words': 422}