<commit_before>angular.module("sagremorApp")
    .controller("DashboardCtrl", 
    function($scope, $location, $translate, $timeout, toaster, sharedData, sagremorParams, sagremorService, sagremorEdit, benoicFactory, carleonFactory, sagGenericInjectorManager, carleonComponentsConfig) {

        var self = this;

		this._timeout = null;
		this.sagremorParams = sagremorParams;
		this.profileName = "";
		
        this.options = {
            cellHeight: 100,
            verticalHargin: 10,
            disableResize: false
        };
        
        this.init = function () {
            getDashboardElements();
			self.menu = [
				{
					name: "remove_from_dashboard", 
					display: $translate.instant("remove_from_dashboard"), 
					action: function (param) {
						self.removeFromDashboard(param);
					}
				}
			];
		};
		
		this.menuSelect = function(menuItem, element) {
			menuItem.action(element);
		};
		
		this.addTitleLine = function () {
			return sagremorEdit.open($translate.instant("dashboard_add_line"), $translate.instant("dashboard_add_line_value")).then(function (result) {
				newDashboardSeparator(result.value);
			});
		};

        function getDashboardElements () {
            self.dashboardWidgets = [];
            if (!!sagremorParams.currentProfile) {
				getDashboardElementsCurrentProfiles();
			} else {
				getDashboardElementsNoProfile();
			}
        }
        
        function getDashboardElementsNoProfile () {
			// Carleon not enabled, adding all benoic elements to the dashboard (if enabled)
			if (sagremorParams.benoicEnabled) {
				var defaultTag = "SGMR$D$";
				var defaultY = 0;
				
				var x = 0;
				_.forEach(sharedData.all("benoicDevices"), function (device) {
					if (!!device.element) {
						_.forEach(device.element.sensors, function (element, name) {
							element.type = "sensor";
							element.device = device.name;
							element.name = name;
							addBenoicElementToDashboard(element, defaultTag + x + "$" + defaultY);
							x += 2;
						});
					}
				});
				addDashboardSeparator($translate.instant("sensors_title"), defaultTag + x + "$" + defaultY);
				
				var x = 0;
				_.forEach(sharedData.all("benoicDevices"), function (device) {
					if (!!device.element) {
						_.forEach(device.element.heaters, function (element, name) {
							element.type = "heater";
							element.device = device.name;
							element.name = name;
							addBenoicElementToDashboard(element, defaultTag + x + "$" + defaultY);
							x += 2;
						});
					}
				});
				addDashboardSeparator($translate.instant("heaters_title"), defaultTag + x + "$" + defaultY);;
				
				var x = 0;
				_.forEach(sharedData.all("benoicDevices"), function (device) {
					if (!!device.element) {
						_.forEach(device.element.dimmers, function (element, name) {
							element.type = "dimmer";
							element.device = device.name;
							element.name = name;
							addBenoicElementToDashboard(element, defaultTag + x + "$" + defaultY);
							x += 2;
						});
					}
				});
				var x = 0;
				_.forEach(sharedData.all("benoicDevices"), function (device) {
					if (!!device.element) {
						_.forEach(device.element.switches, function (element, name) {
							element.type = "switch";
							element.device = device.name;
							element.name = name;
							addBenoicElementToDashboard(element, defaultTag + x + "$" + defaultY);
							x += 2;
						});
					}
				});
				addDashboardSeparator($translate.instant("switches_title"), defaultTag + x + "$" + defaultY);
				
			}
		}

        function getDashboardElementsCurrentProfiles () {
            var profile = sagremorParams.currentProfile;
            if (!!profile) {
				self.profileName = profile.name;
			} else {
				self.profileName = "";
			}
			if (!!profile && !!profile.addTo && !!profile.addTo.D) {
				_.forEach(profile.addTo.D, function (element) {
					if (!!element.device) {
						if (sagremorParams.benoicEnabled) {
							addBenoicElementToDashboard(element, element.tag);
						}
					} else if (element.type === "script") {
						addScriptToDashboard(element, element.tag);
					} else if (element.type === "scheduler" || element.type === "trigger") {
						addEventToDashboard(element, element.tag);
					} else if (element.type === "separator") {
						addDashboardSeparator(element.name, element.tag);
					} else if (element.type === "monitor") {
						addMonitorToDashboard(element, element.tag);
					} else if (sagremorParams.carleonEnabled) {
						addCarleonElementToDashboard(element, element.tag);
					}
				});
			}
        }

        function addBenoicElementToDashboard(element, tag) {
            var tagParams = tag.split("$");
            if (tagParams.length >= 4) {
                var x = tagParams[2];
                var y = tagParams[3];
                var curHeight = 1;
                if (element.type === "dimmer" || element.type === "heater") {
                    curHeight = 2;
                }
                var bElt = sagremorService.getBenoicElement(element.device, element.type, element.name);
                if (!!bElt) {
					bElt.device = element.device;
					bElt.name = element.name;
					var dashboardElement = { type: element.type, device: element.device, name: element.name, element: bElt, x: x, y: y, width: 2, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
            }
        }
        
        function addScriptToDashboard(element, tag) {
			var elt = sharedData.get("angharadScripts", element.name);
			if (!!elt) {
				var tagParams = tag.split("$");
				if (tagParams.length >= 4) {
					var x = tagParams[2];
					var y = tagParams[3];
					var curHeight = 1;
					var dashboardElement = { type: element.type, name: element.name, element: elt, x: x, y: y, width: 2, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
			}
		}
        
        function addEventToDashboard(element, tag) {
			var elt = false;
			if (element.type === "scheduler") {
				elt = sharedData.get("angharadSchedulers", element.name);
			} else {
				elt = sharedData.get("angharadTriggers", element.name);
			}
			if (!!elt) {
				var tagParams = tag.split("$");
				if (tagParams.length >= 4) {
					var x = tagParams[2];
					var y = tagParams[3];
					var curHeight = element.type === "scheduler"?2:1;
					var dashboardElement = { type: element.type, name: element.name, element: elt, x: x, y: y, width: 2, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
			}
		}
        
        function addCarleonElementToDashboard(element, tag) {
			var injector = _.find(sagGenericInjectorManager.components, function (inject) {
				return inject.type === element.type && !!carleonComponentsConfig[inject.type] && !!carleonComponentsConfig[inject.type].enabled;
			});
			var service = sharedData.get("carleonServices", element.type);
			var elt = _.find(service.element, function (cElt) {
				return cElt.name === element.name;
			});
			if (!!elt) {
				var tagParams = tag.split("$");
				if (tagParams.length >= 4) {
					var x = tagParams[2];
					var y = tagParams[3];
					var curHeight = injector.widgetHeight;
					var dashboardElement = { type: element.type, name: element.name, element: element, x: x, y: y, width: 2, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
			}
        }
        
        function addMonitorToDashboard(element, tag) {
			var elt = _.find(sagremorParams.currentProfile.monitorList, function (monitor) {
				return monitor.name === element.name;
			});
			if (!!elt) {
				var tagParams = tag.split("$");
				if (tagParams.length >= 4) {
					var x = tagParams[2];
					var y = tagParams[3];
					var curHeight = 4;
					var dashboardElement = { type: element.type, name: element.name, element: elt, x: x, y: y, width: 6, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
			}
		}
        <commit_msg>Implement injector.widgetWidth<commit_after>angular.module("sagremorApp")
    .controller("DashboardCtrl", 
    function($scope, $location, $translate, $timeout, toaster, sharedData, sagremorParams, sagremorService, sagremorEdit, benoicFactory, carleonFactory, sagGenericInjectorManager, carleonComponentsConfig) {

        var self = this;

		this._timeout = null;
		this.sagremorParams = sagremorParams;
		this.profileName = "";
		
        this.options = {
            cellHeight: 100,
            verticalHargin: 10,
            disableResize: false
        };
        
        this.init = function () {
            getDashboardElements();
			self.menu = [
				{
					name: "remove_from_dashboard", 
					display: $translate.instant("remove_from_dashboard"), 
					action: function (param) {
						self.removeFromDashboard(param);
					}
				}
			];
		};
		
		this.menuSelect = function(menuItem, element) {
			menuItem.action(element);
		};
		
		this.addTitleLine = function () {
			return sagremorEdit.open($translate.instant("dashboard_add_line"), $translate.instant("dashboard_add_line_value")).then(function (result) {
				newDashboardSeparator(result.value);
			});
		};

        function getDashboardElements () {
            self.dashboardWidgets = [];
            if (!!sagremorParams.currentProfile) {
				getDashboardElementsCurrentProfiles();
			} else {
				getDashboardElementsNoProfile();
			}
        }
        
        function getDashboardElementsNoProfile () {
			// Carleon not enabled, adding all benoic elements to the dashboard (if enabled)
			if (sagremorParams.benoicEnabled) {
				var defaultTag = "SGMR$D$";
				var defaultY = 0;
				
				var x = 0;
				_.forEach(sharedData.all("benoicDevices"), function (device) {
					if (!!device.element) {
						_.forEach(device.element.sensors, function (element, name) {
							element.type = "sensor";
							element.device = device.name;
							element.name = name;
							addBenoicElementToDashboard(element, defaultTag + x + "$" + defaultY);
							x += 2;
						});
					}
				});
				addDashboardSeparator($translate.instant("sensors_title"), defaultTag + x + "$" + defaultY);
				
				var x = 0;
				_.forEach(sharedData.all("benoicDevices"), function (device) {
					if (!!device.element) {
						_.forEach(device.element.heaters, function (element, name) {
							element.type = "heater";
							element.device = device.name;
							element.name = name;
							addBenoicElementToDashboard(element, defaultTag + x + "$" + defaultY);
							x += 2;
						});
					}
				});
				addDashboardSeparator($translate.instant("heaters_title"), defaultTag + x + "$" + defaultY);;
				
				var x = 0;
				_.forEach(sharedData.all("benoicDevices"), function (device) {
					if (!!device.element) {
						_.forEach(device.element.dimmers, function (element, name) {
							element.type = "dimmer";
							element.device = device.name;
							element.name = name;
							addBenoicElementToDashboard(element, defaultTag + x + "$" + defaultY);
							x += 2;
						});
					}
				});
				var x = 0;
				_.forEach(sharedData.all("benoicDevices"), function (device) {
					if (!!device.element) {
						_.forEach(device.element.switches, function (element, name) {
							element.type = "switch";
							element.device = device.name;
							element.name = name;
							addBenoicElementToDashboard(element, defaultTag + x + "$" + defaultY);
							x += 2;
						});
					}
				});
				addDashboardSeparator($translate.instant("switches_title"), defaultTag + x + "$" + defaultY);
				
			}
		}

        function getDashboardElementsCurrentProfiles () {
            var profile = sagremorParams.currentProfile;
            if (!!profile) {
				self.profileName = profile.name;
			} else {
				self.profileName = "";
			}
			if (!!profile && !!profile.addTo && !!profile.addTo.D) {
				_.forEach(profile.addTo.D, function (element) {
					if (!!element.device) {
						if (sagremorParams.benoicEnabled) {
							addBenoicElementToDashboard(element, element.tag);
						}
					} else if (element.type === "script") {
						addScriptToDashboard(element, element.tag);
					} else if (element.type === "scheduler" || element.type === "trigger") {
						addEventToDashboard(element, element.tag);
					} else if (element.type === "separator") {
						addDashboardSeparator(element.name, element.tag);
					} else if (element.type === "monitor") {
						addMonitorToDashboard(element, element.tag);
					} else if (sagremorParams.carleonEnabled) {
						addCarleonElementToDashboard(element, element.tag);
					}
				});
			}
        }

        function addBenoicElementToDashboard(element, tag) {
            var tagParams = tag.split("$");
            if (tagParams.length >= 4) {
                var x = tagParams[2];
                var y = tagParams[3];
                var curHeight = 1;
                if (element.type === "dimmer" || element.type === "heater") {
                    curHeight = 2;
                }
                var bElt = sagremorService.getBenoicElement(element.device, element.type, element.name);
                if (!!bElt) {
					bElt.device = element.device;
					bElt.name = element.name;
					var dashboardElement = { type: element.type, device: element.device, name: element.name, element: bElt, x: x, y: y, width: 2, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
            }
        }
        
        function addScriptToDashboard(element, tag) {
			var elt = sharedData.get("angharadScripts", element.name);
			if (!!elt) {
				var tagParams = tag.split("$");
				if (tagParams.length >= 4) {
					var x = tagParams[2];
					var y = tagParams[3];
					var curHeight = 1;
					var dashboardElement = { type: element.type, name: element.name, element: elt, x: x, y: y, width: 2, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
			}
		}
        
        function addEventToDashboard(element, tag) {
			var elt = false;
			if (element.type === "scheduler") {
				elt = sharedData.get("angharadSchedulers", element.name);
			} else {
				elt = sharedData.get("angharadTriggers", element.name);
			}
			if (!!elt) {
				var tagParams = tag.split("$");
				if (tagParams.length >= 4) {
					var x = tagParams[2];
					var y = tagParams[3];
					var curHeight = element.type === "scheduler"?2:1;
					var dashboardElement = { type: element.type, name: element.name, element: elt, x: x, y: y, width: 2, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
			}
		}
        
        function addCarleonElementToDashboard(element, tag) {
			var injector = _.find(sagGenericInjectorManager.components, function (inject) {
				return inject.type === element.type && !!carleonComponentsConfig[inject.type] && !!carleonComponentsConfig[inject.type].enabled;
			});
			var service = sharedData.get("carleonServices", element.type);
			var elt = _.find(service.element, function (cElt) {
				return cElt.name === element.name;
			});
			if (!!elt) {
				var tagParams = tag.split("$");
				if (tagParams.length >= 4) {
					var x = tagParams[2];
					var y = tagParams[3];
					var curHeight = injector.widgetHeight;
					var curWidth = injector.widgetWidth;
					var dashboardElement = { type: element.type, name: element.name, element: element, x: x, y: y, width: curWidth, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
			}
        }
        
        function addMonitorToDashboard(element, tag) {
			var elt = _.find(sagremorParams.currentProfile.monitorList, function (monitor) {
				return monitor.name === element.name;
			});
			if (!!elt) {
				var tagParams = tag.split("$");
				if (tagParams.length >= 4) {
					var x = tagParams[2];
					var y = tagParams[3];
					var curHeight = 4;
					var dashboardElement = { type: element.type, name: element.name, element: elt, x: x, y: y, width: 6, height: curHeight, tag: tag };
					self.dashboardWidgets.push(dashboardElement);
				}
			}
		}
        
{'fraction_non_alphanumeric': 0.1374922021210231, 'fraction_numerical': 0.004928259513412352, 'mean_word_length': 2.6592102259758046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4811728', 'n_tokens_mistral': 6266, 'n_tokens_neox': 5017, 'n_words': 1018}