Guest User

irc reddit angular

a guest
Apr 3rd, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. //app.js
  2.  
  3. var app = angular.module('bahquiz', ['ionic'])
  4.  
  5. app.config(function($stateProvider, $urlRouterProvider) {
  6.  
  7. // Ionic uses AngularUI Router which uses the concept of states
  8. // Learn more here: https://github.com/angular-ui/ui-router
  9. // Set up the various states which the app can be in.
  10. // Each state's controller can be found in controllers.js
  11. $stateProvider
  12.  
  13. // setup an abstract state for the tabs directive
  14. .state('tab', {
  15. url: '/tab',
  16. abstract: true,
  17. templateUrl: 'templates/tabs.html'
  18. })
  19.  
  20. // Each tab has its own nav history stack:
  21.  
  22. .state('tab.profile', {
  23. url: '/profile',
  24. views: {
  25. 'tab-profile': {
  26. templateUrl: 'templates/tab-profile.html',
  27. controller: 'ProfileCtrl'
  28. }
  29. }
  30. })
  31.  
  32. ...
  33.  
  34. .state('tab.settings', {
  35. url: '/settings',
  36. views: {
  37. 'tab-settings': {
  38. templateUrl: 'templates/tab-settings.html',
  39. controller: 'SettingsCtrl'
  40. }
  41. }
  42. });
  43.  
  44. // if none of the above states are matched, use this as the fallback
  45. $urlRouterProvider.otherwise('/tab/profile');
  46.  
  47. });
  48.  
  49. app.run(function($ionicPlatform) {
  50. $ionicPlatform.ready(function() {
  51. // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
  52. // for form inputs)
  53. if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
  54. cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  55. cordova.plugins.Keyboard.disableScroll(true);
  56.  
  57. }
  58. if (window.StatusBar) {
  59. // org.apache.cordova.statusbar required
  60. StatusBar.styleDefault();
  61. }
  62. });
  63. })
  64.  
  65. --------------------------------------------------------------------------------------------
  66. //services.js
  67. app.service('questionService', function() { //Later to be replaced by service with http requests
  68.  
  69. ...
  70.  
  71. app.factory('userFactory', ['$http', function($http){
  72. var userFactory = {};
  73. var username;
  74. var password;
  75.  
  76. userFactory.getList = function() {
  77. console.log("success");
  78. return $http.get('http://localhost:3000/users');
  79. };
  80.  
  81. userFactory.setUser = function(name,pass) {
  82. username = name;
  83. password = pass;
  84. }
  85.  
  86. userFactory.getUser = function() {
  87. if(username != null){
  88. return username;
  89. }
  90. }
  91.  
  92. return userFactory;
  93. }]);
  94. --------------------------------------------------------
  95. //one of my controllers, ProfileCtrl.js. Ignore the lack of authentication and any other questionable logic. Not done yet
  96.  
  97. app.controller('ProfileCtrl', ['$scope','userFactory', function($scope,userFactory) {
  98.  
  99. $scope.username;
  100. $scope.password;
  101.  
  102. $scope.register = function(){
  103. var i;
  104. var registered;
  105.  
  106. $scope.username = document.getElementById("username");
  107. $scope.password = document.getElementById("password");
  108.  
  109. while($scope.users[i] != null){
  110. if($scope.username == $scope.users[i].username){
  111. //somehow print the user exsits
  112. registered = true;
  113. break;
  114. }
  115. i++;
  116. }
  117.  
  118. if(registered != true){
  119. //post request
  120. $scope.signedIn = true;
  121. updateBar();
  122. }
  123. }
  124.  
  125. $scope.authenticate = function(){
  126. var i;
  127.  
  128. $scope.username = document.getElementById("username");
  129. $scope.password = document.getElementById("password");
  130.  
  131. getUsers();
  132.  
  133. while($scope.users[i] != null){
  134. if($scope.username == $scope.users[i].username){
  135. if($scope.password == $scope.users[i].password){
  136. $scope.signedIn = true;
  137. updateBar();
  138. break;
  139. } else{
  140. //somehow display the password is incorrect
  141. break;
  142. }
  143. }
  144. i++;
  145. }
  146.  
  147. if($scope.signedIn != true){
  148. //somehow display the username is incorrect
  149. }
  150. }
  151.  
  152. function updateBar() {
  153. var elem = document.getElementById("progressBar");
  154. var width = 0;
  155. var interval = setInterval(frame, 10);
  156. function frame() {
  157. if (width >= 76) { // this will be user progress number
  158. clearInterval(interval);
  159. } else {
  160. width++;
  161. elem.style.width = width + '%';
  162. document.getElementById("label").innerHTML = width * 1 + '%';
  163. }
  164. }
  165. }
  166.  
  167. function getUsers(){
  168. userFactory.getList()
  169. .then(function (response) {
  170. $scope.users = response.data.users; //check on this
  171. }, function (error) {
  172. $scope.status = 'unable to load users in controller: ' + error.message;
  173. });
  174. }
  175. }])
Add Comment
Please, Sign In to add comment