<commit_before>/**
 * BMotion Studio for ProB Editor Module
 *
 */
define(['prob.modal', 'bms.common', 'bms.nodejs', 'ng-electron'], function () {

    var module = angular.module('prob.iframe.editor', ['prob.modal', 'bms.common', 'bms.nodejs', 'ngElectron'])
        .directive('bmsVisualisationEditor', ['bmsVisualizationService', 'bmsModalService', 'bmsMainService', '$q', '$http', 'fs', '$rootScope', 'electron',
            function (bmsVisualizationService, bmsModalService, bmsMainService, $q, $http, fs, $rootScope, electron) {
                return {
                    replace: false,
                    scope: {
                        svg: '@bmsSvgFile',
                        id: '@bmsVisualisationId',
                        view: '@bmsVisualisationView',
                        sessionId: '@bmsVisualisationEditor'
                    },
                    template: '<iframe src="editor/editor.html" class="editorIframe"></iframe>',
                    controller: ['$scope', '$rootScope', function ($scope, $rootScope) {

                        // Parent API (called from prob.template)
                        // --------------------------------------

                        $scope.addObserver = function (type, data) {
                            bmsVisualizationService.addObserver($scope.id, {
                                type: type,
                                data: data
                            }, 'json');
                        };

                        $scope.addEvent = function (type, data) {
                            bmsVisualizationService.addEvent($scope.id, {
                                type: type,
                                data: data
                            }, 'json');
                        };

                        $scope.disableEditor = function (reason) {
                            bmsVisualizationService.disableTab($scope.svg, reason);
                        };

                        $scope.openDialog = function (msg, cb) {
                            electron.dialog.showMessageBox({
                                title: "Please confirm",
                                type: "info",
                                buttons: ["Ok", "Cancel"],
                                message: msg,
                            }, cb);
                        };

                        // --------------------------------------

                        $scope.bmsModalService = bmsModalService;

                        $scope.init = function () {

                            var defer = $q.defer();

                            var vis = bmsVisualizationService.getVisualization($scope.id);
                            if (vis) {
                                $http.get(vis['templateFolder'] + '/' + $scope.svg).success(function (svgContent) {
                                    defer.resolve({
                                        vis: vis,
                                        svgFile: $scope.svg,
                                        svgContent: svgContent
                                    });
                                }).error(function () {
                                    defer.reject("Some error occurred while requesting SVG file " + $scope.svg);
                                });
                            } else {
                                defer.reject("No visualisation found with id " + $scope.id);
                            }

                            return defer.promise;

                        };

                        var saveSvg = function (templateFolder, svg) {
                            var defer = $q.defer();
                            fs.writeFile(templateFolder + '/' + $scope.svg, svg,
                                function (err) {
                                    if (err) {
                                        defer.reject("An error occurred while writing svg file " + $scope.svg + ": " + err);
                                    } else {
                                        defer.resolve();
                                    }
                                });
                            return defer.promise;
                        };

                        var saveObservers = function (templateFolder, viewData) {
                            var defer = $q.defer();
                            var jsonObservers = {observers: bmsVisualizationService.getJsonObservers($scope.id)};
                            var jsonString = JSON.stringify(jsonObservers, null, "    ");
                            var observersViewPath = viewData['observers'] ? viewData['observers'] : viewData['id'] + '.observers.json';
                            fs.writeFile(templateFolder + '/' + observersViewPath, jsonString,
                                function (err) {
                                    if (err) {
                                        defer.reject("An error occurred while writing file " + observersViewPath + ": " + err);
                                    } else {
                                        defer.resolve();
                                    }
                                });
                            return defer.promise;
                        };
<commit_msg>fixed saving svg with images (set correct path)<commit_after>/**
 * BMotion Studio for ProB Editor Module
 *
 */
define(['prob.modal', 'bms.common', 'bms.nodejs', 'ng-electron'], function () {

    var module = angular.module('prob.iframe.editor', ['prob.modal', 'bms.common', 'bms.nodejs', 'ngElectron'])
        .directive('bmsVisualisationEditor', ['bmsVisualizationService', 'bmsModalService', 'bmsMainService', '$q', '$http', 'fs', '$rootScope', 'electron',
            function (bmsVisualizationService, bmsModalService, bmsMainService, $q, $http, fs, $rootScope, electron) {
                return {
                    replace: false,
                    scope: {
                        svg: '@bmsSvgFile',
                        id: '@bmsVisualisationId',
                        view: '@bmsVisualisationView',
                        sessionId: '@bmsVisualisationEditor'
                    },
                    template: '<iframe src="editor/editor.html" class="editorIframe"></iframe>',
                    controller: ['$scope', '$rootScope', function ($scope, $rootScope) {

                        // Parent API (called from prob.template)
                        // --------------------------------------

                        $scope.addObserver = function (type, data) {
                            bmsVisualizationService.addObserver($scope.id, {
                                type: type,
                                data: data
                            }, 'json');
                        };

                        $scope.addEvent = function (type, data) {
                            bmsVisualizationService.addEvent($scope.id, {
                                type: type,
                                data: data
                            }, 'json');
                        };

                        $scope.disableEditor = function (reason) {
                            bmsVisualizationService.disableTab($scope.svg, reason);
                        };

                        $scope.openDialog = function (msg, cb) {
                            electron.dialog.showMessageBox({
                                title: "Please confirm",
                                type: "info",
                                buttons: ["Ok", "Cancel"],
                                message: msg,
                            }, cb);
                        };

                        // --------------------------------------

                        $scope.bmsModalService = bmsModalService;

                        $scope.init = function () {

                            var defer = $q.defer();

                            var vis = bmsVisualizationService.getVisualization($scope.id);
                            if (vis) {
                                $http.get(vis['templateFolder'] + '/' + $scope.svg).success(function (svgContent) {
                                    defer.resolve({
                                        vis: vis,
                                        svgFile: $scope.svg,
                                        svgContent: svgContent
                                    });
                                }).error(function () {
                                    defer.reject("Some error occurred while requesting SVG file " + $scope.svg);
                                });
                            } else {
                                defer.reject("No visualisation found with id " + $scope.id);
                            }

                            return defer.promise;

                        };

                        var saveSvg = function (templateFolder, svg) {
                            var defer = $q.defer();
                            svg = svg.replace(templateFolder + '/', "");
                            fs.writeFile(templateFolder + '/' + $scope.svg, svg,
                                function (err) {
                                    if (err) {
                                        defer.reject("An error occurred while writing svg file " + $scope.svg + ": " + err);
                                    } else {
                                        defer.resolve();
                                    }
                                });
                            return defer.promise;
                        };

                        var saveObservers = function (templateFolder, viewData) {
                            var defer = $q.defer();
                            var jsonObservers = {observers: bmsVisualizationService.getJsonObservers($scope.id)};
                            var jsonString = JSON.stringify(jsonObservers, null, "    ");
                            var observersViewPath = viewData['observers'] ? viewData['observers'] : viewData['id'] + '.observers.json';
                            fs.writeFile(templateFolder + '/' + observersViewPath, jsonString,
                                function (err) {
                                    if (err) {
                                        defer.reject("An error occurred while writing file " + observersViewPath + ": " + err);
                                    } else {
                                        defer.resolve();
                                    }
                                });
                            return defer.promise;
                        };

{'fraction_non_alphanumeric': 0.11143365483659519, 'fraction_numerical': 0.0, 'mean_word_length': 0.8375774260151411, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2745503', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2118, 'n_words': 437}