Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hashroute redirect with machine listing fallthrough. #1177

Merged
merged 4 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion legacy/src/app/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function configureMaas(
$locationProvider,
$compileProvider,
tagsInputConfigProvider,
$urlRouterProvider
$urlRouterProvider,
) {
// Disable debugInfo unless in a Jest context.
// Re-enable debugInfo in development by running
Expand Down
30 changes: 28 additions & 2 deletions legacy/src/app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,14 @@ const configureRoutes = ($stateProvider, $urlRouterProvider) => {
template: podDetailsTmpl,
controller: "PodDetailsController",
})
.state("pods", { url: prefixRoute("/pods"), redirectTo: prefixRoute("/kvm") })
.state("podDetails", { url: prefixRoute("/pod/:id"), redirectTo: prefixRoute("/kvm/:id") })
.state("pods", {
url: prefixRoute("/pods"),
redirectTo: prefixRoute("/kvm"),
})
.state("podDetails", {
url: prefixRoute("/pod/:id"),
redirectTo: prefixRoute("/kvm/:id"),
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just reformatting here.

.state("master.rsd", {
url: prefixRoute("/rsd"),
template: podsListTmpl,
Expand Down Expand Up @@ -227,6 +233,26 @@ const configureRoutes = ($stateProvider, $urlRouterProvider) => {
template: dashboardTmpl,
controller: "DashboardController",
});

$urlRouterProvider.otherwise(($injector, $location) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately $rootScope isn't available in the angularjs config function, so I can't reuse caleb's nice navigation functions.

// Redirect old hash routes to new routes
if ($location.hash()) {
window.history.pushState(
null,
null,
`${process.env.BASENAME}${
process.env.ANGULAR_BASENAME
}${$location.hash()}`
);
} else {
// fallthrough redirect machine listing
window.history.pushState(
null,
null,
`${process.env.BASENAME}${process.env.REACT_BASENAME}/machines`
);
}
});
};

export default configureRoutes;
6 changes: 5 additions & 1 deletion legacy/src/app/services/tests/test_region.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import MockWebSocket from "testing/websocket";

describe("RegionConnection", function() {
// Load the MAAS module to test.
beforeEach(angular.mock.module("MAAS"));
beforeEach(
angular.mock.module("MAAS", ($urlRouterProvider) =>
$urlRouterProvider.deferIntercept()
)
);

// Grab the needed angular pieces.
var $timeout, $rootScope, $q, $cookies, $window;
Expand Down
5 changes: 4 additions & 1 deletion root/src/root-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ registerApplication({
showLoading();
return import("@maas-ui/maas-ui-legacy");
},
activeWhen: `${process.env.BASENAME}${process.env.ANGULAR_BASENAME}`,
activeWhen: (location) =>
location.pathname.startsWith(
`${process.env.BASENAME}${process.env.ANGULAR_BASENAME}`
) || location.hash.startsWith("#"),
});

registerApplication({
Expand Down