From f14337885fb5be4c3c457dc06509ba14d4376ee2 Mon Sep 17 00:00:00 2001 From: Dom Harrington Date: Wed, 7 Mar 2018 11:33:31 -0800 Subject: [PATCH] Add some missing jwt legacy stuff --- legacy-stuff/variables/auth-template.jade | 9 +++ legacy-stuff/variables/key-vars.jade | 22 +++++++ legacy-stuff/variables/variables.js | 80 +++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 legacy-stuff/variables/auth-template.jade create mode 100644 legacy-stuff/variables/key-vars.jade create mode 100644 legacy-stuff/variables/variables.js diff --git a/legacy-stuff/variables/auth-template.jade b/legacy-stuff/variables/auth-template.jade new file mode 100644 index 000000000..b3b81b923 --- /dev/null +++ b/legacy-stuff/variables/auth-template.jade @@ -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 \ No newline at end of file diff --git a/legacy-stuff/variables/key-vars.jade b/legacy-stuff/variables/key-vars.jade new file mode 100644 index 000000000..724c75bdc --- /dev/null +++ b/legacy-stuff/variables/key-vars.jade @@ -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 \ No newline at end of file diff --git a/legacy-stuff/variables/variables.js b/legacy-stuff/variables/variables.js new file mode 100644 index 000000000..39b20b4fa --- /dev/null +++ b/legacy-stuff/variables/variables.js @@ -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;