<commit_before>(function(jQuery) {
"use strict";

if (Echo.AppServer.Dashboard.isDefined("Echo.Apps.TopicRadar.Dashboard")) return;

var dashboard = Echo.AppServer.Dashboard.manifest("Echo.Apps.TopicRadar.Dashboard");

dashboard.inherits = Echo.Utils.getComponent("Echo.AppServer.Dashboards.AppSettings");

dashboard.templates.main =
	'<div class="{class:container}"></div>';

dashboard.vars = {
	"apps": {},
	"meta": {}
};

dashboard.config = {
	"featuredApps": [],
	"disabledApps": ["echo-topic-radar-dev", "echo-topic-radar"]
};

dashboard.events = {
	"Echo.AppServer.Controls.Bundler.Item.onCollapse": function() {
		return {"stop": ["bubble"]};
	},
	"Echo.Apps.TopicRadar.Dashboard.List.onItemAdd": function(_, data) {
		// we should save instance meta if it added
		var item = data.item;
		if (item && item.name === "Echo.Apps.TopicRadar.Dashboard.InstanceList.Instance") {
			var itemId = item.get("data.id");
			var meta = this.get("meta", {});
			meta[itemId] = {
				"appId": item.get("data.app.id")
			};
			this.set("meta", meta);
		}
		this._configChanged();
	},
	"Echo.Apps.TopicRadar.Dashboard.Item.onRemove": function(_, data) {
		this._configChanged();
	},
	"Echo.Apps.TopicRadar.Dashboard.Item.onChange": function() {
		this._configChanged();
	},
	"Echo.Apps.TopicRadar.Dashboard.InstanceList.Instance.onDestroy": function(_, data) {
		var meta = this.get("meta");
		var itemId = data.item && data.item.get("data.id");
		delete meta[itemId];
		this.set("meta", meta);
	}
};

dashboard.init = function() {
	var self = this;
	var parent = $.proxy(this.parent, this);
	this.set("meta", this.get("data.instance.meta", {}));
	this._fetchAppList(function() {
		// TODO BC code. 'Old' instances has appId in the config(not in meta).
		// So, we should find such instances and generate its meta.
		self._generateMeta();
		parent();
	});
};

dashboard.renderers.container = function(element) {
	this.tabList = new Echo.Apps.TopicRadar.Dashboard.TabList({
		"target": element,
		"context": this.config.get("context"),
		"cdnBaseURL": this.config.get("cdnBaseURL"),
		"apps": this.get("apps"),
		"meta": this.get("data.instance.meta", {}),
		"dashboard": {
			"data": this.config.get("data"),
			"events": this.config.get("events"),
			"request": this.config.get("request")
		},
		"data": {
			"value": this.get("data.instance.config.tabs")
		}
	});
	return element;
};

dashboard.methods.update = function(data) {
	var self = this;
	Echo.AppServer.API.request({
		"apiBaseURL": this.config.get("apiBaseURL"),
		"method": "POST",
		"endpoint": "instance/{id}/update",
		"id": this.get("data.instance.id"),
		"data": {
			"data": data
		},
		"onData": function() {
			Echo.Events.publish({
				"topic": "Echo.AppServer.Controls.Dashboard.onConfigChanged",
				"context": self.config.get("context"),
				"data": $.extend({
					"local": true
				}, data)
			});
		}
	}).send();
};

dashboard.methods._configChanged = function() {
	if (this.tabList) {
		this.update({
			"meta": this.get("meta"),
			"config": {
				"tabs": this.tabList.value()
			}
		});
	}<commit_msg>Override 'request' function in config instead of overriding 'update' method<commit_after>(function(jQuery) {
"use strict";

if (Echo.AppServer.Dashboard.isDefined("Echo.Apps.TopicRadar.Dashboard")) return;

var dashboard = Echo.AppServer.Dashboard.manifest("Echo.Apps.TopicRadar.Dashboard");

dashboard.inherits = Echo.Utils.getComponent("Echo.AppServer.Dashboards.AppSettings");

dashboard.templates.main =
	'<div class="{class:container}"></div>';

dashboard.vars = {
	"apps": {},
	"meta": {}
};

dashboard.config = {
	"featuredApps": [],
	"disabledApps": ["echo-topic-radar-dev", "echo-topic-radar"]
};

dashboard.events = {
	"Echo.AppServer.Controls.Bundler.Item.onCollapse": function() {
		return {"stop": ["bubble"]};
	},
	"Echo.Apps.TopicRadar.Dashboard.List.onItemAdd": function(_, data) {
		// we should save instance meta if it added
		var item = data.item;
		if (item && item.name === "Echo.Apps.TopicRadar.Dashboard.InstanceList.Instance") {
			var itemId = item.get("data.id");
			var meta = this.get("meta", {});
			meta[itemId] = {
				"appId": item.get("data.app.id")
			};
			this.set("meta", meta);
		}
		this._configChanged();
	},
	"Echo.Apps.TopicRadar.Dashboard.Item.onRemove": function(_, data) {
		this._configChanged();
	},
	"Echo.Apps.TopicRadar.Dashboard.Item.onChange": function() {
		this._configChanged();
	},
	"Echo.Apps.TopicRadar.Dashboard.InstanceList.Instance.onDestroy": function(_, data) {
		var meta = this.get("meta");
		var itemId = data.item && data.item.get("data.id");
		delete meta[itemId];
		this.set("meta", meta);
	}
};

dashboard.init = function() {
	var self = this;

	// We cannot update instances with large config/meta using GET request (there is limit for URL length).
	// So, we override 'request' function and set method to 'POST' for 'instance/{id}/update' endpoint.
	var parentRequest = this.config.get("request");
	this.config.set("request", function(params) {
		if (params.endpoint === "instance/{data:instance.id}/update") {
			params.method = "POST";
		}
		parentRequest.apply(this, arguments);
	});

	var parent = $.proxy(this.parent, this);
	this.set("meta", this.get("data.instance.meta", {}));
	this._fetchAppList(function() {
		// TODO BC code. 'Old' instances has appId in the config(not in meta).
		// So, we should find such instances and generate its meta.
		self._generateMeta();
		parent();
	});
};

dashboard.renderers.container = function(element) {
	this.tabList = new Echo.Apps.TopicRadar.Dashboard.TabList({
		"target": element,
		"context": this.config.get("context"),
		"cdnBaseURL": this.config.get("cdnBaseURL"),
		"apps": this.get("apps"),
		"meta": this.get("data.instance.meta", {}),
		"dashboard": {
			"data": this.config.get("data"),
			"events": this.config.get("events"),
			"request": this.config.get("request")
		},
		"data": {
			"value": this.get("data.instance.config.tabs")
		}
	});
	return element;
};

dashboard.methods._configChanged = function() {
	if (this.tabList) {
		this.update({
			"meta": this.get("meta"),
			"config": {
				"tabs": this.tabList.value()
			}
		});
	}
{'fraction_non_alphanumeric': 0.19586790304213436, 'fraction_numerical': 0.0, 'mean_word_length': 4.268209083119109, 'pattern_counts': {'":': 61, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4756107', 'n_tokens_mistral': 2318, 'n_tokens_neox': 2189, 'n_words': 385}