Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
Jeremy Mowery | 1b09b33 | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 3 | angular.module('xos.openVPNDashboard', [ |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 4 | 'ngResource', |
| 5 | 'ngCookies', |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 6 | 'ui.router', |
| 7 | 'xos.helpers' |
| 8 | ]) |
| 9 | .config(($stateProvider) => { |
| 10 | $stateProvider |
Jeremy Mowery | 1b09b33 | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 11 | .state('openVPNList', { |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 12 | url: '/', |
Jeremy Mowery | da6bde0 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 13 | template: '<vpn-list></vpn-list>' |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 14 | }); |
| 15 | }) |
Jeremy Mowery | bd3dfae | 2016-03-01 19:15:40 -0700 | [diff] [blame] | 16 | .config(($compileProvider) => { |
| 17 | $compileProvider.aHrefSanitizationWhitelist( |
| 18 | /^\s*(https?|ftp|mailto|tel|file|blob):/); |
| 19 | }) |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 20 | .service('Vpn', function($http, $q){ |
| 21 | |
Jeremy Mowery | da6bde0 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 22 | this.getOpenVpnTenants = () => { |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 23 | let deferred = $q.defer(); |
| 24 | |
Jeremy Mowery | c1dc4d2 | 2016-04-23 14:31:10 -0700 | [diff] [blame] | 25 | $http.get('/api/tenant/openvpn/list/') |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 26 | .then((res) => { |
| 27 | deferred.resolve(res.data) |
| 28 | }) |
| 29 | .catch((e) => { |
| 30 | deferred.reject(e); |
| 31 | }); |
| 32 | |
| 33 | return deferred.promise; |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 34 | } |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 35 | }) |
| 36 | .config(function($httpProvider){ |
| 37 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 38 | }) |
Jeremy Mowery | da6bde0 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 39 | .directive('vpnList', function(){ |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 40 | return { |
| 41 | restrict: 'E', |
| 42 | scope: {}, |
| 43 | bindToController: true, |
| 44 | controllerAs: 'vm', |
Jeremy Mowery | 1b09b33 | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 45 | templateUrl: 'templates/openvpn-list.tpl.html', |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 46 | controller: function(Vpn){ |
Jeremy Mowery | da6bde0 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 47 | Vpn.getOpenVpnTenants() |
Jeremy Mowery | 05cdae8 | 2016-02-28 22:21:54 -0700 | [diff] [blame] | 48 | .then((vpns) => { |
Jeremy Mowery | 42b2c01 | 2016-02-25 11:25:53 -0700 | [diff] [blame] | 49 | this.vpns = vpns; |
Jeremy Mowery | 47c9374 | 2016-03-02 00:01:25 -0700 | [diff] [blame] | 50 | for (var i = 0; i < this.vpns.length; i++) { |
Jeremy Mowery | 5ab3415 | 2016-04-17 19:20:01 -0700 | [diff] [blame] | 51 | var blob = new Blob([this.vpns[i].script_text], {type: 'text/plain'}); |
Jeremy Mowery | 47c9374 | 2016-03-02 00:01:25 -0700 | [diff] [blame] | 52 | this.vpns[i].script_text = (window.URL || window.webkitURL).createObjectURL( blob ); |
| 53 | } |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 54 | }) |
| 55 | .catch((e) => { |
| 56 | throw new Error(e); |
| 57 | }); |
Jeremy Mowery | 33e861a | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 58 | } |
| 59 | }; |
Jeremy Mowery | 159f97b | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 60 | }); |