view.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. var App = require('app');
  19. module.exports = Em.Route.extend({
  20. route: '/view',
  21. enter: function (router) {
  22. router.get('mainViewsController').loadAmbariViews();
  23. },
  24. index: Em.Route.extend({
  25. route: '/',
  26. connectOutlets: function (router) {
  27. router.get('mainViewsController').dataLoading().done(function() {
  28. router.get('mainController').connectOutlet('mainViews');
  29. });
  30. }
  31. }),
  32. shortViewDetails: Em.Route.extend({
  33. route: '/:viewName/:shortName',
  34. connectOutlets: function (router, params) {
  35. var viewPath = this.parseViewPath(window.location.href.slice(window.location.href.indexOf('?')));
  36. var slicedShortName = params.shortName;
  37. if (viewPath) {
  38. slicedShortName = this._getSlicedShortName(params.shortName);
  39. if (slicedShortName === params.shortName) {
  40. viewPath = '';
  41. }
  42. if (viewPath.charAt(0) === '/') viewPath = viewPath.slice(1);
  43. }
  44. router.get('mainViewsController').dataLoading().done(function() {
  45. var content = App.router.get('mainViewsController.ambariViews').filterProperty('viewName', params.viewName).findProperty('shortUrl', slicedShortName)
  46. if (content) content.set('viewPath', viewPath);
  47. router.get('mainController').connectOutlet('mainViewsDetails', content);
  48. });
  49. },
  50. /**
  51. * parse the short name and slice if needed
  52. *
  53. * @param {string}
  54. * @returns {string}
  55. * @private
  56. */
  57. _getSlicedShortName: function (instanceName) {
  58. if (instanceName.lastIndexOf('?') > -1) {
  59. return instanceName.slice(0, instanceName.lastIndexOf('?'));
  60. }
  61. return instanceName;
  62. },
  63. /**
  64. * parse internal view path
  65. * "viewPath" - used as a key of additional path
  66. * Example:
  67. * origin URL: viewName?viewPath=%2Fuser%2Fadmin%2Faddress&foo=bar&count=1
  68. * should be translated to
  69. * view path: /user/admin/address?foo=bar&count=1
  70. *
  71. * @param {string} instanceName
  72. * @returns {string}
  73. */
  74. parseViewPath: function (instanceName) {
  75. var path = '';
  76. if (instanceName.contains('?')) {
  77. path = instanceName.slice(instanceName.indexOf('?'));
  78. if (path.contains('viewPath')) {
  79. path = decodeURIComponent(path.slice((path.lastIndexOf('?viewPath=') + 10))).replace('&', '?');
  80. }
  81. }
  82. return path;
  83. }
  84. })
  85. });