Skip to content

Commit cc7ef04

Browse files
pavel-blagodovdave-finlay
authored andcommitted
MB-12222: update ui-router to version 1.0.0 alpha0
We have to use latest ui router because it has transitionsProvider, we need transitionsProvider in order to properly handle transition to the state with rbac permissions https://github.com/angular-ui/ui-router/releases/tag/1.0.0alpha0 Old ui-router is deprecated https://github.com/angular-ui/ui-router/releases/tag/0.2.17 Process of migrating is pretty smooth, although there are couple bugs angular-ui/ui-router#2504 angular-ui/ui-router#2503 Change-Id: I67fc81adecf5ebf9cf294171d5583f8555696cee Reviewed-on: http://review.couchbase.org/59318 Reviewed-by: Dave Finlay <[email protected]> Tested-by: Dave Finlay <[email protected]>
1 parent 51482e2 commit cc7ef04

File tree

8 files changed

+4353
-4421
lines changed

8 files changed

+4353
-4421
lines changed

Diff for: priv/public/ui/app/app.js

+22-41
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,10 @@
1010
'ui.bootstrap'
1111
]).run(appRun);
1212

13-
function appRun($rootScope, $state, $urlRouter, mnPools, $uibModalStack, $window, $exceptionHandler, $http, $templateCache, mnPendingQueryKeeper) {
14-
var originalOnerror = $window.onerror;
13+
function appRun($state, $urlRouter, $exceptionHandler, mnPools, $window, $http, $templateCache, $transitions) {
1514

15+
var originalOnerror = $window.onerror;
1616
$window.onerror = onError;
17-
$rootScope.$on('$stateChangeError', onStateChangeError);
18-
$rootScope.$on('$stateChangeStart', onStateChangeStart);
19-
$rootScope.$on('$locationChangeSuccess', onLocationChangeSuccess);
20-
$urlRouter.listen();
21-
angular.forEach(angularTemplatesList, function (url) {
22-
$http.get(url, {cache: $templateCache});
23-
});
24-
2517
function onError(message, url, lineNumber, columnNumber, exception) {
2618
$exceptionHandler({
2719
message: message,
@@ -32,37 +24,26 @@
3224
});
3325
originalOnerror && originalOnerror.apply($window, Array.prototype.slice.call(arguments));
3426
}
35-
function onStateChangeError(event, toState, toParams, fromState, fromParams, error) {
36-
$exceptionHandler(error);
37-
}
38-
function onStateChangeStart(event, toState, toParams, fromState, fromParams, error) {
39-
if (fromState.name.indexOf('app.admin') > -1 && toState.name.indexOf('app.admin') > -1) {
40-
if ($uibModalStack.getTop()) {
41-
return event.preventDefault();
42-
}
43-
mnPools.get().then(function (pools) {
44-
var required = (toState.data && toState.data.required) || {};
45-
var isOnlyForEnterprise = (required.enterprise && !pools.isEnterprise);
46-
if (isOnlyForEnterprise) {
47-
event.preventDefault();
48-
return $state.go('app.admin.overview');
49-
}
50-
});
27+
28+
angular.forEach(angularTemplatesList, function (url) {
29+
$http.get(url, {cache: $templateCache});
30+
});
31+
32+
mnPools.get().then(function (pools) {
33+
if (!pools.isInitialized) {
34+
return $state.go('app.wizard.welcome');
5135
}
52-
}
53-
function onLocationChangeSuccess(event) {
54-
event.preventDefault();
55-
mnPools.get().then(function (pools) {
56-
if (pools.isInitialized) {
57-
$urlRouter.sync();
58-
} else {
59-
$state.go('app.wizard.welcome');
60-
}
61-
}, function (resp) {
62-
switch (resp.status) {
63-
case 401: return $state.go('app.auth');
64-
}
65-
});
66-
}
36+
}, function (resp) {
37+
switch (resp.status) {
38+
case 401: return $state.go('app.auth');
39+
}
40+
}).then(function () {
41+
$urlRouter.listen();
42+
$urlRouter.sync();
43+
})
44+
45+
$transitions.defaultErrorHandler(function (error) {
46+
error && $exceptionHandler(error);
47+
});
6748
}
6849
})();

Diff for: priv/public/ui/app/app_config.js

+62-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
.module('app')
66
.config(appConfig);
77

8-
function appConfig($httpProvider, $stateProvider, $urlRouterProvider, $uibModalProvider) {
8+
function appConfig($httpProvider, $stateProvider, $urlRouterProvider, $uibModalProvider, $transitionsProvider) {
99
$httpProvider.defaults.headers.common['invalid-auth-response'] = 'on';
1010
$httpProvider.defaults.headers.common['Cache-Control'] = 'no-cache';
1111
$httpProvider.defaults.headers.common['Pragma'] = 'no-cache';
@@ -29,7 +29,67 @@
2929
template: '<div ui-view="" />'
3030
});
3131

