From 9b282dadab736821e4d183b821f0362f1d1eeaad Mon Sep 17 00:00:00 2001 From: man13 <man13@inf.ufpr.br> Date: Wed, 3 Feb 2016 09:19:14 -0200 Subject: [PATCH] migrating institutions Signed-off-by: man13 <man13@inf.ufpr.br> --- .../management/institutions.coffee | 2 +- app/controllers/institutions_controller.rb | 4 +-- .../management/institutions_controller.rb | 33 ++++++++++--------- app/controllers/users_controller.rb | 2 +- .../management/institutions/show.html.erb | 2 +- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/management/institutions.coffee b/app/assets/javascripts/management/institutions.coffee index 24edb353..b9fc9e96 100644 --- a/app/assets/javascripts/management/institutions.coffee +++ b/app/assets/javascripts/management/institutions.coffee @@ -24,7 +24,7 @@ $ -> len = all.length html = '' while i < len - name = 'user_' + all[i].rid.split(':').slice(-1)[0] + name = 'user_' + all[i].id html += '<input type="checkbox" class="institutional-user-element" data-uid="' + all[i].id + '" data-institution-id="' + institution_id + '" id="' + name + '"' if lookup[all[i].id] != undefined html += " checked" diff --git a/app/controllers/institutions_controller.rb b/app/controllers/institutions_controller.rb index 9bc354c5..15c60d02 100644 --- a/app/controllers/institutions_controller.rb +++ b/app/controllers/institutions_controller.rb @@ -58,13 +58,13 @@ class InstitutionsController < ApplicationController end def users - @users = institution_repository.associated_with @institution + @users = @institution.users end private def set_institution - @institution = institution_repository.find(params[:id]) + @institution = Institution.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/controllers/management/institutions_controller.rb b/app/controllers/management/institutions_controller.rb index 7ae24fe5..9cc46be0 100644 --- a/app/controllers/management/institutions_controller.rb +++ b/app/controllers/management/institutions_controller.rb @@ -4,7 +4,7 @@ class Management::InstitutionsController < ManagementController # GET /management/institutions # GET /management/institutions.json def index - @institutions = institution_repository.all || [] + @institutions = Institution.all end # GET /management/institutions/1 @@ -27,7 +27,7 @@ class Management::InstitutionsController < ManagementController @institution = Institution.new(institution_params) respond_to do |format| - if institution_repository.create @institution + if @institution.save format.html { redirect_to [:management, @institution], notice: 'Instituição criada com sucesso.' } format.json { render :show, status: :created, location: @institution } else @@ -42,7 +42,10 @@ class Management::InstitutionsController < ManagementController def add_user user = User.find(params[:user_id]) - institution_repository.add_user(user, @institution) unless user.blank? + unless user.blank? + @institution.users << user + @institution.save + end render json: true end @@ -50,9 +53,7 @@ class Management::InstitutionsController < ManagementController # DELETE /management/institutions/:id/user/:user_id # remove user from institution def remove_user - user = User.find(params[:user_id]) - - institution_repository.remove_user(user, @institution) unless user.blank? + @institution.users.delete(params[:user_id]) render json: true end @@ -61,7 +62,7 @@ class Management::InstitutionsController < ManagementController # PATCH/PUT /management/institutions/1.json def update respond_to do |format| - if @institution.update(institution_params) + if @institution.update institution_params format.html { redirect_to [:management, @institution], notice: 'Instituição modificada com sucesso.' } format.json { render :show, status: :ok, location: @institution } else @@ -74,7 +75,7 @@ class Management::InstitutionsController < ManagementController # DELETE /management/institutions/1 # DELETE /management/institutions/1.json def destroy - institution_repository.destroy @institution + @institution.destroy respond_to do |format| format.html { redirect_to management_institutions_url, notice: 'Instituição deletada com sucesso.' } format.json { head :no_content } @@ -82,13 +83,13 @@ class Management::InstitutionsController < ManagementController end private - # Use callbacks to share common setup or constraints between actions. - def set_institution - @institution = institution_repository.find(params[:id]) - end + # Use callbacks to share common setup or constraints between actions. + def set_institution + @institution = Institution.find params[:id] + end - # Never trust parameters from the scary internet, only allow the white list through. - def institution_params - params[:institution] - end + # Never trust parameters from the scary internet, only allow the white list through. + def institution_params + params.require(:institution).permit(:name, :city, :country, :address, :description) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fecbdf30..0d058258 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -33,7 +33,7 @@ class UsersController < ApplicationController end def list - @users = user_repository.all + @users = User.all end private diff --git a/app/views/management/institutions/show.html.erb b/app/views/management/institutions/show.html.erb index 675726e7..de1e5d1e 100644 --- a/app/views/management/institutions/show.html.erb +++ b/app/views/management/institutions/show.html.erb @@ -1,4 +1,4 @@ <p id="notice"><%= notice %></p> -<%= link_to 'Edit', edit_management_institution_path(@management_institution) %> | +<%= link_to 'Edit', edit_management_institution_path(@institution) %> | <%= link_to 'Back', management_institutions_path %> -- GitLab