forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nav.js
139 lines (125 loc) · 3.92 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use strict';
angular.module('openshiftConsole')
.directive('sidebar', function(HawtioNav) {
return {
restrict: 'E',
templateUrl: 'views/_sidebar.html',
link: function($scope) {
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, DataService, projectOverviewURLFilter) {
return {
restrict: 'EA',
templateUrl: 'views/_project-nav.html',
link: function($scope, $elem) {
var select = $elem.find('.selectpicker');
var projects = {};
var sortedProjects = [];
var options = [];
var updateOptions = function() {
var project = $scope.project || {};
var name = $scope.projectName;
var isRealProject = project.metadata && project.metadata.name;
// If we don't have a name or a real project, nothing to do yet.
if (!name && !isRealProject) {
return;
}
if (!name) {
name = project.metadata.name;
}
if (!isRealProject) {
project = {
metadata: {
name: name
}
};
}
if(!projects[name]) {
projects[name] = project;
}
sortedProjects = $filter('orderByDisplayName')(projects);
options = _.map(sortedProjects, function(item) {
return $('<option>')
.attr("value", item.metadata.name)
.attr("selected", item.metadata.name === name)
.text($filter("uniqueDisplayName")(item, sortedProjects));
});
select.empty();
select.append(options);
select.append($('<option data-divider="true"></option>'));
select.append($('<option value="">View all projects</option>'));
select.selectpicker('refresh');
};
DataService.list("projects", $scope, function(items) {
projects = items.by("metadata.name");
updateOptions();
});
updateOptions();
select
.selectpicker({
iconBase: 'fa',
tickIcon: 'fa-check'
})
.change(function() {
var val = $(this).val();
var newURL = (val === "") ? "/" : projectOverviewURLFilter(val);
$scope.$apply(function() {
$location.url(newURL);
});
});
LabelFilter.setupFilterWidget($elem.find('.navbar-filter-widget'), $elem.find('.active-filters'), { addButtonText: "Add" });
LabelFilter.toggleFilterWidget(!$scope.renderOptions || !$scope.renderOptions.hideFilterWidget);
$scope.$watch("project", updateOptions);
$scope.$watch("renderOptions", function(renderOptions) {
LabelFilter.toggleFilterWidget(!renderOptions || !renderOptions.hideFilterWidget);
});
}
};
})
.directive('projectPage', function() {
return {
restrict: 'E',
transclude: true,
templateUrl: 'views/_project-page.html'
};
})
.directive('breadcrumbs', function() {
return {
restrict: 'E',
scope: {
breadcrumbs: '='
},
templateUrl: 'views/directives/breadcrumbs.html'
};
})
.directive('back', ['$window', function($window) {
return {
restrict: 'A',
link: function (scope, elem) {
elem.bind('click', function () {
$window.history.back();
});
}
};
}])
.directive('oscSecondaryNav', function() {
return {
restrict: 'A',
scope: {
tabs: '='
},
templateUrl: 'views/directives/osc-secondary-nav.html'
};
});