<commit_before>'use strict';

(function () {
    var view = app.commentsView = kendo.observable();
    var provider = app.data.defaultProvider;
    var commentsData = provider.data('Comments');
    var commentsListScroller;

    var commentsViewModel = kendo.observable({
        commentsDataSource: [],
        currentActivityId: null,

        _getCommentsDataSource: function (filter) {
            return new kendo.data.DataSource({
                type: 'everlive',
                transport: {
                    typeName: 'Comments',
                    read: {
                        headers: {
                            'X-Everlive-Expand': JSON.stringify({
                                CreatedBy: {
                                    TargetTypeName: 'Users',
                                    ReturnAs: 'User',
                                    Expand: {
                                        Picture: {
                                            TargetTypeName: 'System.Files',
                                            ReturnAs: 'PictureUrl',
                                            SingleField: 'Uri'
                                        }
                                    }
                                }
                            })
                        }
                    }
                },
                change: function () {
                    var data = this.data();

                    data.forEach(function (comment) {
                        comment.CreatedAt = kendo.toString(new Date(comment.CreatedAt), app.constants.dateFormat);
                        comment.User = comment.User || {DisplayName: 'Anonymous'};
                        comment.User.PictureUrl = comment.User.PictureUrl || app.constants.defaultPicture;
                    });
                },
                filter: filter || {},
                serverFiltering: true,
                serverPaging: true,
                error: app.notify.error,
                pageSize: 20
            });
        },
        onShow: function (e) {
            app.utils.loading(true);

            var activityId = e.view.params.activityId;

            commentsListScroller = e.view.scroller;
            commentsListScroller.reset();

            this.set('currentActivityId', activityId);

            var commentsDataSource = this._getCommentsDataSource({
                field: 'ActivityId',
                operator: 'eq',
                value: this.currentActivityId
            });

            this.set('commentsDataSource', commentsDataSource);

            commentsDataSource.one('change', function () {
                if (!commentsDataSource.data().length) {
                    this.addComment(true);
                }

                app.utils.loading(false);
            }.bind(this));
        },
        editComment: function (e) {
            var commentId = e.data.Id;
            app.mobileApp.navigate('#components/commentsView/addEdit.html?commentId=' + commentId);
        },
        removeComment: function (e) {
            var commentId = e.data.Id;
            app.notify.confirmation(null, 'Remove comment', function (confirmed) {
                app.activitiesView.shouldRefresh = true;
                if (!confirmed) {
                    return;
                }

                var comment = this.commentsDataSource.get(commentId);
                this.commentsDataSource.remove(comment);
                this.commentsDataSource.sync().then(function () {
                    return this.commentsDataSource.read();
                }.bind(this), app.notify.error).then(function () {
                    if (!this.commentsDataSource.data().length) {
                        app.mobileApp.navigate('#components/activitiesView/view.html');
                    }
                }.bind(this), app.notify.error);
            }.bind(this));
        },
        addComment: function (replace) {
            app.activitiesView.shouldRefresh = true;
            var view = '#components/commentsView/addEdit.html?activityId=' + this.currentActivityId;
            if (replace) {
                app.mobileApp.replace(view);
            } else {
                app.mobileApp.navigate(view);
            }
        }
    });

    var addEditCommentsViewModel = kendo.observable({
        activityId: null,
        commentId: null,
        comment: null,
        isEdit: false,
        fields: {
            comment: ''
        },
        onShow: function (e) {
            var params = e.view.params;
            var textarea = $('#comment-text');

            if (params.activityId) {
                this.set('activityId', params.activityId);<commit_msg>fixed navigating to activity details when delete last comment<commit_after>'use strict';

(function () {
    var view = app.commentsView = kendo.observable();
    var provider = app.data.defaultProvider;
    var commentsData = provider.data('Comments');
    var commentsListScroller;

    var commentsViewModel = kendo.observable({
        commentsDataSource: [],
        currentActivityId: null,

        _getCommentsDataSource: function (filter) {
            return new kendo.data.DataSource({
                type: 'everlive',
                transport: {
                    typeName: 'Comments',
                    read: {
                        headers: {
                            'X-Everlive-Expand': JSON.stringify({
                                CreatedBy: {
                                    TargetTypeName: 'Users',
                                    ReturnAs: 'User',
                                    Expand: {
                                        Picture: {
                                            TargetTypeName: 'System.Files',
                                            ReturnAs: 'PictureUrl',
                                            SingleField: 'Uri'
                                        }
                                    }
                                }
                            })
                        }
                    }
                },
                change: function () {
                    var data = this.data();

                    data.forEach(function (comment) {
                        comment.CreatedAt = kendo.toString(new Date(comment.CreatedAt), app.constants.dateFormat);
                        comment.User = comment.User || {DisplayName: 'Anonymous'};
                        comment.User.PictureUrl = comment.User.PictureUrl || app.constants.defaultPicture;
                    });
                },
                filter: filter || {},
                serverFiltering: true,
                serverPaging: true,
                error: app.notify.error,
                pageSize: 20
            });
        },
        onShow: function (e) {
            app.utils.loading(true);

            var activityId = e.view.params.activityId;

            commentsListScroller = e.view.scroller;
            commentsListScroller.reset();

            this.set('currentActivityId', activityId);

            var commentsDataSource = this._getCommentsDataSource({
                field: 'ActivityId',
                operator: 'eq',
                value: this.currentActivityId
            });

            this.set('commentsDataSource', commentsDataSource);

            commentsDataSource.one('change', function () {
                if (!commentsDataSource.data().length) {
                    this.addComment(true);
                }

                app.utils.loading(false);
            }.bind(this));
        },
        editComment: function (e) {
            var commentId = e.data.Id;
            app.mobileApp.navigate('#components/commentsView/addEdit.html?commentId=' + commentId);
        },
        removeComment: function (e) {
            var commentId = e.data.Id;
            app.notify.confirmation(null, 'Remove comment', function (confirmed) {
                app.utils.loading(true);
                app.activitiesView.shouldRefresh = true;
                if (!confirmed) {
                    return;
                }

                var comment = this.commentsDataSource.get(commentId);
                this.commentsDataSource.remove(comment);
                this.commentsDataSource.sync().then(function () {
                    return this.commentsDataSource.read();
                }.bind(this), app.notify.error).then(function () {
                    if (!this.commentsDataSource.data().length) {
                        app.mobileApp.navigate('#components/activitiesView/details.html?id=' + this.currentActivityId);
                    }
                    app.utils.loading(false);
                }.bind(this), app.notify.error);
            }.bind(this));
        },
        addComment: function (replace) {
            app.activitiesView.shouldRefresh = true;
            var view = '#components/commentsView/addEdit.html?activityId=' + this.currentActivityId;
            if (replace) {
                app.mobileApp.replace(view);
            } else {
                app.mobileApp.navigate(view);
            }
        }
    });

    var addEditCommentsViewModel = kendo.observable({
        activityId: null,
        commentId: null,
        comment: null,
        isEdit: false,
        fields: {
            comment: ''
        },
        onShow: function (e) {
            var params = e.view.params;
            var textarea = $('#comment-text');

            if (params.activityId) {
                this.set('activityId', params.activityId);
{'fraction_non_alphanumeric': 0.10153556878721404, 'fraction_numerical': 0.00041784184686096315, 'mean_word_length': 1.1999080882352942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4177', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2081, 'n_words': 382}