<commit_before>"use strict";
var contentBuilderService = soajsApp.components;
contentBuilderService.service('cbHelper', ['ngDataApi', '$timeout', '$modal', '$window', function(ngDataApi, $timeout, $modal, $window) {

	function listEntries(currentScope, moduleConfig, callback) {
		getSendDataFromServer(currentScope, ngDataApi, {
			"method": "get",
			"routeName": (callback && typeof(callback) === 'function') ? "/dashboard/cb/listRevisions" : "/dashboard/cb/list",
			"params": {}
		}, function(error, response) {
			if(error) {
				currentScope.$parent.displayAlert("danger", error.message);
			}
			else {
				if(callback && typeof(callback) === 'function') {
					return callback(response);
				}
				else {
					printEntries(currentScope, response, moduleConfig.grid.active);
				}
			}
		});
	}

	function printEntries(currentScope, response, grid, viewOnly) {
		var options = {
			data: response,
			grid: grid,
			defaultSortField: grid.defaultSortField,
			left: [],
			top: []
		};

		if(currentScope.access.getService) {
			options.left.push({
				'label': translation.view[LANG],
				'icon': 'search',
				'handler': 'viewService'
			});
		}

		if(currentScope.access.updateService && !viewOnly) {
			options.left.push({
				'label': translation.edit[LANG],
				'icon': 'pencil2',
				'handler': 'editService'
			});
		}
		buildGrid(currentScope, options);
	}

	function viewEntry(currentScope, params, cb) {
		getSendDataFromServer(currentScope, ngDataApi, {
			"method": "get",
			"routeName": "/dashboard/cb/get",
			"params": params
		}, function(error, response) {
			if(error) {
				currentScope.$parent.displayAlert("danger", error.message);
			}
			else {
				if(cb && typeof(cb) === 'function') {
					return cb(response);
				}
				else {
					$modal.open({
						templateUrl: "serviceInfoBox.html",
						size: 'lg',
						backdrop: true,
						keyboard: true,
						controller: function($scope, $modalInstance) {
							$scope.data = response;

							if(Object.keys($scope.data.soajsService.db.config).length === 0) {
								delete $scope.data.soajsService.db.config;
							}
							var errorCodes = $scope.data.genericService.config.errors;
							var str = "";
							for(var err in errorCodes) {
								str += "<li class='APIInputBox mb5'><b>" + err + "</b>:&nbsp;" + errorCodes[err] + "</li>"
							}
							str = "<ul class='apiErrorCodes'>" + str + "</ul>";
							$scope.data.genericService.config.errors = str;


							for(var api in $scope.data.soajsService.apis) {
								if($scope.data.soajsService.apis.hasOwnProperty(api)) {
									for(var stepName in $scope.data.soajsService.apis[api].workflow) {
										if($scope.data.soajsService.apis[api].workflow.hasOwnProperty(stepName)) {
											$scope.data.soajsService.apis[api].workflow[stepName] = $scope.data.soajsService.apis[api].workflow[stepName].replace(/\\n/g, "<br />");
										}
									}
								}
							}
                            var files = [];
							for(var i = 0; i < $scope.data.soajsUI.form.add.length; i++) {
                                if($scope.data.soajsUI.form.add[i].limit !== undefined){
                                    files.push(angular.copy($scope.data.soajsUI.form.add[i]));
                                }
								$scope.data.soajsUI.form.add[i].print = JSON.stringify($scope.data.soajsUI.form.add[i], null, 2);
							}

							for(var i = 0; i < $scope.data.soajsUI.form.update.length; i++) {
								$scope.data.soajsUI.form.update[i].print = JSON.stringify($scope.data.soajsUI.form.update[i], null, 2);
							}

                            $scope.data.genericService.config.maxFileUpload = parseInt($scope.data.genericService.config.maxFileUpload);
                            $scope.data.files = files;
							setTimeout(function() {highlightMyCode()}, 500);
							$scope.ok = function() {
								$modalInstance.dismiss('ok');
							};
						}
					});
				}
			}
		});
	}

	/*
	 Step 1
	 */
	function getEmptySchema(currentScope) {
		currentScope.config = {
			"name": "",
			"dbtoUse": {},
			"clustertoUse": {},
			"genericService": {
				"config": {
					"errors": {},
					"schema": {
						"commonFields": {
							"id": {
								"source": ['query.id'],
								"req": true,
								"validation": {
									"type": "string"
								}
							}
						}
					}<commit_msg>Added service group for GCS.<commit_after>"use strict";
var contentBuilderService = soajsApp.components;
contentBuilderService.service('cbHelper', ['ngDataApi', '$timeout', '$modal', '$window', function(ngDataApi, $timeout, $modal, $window) {

	function listEntries(currentScope, moduleConfig, callback) {
		getSendDataFromServer(currentScope, ngDataApi, {
			"method": "get",
			"routeName": (callback && typeof(callback) === 'function') ? "/dashboard/cb/listRevisions" : "/dashboard/cb/list",
			"params": {}
		}, function(error, response) {
			if(error) {
				currentScope.$parent.displayAlert("danger", error.message);
			}
			else {
				if(callback && typeof(callback) === 'function') {
					return callback(response);
				}
				else {
					printEntries(currentScope, response, moduleConfig.grid.active);
				}
			}
		});
	}

	function printEntries(currentScope, response, grid, viewOnly) {
		var options = {
			data: response,
			grid: grid,
			defaultSortField: grid.defaultSortField,
			left: [],
			top: []
		};

		if(currentScope.access.getService) {
			options.left.push({
				'label': translation.view[LANG],
				'icon': 'search',
				'handler': 'viewService'
			});
		}

		if(currentScope.access.updateService && !viewOnly) {
			options.left.push({
				'label': translation.edit[LANG],
				'icon': 'pencil2',
				'handler': 'editService'
			});
		}
		buildGrid(currentScope, options);
	}

	function viewEntry(currentScope, params, cb) {
		getSendDataFromServer(currentScope, ngDataApi, {
			"method": "get",
			"routeName": "/dashboard/cb/get",
			"params": params
		}, function(error, response) {
			if(error) {
				currentScope.$parent.displayAlert("danger", error.message);
			}
			else {
				if(cb && typeof(cb) === 'function') {
					return cb(response);
				}
				else {
					$modal.open({
						templateUrl: "serviceInfoBox.html",
						size: 'lg',
						backdrop: true,
						keyboard: true,
						controller: function($scope, $modalInstance) {
							$scope.data = response;

							if(Object.keys($scope.data.soajsService.db.config).length === 0) {
								delete $scope.data.soajsService.db.config;
							}
							var errorCodes = $scope.data.genericService.config.errors;
							var str = "";
							for(var err in errorCodes) {
								str += "<li class='APIInputBox mb5'><b>" + err + "</b>:&nbsp;" + errorCodes[err] + "</li>"
							}
							str = "<ul class='apiErrorCodes'>" + str + "</ul>";
							$scope.data.genericService.config.errors = str;


							for(var api in $scope.data.soajsService.apis) {
								if($scope.data.soajsService.apis.hasOwnProperty(api)) {
									for(var stepName in $scope.data.soajsService.apis[api].workflow) {
										if($scope.data.soajsService.apis[api].workflow.hasOwnProperty(stepName)) {
											$scope.data.soajsService.apis[api].workflow[stepName] = $scope.data.soajsService.apis[api].workflow[stepName].replace(/\\n/g, "<br />");
										}
									}
								}
							}
                            var files = [];
							for(var i = 0; i < $scope.data.soajsUI.form.add.length; i++) {
                                if($scope.data.soajsUI.form.add[i].limit !== undefined){
                                    files.push(angular.copy($scope.data.soajsUI.form.add[i]));
                                }
								$scope.data.soajsUI.form.add[i].print = JSON.stringify($scope.data.soajsUI.form.add[i], null, 2);
							}

							for(var i = 0; i < $scope.data.soajsUI.form.update.length; i++) {
								$scope.data.soajsUI.form.update[i].print = JSON.stringify($scope.data.soajsUI.form.update[i], null, 2);
							}

                            $scope.data.genericService.config.maxFileUpload = parseInt($scope.data.genericService.config.maxFileUpload);
                            $scope.data.files = files;
							setTimeout(function() {highlightMyCode()}, 500);
							$scope.ok = function() {
								$modalInstance.dismiss('ok');
							};
						}
					});
				}
			}
		});
	}

	/*
	 Step 1
	 */
	function getEmptySchema(currentScope) {
		currentScope.config = {
			"name": "",
			"dbtoUse": {},
			"clustertoUse": {},
			"genericService": {
				"config": {
					"serviceGroup": "GCS Group",
					"errors": {},
					"schema": {
						"commonFields": {
							"id": {
								"source": ['query.id'],
								"req": true,
								"validation": {
									"type": "string"
								}
							}
						}
					}
{'fraction_non_alphanumeric': 0.1692095904554319, 'fraction_numerical': 0.002523804061030171, 'mean_word_length': 2.515322580645161, 'pattern_counts': {'":': 39, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3955196', 'n_tokens_mistral': 3713, 'n_tokens_neox': 2799, 'n_words': 433}