forked from Freifunk-Sankt-Augustin/md-fw-dl
-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
executable file
·106 lines (82 loc) · 3.97 KB
/
app.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Copyright 2015 PetaByteBoy
This file is part of the Material Design Firmware Downloader.
The Material Design Firmware Downloader is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The Material Design Firmware Downloader is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Material Design Firmware Downloader. If not, see <http://www.gnu.org/licenses/>. */
angular.module('firmwareDownload', ['ngMaterial', 'leaflet-directive'])
.controller('DownloadCtrl', function($scope, $location, $interpolate, $filter, $http, leafletData){
mapTools.prepare(config.sites);
$scope.config = config;
leafletData.getGeoJSON().then(function(lObjs){
window.leafletDataGeoJSON = lObjs;
});
mapTools.initMap($scope, $http);
$scope.$on("leafletDirectiveGeoJson.dommap.mouseover", function(ev, leafletPayload) {
mapTools.mouseOver($scope, ev, leafletPayload);
});
$scope.$on("leafletDirectiveGeoJson.dommap.mouseout", function(ev, leafletPayload) {
mapTools.mouseOut($scope, ev, leafletPayload);
});
//TODO: better way for "external" updating layer style
$scope.$watch("selectedSite", function(newValue, oldValue) {
mapTools.watchSelectedSite($scope, leafletData, newValue, oldValue);
});
$scope.$on("leafletDirectiveGeoJson.dommap.click", function(ev, leafletPayload) {
mapTools.onLeafletDirectiveGeoJsonDommapClick($scope, $filter, ev, leafletPayload);
});
$scope.parse = function (string) {
try {
return JSON.parse(string);
} catch (error) {}
};
$scope.splitString = function (string, nb) {
return string.substring(0,nb);
};
$scope.interpolate = function (value) {
try {
if (typeof(value) != undefined) {
return $interpolate(value)($scope);
}
} catch (error) {}
};
$scope.buildFirmwareUrl = function() {
var site = angular.fromJson($scope.selectedSite);
if (site != null && site.proxy_to != null){
$scope.downloadableSite = $filter('json')(config.sites[site.proxy_to]);
}else {
$scope.downloadableSite = angular.copy($scope.selectedSite);
}
var url = $scope.interpolate(config.url);
var manufacturer = angular.fromJson($scope.selectedManufacturer);
var router = angular.fromJson($scope.selectedRouter);
if (manufacturer == null || router == null) {
return url;
}
if ('extensionupgrade' in router && $scope.selectedMode == 'sysupgrade') {
url += '.'+router.extensionupgrade;
} else if ( 'extension' in router) {
url += '.'+router.extension;
} else {
url += '.bin';
}
return url;
};
//select factory by default
$scope.selectedMode = "factory";
//read selection from url parameters
if($location.search().mode != null) { $scope.selectedMode = $location.search().mode; }
if($location.search().region != null) { $scope.selectedSite = $filter('json')(config.sites[$location.search().region]); }
if($location.search().manufacturer != null) { $scope.selectedManufacturer = $filter('json')(config.manufacturers[$location.search().manufacturer]); }
if($location.search().router != null) { $scope.selectedRouter = $filter('json')(config.routers[$location.search().router]); }
})
//make parameters work without #! in the url
.config(function($locationProvider) {
$locationProvider.html5Mode({ enabled: true, requireBase: false });
});