diff --git a/app/assets/javascripts/management/institutions.coffee b/app/assets/javascripts/management/institutions.coffee index 24edb353d62c2955277978889d478edf15b0666b..b9fc9e9669381a293bbe1c93a9a5910a3ab0c590 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 9bc354c56c7823d2b44ef7eb378807a43ab2ec7e..15c60d0212fde1e5f4dd7893a16bf9a1089d6191 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 7ae24fe55649646028423c0171b9fbb2fd3ae115..9cc46be075da09ef71d754c0a5db64aef3f6ec42 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 fecbdf30bf6e523bb4ea00875cc91c795126e63d..0d05825874299f4a0adc22779709c322c8ac3035 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 675726e73ddedc66946cc170b3c4fd0cf17689b8..de1e5d1e4b50bd48157719ac7bfa5ab6529ab787 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 %>