Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 19 | 'use strict'; |
| 20 | |
Jeremy Mowery | 81e84cc | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 21 | angular.module('xos.openVPNDashboard', [ |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 22 | 'ngResource', |
| 23 | 'ngCookies', |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 24 | 'ui.router', |
| 25 | 'xos.helpers' |
| 26 | ]) |
| 27 | .config(($stateProvider) => { |
| 28 | $stateProvider |
Jeremy Mowery | 81e84cc | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 29 | .state('openVPNList', { |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 30 | url: '/', |
Jeremy Mowery | 41d6e88 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 31 | template: '<vpn-list></vpn-list>' |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 32 | }); |
| 33 | }) |
Jeremy Mowery | c257c41 | 2016-03-01 19:15:40 -0700 | [diff] [blame] | 34 | .config(($compileProvider) => { |
| 35 | $compileProvider.aHrefSanitizationWhitelist( |
| 36 | /^\s*(https?|ftp|mailto|tel|file|blob):/); |
| 37 | }) |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 38 | .service('Vpn', function($http, $q){ |
| 39 | |
Jeremy Mowery | 41d6e88 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 40 | this.getOpenVpnTenants = () => { |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 41 | let deferred = $q.defer(); |
| 42 | |
Jeremy Mowery | 441c3d6 | 2016-04-23 14:31:10 -0700 | [diff] [blame] | 43 | $http.get('/api/tenant/openvpn/list/') |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 44 | .then((res) => { |
| 45 | deferred.resolve(res.data) |
| 46 | }) |
| 47 | .catch((e) => { |
| 48 | deferred.reject(e); |
| 49 | }); |
| 50 | |
| 51 | return deferred.promise; |
Jeremy Mowery | c770ba0 | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 52 | } |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 53 | }) |
| 54 | .config(function($httpProvider){ |
| 55 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 56 | }) |
Jeremy Mowery | 41d6e88 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 57 | .directive('vpnList', function(){ |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 58 | return { |
| 59 | restrict: 'E', |
| 60 | scope: {}, |
| 61 | bindToController: true, |
| 62 | controllerAs: 'vm', |
Jeremy Mowery | 81e84cc | 2016-04-19 17:01:48 -0700 | [diff] [blame] | 63 | templateUrl: 'templates/openvpn-list.tpl.html', |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 64 | controller: function(Vpn){ |
Jeremy Mowery | 41d6e88 | 2016-04-19 19:31:11 -0700 | [diff] [blame] | 65 | Vpn.getOpenVpnTenants() |
Jeremy Mowery | e84e3ee | 2016-02-28 22:21:54 -0700 | [diff] [blame] | 66 | .then((vpns) => { |
Jeremy Mowery | 98dd6c8 | 2016-02-25 11:25:53 -0700 | [diff] [blame] | 67 | this.vpns = vpns; |
Jeremy Mowery | 37e4efe | 2016-03-02 00:01:25 -0700 | [diff] [blame] | 68 | for (var i = 0; i < this.vpns.length; i++) { |
Jeremy Mowery | ee13991 | 2016-04-17 19:20:01 -0700 | [diff] [blame] | 69 | var blob = new Blob([this.vpns[i].script_text], {type: 'text/plain'}); |
Jeremy Mowery | 37e4efe | 2016-03-02 00:01:25 -0700 | [diff] [blame] | 70 | this.vpns[i].script_text = (window.URL || window.webkitURL).createObjectURL( blob ); |
| 71 | } |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 72 | }) |
| 73 | .catch((e) => { |
| 74 | throw new Error(e); |
| 75 | }); |
Jeremy Mowery | c770ba0 | 2016-02-25 18:14:03 -0700 | [diff] [blame] | 76 | } |
| 77 | }; |
Jeremy Mowery | 6efeb7a | 2016-02-25 09:32:00 -0700 | [diff] [blame] | 78 | }); |