This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dom Harrington
committed
Mar 7, 2018
1 parent
6ef994f
commit f143378
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |