Skip to content
Snippets Groups Projects
Commit 9b282dad authored by Matheus Agio Nerone's avatar Matheus Agio Nerone
Browse files

migrating institutions


Signed-off-by: default avatarman13 <man13@inf.ufpr.br>
parent 70ae479a
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ $ -> ...@@ -24,7 +24,7 @@ $ ->
len = all.length len = all.length
html = '' html = ''
while i < len 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 + '"' 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 if lookup[all[i].id] != undefined
html += " checked" html += " checked"
......
...@@ -58,13 +58,13 @@ class InstitutionsController < ApplicationController ...@@ -58,13 +58,13 @@ class InstitutionsController < ApplicationController
end end
def users def users
@users = institution_repository.associated_with @institution @users = @institution.users
end end
private private
def set_institution def set_institution
@institution = institution_repository.find(params[:id]) @institution = Institution.find(params[:id])
end end
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
......
...@@ -4,7 +4,7 @@ class Management::InstitutionsController < ManagementController ...@@ -4,7 +4,7 @@ class Management::InstitutionsController < ManagementController
# GET /management/institutions # GET /management/institutions
# GET /management/institutions.json # GET /management/institutions.json
def index def index
@institutions = institution_repository.all || [] @institutions = Institution.all
end end
# GET /management/institutions/1 # GET /management/institutions/1
...@@ -27,7 +27,7 @@ class Management::InstitutionsController < ManagementController ...@@ -27,7 +27,7 @@ class Management::InstitutionsController < ManagementController
@institution = Institution.new(institution_params) @institution = Institution.new(institution_params)
respond_to do |format| 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.html { redirect_to [:management, @institution], notice: 'Instituição criada com sucesso.' }
format.json { render :show, status: :created, location: @institution } format.json { render :show, status: :created, location: @institution }
else else
...@@ -42,7 +42,10 @@ class Management::InstitutionsController < ManagementController ...@@ -42,7 +42,10 @@ class Management::InstitutionsController < ManagementController
def add_user def add_user
user = User.find(params[:user_id]) 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 render json: true
end end
...@@ -50,9 +53,7 @@ class Management::InstitutionsController < ManagementController ...@@ -50,9 +53,7 @@ class Management::InstitutionsController < ManagementController
# DELETE /management/institutions/:id/user/:user_id # DELETE /management/institutions/:id/user/:user_id
# remove user from institution # remove user from institution
def remove_user def remove_user
user = User.find(params[:user_id]) @institution.users.delete(params[:user_id])
institution_repository.remove_user(user, @institution) unless user.blank?
render json: true render json: true
end end
...@@ -61,7 +62,7 @@ class Management::InstitutionsController < ManagementController ...@@ -61,7 +62,7 @@ class Management::InstitutionsController < ManagementController
# PATCH/PUT /management/institutions/1.json # PATCH/PUT /management/institutions/1.json
def update def update
respond_to do |format| 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.html { redirect_to [:management, @institution], notice: 'Instituição modificada com sucesso.' }
format.json { render :show, status: :ok, location: @institution } format.json { render :show, status: :ok, location: @institution }
else else
...@@ -74,7 +75,7 @@ class Management::InstitutionsController < ManagementController ...@@ -74,7 +75,7 @@ class Management::InstitutionsController < ManagementController
# DELETE /management/institutions/1 # DELETE /management/institutions/1
# DELETE /management/institutions/1.json # DELETE /management/institutions/1.json
def destroy def destroy
institution_repository.destroy @institution @institution.destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to management_institutions_url, notice: 'Instituição deletada com sucesso.' } format.html { redirect_to management_institutions_url, notice: 'Instituição deletada com sucesso.' }
format.json { head :no_content } format.json { head :no_content }
...@@ -82,13 +83,13 @@ class Management::InstitutionsController < ManagementController ...@@ -82,13 +83,13 @@ class Management::InstitutionsController < ManagementController
end end
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_institution def set_institution
@institution = institution_repository.find(params[:id]) @institution = Institution.find params[:id]
end end
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def institution_params def institution_params
params[:institution] params.require(:institution).permit(:name, :city, :country, :address, :description)
end end
end end
...@@ -33,7 +33,7 @@ class UsersController < ApplicationController ...@@ -33,7 +33,7 @@ class UsersController < ApplicationController
end end
def list def list
@users = user_repository.all @users = User.all
end end
private private
......
<p id="notice"><%= notice %></p> <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 %> <%= link_to 'Back', management_institutions_path %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment