application.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import Ember from 'ember';
  19. import AbstractRoute from './abstract';
  20. export default AbstractRoute.extend({
  21. model() {
  22. return Ember.RSVP.hash({
  23. clusterInfo: this.store.findAll('ClusterInfo', {reload: true}).catch(function() {
  24. return null;
  25. }),
  26. userInfo: this.store.findAll('cluster-user-info', {reload: true}).catch(function() {
  27. return null;
  28. }),
  29. jhsHealth: this.store.queryRecord('jhs-health', {}).catch(function() {
  30. return null;
  31. }),
  32. timelineHealth: this.store.queryRecord('timeline-health', {}).catch(function() {
  33. return null;
  34. })
  35. });
  36. },
  37. actions: {
  38. /**
  39. * Base error handler for the application.
  40. * If specific routes do not handle the error, it will bubble up to
  41. * this handler. Here we redirect to either 404 page or a generic
  42. * error handler page.
  43. */
  44. error: function (error) {
  45. if (error && error.stack) {
  46. Ember.Logger.log(error.stack);
  47. }
  48. if (error && error.errors[0] && parseInt(error.errors[0].status) === 404) {
  49. this.intermediateTransitionTo('/notfound');
  50. } else if (error && error.errors[0] && parseInt(error.errors[0].status) === 401) {
  51. this.intermediateTransitionTo('/notauth');
  52. } else {
  53. this.intermediateTransitionTo('/error');
  54. }
  55. }
  56. },
  57. unloadAll: function() {
  58. this.store.unloadAll('ClusterInfo');
  59. this.store.unloadAll('cluster-user-info');
  60. this.store.unloadAll('timeline-health');
  61. this.store.unloadAll('jhs-health');
  62. },
  63. });