Created
October 30, 2016 11:46
-
-
Save Unkas82/3f34337319ee26bdbb40415181cd0db8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProjectsController < ApplicationController | |
| def index | |
| get_index_records | |
| if current_user.role.name == "expert" | |
| @tiles = get_user_tiles | |
| end | |
| end | |
| def show | |
| @project = Project.find(params[:id]) | |
| #binding.pry | |
| redirect_to :root if (@project.nil?) || (@project.id == 0) || (@project.archive? && current_user.role.name != "admin") | |
| get_notifications(params[:id]) | |
| if params[:subaction] == 'archive' | |
| theproject = Project.find(params[:id]) | |
| theproject.archive = true | |
| theproject.save | |
| flash[:notice] = "проект #{@project.id} помещен в архив" | |
| redirect_to :root | |
| end | |
| @tiles = ProjectTile.where(project_id: params[:id]).order(:section_id, :stage_id) | |
| @stages = Stage.all.order(:id) | |
| end | |
| def create | |
| @project = Project.new(project_params) | |
| if @project.save | |
| create_proj_tiles (@project) | |
| flash[:notice] = "создан новый проект - #{@project.name}" | |
| redirect_to project_path(@project.id) | |
| else | |
| #binding.pry | |
| #object = @project | |
| #@project = @project | |
| get_index_records | |
| render :action => "index" | |
| #redirect_to :root | |
| end | |
| end | |
| def update | |
| #binding.pry | |
| project = Project.find(params[:id]) | |
| project.info = params[:project][:info] | |
| project.save | |
| #binding.pry | |
| redirect_to project_path | |
| end | |
| def get_index_records | |
| @projects = Project.not_archive | |
| get_notifications | |
| end | |
| def create_proj_tiles (thisproj) | |
| sections = Section.where(linear: [thisproj.linear, nil]).order(:id) | |
| if thisproj.exp_type_id.present? | |
| sections = sections.where(exp_type_id: thisproj.exp_type_id) | |
| end | |
| #binding.pry | |
| stages = Stage.all | |
| sections.each do |sect| | |
| stages.each do |stage| | |
| tile = ProjectTile.new | |
| tile.project_id = thisproj.id | |
| tile.section_id = sect.id | |
| tile.stage_id = stage.id | |
| #tile.deadline = "03-03-2017" | |
| tile.save! | |
| end | |
| end | |
| #flash[:notice] = "User has been activated again" | |
| end | |
| def render_new_project_form | |
| @project = Project.new | |
| @linearment = {'Линейный' => 1, 'Нелинейный' => 2} | |
| #binding.pry | |
| render layout: false | |
| end | |
| def render_docboard | |
| @documents = Document.where(project_tile_id: params[:tile_id]).order(created_at: :desc) | |
| #binding.pry | |
| if ["1", "2", "3"].include?(params[:tile_id]) | |
| @header_str = get_storage_name_by_id(params[:tile_id]) | |
| #binding.pry | |
| end | |
| render layout: false | |
| end | |
| def render_infoboard | |
| @project = Project.find(params[:project_id]) | |
| #@project_info ||= "" | |
| #binding.pry | |
| render layout: false | |
| end | |
| def render_expert_modal | |
| @experts = User.only_experts | |
| #binding.pry | |
| @tile = ProjectTile.find(params[:tile_id]) | |
| render layout: false | |
| end | |
| def render_message_send_form | |
| @experts = User.only_experts | |
| @projects = Project.not_archive | |
| render layout: false | |
| end | |
| def set_expert | |
| #binding.pry | |
| end | |
| def get_storage_name_by_id(storage_id) | |
| tile = ProjectTile.find(storage_id) | |
| #binding.pry | |
| return "Приказы" if tile.id == 1 | |
| return "Законы" if tile.id == 2 | |
| return "Образцы" if tile.id == 3 | |
| "" | |
| end | |
| private | |
| def get_notifications(theproject_id = nil) | |
| if theproject_id.present? | |
| if current_user.name == "admin" | |
| @notifications = Notification.where(project_id: theproject_id).order(created_at: :desc) | |
| else | |
| @notifications = Notification.where('r_user_id = ? OR r_user_id = ? OR user_id = ?', current_user.id, nil, 1) | |
| @notifications = @notifications.where(:project_id => [theproject_id, nil] ).order(created_at: :desc) | |
| end | |
| else | |
| @notifications = Notification.where(:project_id => [nil] ).order(created_at: :desc) | |
| end | |
| end | |
| def get_user_tiles | |
| user_tiles = ProjectTile.where(user_id: current_user.id, ) | |
| user_tiles.includes(:project).where(:projects => {:archive => false}) | |
| #binding.pry | |
| #user_tiles = user_tiles.includes(:projects).where('projects.archive = ?', false) | |
| #.not_archive | |
| #binding.pry | |
| #Project.where(id: ProjectTile.where(user_id: current_user.id).distinct.pluck(:project_id)).count | |
| end | |
| def project_params | |
| params.require(:project).permit(:name, :client, :city, :linear, :exp_type_id) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment