<commit_before>(function ($) {

	"use strict";

	var app = angular.module('RbsChange');


	/**
	 * Routes and URL definitions.
	 */
	app.config(['$provide', function ($provide)
	{
		$provide.decorator('RbsChange.UrlManager', ['$delegate', function ($delegate)
		{
			$delegate.model('Rbs_Tag').route('home', 'Rbs/Tag', { 'redirectTo': 'Rbs/Tag/Tag/'});
			$delegate.routesForModels(['Rbs_Tag_Tag']);
			return $delegate;
		}]);
	}]);


	__change.createEditorForModel('Rbs_Tag_Tag');


	//-------------------------------------------------------------------------
	//
	// Configuration and handlers.
	//
	//-------------------------------------------------------------------------


	/**
	 * Attach handlers:
	 * - create new tags in a Document's Editor (pre-save).
	 * - affect tags in a Document's Editor (post-save).
	 * - build predicates for "filter:hasTag" in <rbs-document-list/>.
	 */
	app.run(['RbsChange.TagService', 'RbsChange.Loading', 'RbsChange.Events', 'RbsChange.i18n', '$rootScope', '$q', '$timeout', function (TagService, Loading, Events, i18n, $rootScope, $q, $timeout) {

		// Create new and unsaved tags when an Editor is submitted.
		$rootScope.$on(Events.EditorPreSave, function (event, args) {
			angular.forEach(args.document.META$.tags, function (tag) {
				if (tag.unsaved) {
					args.promises.push(TagService.create(tag));
				}
			});
		});

		// Affect tags to a document that has just been saved in an Editor.
		$rootScope.$on(Events.EditorPostSave, function (event, args) {
			var	doc = args.document,
				tags = doc.META$.tags;
			if (angular.isArray(tags) && tags.length) {
				args.promises.push(TagService.setDocumentTags(doc, tags));
			}
		});

		// Load tags of the document being edited in an Editor.
		$rootScope.$on(Events.EditorLoaded, function (event, args) {
			var doc = args.document;
			if (doc.model !== 'Rbs_Tag_Tag') {
				args.promises.push(doc.loadTags());
			}
		});


		// Filter 'hasTag' for <rbs-document-list/>.
		$rootScope.$on(Events.DocumentListApplyFilter, function (event, args) {
			var	filter = args.filter,
				predicates = args.predicates,
				p, filterName, filterValue, tags;

			p = filter.indexOf(':');
			if (p === -1) {
				return;
			}

			filterName = filter.substring(0, p);
			if (filterName !== 'hasTag') {
				return;
			}

			filterValue = filter.substring(p+1);
			tags = filterValue.split(/,/);
			for (p=0 ; p<tags.length ; p++) {
				predicates.push({
					"op"  : "hasTag",
					"tag" : parseInt(tags[p], 10)
				});
			}
		});

		$rootScope.$on(Events.EditorFormButtonBarContents, function (event, args) {
			if (args.document.model !== 'Rbs_Tag_Tag') {
				args.contents.push('<div>' + i18n.trans('m.rbs.tag.admin.js.tags | ucf')  + '<rbs-tag-selector ng-model="document.META$.tags"></rbs-tag-selector></div>');
			}
		});


		function affectTagToDocuments (tag, documents) {
			var promises = [];
			angular.forEach(documents, function (doc) {
				promises.push(TagService.addTagToDocument(tag, doc));
			});
			return $q.all(promises);
		}


		// Attach 'drop' handler on every <rbs-document-list/> to allow setting a Tag to the selected documents
		// with drag and drop.
		$(document).on({

			'dragover.rbs.tag' : function (e) {
				e.dataTransfer.dropEffect = "copy";
				e.preventDefault();
				e.stopPropagation();
			},

			'drop.rbs.tag' : function (e) {
				e.dataTransfer.dropEffect = "copy";
				e.preventDefault();
				e.stopPropagation();
				var	tag = e.dataTransfer.getData('Rbs/Tag'),
					documents = $(this).scope().selectedDocuments;
				if (tag && documents && documents.length) {
					$timeout(function () {
						Loading.start(i18n.trans('m.rbs.tag.admin.js.applying-tags | ucf | etc'));
						affectTagToDocuments(JSON.parse(tag), documents).then(function () {
							Loading.stop();
						});
					});
				}
			}

		}, 'rbs-document-list');

	}]);


	//-------------------------------------------------------------------------
	//
	// TagService
	//
	//-------------------------------------------------------------------------


	app.service('RbsChange.TagService', ['RbsChange.REST', 'RbsChange.Utils', '$q', '$http', function (REST, Utils, $q, $http) {

		function getIdArray (data) {<commit_msg>Fixed loading indicator problem.<commit_after>(function ($) {

	"use strict";

	var app = angular.module('RbsChange');


	/**
	 * Routes and URL definitions.
	 */
	app.config(['$provide', function ($provide)
	{
		$provide.decorator('RbsChange.UrlManager', ['$delegate', function ($delegate)
		{
			$delegate.model('Rbs_Tag').route('home', 'Rbs/Tag', { 'redirectTo': 'Rbs/Tag/Tag/'});
			$delegate.routesForModels(['Rbs_Tag_Tag']);
			return $delegate;
		}]);
	}]);


	__change.createEditorForModel('Rbs_Tag_Tag');


	//-------------------------------------------------------------------------
	//
	// Configuration and handlers.
	//
	//-------------------------------------------------------------------------


	/**
	 * Attach handlers:
	 * - create new tags in a Document's Editor (pre-save).
	 * - affect tags in a Document's Editor (post-save).
	 * - build predicates for "filter:hasTag" in <rbs-document-list/>.
	 */
	app.run(['RbsChange.TagService', 'RbsChange.Loading', 'RbsChange.Events', 'RbsChange.i18n', '$rootScope', '$q', '$timeout', function (TagService, Loading, Events, i18n, $rootScope, $q, $timeout) {

		// Create new and unsaved tags when an Editor is submitted.
		$rootScope.$on(Events.EditorPreSave, function (event, args) {
			angular.forEach(args.document.META$.tags, function (tag) {
				if (tag.unsaved) {
					args.promises.push(TagService.create(tag));
				}
			});
		});

		// Affect tags to a document that has just been saved in an Editor.
		$rootScope.$on(Events.EditorPostSave, function (event, args) {
			var	doc = args.document,
				tags = doc.META$.tags;
			if (angular.isArray(tags) && tags.length) {
				args.promises.push(TagService.setDocumentTags(doc, tags));
			}
		});

		// Load tags of the document being edited in an Editor.
		$rootScope.$on(Events.EditorLoaded, function (event, args) {
			var doc = args.document;
			if (doc.model !== 'Rbs_Tag_Tag') {
				args.promises.push(doc.loadTags());
			}
		});


		// Filter 'hasTag' for <rbs-document-list/>.
		$rootScope.$on(Events.DocumentListApplyFilter, function (event, args) {
			var	filter = args.filter,
				predicates = args.predicates,
				p, filterName, filterValue, tags;

			p = filter.indexOf(':');
			if (p === -1) {
				return;
			}

			filterName = filter.substring(0, p);
			if (filterName !== 'hasTag') {
				return;
			}

			filterValue = filter.substring(p+1);
			tags = filterValue.split(/,/);
			for (p=0 ; p<tags.length ; p++) {
				predicates.push({
					"op"  : "hasTag",
					"tag" : parseInt(tags[p], 10)
				});
			}
		});

		$rootScope.$on(Events.EditorFormButtonBarContents, function (event, args) {
			if (args.document.model !== 'Rbs_Tag_Tag') {
				args.contents.push('<div>' + i18n.trans('m.rbs.tag.admin.js.tags | ucf')  + '<rbs-tag-selector ng-model="document.META$.tags"></rbs-tag-selector></div>');
			}
		});


		function affectTagToDocuments (tag, documents) {
			var promises = [];
			angular.forEach(documents, function (doc) {
				promises.push(TagService.addTagToDocument(tag, doc));
			});
			return $q.all(promises);
		}


		// Attach 'drop' handler on every <rbs-document-list/> to allow setting a Tag to the selected documents
		// with drag and drop.
		$(document).on({

			'dragover.rbs.tag' : function (e) {
				e.dataTransfer.dropEffect = "copy";
				e.preventDefault();
				e.stopPropagation();
			},

			'drop.rbs.tag' : function (e) {
				e.dataTransfer.dropEffect = "copy";
				e.preventDefault();
				e.stopPropagation();
				var	tag = e.dataTransfer.getData('Rbs/Tag'),
					documents = $(this).scope().selectedDocuments;
				if (tag && documents && documents.length) {
					$timeout(function () {
						Loading.start(i18n.trans('m.rbs.tag.admin.js.applying-tags | ucf | etc'));
						affectTagToDocuments(JSON.parse(tag), documents).then(
							function () {
								Loading.stop();
							},
							function () {
								// TODO Notify user.
								Loading.stop();
							}
						);
					});
				}
			}

		}, 'rbs-document-list');

	}]);


	//-------------------------------------------------------------------------
	//
	// TagService
	//
	//-------------------------------------------------------------------------


	app.service('RbsChange.TagService', ['RbsChange.REST', 'RbsChange.Utils', '$q', '$http', function (REST, Utils, $q, $http) {

		function getIdArray (data) {
{'fraction_non_alphanumeric': 0.23665105386416863, 'fraction_numerical': 0.003278688524590164, 'mean_word_length': 2.4370221327967805, 'pattern_counts': {'":': 0, '<': 19, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7142909', 'n_tokens_mistral': 3264, 'n_tokens_neox': 2724, 'n_words': 545}