Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Add some missing jwt legacy stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Mar 7, 2018
1 parent 6ef994f commit f143378
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
9 changes: 9 additions & 0 deletions legacy-stuff/variables/auth-template.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
script(type='text/ng-template' id='login#{loginDropdownID}')
#loginDropdown.ns-popover-tooltip
.triangle
.ns-triangle
.pad
.text-center
// TODO-JWT figure out better title
| Authenticate to personalize this page
a.btn.btn-primary(href="/oauth" target="_self") Authenticate
22 changes: 22 additions & 0 deletions legacy-stuff/variables/key-vars.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
span
span(ng-show='!dropdown')
span(ng-show='!showDropdown')
| {{value}}
span(ng-show='showDropdown')
-var loginDropdownID = Math.floor((Math.random() * 1000))
span(class='variable-underline' ns-popover ns-popover-trigger='click' ns-popover-theme='ns-popover-auth-theme' ns-popover-placement='bottom|center' ns-popover-template='login#{loginDropdownID}' ns-popover-timeout="-1" ns-popover-hide-on-inside-click="true") {{value}}
span(ng-show='dropdown')
-var id = Math.floor((Math.random() * 1000))
span(class='variable-underline' ns-popover ns-popover-trigger='click' ns-popover-theme='ns-popover-dropdown-theme' ns-popover-placement='bottom|right' ns-popover-template='variable#{id}' ns-popover-timeout="-1" ns-popover-hide-on-inside-click="true") {{value}}

// Project Picker Dropdown
script(type='text/ng-template' id='variable#{id}')
#variableDropdown.ns-popover-tooltip
.ns-triangle
.triangle
ul
li(ng-repeat="name in project_names")
a(href='' ng-class='{active: $index == selected}' ng-click='select($index)') {{name}}

// Auth Login Dropdown
include auth-template
80 changes: 80 additions & 0 deletions legacy-stuff/variables/variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import 'angular-cookies';

/* @ngInject */
function variableKeys($cookies, user) {
return {
restrict: 'E',
templateUrl: '/directive/variables/key-vars',
replace: true,
scope: {
v: '@',
data: '@',
isdefault: '@',
},
link(scope) {
scope.selected = window.localStorage.selected_app ? window.localStorage.selected_app : 0;

scope.showDropdown = !!scope.isdefault && !!user.oauthEnabled;

scope.select = function (i) {
window.localStorage.selected_app = i;
};

let initializing = true;

const variableName = scope.v;

let cookie = {};
try {
cookie = JSON.parse($cookies.user_data);
if (scope.selected >= cookie.keys.length) scope.selected = 0;
scope.value = cookie.keys[scope.selected][variableName];
scope.dropdown = cookie.keys.length > 1; // only show dropdown picker if multiple keys
scope.project_names = cookie.keys.map(v => v.name);
} catch (e) {
// console.log(e);
scope.value = scope.data;
}

function updateSelected(i) {
scope.selected = i;
scope.value = cookie.keys[scope.selected][variableName];
}

scope.$watch(
() => window.localStorage.selected_app,
(newVal) => {
if (!initializing) {
updateSelected(newVal);
} else {
initializing = false;
}
},
);
},
};
}

/* @ngInject */
function variable($cookies, $http, user) {
return {
restrict: 'E',
templateUrl: '/directive/variables/user-vars',
replace: true,
scope: {
v: '@',
data: '@',
isdefault: '@',
},
link(scope) {
scope.showDropdown = !!scope.isdefault && !!user.oauthEnabled;
// Have to assign to something than data cause of weird angular scoping
scope.value = scope.data;
},
};
}

export default angular.module('rm.variable', ['ngCookies'])
.directive('variable', variable)
.directive('variableKeys', variableKeys)
.name;

0 comments on commit f143378

Please sign in to comment.