<commit_before>'use strict';

angular.module('chronontology.controllers')

.controller("PeriodController", function($scope, $location, $routeParams, $http, $sce, chronontologySettings) {

	// possible relations
	// (labels are now in transl8 keys "relation_isSenseOf" etc.)
	$scope.internalRelations = chronontologySettings.internalRelations;
	$scope.gazetteerRelations = chronontologySettings.gazetteerRelations;

	// store related periods, should be a central app-wide cache
	$scope.relatedDocuments = {};

	$http.get('/data/period/' + $routeParams.id).success( function(result) {

		$scope.activeTab = 'info';
		$scope.document = result;
		$scope.period = result.resource;

		var geoFrameUrl = chronontologySettings.geoFrameBaseUri + "?uri=" + chronontologySettings.baseUri;
		$scope.geoFrameUrl = $sce.trustAsResourceUrl(geoFrameUrl + "/period/" + result.resource.id);

		// note: for(var relation in $scope.internalRelations) would yield 0, 1, 2, ...
		for(var i = 0; i < $scope.internalRelations.length; i += 1) {
			var relation = $scope.internalRelations[i];
			$scope.relatedDocuments[relation] = [];
			if($scope.period.relations[relation]) $scope.period.relations[relation].forEach(function(periodUri) {
				(function(relation) {
					$http.get('/data/period/'+periodUri).success(function(result) {
						$scope.relatedDocuments[relation].push(result);
					})
				}(relation));
			});
		}

		$http.get('/data/period/?size=1000&q=provenance:' + $scope.period.provenance).success( function(result) {
			$scope.provenancePeriods = result.results;
		});

	});

	$scope.exportJSON = function() {
		var JSONexport = angular.toJson($scope.period, true);
		var blob = new Blob([JSONexport], {type: "text/plain;charset=utf-8"});
		saveAs(blob, 'period-' + $scope.period.id + ".json");
	};

	$scope.savePeriod = function(updatedPeriod) {

        $scope.period = angular.copy(updatedPeriod);
        $scope.document.resource = $scope.period;

		$http.put("/data/period/" + $scope.period.id, JSON.stringify($scope.document))
			.success(function (data) {
				//putMsg('ui.update.success', 'success')
				console.log("success");
				console.dir(data);
		})
			.error(function (data) {
                console.log("error");
                console.dir(data);
		});
    }
});<commit_msg>Redirect to info tab after saving edits.<commit_after>'use strict';

angular.module('chronontology.controllers')

.controller("PeriodController", function($scope, $location, $routeParams, $http, $sce, chronontologySettings) {

	// possible relations
	// (labels are now in transl8 keys "relation_isSenseOf" etc.)
	$scope.internalRelations = chronontologySettings.internalRelations;
	$scope.gazetteerRelations = chronontologySettings.gazetteerRelations;

	// store related periods, should be a central app-wide cache
	$scope.relatedDocuments = {};

	$http.get('/data/period/' + $routeParams.id).success( function(result) {

		$scope.activeTab = 'info';
		$scope.document = result;
		$scope.period = result.resource;

		var geoFrameUrl = chronontologySettings.geoFrameBaseUri + "?uri=" + chronontologySettings.baseUri;
		$scope.geoFrameUrl = $sce.trustAsResourceUrl(geoFrameUrl + "/period/" + result.resource.id);

		// note: for(var relation in $scope.internalRelations) would yield 0, 1, 2, ...
		for(var i = 0; i < $scope.internalRelations.length; i += 1) {
			var relation = $scope.internalRelations[i];
			$scope.relatedDocuments[relation] = [];
			if($scope.period.relations[relation]) $scope.period.relations[relation].forEach(function(periodUri) {
				(function(relation) {
					$http.get('/data/period/'+periodUri).success(function(result) {
						$scope.relatedDocuments[relation].push(result);
					})
				}(relation));
			});
		}

		$http.get('/data/period/?size=1000&q=provenance:' + $scope.period.provenance).success( function(result) {
			$scope.provenancePeriods = result.results;
		});

	});

	$scope.exportJSON = function() {
		var JSONexport = angular.toJson($scope.period, true);
		var blob = new Blob([JSONexport], {type: "text/plain;charset=utf-8"});
		saveAs(blob, 'period-' + $scope.period.id + ".json");
	};

	$scope.savePeriod = function(updatedPeriod) {

        $scope.period = angular.copy(updatedPeriod);
        $scope.document.resource = $scope.period;

		$http.put("/data/period/" + $scope.period.id, JSON.stringify($scope.document))
			.success(function (data) {
				console.log("success");
				console.dir(data);

				$scope.activeTab = 'info';
		})
			.error(function (data) {
                console.log("error");
                console.dir(data);
		});
    }
});
{'fraction_non_alphanumeric': 0.16535776614310646, 'fraction_numerical': 0.004799301919720768, 'mean_word_length': 4.1807909604519775, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1766202', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1417, 'n_words': 244}