32+
$transitionsProvider.onBefore({
33+
to: "app.admin.**",
34+
from: "app.admin.**"
35+
}, function ($uibModalStack) {
36+
return !$uibModalStack.getTop();
37+
});
38+
$transitionsProvider.onBefore({
39+
to: "app.admin.**",
40+
from: "app.auth"
41+
}, function (mnPools) {
42+
return mnPools.get().then(function () {
43+
return true;
44+
}, function (resp) {
45+
switch (resp.status) {
46+
case 401: return false;
47+
}
48+
});
49+
});
50+
$transitionsProvider.onBefore({
51+
from: "app.wizard.**",
52+
to: "app.auth"
53+
}, function (mnPools) {
54+
return mnPools.get().then(function (pools) {
55+
return pools.isInitialized;
56+
});
57+
});
58+
$transitionsProvider.onBefore({
59+
from: "app.admin.**",
60+
to: "app.auth"
61+
}, function (mnPools) {
62+
return mnPools.get().then(function () {
63+
return false;
64+
}, function (resp) {
65+
switch (resp.status) {
66+
case 401: return true;
67+
}
68+
});
69+
});
70+
$transitionsProvider.onStart({
71+
to: function (state) {
72+
return state.data && state.data.permissions;
73+
}
74+
}, function ($state, $parse, mnPermissions, $transition$) {
75+
return mnPermissions.check().then(function() {
76+
if (!$parse($transition$.to().data.permissions)(mnPermissions.export)) {
77+
return false;
78+
}
79+
});
80+
});
81+
$transitionsProvider.onStart({
82+
to: function (state) {
83+
return state.data && state.data.required && state.data.required.enterprise;
84+
}
85+
}, function ($state, mnPools) {
86+
return mnPools.get().then(function (pools) {
87+
if (!pools.isEnterprise) {
88+
return false;
89+
}
90+
});
91+
});
92+
3293
$urlRouterProvider.deferIntercept();
33-
$urlRouterProvider.otherwise('/overview');
3494
}
3595
})();

Diff for: priv/public/ui/app/components/mn_helper.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
var stateParams = {};
7272
if ($scope.isDetailsOpened(hashValue)) {
7373
stateParams[hashKey] = _.difference(currentlyOpened, [String(hashValue)]);
74-
$state.go(stateName, stateParams, {notify: false});
74+
$state.go(stateName, stateParams);
7575
} else {
7676
currentlyOpened.push(String(hashValue));
7777
stateParams[hashKey] = currentlyOpened;
78-
$state.go(stateName, stateParams, {notify: false});
78+
$state.go(stateName, stateParams);
7979
}
8080
};
8181
}
@@ -87,7 +87,7 @@
8787
}
8888
function reloadState() {
8989
mnPendingQueryKeeper.cancelAllQueries();
90-
$state.transitionTo($state.current, $stateParams, {reload: true, inherit: true, notify: true});
90+
$state.transitionTo($state.current, $stateParams, {reload: true, inherit: true});
9191
}
9292
}
9393
}

Diff for: priv/public/ui/app/mn_admin/mn_admin_config.js

+3
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
.state('app.admin.analytics.list', {
122122
abstract: true,
123123
url: '?openedStatsBlock',
124+
// reloadOnSearch: false, should be uncomented after this fix will be merget https://github.com/angular-ui/ui-router/issues/2470
124125
params: {
125126
openedStatsBlock: {
126127
array: true
@@ -169,6 +170,7 @@
169170
array: true
170171
}
171172
},
173+
reloadOnSearch: false,
172174
views: {
173175
"": {
174176
controller: 'mnBucketsController as bucketsCtl',
@@ -196,6 +198,7 @@
196198
array: true
197199
}
198200
},
201+
reloadOnSearch: false,
199202
views: {
200203
"" : {
201204
controller: 'mnServersListController as serversListCtl',

Diff for: priv/public/ui/app/mn_admin/mn_indexes/mn_indexes_config.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
value: null
2323
}
2424
},
25+
resolve: {
26+
setDefaultBucketName: mnHelperProvider.setDefaultBucketName("viewsBucket", 'app.admin.indexes.views.list')
27+
},
2528
templateUrl: 'app/mn_admin/mn_indexes/mn_views/mn_views.html',
2629
controller: 'mnViewsController as viewsCtl'
2730
})
@@ -32,9 +35,6 @@
3235
value: 'development'
3336
}
3437
},
35-
resolve: {
36-
setDefaultBucketName: mnHelperProvider.setDefaultBucketName("viewsBucket", 'app.admin.indexes.views.list')
37-
},
3838
controller: 'mnViewsListController as viewsListCtl',
3939
templateUrl: 'app/mn_admin/mn_indexes/mn_views/list/mn_views_list.html'
4040
})
@@ -64,6 +64,7 @@
6464
array: true
6565
}
6666
},
67+
reloadOnSearch: false,
6768
controller: "mnGsiController as gsiCtl",
6869
templateUrl: "app/mn_admin/mn_indexes/mn_gsi/mn_gsi.html"
6970
});

Diff for: priv/public/ui/app/mn_admin/mn_indexes/mn_views/editing/mn_views_editing_service.js

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
}
3333

3434
function buildViewUrl(params) {
35+
if (!params || !params.documentId) {
36+
return;
37+
}
3538
var params = _.clone(params);
3639
if (params.documentId.slice(0, "_design/".length) === "_design/") {
3740
params.documentId = "_design/" + encodeURIComponent(params.documentId.slice("_design/".length));

Diff for: priv/public/ui/app/mn_auth/mn_auth_config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99

1010
function mnAuthConfig($stateProvider, $httpProvider, $urlRouterProvider) {
1111
$httpProvider.interceptors.push(['$q', '$injector', interceptorOf401]);
12-
$urlRouterProvider.when('', '/auth');
13-
$urlRouterProvider.when('/', '/auth');
1412
$stateProvider.state('app.auth', {
13+
url: "/auth",
1514
templateUrl: 'app/mn_auth/mn_auth.html',
1615
controller: 'mnAuthController as authCtl'
1716
});

0 commit comments

Comments
 (0)