blob: b16c2fbea8528a70b1699b9e03e615576eb8026e [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',
6 'ngLodash',
7 'ui.router',
8 'xos.helpers'
9])
10.config(($stateProvider) => {
11 $stateProvider
Jeremy Mowery1b09b332016-04-19 17:01:48 -070012 .state('openVPNList', {
Jeremy Mowery159f97b2016-02-25 09:32:00 -070013 url: '/',
Jeremy Moweryda6bde02016-04-19 19:31:11 -070014 template: '<vpn-list></vpn-list>'
Jeremy Mowery159f97b2016-02-25 09:32:00 -070015 });
16})
Jeremy Mowerybd3dfae2016-03-01 19:15:40 -070017.config(($compileProvider) => {
18 $compileProvider.aHrefSanitizationWhitelist(
19 /^\s*(https?|ftp|mailto|tel|file|blob):/);
20})
Jeremy Mowery159f97b2016-02-25 09:32:00 -070021.service('Vpn', function($http, $q){
22
Jeremy Moweryda6bde02016-04-19 19:31:11 -070023 this.getOpenVpnTenants = () => {
Jeremy Mowery159f97b2016-02-25 09:32:00 -070024 let deferred = $q.defer();
25
Jeremy Moweryc1dc4d22016-04-23 14:31:10 -070026 $http.get('/api/tenant/openvpn/list/')
Jeremy Mowery159f97b2016-02-25 09:32:00 -070027 .then((res) => {
28 deferred.resolve(res.data)
29 })
30 .catch((e) => {
31 deferred.reject(e);
32 });
33
34 return deferred.promise;
Jeremy Mowery33e861a2016-02-25 18:14:03 -070035 }
Jeremy Mowery159f97b2016-02-25 09:32:00 -070036})
37.config(function($httpProvider){
38 $httpProvider.interceptors.push('NoHyperlinks');
39})
Jeremy Moweryda6bde02016-04-19 19:31:11 -070040.directive('vpnList', function(){
Jeremy Mowery159f97b2016-02-25 09:32:00 -070041 return {
42 restrict: 'E',
43 scope: {},
44 bindToController: true,
45 controllerAs: 'vm',
Jeremy Mowery1b09b332016-04-19 17:01:48 -070046 templateUrl: 'templates/openvpn-list.tpl.html',
Jeremy Mowery159f97b2016-02-25 09:32:00 -070047 controller: function(Vpn){
Jeremy Moweryda6bde02016-04-19 19:31:11 -070048 Vpn.getOpenVpnTenants()
Jeremy Mowery05cdae82016-02-28 22:21:54 -070049 .then((vpns) => {
Jeremy Mowery42b2c012016-02-25 11:25:53 -070050 this.vpns = vpns;
Jeremy Mowery47c93742016-03-02 00:01:25 -070051 for (var i = 0; i < this.vpns.length; i++) {
Jeremy Mowery5ab34152016-04-17 19:20:01 -070052 var blob = new Blob([this.vpns[i].script_text], {type: 'text/plain'});
Jeremy Mowery47c93742016-03-02 00:01:25 -070053 this.vpns[i].script_text = (window.URL || window.webkitURL).createObjectURL( blob );
54 }
Jeremy Mowery159f97b2016-02-25 09:32:00 -070055 })
56 .catch((e) => {
57 throw new Error(e);
58 });
Jeremy Mowery33e861a2016-02-25 18:14:03 -070059 }
60 };
Jeremy Mowery159f97b2016-02-25 09:32:00 -070061});