<commit_before>(function () {

	'use strict';
// =========================================================================
//
// topic routes (under admin)
//
// =========================================================================
	angular.module('codelists').config(['$stateProvider', function ($stateProvider) {
		$stateProvider
		// -------------------------------------------------------------------------
		//
		// this is the abstract, top level view for codelists.
		// we resolve codelists to all sub-states
		//
		// -------------------------------------------------------------------------
		.state('admin.codelist', {
			data: {permissions: ['manageCodeLists']},
			abstract: true,
			url: '/codelists',
			template: '<ui-view></ui-view>',
			resolve: {
				codelists: function ($stateParams, CodeListModel) {
					return CodeListModel.getCollection();
				}
			}
		})
		// -------------------------------------------------------------------------
		//
		// the list state for codeLists
		//
		// -------------------------------------------------------------------------
		.state('admin.codelist.list', {
			url: '/:codelistName',
			templateUrl: 'modules/code-lists/client/views/code-list-list.html',
			controllerAs: 'vm',
			controller: function ($scope, $state, $stateParams, $modal, _, NgTableParams, AlertService, CodeListModel, codelists) {
				var vm = this;

				// UI selects which code list to work with. Reload the table:
				vm.changeFieldType = transition;

				vm.codelists = codelists;

				vm.codelistNames = _.pluck(vm.codelists, 'name');

				vm.codelistName = $stateParams.codelistName || 'salutations';

				vm.currentField = _.find(codelists, {name: vm.codelistName});

				vm.nonEmptyFields = _.filter(vm.currentField.items, function (o) {
					return o.value !== '';
				});

				vm.fields = _.sortByOrder(vm.nonEmptyFields, ['active', 'displayPriority', 'display'], ['desc', 'desc', 'asc']);

				// UI invokes add or edit item within current codelist
				vm.openAddEdit = function (item) {
					addEditModal($scope, $modal, vm.currentField, item, onSuccess);
				};

				vm.tableParams = new NgTableParams();
				vm.tableParams.settings({dataset: vm.fields});

				function onSuccess(item, display, displayPriority, active) {
					var newItem = {
						value: item ? item.value : display,
						display: display,
						displayPriority: displayPriority,
						active: active
					};
					var others = !item ? vm.nonEmptyFields : _.filter(vm.nonEmptyFields, function (o) {
							return o.value !== item.value;
						});
					others.push(newItem);
					var newSorted = _.sortByOrder(others, ['active', 'displayPriority', 'display'], ['desc', 'desc', 'asc']);
					vm.currentField.items = newSorted;
					CodeListModel.save(vm.currentField)
					.then(function () {
						transition();
					})
					.catch(function (err) {
						console.error(err);
					});
				}

				function transition() {
					var name = vm.currentField.name;
					$state.transitionTo('admin.codelist.list', {codelistName: name}, {
						reload: true, inherit: false, notify: true
					});
				}<commit_msg>ESM-865 force system reload of code lists after edit<commit_after>(function () {

	'use strict';
// =========================================================================
//
// topic routes (under admin)
//
// =========================================================================
	angular.module('codelists').config(['$stateProvider', function ($stateProvider) {
		$stateProvider
		// -------------------------------------------------------------------------
		//
		// this is the abstract, top level view for codelists.
		// we resolve codelists to all sub-states
		//
		// -------------------------------------------------------------------------
		.state('admin.codelist', {
			data: {permissions: ['manageCodeLists']},
			abstract: true,
			url: '/codelists',
			template: '<ui-view></ui-view>',
			resolve: {
				codelists: function ($stateParams, CodeListModel) {
					return CodeListModel.getCollection();
				}
			}
		})
		// -------------------------------------------------------------------------
		//
		// the list state for codeLists
		//
		// -------------------------------------------------------------------------
		.state('admin.codelist.list', {
			url: '/:codelistName',
			templateUrl: 'modules/code-lists/client/views/code-list-list.html',
			controllerAs: 'vm',
			controller: function ($scope, $state, $stateParams, $modal, _, NgTableParams, AlertService, CodeListModel, codelists, CodeLists) {
				var vm = this;

				// UI selects which code list to work with. Reload the table:
				vm.changeFieldType = transition;

				vm.codelists = codelists;

				vm.codelistNames = _.pluck(vm.codelists, 'name');

				vm.codelistName = $stateParams.codelistName || 'salutations';

				vm.currentField = _.find(codelists, {name: vm.codelistName});

				vm.nonEmptyFields = _.filter(vm.currentField.items, function (o) {
					return o.value !== '';
				});

				vm.fields = _.sortByOrder(vm.nonEmptyFields, ['active', 'displayPriority', 'display'], ['desc', 'desc', 'asc']);

				// UI invokes add or edit item within current codelist
				vm.openAddEdit = function (item) {
					addEditModal($scope, $modal, vm.currentField, item, onSuccess);
				};

				vm.tableParams = new NgTableParams();
				vm.tableParams.settings({dataset: vm.fields});

				function onSuccess(item, display, displayPriority, active) {
					var newItem = {
						value: item ? item.value : display,
						display: display,
						displayPriority: displayPriority,
						active: active
					};
					var others = !item ? vm.nonEmptyFields : _.filter(vm.nonEmptyFields, function (o) {
							return o.value !== item.value;
						});
					others.push(newItem);
					var newSorted = _.sortByOrder(others, ['active', 'displayPriority', 'display'], ['desc', 'desc', 'asc']);
					vm.currentField.items = newSorted;
					CodeListModel.save(vm.currentField)
					.then(function() {
						CodeLists.refresh();
					})
					.then(function () {
						transition();
					})
					.catch(function (err) {
						console.error(err);
					});
				}

				function transition() {
					var name = vm.currentField.name;
					$state.transitionTo('admin.codelist.list', {codelistName: name}, {
						reload: true, inherit: false, notify: true
					});
				}
{'fraction_non_alphanumeric': 0.2713227179568028, 'fraction_numerical': 0.00047296232066845344, 'mean_word_length': 2.2516658124038953, 'pattern_counts': {'":': 0, '<': 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': '4224796', 'n_tokens_mistral': 2221, 'n_tokens_neox': 1707, 'n_words': 387}