Commit e2db4a265b052a23c1634c5cb3fdbdab4a30ad1c

Authored by Andrew Buss
1 parent 8fa323ef66

class add functional now

Showing 5 changed files with 31 additions and 12 deletions Side-by-side Diff

... ... @@ -22,11 +22,8 @@
22 22 <!--<a ui-sref="addclass"><i class="mdi-content-add"></i></a>-->
23 23 </li>
24 24 <li>
25   - <ul>
26   - <li ui-sref="feed">WRONG 123</li>
27   - <li ui-sref="feed(4567)">CSE 1337</li>
28   - <li ui-sref="feed(1242)">MATH 20Z</li>
29   - <li ui-sref="feed(2842)">BILD 99</li>
  25 + <ul ng-repeat="section in sections">
  26 + <li ui-sref="feed({{section.id}})">{{section.short_name}} </li>
30 27 </ul>
31 28 </li>
32 29 <li class="bold"><a ui-sref="addclass">Add Class</a></li>
... ... @@ -58,6 +55,7 @@
58 55 <script src="scripts/RequestResetController.js"></script>
59 56 <script src="scripts/ClassAddController.js"></script>
60 57 <script src="scripts/StudyController.js"></script>
  58 +<script src="scripts/ResetPasswordController.js"></script>
61 59 <script src="scripts/VerifyEmailController.js"></script>
62 60 <!--<script src="scripts/SidebarController.js"></script>-->
63 61  
... ... @@ -69,10 +67,7 @@
69 67  
70 68 <!-- Other -->
71 69 <!--<script src="scripts/StudyController.js"></script>-->
72   -<script src="scripts/UserService.js"></script>
73   -<script src="scripts/ResetPasswordController.js"></script>
74   -<script src="//ghiden.github.io/angucomplete-alt/js/libs/angucomplete-alt.js"></script>
75   -<!--<script src="scripts/bootstrap.js"></script>-->
  70 +
76 71  
77 72 </body>
78 73 </html>
scripts/ClassAddController.js View file @ e2db4a2
1   -angular.module('flashy.ClassAddController', ['ui.router', 'angucomplete-alt', 'ngMaterial']).
  1 +angular.module('flashy.ClassAddController', ['ui.router', 'ngMaterial']).
2 2  
3 3 controller('ClassAddController', ['$scope', '$state', '$http', function($scope, $state, $http) {
4 4  
... ... @@ -13,6 +13,16 @@
13 13 };
14 14  
15 15 $scope.searchText = '';
  16 + $scope.submit = function() {
  17 + $http.post('/api/sections/' + $scope.selectedItem.id + '/enroll/').
  18 + success(function(data) {
  19 + $scope.sections.push($scope.selectedItem);
  20 + $state.go('feed', {sectionId: $scope.selectedItem.id});
  21 + }).
  22 + error(function(data, status, header, config) {
  23 + console.log(data);
  24 + });
  25 + };
16 26  
17 27 /*$scope.trySearch = function() {
18 28 $http.get('/api/sections/search', [$scope.searchText]).
scripts/RootController.js View file @ e2db4a2
... ... @@ -6,5 +6,10 @@
6 6 if (UserService.isLoggedIn()) $state.go('login');
7 7 else $state.go('addclass');
8 8 $rootScope.isLoggedIn = false;
  9 + console.log(UserService._user);
  10 + UserService.getUserData().then(function(data) {
  11 + console.log(data);
  12 + $rootScope.user = data;
  13 + });
9 14 }]);
scripts/UserService.js View file @ e2db4a2
1 1 angular.module('flashy.UserService', ['ui.router']).
2 2 service('UserService', function($rootScope, $http, $q) {
3 3 var _user = undefined;
4   - this.getUserData = function() {
  4 + $rootScope.sections = [];
  5 + this.getUserData = function(refresh) {
5 6 var deferred = $q.defer();
6 7 if (angular.isDefined(_user)) {
7 8 console.log('user is already defined: ' + _user);
... ... @@ -10,6 +11,7 @@
10 11 deferred.reject(_user);
11 12 } else {
12 13 $rootScope.isLoggedIn = true;
  14 + $rootScope.sections = _user.sections;
13 15 deferred.resolve(_user);
14 16 }
15 17 return deferred.promise;
... ... @@ -18,6 +20,7 @@
18 20 console.log('user is logged in!');
19 21 _user = data;
20 22 $rootScope.isLoggedIn = true;
  23 + $rootScope.sections = _user.sections;
21 24 deferred.resolve(data);
22 25 }).error(function(data) {
23 26 console.log('not logged in yet: ' + data.detail);
templates/addclass.html View file @ e2db4a2
... ... @@ -4,13 +4,15 @@
4 4 <md-content layout-padding="" layout="column" style="overflow:hidden">
5 5  
6 6 <form ng-submit="$event.preventDefault()">
7   - <div layout="column">
  7 + <div layout="row">
8 8 <md-autocomplete flex=""
9 9 md-autofocus="true"
10 10 md-selected-item="selectedItem"
11 11 md-search-text="searchText"
12 12 md-items="item in trySearch(searchText)"
13 13 md-item-text="item.short_name"
  14 + md-selected-item-change="selectObject(event)"
  15 + md-autoselect="true"
14 16 >
15 17 <md-item-template>
16 18 <div layout="row">
17 19  
... ... @@ -26,7 +28,11 @@
26 28 No classes match "{{searchText}}".
27 29 </md-not-found>
28 30 </md-autocomplete>
  31 + <button class="btn waves-effect waves-light" type="submit" name="add" ng-click="submit()">Add
  32 + <i class="mdi-content-add right"></i>
  33 + </button>
29 34 </div>
  35 +
30 36 </form>
31 37 </md-content>
32 38 </div>