Skip to main content
summaryrefslogtreecommitdiffstats
blob: c5970226308c93d98552cf3588ab3835f80f73d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var app = angular.module('OrcsWriterApp', ['ngFileUpload']);

app.controller("FormController", ['$scope', '$http', 'Upload', function($scope, $http, Upload) {

	$scope.formData = {
		filename : '',
		json : ''
	};
	$scope.message = '';

	$scope.validate = function() {
		$scope.run(true);
	}

	$scope.execute = function() {
		$scope.run(false);
	}

	$scope.run = function(validate) {
		$scope.message = '';
		var url = "";
		if (validate) {
			url = "../../writer/validate";
		} else {
			url = "../../writer";
		}
		var data = {};
		if (!$scope.formData.json && !$scope.file) {
			$scope.message = "ERROR: Must select Excel or enter JSON";
		} else if ($scope.formData.json) {
			$scope.message = "Processing JSON";
			data = $scope.formData.json;
			$http({
				method : 'POST',
				url : url,
				data : data,
				headers : {
					'Accept' : 'application/json',
					'Content-Type' : 'application/json'
				}
			}).success(function(data, status, headers, config) {
				$scope.message += "\nValidation Passed";
				if (!validate) {
					$scope.message += "...Execution Succeeded";
				}
			}).error(function(data, status, headers, config) {
				var message = 'error - status: ' + status + ' ' + data;
				if (data.exception) {
					message += ' Exception: ' + data.exception;
				}
				$scope.message += '\n' + message;
			});
		} else if ($scope.file) {
			Upload.upload({
                url: url + '/excel',
                file: $scope.file});
		}
	}
}]);

Back to the top