Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Djello #18

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added members
  • Loading branch information
leoahnn committed Oct 10, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 1deaed2970a8c6c285efb3809925d388a315799e
23 changes: 22 additions & 1 deletion app/assets/javascripts/controllers/edit_card_ctrl.js
Original file line number Diff line number Diff line change
@@ -3,8 +3,9 @@ Djello.controller('EditCardCtrl', [
'close',
'card',
'CardService',
'UserService',
'$rootScope',
function($scope, close, card, CardService, $rootScope) {
function($scope, close, card, CardService, UserService, $rootScope) {

$scope.card = card
$scope.close = function(response) {
@@ -22,4 +23,24 @@ Djello.controller('EditCardCtrl', [
})
}

$scope.addCardMember = function(user_id) {
console.log("adding member")
CardService.addCardMember($scope.card.id, user_id)
.then(function(){
$rootScope.$broadcast('memeber.changed')
})
}

$scope.removeCardMember = function(user_id) {
CardService.removeCardMember($scope.card.id, user_id)
.then(function(){
$rootScope.$broadcast('member.changed')
})
}

UserService.getUsers()
.then(function(response) {
$scope.users = response
});

}])
1 change: 0 additions & 1 deletion app/assets/javascripts/controllers/show_list_ctrl.js
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ Djello.controller('ShowListCtrl', [
card: card
}
}).then(function(modal) {
//it's a bootstrap element, use 'modal' to show it
modal.element.modal();
modal.close.then(function(result) {
console.log(result);
3 changes: 3 additions & 0 deletions app/assets/javascripts/members.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
16 changes: 15 additions & 1 deletion app/assets/javascripts/services/card_service.js
Original file line number Diff line number Diff line change
@@ -30,8 +30,22 @@ Djello.factory('CardService', [
return Restangular.one('cards', card_id).remove();
}

// var getCardMembers = function(card_id) {
// return Restangular.one('cards', card_id)
// }

return {getAllCards: getAllCards, createCard: createCard, changeCard: changeCard, deleteCard: deleteCard}
var addCardMember = function(card_id, user_id) {
var data = {
member: {
card_id: card_id,
user_id: user_id
}
}
return Restangular.all('members').post(data)
}


return {getAllCards: getAllCards, createCard: createCard, changeCard: changeCard, deleteCard: deleteCard, addCardMember: addCardMember}

}
])
12 changes: 12 additions & 0 deletions app/assets/javascripts/services/user_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Djello.factory('UserService', [
'Restangular', function(Restangular) {

var getUsers = function() {
return Restangular.all('users').getList();
}

return {
getUsers: getUsers
}

}])
3 changes: 3 additions & 0 deletions app/assets/javascripts/users.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
6 changes: 6 additions & 0 deletions app/assets/stylesheets/lists.scss
Original file line number Diff line number Diff line change
@@ -39,3 +39,9 @@ h4 {
}
}
}

.new-list-form {
label {
color: white;
}
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/members.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the members controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception


before_filter :configure_permitted_parameters, if: :devise_controller?

protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end
end
2 changes: 1 addition & 1 deletion app/controllers/boards_controller.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ def show
@board = Board.find(params[:id])
respond_to do |format|
format.json { render json:
@board.to_json(include:{ lists:{include: :cards }})}
@board.to_json(include:{ lists:{include: {cards:{include: :users}}}})}
end
end

2 changes: 1 addition & 1 deletion app/controllers/cards_controller.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ def create
@card = @list.cards.build(card_params)
respond_to do |format|
if @card.save
format.json { render json: @card }
format.json { render json: @card.to_json(include: :users) }
else
format.json { render status: :unprocessable_entity }
end
2 changes: 1 addition & 1 deletion app/controllers/lists_controller.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ def create
@list = @board.lists.build(list_params)
respond_to do |format|
if @list.save
format.json { render json: @list.to_json(include: :cards) }
format.json { render json: @list.to_json(include:{ cards:{include: :users}}) }
else
format.json { render status: :unprocessable_entity }
end
19 changes: 19 additions & 0 deletions app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class MembersController < ApplicationController

def create
@member = Member.new(member_params)
respond_to do |format|
if @member.save
format.json { render json: @member }
end
end
end


private

def member_params
params.require(:member).permit(:user_id, :card_id)
end

end
10 changes: 10 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class UsersController < ApplicationController

def index
@users = User.all
respond_to do |format|
format.json { render json: @users }
end
end

end
2 changes: 2 additions & 0 deletions app/helpers/members_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MembersHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
2 changes: 2 additions & 0 deletions app/models/card.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Card < ApplicationRecord
belongs_to :list
has_many :members
has_many :users, through: :members
end
4 changes: 4 additions & 0 deletions app/models/member.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class Member < ApplicationRecord

