-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.js
executable file
·227 lines (193 loc) · 9.13 KB
/
index.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//# sourceURL=storage-management-plugin.js
(function() {
var storageModule = angular.module("TendrlModule", [
"ui.router",
"ui.bootstrap",
"frapontillo.bootstrap-switch",
"gridshore.c3js.chart",
"patternfly.charts",
"patternfly.card",
"patternfly.form",
"patternfly.notification",
"patternfly.table",
"patternfly.filters",
"react"
]);
/* Setting up provider for getting config data */
storageModule.provider("config", function() {
/*Ideally this config should only contain
configuration related stuff . it should not hold
cluster data */
var config = {};
/* Accessible only in config function */
this.setConfigData = function(dataFromServer) {
config = dataFromServer;
};
/* Accessible in controller/service/factory */
this.$get = function() {
return config;
};
});
/* First fetch the config data than only application will bootstrap */
fetchConfigData()
.then(bootstrapApplication);
function fetchConfigData() {
var initInjector = angular.injector(["ng"]);
var $http = initInjector.get("$http");
return $http.get("../../config.json").then(function(response) {
storageModule.config(function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider, configProvider) {
configProvider.setConfigData(response.data);
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.delete = {};
$urlRouterProvider.otherwise("/login");
$stateProvider
.state("login", {
url: "/login",
template: "<login></login>"
})
.state("clusters", {
url: "/clusters",
template: "<cluster-list></cluster-list>"
})
.state("import-cluster", {
url: "/import-cluster/:clusterId",
template: "<import-cluster cluster='clusterTobeImported'></import-cluster>"
})
.state("cluster-hosts", {
url: "/cluster-hosts/:clusterId",
template: "<cluster-hosts></cluster-hosts>"
})
.state("cluster-volumes", {
url: "/cluster-volumes/:clusterId",
template: "<cluster-volumes></cluster-volumes>"
})
.state("cluster-events", {
url: "/cluster-events/:clusterId",
template: "<cluster-events></cluster-events>"
})
.state("cluster-tasks", {
url: "/cluster-tasks/:clusterId",
template: "<cluster-tasks></cluster-tasks>"
})
.state("host-detail", {
url: "/cluster-hosts/:clusterId/host-detail/:hostId",
template: "<host-detail></host-detail>"
})
.state("volume-detail", {
url: "/cluster-volumes/:clusterId/volume-detail/:volumeId",
template: "<volume-detail></volume-detail>"
})
.state("users", {
url: "/admin/users",
template: "<users></users>"
})
.state("add-user", {
url: "/admin/users/add",
template: "<add-user></add-user>"
})
.state("edit-user", {
url: "/admin/users/edit/:userId",
template: "<edit-user></edit-user>"
})
.state("task-detail", {
url: "/cluster-tasks/:clusterId/task-detail/:taskId",
template: "<task-detail></task-detail>"
})
.state("global-task-detail", {
url: "/global-cluster-tasks/:clusterId/task-detail/:taskId",
template: "<global-task-detail></global-task-detail>"
})
.state("forbidden", {
url: "/forbidden",
template: "<div class='un-auth-user'>You are not authorised to see this view.<div>"
});
});
storageModule.run(function($rootScope, $location, $http, $interval, $transitions, menuService, AuthManager, utils, eventStore, config, clusterStore, userStore) {
var restrictedPage, loggedIn, alertListTimer;
$rootScope.$on("$locationChangeStart", function(event, current, next) {
// redirect to login page if not logged in and trying to access a restricted page
$rootScope.isHeaderShow = true;
restrictedPage = $.inArray($location.path(), ["/login"]) === -1;
loggedIn = JSON.parse(localStorage.getItem("userInfo"));
if (restrictedPage && !loggedIn) {
$location.path("/login");
}
if (!restrictedPage) {
$rootScope.isHeaderShow = false;
}
});
$transitions.onSuccess({}, function($transitions) {
var current = $transitions.$to();
menuService.setActive(current.name);
});
$transitions.onStart({}, function($transitions) {
var current = $transitions.$to();
if (AuthManager.isAuthenticated(current.name)) {
$location.path("/forbidden");
}
});
if (JSON.parse(localStorage.getItem("userInfo")) && JSON.parse(localStorage.getItem("userInfo")).username && JSON.parse(localStorage.getItem("userInfo")).accessToken) {
AuthManager.isUserLoggedIn = true;
AuthManager.setAuthHeader();
$rootScope.userRole = AuthManager.getUserRole();
}
$rootScope.forceHideNav = function() {
return !$rootScope.selectedClusterOption ||
$rootScope.selectedClusterOption === "allClusters" ||
!AuthManager.isUserLoggedIn;
}
if (AuthManager.isUserLoggedIn) {
/* Tracking the current URI for navigation*/
$rootScope.isAPINotFoundError = false;
$rootScope.clusterData = null;
$rootScope.alertList = null;
$rootScope.selectedClusterOption = null;
menuService.setMenus();
var url = $location.path();
clusterStore.getClusterList().then(function(list) {
$rootScope.clusterData = list;
/* Setting up manual broadcast event for ClusterData*/
$rootScope.$broadcast("GotClusterData", $rootScope.clusterData); // going down!
if ($rootScope.clusterData !== null && $rootScope.clusterData.length !== 0) {
/* Forward to cluster view if we have cluster data. */
getAlertList();
}
}).catch(function(error) {
$rootScope.$broadcast("GotClusterData", $rootScope.clusterData); // going down!
$rootScope.isAPINotFoundError = true;
});
}
function getAlertList() {
eventStore.getAlertList()
.then(function(alertList) {
$interval.cancel(alertListTimer);
$rootScope.alertList = alertList;
$rootScope.$broadcast("GotAlertData", $rootScope.alertList);
startAlertTimer();
})
.catch(function(error) {
$rootScope.alertList = null;
});
}
function startAlertTimer() {
alertListTimer = $interval(function() {
getAlertList();
}, 1000 * config.eventsRefreshIntervalTime, 1);
}
$rootScope.$on("$destroy", function() {
$interval.cancel(alertListTimer);
});
$rootScope.$on("UserLogsOut", function() {
$interval.cancel(alertListTimer);
});
});
}, function(errorResponse) {
// Handle error case
});
}
function bootstrapApplication() {
angular.element(document).ready(function() {
angular.bootstrap(document, ["TendrlModule"]);
});
}
}());