app.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. // Application bootstrapper
  19. module.exports = Em.Application.create({
  20. name: 'Ambari Web',
  21. rootElement: '#wrapper',
  22. store: DS.Store.create({
  23. revision: 4,
  24. adapter: DS.FixtureAdapter.create({
  25. simulateRemoteResponse: false
  26. })
  27. }),
  28. isAdmin : function(){
  29. var user = this.db && this.db.getUser();
  30. return user ? user.admin : false;
  31. }.property(),
  32. /**
  33. * return url prefix with number value of version of HDP stack
  34. */
  35. stackVersionURL:function(){
  36. var stackVersion = this.get('currentStackVersion') || this.get('defaultStackVersion');
  37. return '/stacks/HDP/version/' + stackVersion.replace(/HDP-/g, '');
  38. }.property('currentStackVersion'),
  39. clusterName: null,
  40. currentStackVersion: null,
  41. ready: function(){
  42. this.set('currentStackVersion', this.get('defaultStackVersion'));
  43. }
  44. });
  45. /**
  46. * Ambari overrides the default date transformer.
  47. * This is done because of the non-standard data
  48. * sent. For example Nagios sends date as "12345678".
  49. * The problem is that it is a String and is represented
  50. * only in seconds whereas Javascript's Date needs
  51. * milliseconds representation.
  52. */
  53. DS.attr.transforms.date = {
  54. from: function (serialized) {
  55. var type = typeof serialized;
  56. if (type === "string") {
  57. serialized = parseInt(serialized);
  58. type = typeof serialized;
  59. }
  60. if (type === "number") {
  61. // The number could be seconds or milliseconds.
  62. // If seconds, then multiplying with 1000 should still
  63. // keep it below the current time.
  64. if (serialized * 1000 < new Date().getTime()) {
  65. serialized = serialized * 1000;
  66. }
  67. return new Date(serialized);
  68. } else if (serialized === null || serialized === undefined) {
  69. // if the value is not present in the data,
  70. // return undefined, not null.
  71. return serialized;
  72. } else {
  73. return null;
  74. }
  75. },
  76. to: function (deserialized) {
  77. if (deserialized instanceof Date) {
  78. return deserialized.getTime();
  79. } else if (deserialized === undefined) {
  80. return undefined;
  81. } else {
  82. return null;
  83. }
  84. }
  85. }