projects_controller.rb - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
 (HTM) git clone git://jay.scot/warvox
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
       projects_controller.rb (3927B)
       ---
            1 class ProjectsController < ApplicationController
            2 
            3   def index
            4      @projects = Project.order('id DESC').paginate(
            5       page: params[:page],
            6       per_page: 10
            7     )
            8 
            9     @new_project = Project.new
           10 
           11     respond_to do |format|
           12       format.html
           13       format.xml  { render xml: @projects }
           14     end
           15   end
           16 
           17   def show
           18     @project = Project.find(params[:id])
           19     @active_jobs = @project.jobs.where(status: 'running', completed_at: nil)
           20     @inactive_jobs  = @project.jobs.order('id DESC').where('status NOT IN (?)', ['submitted', 'scheduled', 'running']).paginate(
           21       page: params[:page],
           22       per_page: 30
           23     )
           24 
           25     @boxes = {
           26       called: { cnt: @project.calls.count },
           27       answered: { cnt: @project.calls.where(answered: true).count },
           28       analyzed: { cnt: @project.calls.where('analysis_completed_at IS NOT NULL').count },
           29       voice: { cnt: @project.lines.where(line_type: 'voice').count },
           30       voicemail: { cnt: @project.lines.where(line_type: 'voicemail').count },
           31       fax: { cnt: @project.lines.where(line_type: 'fax').count },
           32       modem: { cnt: @project.lines.where(line_type: 'modem').count }
           33     }
           34 
           35     if @boxes[:called][:cnt] == 0
           36       @boxes[:called][:txt] = '0'
           37       @boxes[:called][:cls] = 'nodata'
           38 
           39       # No calls, so everything else is unknown
           40       [ :answered, :analyzed, :voice, :voicemail, :fax, :modem ].each do |t|
           41         @boxes[t][:txt] = '?'
           42         @boxes[t][:cls] = 'nodata'
           43       end
           44 
           45     else
           46 
           47       [ :called, :answered, :analyzed].each do |t|
           48         @boxes[t][:txt] = number_with_delimiter(@boxes[t][:cnt])
           49         @boxes[t][:cls] = 'completed'
           50       end
           51 
           52       if @boxes[:answered][:cnt] == 0
           53         @boxes[:answered][:txt] = '0'
           54         @boxes[:answered][:cls] = 'nodata'
           55       end
           56 
           57       if @boxes[:analyzed][:cnt] == 0
           58         [ :voice, :voicemail, :fax, :modem ].each do |t|
           59           @boxes[t][:txt] = '?'
           60           @boxes[t][:cls] = 'nodata'
           61         end
           62         @boxes[:analyzed][:cls] = 'nodata'
           63       else
           64 
           65         @boxes[:voice][:txt] = number_with_delimiter(@boxes[:voice][:cnt])
           66         @boxes[:voice][:cls] = 'voice'
           67 
           68         @boxes[:voicemail][:txt] = number_with_delimiter(@boxes[:voicemail][:cnt])
           69         @boxes[:voicemail][:cls] = 'voicemail'
           70 
           71         @boxes[:fax][:txt] = number_with_delimiter(@boxes[:fax][:cnt])
           72         @boxes[:fax][:cls] = 'fax'
           73 
           74         @boxes[:modem][:txt] = number_with_delimiter(@boxes[:modem][:cnt])
           75         @boxes[:modem][:cls] = 'modem'
           76       end
           77     end
           78 
           79     respond_to do |format|
           80       format.html
           81       format.xml  { render xml: @project }
           82     end
           83   end
           84 
           85   def new
           86     @new_project = Project.new
           87     respond_to do |format|
           88       format.html
           89       format.xml  { render xml: @new_project }
           90     end
           91   end
           92 
           93 
           94   def edit
           95     @project = Project.find(params[:id])
           96   end
           97 
           98   def create
           99     @new_project = Project.new(project_params)
          100     @new_project.created_by = current_user.login
          101 
          102     respond_to do |format|
          103       if @new_project.save
          104         format.html { redirect_to(project_path(@new_project)) }
          105         format.xml  { render xml: @project, status: :created, location: @new_project }
          106       else
          107         format.html { render action: "new" }
          108         format.xml  { render xml: @new_project.errors, status: :unprocessable_entity }
          109       end
          110     end
          111   end
          112 
          113   def update
          114     @project = Project.find(params[:id])
          115 
          116     respond_to do |format|
          117       if @project.update_attributes(project_params)
          118         format.html { redirect_to projects_path }
          119         format.xml  { head :ok }
          120       else
          121         format.html { render action: "edit" }
          122         format.xml  { render xml: @project.errors, status: :unprocessable_entity }
          123       end
          124     end
          125   end
          126 
          127   def destroy
          128     @project = Project.find(params[:id])
          129     @project.destroy
          130 
          131     respond_to do |format|
          132       format.html { redirect_to(projects_url) }
          133       format.xml  { head :ok }
          134     end
          135   end
          136 
          137   private
          138 
          139   def project_params
          140     params.require(:project).permit(:name, :description)
          141   end
          142 end