From 84d48bbee3b1c99979fe5071f00fe78a8c539077 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Thu, 28 Apr 2016 01:58:48 +0000 Subject: [PATCH] Made login form look better and made user menu look better. --- app/controllers/api_controller.rb | 4 ++++ app/views/api/currentUserTournaments.jbuilder | 3 +++ config/routes.rb | 1 + frontend/app/js/controllers/my-tournaments.js | 11 +++++++++ frontend/app/js/routes.js | 5 ++++ .../app/js/services/tournaments-service.js | 7 +++++- frontend/app/pages/index.us | 23 ++++++++++--------- .../app/pages/tournaments/my-tournaments.html | 17 ++++++++++++++ 8 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 app/views/api/currentUserTournaments.jbuilder create mode 100644 frontend/app/js/controllers/my-tournaments.js create mode 100644 frontend/app/pages/tournaments/my-tournaments.html diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 679c84f..4b58505 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -21,4 +21,8 @@ class ApiController < ApplicationController @tournament = Tournament.new(JSON.parse(params[:tournament])) @tournament.save end + + def currentUserTournaments + @tournaments = current_user.tournaments + end end diff --git a/app/views/api/currentUserTournaments.jbuilder b/app/views/api/currentUserTournaments.jbuilder new file mode 100644 index 0000000..c9f6ee7 --- /dev/null +++ b/app/views/api/currentUserTournaments.jbuilder @@ -0,0 +1,3 @@ +json.array!(@tournaments) do |tournament| + json.extract! tournament, :id, :name, :address, :director, :director_email, :date +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 30007fe..94cc729 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,6 +54,7 @@ Wrestling::Application.routes.draw do #API get "/api/tournaments" => "api#tournaments" + get "/api/tournaments/user" => "api#currentUserTournaments" get "/api/tournaments/:tournament" => "api#tournament" get "/api/index" => "api#index" post "/api/tournaments/new" => "newTournament" diff --git a/frontend/app/js/controllers/my-tournaments.js b/frontend/app/js/controllers/my-tournaments.js new file mode 100644 index 0000000..567374b --- /dev/null +++ b/frontend/app/js/controllers/my-tournaments.js @@ -0,0 +1,11 @@ +'use strict'; + +app.controller("myTournamentsController", function($scope, tournamentsService, $rootScope) { + + tournamentsService.getMyTournaments().then(function(data) { + //this will execute when the + //AJAX call completes. + $scope.allTournaments = data; + }); + +}); \ No newline at end of file diff --git a/frontend/app/js/routes.js b/frontend/app/js/routes.js index 194d2f6..84ba476 100644 --- a/frontend/app/js/routes.js +++ b/frontend/app/js/routes.js @@ -24,6 +24,11 @@ app.config(['$routeProvider', '$locationProvider', function($routeProvider,$loca controller: 'tournamentsController' }); + $routeProvider.when('/tournaments/user', { + templateUrl: 'my-tournaments.html', + controller: 'myTournamentsController' + }); + $routeProvider.when('/tournaments/:id', { templateUrl: 'tournaments-show.html', controller: 'tournamentController' diff --git a/frontend/app/js/services/tournaments-service.js b/frontend/app/js/services/tournaments-service.js index 36d2a02..ecba5fa 100644 --- a/frontend/app/js/services/tournaments-service.js +++ b/frontend/app/js/services/tournaments-service.js @@ -4,7 +4,12 @@ app.factory('tournamentsService', tournamentsService); function tournamentsService($http){ var service = {}; - + service.getMyTournaments = function(user){ + return $http({ + url: '/api/tournaments/user/', + method: "GET" + }).then(successResponse, errorCallback); + }; service.getAllTournaments = function(){ return $http({ diff --git a/frontend/app/pages/index.us b/frontend/app/pages/index.us index 213c950..902d9da 100644 --- a/frontend/app/pages/index.us +++ b/frontend/app/pages/index.us @@ -28,22 +28,23 @@
  • Browse Tournaments
  • About
  • Tutorials
  • - diff --git a/frontend/app/pages/tournaments/my-tournaments.html b/frontend/app/pages/tournaments/my-tournaments.html new file mode 100644 index 0000000..9038c29 --- /dev/null +++ b/frontend/app/pages/tournaments/my-tournaments.html @@ -0,0 +1,17 @@ +

    My Tournaments

    +
    + + + + + + + + + + + + + + +
    NameDate
    {{ tournament.name }}{{ tournament.date }}