belongs_to :user
belongs_to :card

end
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -4,4 +4,7 @@ class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

has_many :members
has_many :cards, through: :members

end
4 changes: 4 additions & 0 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -7,6 +7,10 @@
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :username %><br />
<%= f.text_field :username %>
</div>

<div class="field">
<%= f.label :password %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@

scope :api do
scope :v1 do
resources :users
resources :members, only: [:create]
resources :boards do
resources :lists, shallow: true do
resources :cards, shallow: true
15 changes: 5 additions & 10 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)

puts "purging database"
User.destroy_all
Board.destroy_all

puts "creating new users + boards"
User.create(username: Faker::Superhero.name, email: Faker::Internet.email, password: 'password')
5.times do
User.create(username: Faker::Superhero.name, email: Faker::Internet.email, password: 'password')
end

5.times do
b = Board.create(title: Faker::Hipster.word)

2.times do
l = b.lists.create!(title: Faker::Company.buzzword, description: Faker::Commerce.product_name)
3.times do
l.cards.create!(title: Faker::Book.title, description: Faker::Company.bs)
c = l.cards.create!(title: Faker::Book.title, description: Faker::Company.bs)
c.users.push(User.all.sample)
end
end

10 changes: 5 additions & 5 deletions public/templates/boards/show.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="col-sm-12">

<h2 href="" editable-text="board.title" onbeforesave="changeBoard($data)">{{board.title || ""}}</h2>
<h2 href="" editable-text="board.title" onbeforesave="changeBoard($data)">{{board.title || ""}}</h2>

<div class="dropdown pull-right">
<button class='btn btn-danger btn-sm' ng-click="deleteBoard()">Delete Board</button>
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-toggle="dropdown">{{board.title}}
<div class="dropdown pull-right">
<button class='btn btn-danger btn-sm' ng-click="deleteBoard()">Delete Board</button>
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-toggle="dropdown">{{board.title}}
<span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li ng-repeat="board in boards"><a href="" ui-sref="main.board({id:{{board.id}}})">{{board.title}}</a></li>
@@ -13,7 +13,7 @@ <h2 href="" editable-text="board.title" onbeforesave="changeBoard($data)">{{boar
</div>

<div class="col-sm-3" ui-view="lists" ng-repeat="list in board.lists"></div>
<div class ='col-sm-3'>
<div class='col-sm-3'>
<div class="new-list" ng-click="newList=true" ng-hide="newList">
<h4><a>Add a new list...</a></h4>
</div>
20 changes: 18 additions & 2 deletions public/templates/cards/edit.html
Original file line number Diff line number Diff line change
@@ -6,8 +6,24 @@
<h4><a class="modal-title" editable-text="card.title" buttons="no" onbeforesave="changeCard({title: $data})">{{card.title}}<a></h4>
</div>
<div class="modal-body">
<a editable-text="card.description" buttons="no" onbeforesave="changeCard({description: $data})">{{card.description}}</a>
<a ng-hide="card.description" editable-text="card.description" buttons="no" onbeforesave="changeCard({description: $data})">description here</a>
<div class="">
<a editable-text="card.description" buttons="no" onbeforesave="changeCard({description: $data})">{{card.description}}</a>
<a ng-hide="card.description" editable-text="card.description" buttons="no" onbeforesave="changeCard({description: $data})">description here</a>
</div>
<div class="">
<ul>
<li ng-repeat="user in card.users">{{user.username}}</li>
</ul>
</div>
<div class="dropdown">
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-toggle="dropdown">Add a Member
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li ng-repeat="user in users ><a href="" ng-click="addCardMember(user.id)">{{user.username}}</a></li>
</ul>
</div>


</div>
<div class="modal-footer">
<button type="button" ng-click="deleteCard()" class="btn btn-danger btn-sm" data-dismiss="modal">delete</button>
3 changes: 3 additions & 0 deletions public/templates/lists/show.html
Original file line number Diff line number Diff line change
@@ -11,6 +11,9 @@ <h3>
<h4><a href="" editable-text="list.description" buttons="no" onbeforesave="changeList({description: $data})">{{list.description}}</a></h4>
<div class='card' ng-repeat='card in list.cards'>
<a href="" ng-click="editCard(card)">{{card.title}}</a>
<ul>
<li ng-repeat='user in card.users'>{{user.username}}</li>
</ul>
</div>
<div class="add-card text-center" ng-click="newCard=true" ng-hide="newCard">
<a>Add a card..</a>
7 changes: 7 additions & 0 deletions test/controllers/members_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class MembersControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class UsersControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end