blob: b16c2fbea8528a70b1699b9e03e615576eb8026e [file] [log] [blame]
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -07001'use strict';
2
Jeremy Mowery81e84cc2016-04-19 17:01:48 -07003angular.module('xos.openVPNDashboard', [
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -07004 'ngResource',
5 'ngCookies',
6 'ngLodash',
7 'ui.router',
8 'xos.helpers'
9])
10.config(($stateProvider) => {
11 $stateProvider
Jeremy Mowery81e84cc2016-04-19 17:01:48 -070012 .state('openVPNList', {
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070013 url: '/',
Jeremy Mowery41d6e882016-04-19 19:31:11 -070014 template: '<vpn-list></vpn-list>'
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070015 });
16})
Jeremy Moweryc257c412016-03-01 19:15:40 -070017.config(($compileProvider) => {
18 $compileProvider.aHrefSanitizationWhitelist(
19 /^\s*(https?|ftp|mailto|tel|file|blob):/);
20})
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070021.service('Vpn', function($http, $q){
22
Jeremy Mowery41d6e882016-04-19 19:31:11 -070023 this.getOpenVpnTenants = () => {
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070024 let deferred = $q.defer();
25
Jeremy Mowery441c3d62016-04-23 14:31:10 -070026 $http.get('/api/tenant/openvpn/list/')
Jeremy Mowery6efeb7a2016-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 Moweryc770ba02016-02-25 18:14:03 -070035 }
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070036})
37.config(function($httpProvider){
38 $httpProvider.interceptors.push('NoHyperlinks');
39})
Jeremy Mowery41d6e882016-04-19 19:31:11 -070040.directive('vpnList', function(){
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070041 return {
42 restrict: 'E',
43 scope: {},
44 bindToController: true,
45 controllerAs: 'vm',
Jeremy Mowery81e84cc2016-04-19 17:01:48 -070046 templateUrl: 'templates/openvpn-list.tpl.html',
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070047 controller: function(Vpn){
Jeremy Mowery41d6e882016-04-19 19:31:11 -070048 Vpn.getOpenVpnTenants()
Jeremy Mowerye84e3ee2016-02-28 22:21:54 -070049 .then((vpns) => {
Jeremy Mowery98dd6c82016-02-25 11:25:53 -070050 this.vpns = vpns;
Jeremy Mowery37e4efe2016-03-02 00:01:25 -070051 for (var i = 0; i < this.vpns.length; i++) {
Jeremy Moweryee139912016-04-17 19:20:01 -070052 var blob = new Blob([this.vpns[i].script_text], {type: 'text/plain'});
Jeremy Mowery37e4efe2016-03-02 00:01:25 -070053 this.vpns[i].script_text = (window.URL || window.webkitURL).createObjectURL( blob );
54 }
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070055 })
56 .catch((e) => {
57 throw new Error(e);
58 });
Jeremy Moweryc770ba02016-02-25 18:14:03 -070059 }
60 };
Jeremy Mowery6efeb7a2016-02-25 09:32:00 -070061});