forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nav.js
125 lines (114 loc) · 4.08 KB
/
nav.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict';
angular.module('openshiftConsole')
.directive('sidebar', function(HawtioNav) {
return {
restrict: 'E',
templateUrl: 'views/_sidebar.html',
link: function($scope, element, attrs) {
var selectedTab = HawtioNav.selected();
if (selectedTab) {
$scope.sidebarHeading = selectedTab.title();
}
}
};
})
.directive('sidebarNavItem', function() {
return {
restrict: 'E',
replace: true,
templateUrl: "views/_sidebar-main-nav-item.html"
};
})
.directive('projectNav', function($timeout, $location, $filter, LabelFilter) {
return {
restrict: 'E',
templateUrl: 'views/_project-nav.html',
link: function ($scope, element, attrs) {
var select = $('.selectpicker', element);
var updateOptions = function() {
var currentProject = $scope.project;
if (!currentProject || angular.equals({}, currentProject)) {
if (!$scope.projectName) {
// Wait until we have at least $scope.projectName or $scope.project.
return;
}
currentProject = {
metadata: {
name: $scope.projectName
}
};
}
var projectName = $scope.projectName || currentProject.metadata.name;
// Locally add the "current" project to the projects list if it
// doesn't exist. This can happen when creating a new project from
// the web, which navigates immediately to the project page.
var projects;
if (!$scope.projects || !$scope.projects[projectName]) {
projects = {};
projects[$scope.projectName] = currentProject;
projects = angular.extend(projects, $scope.projects);
} else {
projects = $scope.projects;
}
var sortedProjects = $filter('orderByDisplayName')(projects);
// Create options from the sorted array.
angular.forEach(sortedProjects, function(project) {
$('<option>')
.attr("value", project.metadata.name)
.attr("selected", project.metadata.name == projectName)
.text($filter('displayName')(project))
.appendTo(select);
});
// TODO
// <option data-divider="true"></option>
// <option>Create new</option>
};
updateOptions();
select.selectpicker({
iconBase: 'fa',
tickIcon: 'fa-check'
}).change(function() {
var newProject = $( this ).val();
var currentURL = $location.url();
var currProjRegex = /\/project\/[^\/]+/;
var currProjPrefix = currProjRegex.exec(currentURL);
var newURL = currentURL.replace(currProjPrefix, "/project/" + encodeURIComponent(newProject));
$scope.$apply(function() {
$location.url(newURL);
});
});
var clearAndUpdateOptions = function(newValue, oldValue) {
if (newValue === oldValue) {
return;
}
select.empty();
updateOptions();
select.selectpicker('refresh');
};
$scope.$watch("project", clearAndUpdateOptions);
$scope.$watch("projects", clearAndUpdateOptions);
LabelFilter.setupFilterWidget($(".navbar-filter-widget", element), $(".active-filters", element), { addButtonText: "Add" });
LabelFilter.toggleFilterWidget(!$scope.renderOptions || !$scope.renderOptions.hideFilterWidget);
$scope.$watch("renderOptions", function(renderOptions) {
LabelFilter.toggleFilterWidget(!renderOptions || !renderOptions.hideFilterWidget);
});
}
};
})
.directive('projectPage', function() {
return {
restrict: 'E',
transclude: true,
templateUrl: 'views/_project-page.html'
};
})
.directive('back', ['$window', function($window) {
return {
restrict: 'A',
link: function (scope, elem) {
elem.bind('click', function () {
$window.history.back();
});
}
};
}]);