application.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. App.ApplicationController = Em.Controller.extend(App.UserPref, {
  20. name: 'applicationController',
  21. isPollerRunning: false,
  22. clusterName: function () {
  23. return (App.router.get('clusterController.clusterName') || 'My Cluster');
  24. }.property('App.router.clusterController.clusterName'),
  25. /**
  26. * set ambari server version from installerController or mainController, making sure version shown up all the time
  27. */
  28. ambariVersion: function () {
  29. return (App.router.get('installerController.ambariServerVersion') || App.router.get('mainController.ambariServerVersion') || Em.I18n.t('common.notAvailable'));
  30. }.property('App.router.installerController.ambariServerVersion', 'App.router.mainController.ambariServerVersion'),
  31. clusterDisplayName: function () {
  32. var name = this.get('clusterName');
  33. return name.length > 13 ? name.substr(0, 10) + "..." : name;
  34. }.property('clusterName'),
  35. isClusterDataLoaded: function() {
  36. return App.router.get('clusterController.isLoaded') && App.router.get('loggedIn');
  37. }.property('App.router.clusterController.isLoaded','App.router.loggedIn'),
  38. isExistingClusterDataLoaded: function () {
  39. return App.router.get('clusterInstallCompleted') && this.get('isClusterDataLoaded');
  40. }.property('App.router.clusterInstallCompleted', 'isClusterDataLoaded'),
  41. init: function(){
  42. this._super();
  43. },
  44. startKeepAlivePoller: function() {
  45. if (!this.get('isPollerRunning')) {
  46. this.set('isPollerRunning',true);
  47. App.updater.run(this, 'getStack', 'isPollerRunning', App.sessionKeepAliveInterval);
  48. }
  49. },
  50. getStack: function(callback) {
  51. App.ajax.send({
  52. name: 'router.login.clusters',
  53. sender: this,
  54. callback: callback
  55. });
  56. },
  57. dataLoading: function () {
  58. var dfd = $.Deferred();
  59. var self = this;
  60. this.getUserPref(this.persistKey()).complete(function () {
  61. var curPref = self.get('currentPrefObject');
  62. self.set('currentPrefObject', null);
  63. dfd.resolve(curPref);
  64. });
  65. return dfd.promise();
  66. },
  67. persistKey: function (loginName) {
  68. if (App.get('testMode')) {
  69. return 'admin_settings_show_bg';
  70. }
  71. if (!loginName)
  72. loginName = App.router.get('loginName');
  73. return 'admin-settings-show-bg-' + loginName;
  74. },
  75. currentPrefObject: null,
  76. getUserPrefSuccessCallback: function (response, request, data) {
  77. if (response != null) {
  78. console.log('Got persist value from server with key ' + data.key + '. Value is: ' + response);
  79. this.set('currentPrefObject', response);
  80. return response;
  81. }
  82. },
  83. getUserPrefErrorCallback: function (request, ajaxOptions, error) {
  84. // this user is first time login
  85. if (request.status == 404) {
  86. console.log('Persist did NOT find the key');
  87. this.set('currentPrefObject', true);
  88. this.postUserPref(this.persistKey(), true);
  89. return true;
  90. }
  91. },
  92. goToAdminView: function () {
  93. App.router.route("adminView");
  94. },
  95. showSettingsPopup: function() {
  96. // Settings only for admins
  97. if (!App.isAccessible('upgrade_ADMIN')) return;
  98. var self = this;
  99. var curValue = null;
  100. this.dataLoading().done(function (initValue) {
  101. App.ModalPopup.show({
  102. header: Em.I18n.t('common.userSettings'),
  103. bodyClass: Em.View.extend({
  104. templateName: require('templates/common/settings'),
  105. isNotShowBgChecked: !initValue,
  106. updateValue: function () {
  107. curValue = !this.get('isNotShowBgChecked');
  108. }.observes('isNotShowBgChecked')
  109. }),
  110. primary: Em.I18n.t('common.save'),
  111. onPrimary: function() {
  112. if (curValue == null) {
  113. curValue = initValue;
  114. }
  115. var key = self.persistKey();
  116. if (!App.get('testMode')) {
  117. self.postUserPref(key, curValue);
  118. }
  119. this.hide();
  120. }
  121. })
  122. });
  123. },
  124. showAboutPopup: function() {
  125. var self = this;
  126. App.ModalPopup.show({
  127. header: Em.I18n.t('common.aboutAmbari'),
  128. secondary: false,
  129. bodyClass: Em.View.extend({
  130. templateName: require('templates/common/about'),
  131. ambariVersion: this.get('ambariVersion')
  132. })
  133. });
  134. }
  135. });