Skip to content

Commit 290ea49

Browse files
committed
KML upload
Missed KML upload in new admin page refactor. Adding back in.
1 parent c8c4584 commit 290ea49

File tree

5 files changed

+65
-80
lines changed

5 files changed

+65
-80
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "MAGE",
3-
"version": "3.0.0",
4-
"description": "Geo spatial situation awareness application",
3+
"version": "4.0.0",
4+
"description": "Geospatial situation awareness application",
55
"keywords": [
66
"NGA",
77
"MAGE"
@@ -35,7 +35,7 @@
3535
"migrate": "0.1.6",
3636
"moment": "2.1.0",
3737
"mongodb-migrations": "0.2.1",
38-
"mongoose": "4.1.3",
38+
"mongoose": "4.2.7",
3939
"multer": "0.1.x",
4040
"optimist": "0.3.x",
4141
"passport": "0.1.x",

public/app/admin/layers/layer.controller.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@ angular
22
.module('mage')
33
.controller('AdminLayerController', AdminLayerController);
44

5-
AdminLayerController.$inject = ['$scope', '$modal', '$routeParams', '$location', '$filter', 'Layer', 'Event'];
5+
AdminLayerController.$inject = ['$scope', '$modal', '$routeParams', '$location', '$filter', 'Layer', 'Event', 'LocalStorageService'];
66

7-
function AdminLayerController($scope, $modal, $routeParams, $location, $filter, Layer, Event) {
7+
function AdminLayerController($scope, $modal, $routeParams, $location, $filter, Layer, Event, LocalStorageService) {
88

99
$scope.layerEvents = [];
1010
$scope.nonTeamEvents = [];
1111
$scope.eventsPage = 0;
1212
$scope.eventsPerPage = 10;
1313

14+
$scope.fileUploadOptions = {
15+
acceptFileTypes: /(\.|\/)(kml)$/i,
16+
url: '/api/layers/' + $routeParams.layerId + '/kml?access_token=' + LocalStorageService.getToken(),
17+
};
18+
$scope.uploads = [{}];
19+
$scope.uploadConfirmed = false;
20+
1421
Layer.get({id: $routeParams.layerId}, function(layer) {
1522
$scope.layer = layer;
1623

@@ -87,4 +94,12 @@ function AdminLayerController($scope, $modal, $routeParams, $location, $filter,
8794
$location.path('/admin/layers');
8895
});
8996
}
97+
98+
$scope.addUploadFile = function() {
99+
$scope.uploads.push({});
100+
}
101+
102+
$scope.confirmUpload = function() {
103+
$scope.uploadConfirmed = true;
104+
}
90105
}

public/app/admin/layers/layer.edit.controller.js

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ function AdminLayerEditController($scope, $injector, $location, $routeParams, Lo
88
$scope.wmsFormats = ['image/jpeg', 'image/png'];
99
$scope.wmsVersions = ['1.1.1', '1.3.0'];
1010

11-
$scope.fileUploadOptions = {
12-
acceptFileTypes: /(\.|\/)(kml)$/i,
13-
};
14-
1511
if ($routeParams.layerId) {
1612
Layer.get({id: $routeParams.layerId}, function(layer) {
1713
$scope.layer = layer;
18-
$scope.fileUploadOptions.url = '/api/layers/' + layer.id + '/kml?access_token=' + LocalStorageService.getToken()
1914
});
2015
} else {
2116
$scope.layer = new Layer();
@@ -32,65 +27,4 @@ function AdminLayerEditController($scope, $injector, $location, $routeParams, Lo
3227
$scope.cancel = function() {
3328
$location.path('/admin/layers/' + $scope.layer.id);
3429
}
35-
36-
$scope.addAnotherFile = function() {
37-
$scope.uploads.push({});
38-
}
39-
40-
$scope.confirmUpload = function() {
41-
$scope.uploadConfirmed = true;
42-
}
43-
44-
$scope.setFiles = function (element) {
45-
$scope.$apply(function(scope) {
46-
console.log('files:', element.files);
47-
// Turn the FileList object into an Array
48-
$scope.files = []
49-
for (var i = 0; i < element.files.length; i++) {
50-
$scope.files.push(element.files[i])
51-
}
52-
$scope.progressVisible = false
53-
});
54-
}
55-
56-
$scope.uploadFile = function() {
57-
var fd = new FormData()
58-
for (var i in $scope.files) {
59-
fd.append("attachment", $scope.files[i])
60-
}
61-
var xhr = new XMLHttpRequest()
62-
xhr.upload.addEventListener("progress", uploadProgress, false)
63-
xhr.addEventListener("load", uploadComplete, false)
64-
xhr.addEventListener("error", uploadFailed, false)
65-
xhr.addEventListener("abort", uploadCanceled, false)
66-
xhr.open("POST", $scope.fileUploadUrl)
67-
$scope.progressVisible = true
68-
xhr.send(fd)
69-
}
70-
71-
function uploadProgress(evt) {
72-
$scope.$apply(function(){
73-
if (evt.lengthComputable) {
74-
$scope.progress = Math.round(evt.loaded * 100 / evt.total)
75-
} else {
76-
$scope.progress = 'unable to compute'
77-
}
78-
});
79-
}
80-
81-
function uploadComplete(evt) {
82-
$scope.files = [];
83-
$scope.progressVisible = false
84-
}
85-
86-
function uploadFailed(evt) {
87-
alert("There was an error attempting to upload the file.")
88-
}
89-
90-
function uploadCanceled(evt) {
91-
$scope.$apply(function(){
92-
$scope.progressVisible = false
93-
})
94-
alert("The upload has been canceled by the user or the browser dropped the connection.")
95-
}
9630
}

public/app/admin/layers/layer.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,42 @@ <h2>
239239
</div>
240240
</div>
241241
</div>
242+
243+
<div class="col-md-6 col-xs-12">
244+
<div class="row">
245+
<div class="col-md-12">
246+
<nav class="navbar navbar-default admin-dashboard-navbar">
247+
<div class="container-fluid">
248+
<div class="navbar-header">
249+
<a class="navbar-brand">Add KML data</a>
250+
</div>
251+
</div>
252+
</nav>
253+
</div>
254+
</div>
255+
256+
<div class="admin-table">
257+
<div class="well-item">
258+
<div ng-show="layer.type == 'Feature'">
259+
<div ng-repeat="upload in uploads" class="bottom-gap">
260+
<form enctype="multipart/form-data" file-upload url="{{fileUploadOptions.url}}" allow-upload="uploadConfirmed" upload-file-form-name="'file'">
261+
</form>
262+
</div>
263+
</div>
264+
265+
<hr>
266+
267+
<div class="row">
268+
<div class="col-md-12">
269+
<button class="btn btn-primary" ng-click="addUploadFile()">Add KML File</button>
270+
<button class="btn btn-success" ng-click="confirmUpload()">Upload File(s)</button>
271+
</div>
272+
</div>
273+
</div>
274+
</div>
275+
276+
</div>
277+
242278
</div>
243279

244280
</div>

public/app/file-upload/file-upload.directive.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
</div>
88
</div>
99

10-
<div class="row" ng-show="uploading || uploadStatus">
11-
<div class="col-md-12">
12-
<div class="progress" ng-show="uploading">
13-
<div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" style="width: {{uploadProgress}}%;">
14-
</div>
15-
</div>
16-
</div>
17-
</div>
18-
1910
<div class="row">
2011
<div class="col-md-12">
2112
<span class="file-input btn btn-default btn-file" ng-show="type == 'button'">
@@ -33,4 +24,13 @@
3324
</div>
3425
</div>
3526

27+
<div class="row top-gap-s" ng-show="uploading || uploadStatus">
28+
<div class="col-md-12">
29+
<div class="progress" ng-show="uploading">
30+
<div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" style="width: {{uploadProgress}}%;">
31+
</div>
32+
</div>
33+
</div>
34+
</div>
35+
3636
</div>

0 commit comments

Comments
 (0)