router.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.Router = Em.Router.extend({
  20. enableLogging: true,
  21. isFwdNavigation: true,
  22. backBtnForHigherStep: false,
  23. setNavigationFlow: function (step) {
  24. var matches = step.match(/\d+$/);
  25. var newStep;
  26. if(matches){
  27. newStep = parseInt(matches[0]);
  28. }
  29. var previousStep = parseInt(this.getInstallerCurrentStep());
  30. if (newStep >= previousStep) {
  31. this.set('isFwdNavigation', true);
  32. } else {
  33. this.set('isFwdNavigation', false);
  34. }
  35. },
  36. loadAllPriorSteps: function(step) {
  37. var stepVal = parseInt(step);
  38. switch(step){
  39. case '10':
  40. this.get('installerStep9Controller').loadStep(false);
  41. case '9':
  42. this.get('installerStep8Controller').loadStep();
  43. case '8':
  44. this.get('installerStep7Controller').loadStepFrmDb();
  45. case '7':
  46. this.get('installerStep6Controller').loadStep();
  47. case '6':
  48. this.get('installerStep5Controller').loadStep();
  49. case '5':
  50. this.get('installerStep4Controller').loadStepFromDb();
  51. case '4':
  52. this.get('installerStep3Controller').loadStep('retainValue');
  53. case '3':
  54. this.get('installerStep2Controller').loadStep();
  55. case '2':
  56. case '1':
  57. }
  58. },
  59. setInstallerCurrentStep: function (currentStep, completed) {
  60. var loginName = this.getLoginName();
  61. App.db.setInstallerCurrentStep(currentStep, completed);
  62. this.set('installerController.currentStep', currentStep);
  63. },
  64. getInstallerCurrentStep: function () {
  65. var loginName = this.getLoginName();
  66. var currentStep = App.db.getInstallerCurrentStep();
  67. console.log('getInstallerCurrentStep: loginName=' + loginName + ", currentStep=" + currentStep);
  68. if (!currentStep) {
  69. currentStep = '1';
  70. }
  71. console.log('returning currentStep=' + currentStep);
  72. return currentStep;
  73. },
  74. loggedIn: false,
  75. getAuthenticated: function () {
  76. // TODO: this needs to be hooked up with server authentication
  77. var auth = App.db.getAuthenticated();
  78. var authResp = (auth && auth === true);
  79. this.set('loggedIn', authResp);
  80. return authResp;
  81. },
  82. setAuthenticated: function (authenticated) {
  83. // TODO: this needs to be hooked up with server authentication
  84. console.log("TRACE: Entering router:setAuthenticated function");
  85. App.db.setAuthenticated(authenticated);
  86. this.set('loggedIn', authenticated);
  87. },
  88. getLoginName: function () {
  89. // TODO: this needs to be hooked up with server authentication
  90. return App.db.getLoginName();
  91. //return localStorage.getItem('Ambari' + 'loginName');
  92. },
  93. setLoginName: function (loginName) {
  94. // TODO: this needs to be hooked up with server authentication
  95. App.db.setLoginName(loginName);
  96. //localStorage.setItem('Ambari' + 'loginName', loginName);
  97. },
  98. // that works incorrectly
  99. setUser: function (user) {
  100. App.db.setUser(user);
  101. },
  102. // that works incorrectly
  103. getUser: function () {
  104. return App.db.getUser();
  105. },
  106. login: function (loginName, user) {
  107. // TODO: this needs to be hooked up with server authentication
  108. console.log("In login function");
  109. this.setAuthenticated(true);
  110. this.setLoginName(loginName);
  111. // refactor to get user attributes
  112. // this.setUser(user);
  113. this.transitionTo(this.getSection());
  114. },
  115. defaultSection: 'installer',
  116. getSection: function () {
  117. var section = App.db.getSection();
  118. console.log("The section is: " + section);
  119. var section = localStorage.getItem(this.getLoginName() + 'section');
  120. return section || this.defaultSection;
  121. },
  122. setSection: function (section) {
  123. App.db.setSection(section);
  124. },
  125. root: Em.Route.extend({
  126. index: Em.Route.extend({
  127. route: '/',
  128. redirectsTo: 'login'
  129. }),
  130. login: Em.Route.extend({
  131. route: '/login',
  132. /**
  133. * If the user is already logged in, redirect to where the user was previously
  134. */
  135. enter: function (router, context) {
  136. if (router.getAuthenticated()) {
  137. Ember.run.next(function () {
  138. console.log(router.getLoginName() + ' already authenticated. Redirecting...');
  139. router.transitionTo(router.getSection(), context);
  140. });
  141. }
  142. },
  143. connectOutlets: function (router, context) {
  144. console.log('/login:connectOutlet');
  145. console.log('currentStep is: ' + router.getInstallerCurrentStep());
  146. console.log('authenticated is: ' + router.getAuthenticated());
  147. router.get('applicationController').connectOutlet('login', App.LoginView);
  148. }
  149. }),
  150. installer: require('routes/installer'),
  151. main: require('routes/main'),
  152. logoff: function (router, context) {
  153. console.log('logging off');
  154. App.db.cleanUp();
  155. router.set('loginController.loginName', '');
  156. router.set('loginController.password', '');
  157. router.transitionTo('login', context);
  158. }
  159. })
  160. })