blob: 6f6bce23f11d3344282c569c5d894848d4b9bfd5 [file] [log] [blame]
Jeremy Mowery159f97b2016-02-25 09:32:00 -07001'use strict';
2
Jeremy Mowery1b09b332016-04-19 17:01:48 -07003angular.module('xos.openVPNDashboard', [
Jeremy Mowery159f97b2016-02-25 09:32:00 -07004 'ngResource',
5 'ngCookies',
Jeremy Mowery159f97b2016-02-25 09:32:00 -07006 'ui.router',
7 'xos.helpers'
8])
9.config(($stateProvider) => {
10 $stateProvider
Jeremy Mowery1b09b332016-04-19 17:01:48 -070011 .state('openVPNList', {
Jeremy Mowery159f97b2016-02-25 09:32:00 -070012 url: '/',
Jeremy Moweryda6bde02016-04-19 19:31:11 -070013 template: '<vpn-list></vpn-list>'
Jeremy Mowery159f97b2016-02-25 09:32:00 -070014 });
15})
Jeremy Mowerybd3dfae2016-03-01 19:15:40 -070016.config(($compileProvider) => {
17 $compileProvider.aHrefSanitizationWhitelist(
18 /^\s*(https?|ftp|mailto|tel|file|blob):/);
19})
Jeremy Mowery159f97b2016-02-25 09:32:00 -070020.service('Vpn', function($http, $q){
21
Jeremy Moweryda6bde02016-04-19 19:31:11 -070022 this.getOpenVpnTenants = () => {
Jeremy Mowery159f97b2016-02-25 09:32:00 -070023 let deferred = $q.defer();
24
Jeremy Moweryc1dc4d22016-04-23 14:31:10 -070025 $http.get('/api/tenant/openvpn/list/')
Jeremy Mowery159f97b2016-02-25 09:32:00 -070026 .then((res) => {
27 deferred.resolve(res.data)
28 })
29 .catch((e) => {
30 deferred.reject(e);
31 });
32
33 return deferred.promise;
Jeremy Mowery33e861a2016-02-25 18:14:03 -070034 }
Jeremy Mowery159f97b2016-02-25 09:32:00 -070035})
36.config(function($httpProvider){
37 $httpProvider.interceptors.push('NoHyperlinks');
38})
Jeremy Moweryda6bde02016-04-19 19:31:11 -070039.directive('vpnList', function(){
Jeremy Mowery159f97b2016-02-25 09:32:00 -070040 return {
41 restrict: 'E',
42 scope: {},
43 bindToController: true,
44 controllerAs: 'vm',
Jeremy Mowery1b09b332016-04-19 17:01:48 -070045 templateUrl: 'templates/openvpn-list.tpl.html',
Jeremy Mowery159f97b2016-02-25 09:32:00 -070046 controller: function(Vpn){
Jeremy Moweryda6bde02016-04-19 19:31:11 -070047 Vpn.getOpenVpnTenants()
Jeremy Mowery05cdae82016-02-28 22:21:54 -070048 .then((vpns) => {
Jeremy Mowery42b2c012016-02-25 11:25:53 -070049 this.vpns = vpns;
Jeremy Mowery47c93742016-03-02 00:01:25 -070050 for (var i = 0; i < this.vpns.length; i++) {
Jeremy Mowery5ab34152016-04-17 19:20:01 -070051 var blob = new Blob([this.vpns[i].script_text], {type: 'text/plain'});
Jeremy Mowery47c93742016-03-02 00:01:25 -070052 this.vpns[i].script_text = (window.URL || window.webkitURL).createObjectURL( blob );
53 }
Jeremy Mowery159f97b2016-02-25 09:32:00 -070054 })
55 .catch((e) => {
56 throw new Error(e);
57 });
Jeremy Mowery33e861a2016-02-25 18:14:03 -070058 }
59 };
Jeremy Mowery159f97b2016-02-25 09:32:00 -070060});