source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/serializers/deep_survey_serializer.rb
Ruby
mit
47
master
358
class DeepSurveySerializer < ActiveModel::Serializer attributes :id, :name, :expiry_date, :description, :published_on has_many :questions, :serializer => DeepQuestionSerializer has_many :categories, :serializer => DeepCategorySerializer def questions object.questions.finalized end def categories ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/reporters/response_count.rb
Ruby
mit
47
master
477
class ResponseCount attr_reader :month attr_accessor :incompletes, :completes def initialize(month, incompletes=0, completes=0) @month = month @incompletes = incompletes @completes = completes end def merge(other) merged_count = ResponseCount.new(self.month, self.incompletes, self.completes)...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/reporters/response_counts.rb
Ruby
mit
47
master
867
require 'forwardable' class ResponseCounts attr_reader :counts extend Forwardable def_delegators :@counts, :<<, :each def initialize(counts=[]) @counts = counts end def merge(other) unique_months_between(other).inject(ResponseCounts.new) do |merged_counts, month| count = find_by_month(mont...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/reporters/multi_choice_question_reporter.rb
Ruby
mit
47
master
776
class MultiChoiceQuestionReporter < QuestionReporter delegate_all SELECTED_STRING = "YES" NOT_SELECTED_STRING = "NO" BLANK_FIELD_FOR_QUESTION = "" def header [super] + model_options.map(&:content) end def formatted_answers_for(answers, options={}) initial_array = [BLANK_FIELD_FOR_QUESTION] ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/reporters/question_reporter.rb
Ruby
mit
47
master
311
class QuestionReporter < QuestionDecorator delegate_all def header "#{question_number}) #{model.content}" end def formatted_answers_for(answers, options={}) if answers answers.map { |answer| answer.content_for_excel(options[:server_url]) }.join(', ') else "" end end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/reporters/survey_reporter.rb
Ruby
mit
47
master
959
class SurveyReporter def initialize(survey) @survey = survey end def monthly_incomplete_responses_for(user_id) incomplete_hash = @survey.responses.where(:user_id => user_id, :status => Response::Status::INCOMPLETE).count(:group => "to_char(created_at, 'Mon YYYY')") incomplete = incomplete_hash.map {|...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/uploaders/image_uploader.rb
Ruby
mit
47
master
618
# encoding: utf-8 class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick before :cache, :generate_secure_token def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end def cache_dir "uploads/tmp" end version :thumb do process :resize_to...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/admin_ability.rb
Ruby
mit
47
master
1,276
class AdminAbility < Ability def initialize(user_info) @user_info = user_info can :create, Survey, :organization_id => user_info[:org_id] can :build, Survey, :organization_id => user_info[:org_id] can :update, Survey, :organization_id => user_info[:org_id] can :destroy, Survey, :organization_id =...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/super_admin_ability.rb
Ruby
mit
47
master
239
class SuperAdminAbility < Ability def initialize(user_info) @user_info = user_info can :manage, :all cannot :create, Survey cannot :create, Response can :view_dashboard, :all can :destroy, Organization end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/supervisor_ability.rb
Ruby
mit
47
master
1,024
class SupervisorAbility < Ability def initialize(user_info) @user_info = user_info can :read, Survey, surveys_published_to_me can :report, Survey, surveys_published_to_me can :archive, Survey, surveys_published_to_me can :generate_excel, Survey, surveys_published_to_me can :view_survey_dashbo...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/designer_ability.rb
Ruby
mit
47
master
1,057
class DesignerAbility < Ability def initialize(user_info) @user_info = user_info can :create, Survey, :organization_id => user_info[:org_id] can :build, Survey, :organization_id => user_info[:org_id] can :update, Survey, :organization_id => user_info[:org_id] can :destroy, Survey, :organization_i...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/viewer_ability.rb
Ruby
mit
47
master
340
class ViewerAbility < Ability def initialize(user_info) @user_info = user_info can_perform_on_own_and_shared_surveys(:read) can_perform_on_own_and_shared_surveys(:report) can :read, Response, :survey => { :organization_id => user_info[:org_id] } can :read, Response, :organization_id => user_info...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/manager_ability.rb
Ruby
mit
47
master
1,232
class ManagerAbility < Ability def initialize(user_info) @user_info = user_info can :create, Survey, :organization_id => user_info[:org_id] can :build, Survey, :organization_id => user_info[:org_id] can :update, Survey, :organization_id => user_info[:org_id] can :destroy, Survey, :organization_id...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/field_agent_ability.rb
Ruby
mit
47
master
560
class FieldAgentAbility < Ability def initialize(user_info) @user_info = user_info can :read, Survey, :survey_users => { :user_id => user_info[:user_id] } can :report, Survey, :survey_users => { :user_id => user_info[:user_id] } can :generate_excel, Survey, :survey_users => { :user_id => user_info[:u...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/ability.rb
Ruby
mit
47
master
1,593
class Ability include CanCan::Ability def self.ability_for(user) if user[:org_type] == "Financial Institution" FinancialInstituteAbility.new(user) elsif user[:user_id].present? case user[:role] when 'viewer' ViewerAbility.new(user) when 'cso_admin' AdminAbility.new(u...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/abilities/financial_institute_ability.rb
Ruby
mit
47
master
357
class FinancialInstituteAbility < Ability def initialize(user_info) @user_info = user_info can_perform_on_own_and_shared_surveys(:read) can_perform_on_own_and_shared_surveys(:generate_excel) can :read, Response, :survey => { :participating_organizations => { :organization_id => user_info[:org_id ] } ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/mailers/privacy_mailer.rb
Ruby
mit
47
master
414
class PrivacyMailer < ActionMailer::Base default from: "no-reply@thesurveys.org" def deactivation_mail(organization, users) @organization_name = organization.name headers['X-SMTPAPI'] = JSON.generate(:category => ENV['SENDGRID_CATEGORY']) mail(:bcc => users.map(&:email), :subject => I18n.t("pr...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/application_controller.rb
Ruby
mit
47
master
2,970
class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale, :session_token helper_method :current_user_info, :register_path, :new_user_path, :current_ability def default_url_options(options={}) return { :locale => I18n.locale } unless I18n.locale == I18n.default_loc...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/responses_controller.rb
Ruby
mit
47
master
4,578
class ResponsesController < ApplicationController include ResponsesHelper load_and_authorize_resource :survey load_and_authorize_resource :through => :survey before_filter :survey_finalized before_filter :authorize_public_response, :only => :create before_filter :survey_not_expired, :only => :create af...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/organization_dashboards_controller.rb
Ruby
mit
47
master
605
class OrganizationDashboardsController < ApplicationController def index authorize! :view_dashboard, :index @decorated_organizations = OrganizationDecorator.decorate_collection(Organization.all(access_token), :context => { :access_token => access_token }) end def show organization = Organization.find...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/survey_dashboard_controller.rb
Ruby
mit
47
master
413
class SurveyDashboardController < ApplicationController def index @survey = Survey.find(params[:survey_id]) authorize! :view_survey_dashboard, @survey @users_with_responses = User.users_for_ids(access_token, @survey.ids_for_users_with_responses) end def show @survey = Survey.find(params[:survey_i...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/sessions_controller.rb
Ruby
mit
47
master
514
class SessionsController < ApplicationController def create auth = request.env["omniauth.auth"] session[:user_id] = auth['uid'] session[:user_info] = auth['info'] session[:access_token] = auth['credentials']['token'] session[:session_token] = nil redirect_to request.env['omniauth.origin'] || ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/publications_controller.rb
Ruby
mit
47
master
2,229
class PublicationsController < ApplicationController before_filter :require_finalized_survey after_filter :only => [:destroy] { send_to_mixpanel("Survey unpublished", { :survey => @survey.name}) if @survey.present? } def edit @survey = Survey.find(params[:survey_id]).decorate authorize! :edit_publicatio...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/records_controller.rb
Ruby
mit
47
master
384
class RecordsController < ApplicationController def create record = Record.new(params[:record]) if record.save redirect_to :back else flash[:error] = record.errors.full_messages redirect_to :back end end def destroy record = Record.find(params[:id]) record.destroy fl...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/surveys_controller.rb
Ruby
mit
47
master
2,656
require 'will_paginate/array' class SurveysController < ApplicationController load_resource :only => :index authorize_resource after_filter(:only => [:create]) { send_to_mixpanel("Survey created") } after_filter(:only => [:destroy]) { send_to_mixpanel("Survey destroyed", {:survey => @survey.name}) if @survey.p...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/v2_survey_builder/surveys_controller.rb
Ruby
mit
47
master
2,866
class V2SurveyBuilder::SurveysController < ApplicationController layout "survey_builder_v2" load_resource :only => :index authorize_resource after_filter(:only => [:create]) { send_to_mixpanel("Survey created") } after_filter(:only => [:destroy]) { send_to_mixpanel("Survey destroyed", {:survey => @survey.name...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/auth_controller.rb
Ruby
mit
47
master
642
module Api module V1 class AuthController < APIApplicationController def create client = OAuth2::Client.new(ENV["OAUTH_ID"], ENV["OAUTH_SECRET"], :site => ENV["OAUTH_SERVER_URL"]) access_token = client.password.get_token(params['username'], params['password']) user_info = access_toke...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/records_controller.rb
Ruby
mit
47
master
859
module Api module V1 class RecordsController < APIApplicationController respond_to :json def create record = Record.create(params[:record]) # TODO: Authorize! if record.valid? render :json => record else render :json => record.errors, :status => :ba...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/api_application_controller.rb
Ruby
mit
47
master
1,040
module Api module V1 class APIApplicationController < ApplicationController rescue_from OAuth2::Error do |exception| if exception.response.status == 401 render :nothing => true, :status => :unauthorized end end rescue_from CanCan::AccessDenied do |exception| r...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/surveys_controller.rb
Ruby
mit
47
master
2,300
module Api module V1 class SurveysController < APIApplicationController authorize_resource :except => [:identifier_questions, :questions_count] after_filter :only => [:update] { send_to_mixpanel("Survey edited", {:survey => @survey.name}) if @survey.present? } after_filter :only => [:duplicate]...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/responses_controller.rb
Ruby
mit
47
master
2,874
module Api::V1 class ResponsesController < APIApplicationController load_resource :survey, :only => [:index, :show, :count] load_resource :through => :survey, :only => [:show, :count] authorize_resource before_filter :decode_base64_images, :convert_to_datetime, :only => [:create, :update] before_...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/options_controller.rb
Ruby
mit
47
master
1,109
module Api module V1 class OptionsController < APIApplicationController before_filter :dont_cache def create option = Option.new(params[:option]) authorize! :update, option.try(:survey) if option.save render :json => option else render :json => opti...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/jobs_controller.rb
Ruby
mit
47
master
218
module Api module V1 class JobsController < APIApplicationController def alive job = Delayed::Job.find_by_id(params[:id]) render :json => { alive: job.present? } end end end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/deep_surveys_controller.rb
Ruby
mit
47
master
486
module Api module V1 class DeepSurveysController < APIApplicationController authorize_resource :class => Survey def index surveys = Survey.accessible_by(current_ability).active_plus(extra_survey_ids) render :json => surveys, :each_serializer => DeepSurveySerializer end pr...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/categories_controller.rb
Ruby
mit
47
master
1,963
module Api module V1 class CategoriesController < APIApplicationController before_filter :dont_cache def create category = Category.new_category_by_type(params[:category][:type], params[:category]) authorize! :update, category.try(:survey) if category.save render :js...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/questions_controller.rb
Ruby
mit
47
master
2,417
module Api module V1 class QuestionsController < APIApplicationController before_filter :dont_cache def create question = Question.new_question_by_type(params[:question][:type], params[:question]) authorize! :update, question.try(:survey) if question.save render :jso...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/organizations_controller.rb
Ruby
mit
47
master
294
module Api module V1 class OrganizationsController < APIApplicationController def destroy authorize! :destroy, :organization organization = Organization.new(params[:id]) organization.delay.destroy! render :nothing => true end end end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/controllers/api/v1/audits_controller.rb
Ruby
mit
47
master
530
module Api module V1 class AuditsController < APIApplicationController def create filename = "#{Rails.root}/log/#{params[:device_id]}.log" file = File.new(filename, "a") file.puts params[:platform_data] file.puts params[:content] render :nothing => true end ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/question_with_options.rb
Ruby
mit
47
master
914
class QuestionWithOptions < Question has_many :options, :dependent => :destroy, :foreign_key => :question_id alias_method :serializable_options, :options def report_data answers = answers_for_reports report_data = options.map { |option| [option.content, option.report_data(answers)] } if report_data...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/publisher.rb
Ruby
mit
47
master
1,718
class Publisher include ActiveModel::Validations validate :users_should_exist, :unless => :public? validate :organizations_should_exist, :unless => :public? validates :expiry_date, :date => { :after => Proc.new { Date.today }} attr_reader :users, :survey, :client, :expiry_date, :organizations def initiali...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/survey_filter.rb
Ruby
mit
47
master
382
class SurveyFilter attr_reader :surveys, :survey_filter def initialize(surveys, survey_filter) @surveys = surveys @survey_filter = survey_filter end def filter case survey_filter when "drafts" surveys.drafts when "archived" surveys.archived when "expired" surveys.unarc...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/user.rb
Ruby
mit
47
master
1,050
class User attr_reader :id, :name, :role, :email def initialize(id, name, role, email) @id = id @name = name @role = role @email = email end def self.find_by_organization(client, organization_id) client.get("/api/organizations/#{organization_id}/users").parsed.inject([]) { |users, user_jso...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/answer.rb
Ruby
mit
47
master
5,448
class Answer < ActiveRecord::Base belongs_to :question belongs_to :response belongs_to :record has_many :choices, :dependent => :destroy attr_accessible :content, :question_id, :option_ids, :updated_at, :response_id, :record_id, :photo mount_uploader :photo, ImageUploader store_in_background :photo, Ans...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/category.rb
Ruby
mit
47
master
3,047
class Category < ActiveRecord::Base belongs_to :parent, :class_name => Option belongs_to :category belongs_to :survey has_many :questions, :dependent => :destroy has_many :categories, :dependent => :destroy validates_presence_of :content attr_accessible :content, :survey_id, :order_number, :category_id, :...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/survey_user.rb
Ruby
mit
47
master
321
class SurveyUser < ActiveRecord::Base attr_accessible :survey_id, :user_id belongs_to :survey validates_uniqueness_of :user_id, :scope => :survey_id validate :survey_finalized def survey_finalized errors.add(:survey, I18n.t('survey_users.validations.require_finalized')) unless survey.finalized? end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/multi_choice_question.rb
Ruby
mit
47
master
431
class MultiChoiceQuestion < QuestionWithOptions def report_data choice_ids = answers_for_reports.joins(:choices).pluck('choices.option_id').map(&:to_i) report_data = options.map { |option| [option.content, choice_ids.count(option.id)] } if report_data.map { |option, count| count }.uniq == [0] [] ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/numeric_question.rb
Ruby
mit
47
master
861
class NumericQuestion < Question attr_accessible :max_value, :min_value validates_numericality_of :max_value, :min_value, :allow_nil => true validate :min_value_less_than_max_value def report_data answers_grouped_by_content = answers_for_reports.count(:group => 'answers.content') answers_grouped_by_c...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/single_line_question.rb
Ruby
mit
47
master
209
# A question with a single line answer class SingleLineQuestion < Question attr_accessible :max_length validates_numericality_of :max_length, :only => :integer, :greater_than => 0, :allow_nil => true end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/response.rb
Ruby
mit
47
master
5,257
class Response < ActiveRecord::Base MAX_PAGE_SIZE = 50 module Status COMPLETE = "complete" INCOMPLETE = "incomplete" end belongs_to :survey has_many :answers, :dependent => :destroy has_many :records, :dependent => :destroy accepts_nested_attributes_for :answers, :allow_destroy => true attr...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/survey.rb
Ruby
mit
47
master
6,841
class Survey < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :auth_key, :allow_nil => true validates :expiry_date, :date => { :after => Proc.new { Date.current }}, :if => :expiry_date_changed? validates_presence_of :expiry_date validate :ensure_survey_to_be_archivable validates :des...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/record.rb
Ruby
mit
47
master
211
class Record < ActiveRecord::Base belongs_to :category belongs_to :response has_many :answers, :dependent => :destroy attr_accessible :category_id, :response_id validates_presence_of :category_id end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/mix_panel.rb
Ruby
mit
47
master
377
class MixPanel class << self def track(event, properties={}, user_info=nil, env={}) tracker = Mixpanel::Tracker.new(ENV["MIXPANEL_TOKEN"], { :env => env }) tracker.set(user_info.user_id, user_info.to_hash) tracker.track(event, properties.merge(:distinct_id => user_info.user_id)) end hand...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/participating_organization.rb
Ruby
mit
47
master
456
class ParticipatingOrganization < ActiveRecord::Base attr_accessible :organization_id, :survey_id belongs_to :survey validates_uniqueness_of :organization_id, :scope => :survey_id validates_presence_of :organization_id, :survey_id validate :survey_must_be_finalized def survey_must_be_finalized unless s...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/public_ability.rb
Ruby
mit
47
master
245
class PublicAbility < Ability def initialize(user_info) super can :read, Survey, :public => true can :manage, Response, :session_token => user_info[:session_token] cannot :destroy, Response cannot :read, Response end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/organization.rb
Ruby
mit
47
master
1,687
class Organization attr_reader :id, :name, :logo_url include Draper::Decoratable def initialize(id, attributes={}) @id = id @name = attributes[:name] @logo_url = attributes[:logo_url] end def self.all(access_token, options={}) return unless access_token organizations = access_token.get('...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/option.rb
Ruby
mit
47
master
2,222
class Option < ActiveRecord::Base belongs_to :question has_many :questions, :foreign_key => :parent_id, :dependent => :destroy has_many :categories, :foreign_key => :parent_id, :dependent => :destroy attr_accessible :content, :question_id, :order_number validates_uniqueness_of :order_number, :scope => :questi...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/date_question.rb
Ruby
mit
47
master
274
# A question with a date type answer class DateQuestion < Question def report_data answers_content = answers_for_reports.map(&:content) answers_content.uniq.inject([]) do |data, content| data.push [content, answers_content.count(content)] end end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/question.rb
Ruby
mit
47
master
3,849
class Question < ActiveRecord::Base belongs_to :parent, :class_name => Option belongs_to :category belongs_to :survey has_many :answers, :dependent => :destroy attr_accessible :content, :mandatory, :image, :type, :survey_id, :order_number, :parent_id, :identifier, :category_id, :private, ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/photo_question.rb
Ruby
mit
47
master
296
# A question with a photo as the answer class PhotoQuestion < Question attr_accessible :max_length validates_numericality_of :max_length, :only => :integer, :greater_than => 0, :allow_nil => true before_create :mark_private private def mark_private self.private = true end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/multi_record_category.rb
Ruby
mit
47
master
665
class MultiRecordCategory < Category has_many :records, :foreign_key => :category_id validate :dont_allow_nested_multi_record, :if => :has_multi_record_ancestor? def records_for_response(response_id) records.where(:response_id => response_id) end def find_or_initialize_answers_for_response(response, opt...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/response_serializer.rb
Ruby
mit
47
master
258
class ResponseSerializer attr_reader :response def initialize(response) @response = response end def to_json_with_answers_and_choices response.to_json(:include => {:answers => {:include => :choices, :methods => :photo_in_base64}}) end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/rating_question.rb
Ruby
mit
47
master
493
class RatingQuestion < Question attr_accessible :max_length validates_numericality_of :max_length, :only => :integer, :greater_than => 0, :allow_nil => true DEFAULT_MAX_LENGTH = 5 def report_data answers_grouped_by_content = answers_for_reports.count(:group => 'answers.content') answers_grouped_by_con...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/reports/excel/job.rb
Ruby
mit
47
master
2,378
class Reports::Excel::Job < Struct.new(:excel_data) def start @delayed_job ||= Delayed::Job.enqueue(self, :queue => 'generate_excel') end def perform Tempfile.open('excel', Rails.root.join('tmp')) do |f| Zip::Archive.open(f.path, Zip::CREATE) do |ar| ar.add_io(excel_data.file_name + ".xlsx...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/reports/excel/responses.rb
Ruby
mit
47
master
560
class Reports::Excel::Responses delegate :all, :to => :responses attr_reader :responses def initialize(responses) @responses = responses end def build(options={}) options ||= {} completed.earliest_first.between(options[:from], options[:to]) self end def completed @responses = @respo...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/reports/excel/metadata.rb
Ruby
mit
47
master
1,501
class Reports::Excel::Metadata def initialize(responses, access_token, options={}) @responses = responses @access_token = access_token @options = options end def headers if disable_filtering? ["Added By", "Organization", "Last updated at", "Address", "IP Address", "State", "Latitude", "Long...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/reports/excel/questions.rb
Ruby
mit
47
master
662
class Reports::Excel::Questions attr_reader :questions alias_method :all, :questions def initialize(survey, current_ability) @survey = survey @questions = survey.ordered_question_tree.select(&:finalized?) @ability = current_ability end def build(options = {}) filter_private_questions(options...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/reports/excel/data.rb
Ruby
mit
47
master
445
class Reports::Excel::Data attr_reader :survey, :responses, :server_url, :file_name, :questions, :metadata, :password def initialize(survey, questions, responses, server_url, metadata) @survey = survey @responses = responses @file_name = survey.filename_for_excel @questions = questions @metadat...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/models/reports/excel/row.rb
Ruby
mit
47
master
226
class Reports::Excel::Row attr_reader :elements def initialize(*args) @elements = args end def to_a @elements.dup end def <<(elements) @elements << elements @elements.flatten! self end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/helpers/responses_helper.rb
Ruby
mit
47
master
200
module ResponsesHelper def merge_arrays_using_attributes(first, second, attributes) (first + second).uniq do |object| attributes.map { |attribute|object.send(attribute) } end end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/helpers/application_helper.rb
Ruby
mit
47
master
286
module ApplicationHelper def format_flash_message(message) message.is_a?(Array) ? message.join("\n") : message end def server_url request.protocol + request.host_with_port end def icon_for(css_class, text) "<i class=#{css_class}></i>".html_safe + text end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/numeric_question_decorator.rb
Ruby
mit
47
master
631
class NumericQuestionDecorator < QuestionDecorator decorates :numeric_question delegate_all def input_tag(f, opts={}) super(f, :as => :string, :hint => numeric_question_hint(model.min_value, model.max_value), :input_html => { :disabled => opts[:disabled] }) end private de...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/multi_record_category_decorator.rb
Ruby
mit
47
master
1,344
class MultiRecordCategoryDecorator < CategoryDecorator decorates :multi_record_category delegate_all def create_record_link(response_id) h.link_to I18n.t('responses.edit.create_record'), h.records_path(:record => { :category_id => model.id, :response_id => response_id }), :method...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/multiline_question_decorator.rb
Ruby
mit
47
master
412
class MultilineQuestionDecorator < QuestionDecorator decorates :multiline_question delegate_all def input_tag(f, opts={}) super(f, :as => :text, :input_html => { :disabled => opts[:disabled], :class => model.max_length ? "max_length" : nil, :dat...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/radio_question_decorator.rb
Ruby
mit
47
master
343
class RadioQuestionDecorator < QuestionWithOptionsDecorator decorates :radio_question delegate_all def input_tag(f, opts={}) super(f, :as => :radio, :collection => options.map { |o| [o.content, o.content, {:data => { :option_id => o.id } }] }, :input_html => { :disabled => opts[:...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/rating_question_decorator.rb
Ruby
mit
47
master
641
class RatingQuestionDecorator < QuestionDecorator decorates :rating_question delegate_all def input_tag(f, opts={}) string = ERB.new " <div class='rating'> <%= f.label label %> <%= '<abbr>*</abbr>' if model.mandatory %> <%= f.input :content, :as => :hidden %> <% answer =...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/organization_decorator.rb
Ruby
mit
47
master
2,337
class OrganizationDecorator < Draper::Decorator delegate_all def survey_count surveys.count end def survey_count_in_words h.pluralize(survey_count, "Survey") end def asset_space_in_bytes question_space = Question.where("photo_file_size IS NOT NULL AND survey_id IN (?)", surveys).sum("photo_fi...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/single_line_question_decorator.rb
Ruby
mit
47
master
378
class SingleLineQuestionDecorator < QuestionDecorator decorates :single_line_question delegate_all def input_tag(f, opts={}) super(f, :as => :string, :input_html => { :disabled => opts[:disabled], :class => model.max_length ? "max_length" : nil, ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/category_decorator.rb
Ruby
mit
47
master
1,263
class CategoryDecorator < Draper::Decorator decorates :category decorates_finders delegate_all include ElementNumberable def create_record_link(response_id) end def category_name(record_id, response_id, cache, disabled) # TODO: REFACTOR # Display a category once only, unless its inside a multi-...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/multi_choice_question_decorator.rb
Ruby
mit
47
master
429
class MultiChoiceQuestionDecorator < QuestionWithOptionsDecorator decorates :multi_choice_question delegate_all def input_tag(f, opts={}) super(f, :field => :option_ids, :as => :check_boxes, :collection => options.map(&:id), :member_label => Proc.new { |id| Option.f...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/date_question_decorator.rb
Ruby
mit
47
master
240
class DateQuestionDecorator < QuestionDecorator decorates :date_question delegate_all def input_tag(f, opts={}) super(f, :as => :string, :input_html => { :disabled => opts[:disabled], :class => 'date' }) end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/photo_question_decorator.rb
Ruby
mit
47
master
549
class PhotoQuestionDecorator < QuestionDecorator decorates :photo_question delegate_all def input_tag(f, opts={}) answer = f.object photo_url = opts[:disabled] ? answer.photo_url : answer.photo_url(:format => :medium) image_thumb = answer.photo_url.present? ? (h.image_tag photo_url, :class => 'mediu...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/element_numberable.rb
Ruby
mit
47
master
1,001
module ElementNumberable def question_number if parent parent_question_number = "#{parent_question_decorator.question_number }" parent_question_number << option_number if multi_choice_parent index = ".#{sibling_elements.index(model) + 1}" parent_question_number + index elsif category ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/question_decorator.rb
Ruby
mit
47
master
453
class QuestionDecorator < Draper::Decorator decorates :question decorates_finders delegate_all include ElementNumberable def input_tag(f, opts={}) f.input (opts[:field] || :content), opts.merge(:label => label, :required => mandatory) end def content_with_answer_count model.content + " " + I18n....
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/drop_down_question_decorator.rb
Ruby
mit
47
master
344
class DropDownQuestionDecorator < QuestionWithOptionsDecorator decorates :drop_down_question delegate_all def input_tag(f, opts={}) super(f, :as => :select, :collection => options.map { |o| [o.content, o.content, {'data-option-id' => o.id }] }, :input_html => { :disabled => opts[...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/response_decorator.rb
Ruby
mit
47
master
307
class ResponseDecorator < Draper::Decorator decorates :response decorates_finders delegate_all def sort_answers(answers) ids_of_questions_in_order = model.survey.ordered_question_tree.map(&:id) answers.sort_by { |answer| ids_of_questions_in_order.index(answer.question_id) || 0 } end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
app/decorators/survey_decorator.rb
Ruby
mit
47
master
2,282
class SurveyDecorator < Draper::Decorator decorates :survey decorates_finders delegate_all self.include_root_in_json = false def build_mustache_templates template_types.inject('') do |string, type| string << template_tag(h.render("/templates/questions/#{type.underscore}"), "#{type.underscore}_templ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
db/schema.rb
Ruby
mit
47
master
6,242
# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative sou...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
db/migrate/20130711130450_populate_completed_at_from_created_at_for_existing_responses.rb
Ruby
mit
47
master
302
class PopulateCompletedAtFromCreatedAtForExistingResponses < ActiveRecord::Migration def up ActiveRecord::Base.connection.execute("UPDATE responses SET completed_at = created_at;") end def down ActiveRecord::Base.connection.execute("UPDATE responses SET completed_at = NULL;") end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
db/migrate/20130603061953_rebase_old_migrations.rb
Ruby
mit
47
master
5,505
class RebaseOldMigrations < ActiveRecord::Migration def change create_table "answers" do |t| t.text "content" t.integer "question_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.integer "response_id" t.string "photo"...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/tasks/delete_data_belonging_to_deleted_organizations.rake
Ruby
mit
47
master
296
namespace :db do desc "Set up coverage config in enviroment" task :remove_deleted_organizations_data => :environment do Organization.deleted_organizations.each do |organization| puts "Deleting data for organization ##{organization.id}" organization.destroy! end end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/tasks/migration.rake
Ruby
mit
47
master
2,957
namespace :db do namespace :migrate do DB_PATH = ActiveRecord::Migrator.migrations_path SEPARATOR = " --- " def run_command(command) %x(#{command}).tap do |result| status = $? unless status.success? raise "Command Error -- (#{status.exitstatus}): [#{command}]" end ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/tasks/responses_with_answers.rake
Ruby
mit
47
master
2,111
namespace :db do desc "Populate DB with Fake Data" task fake_responses: :environment do def answer_for(question, answer_obj) type = question.type case type when 'SingleLineQuestion' (0...50).map{ ('a'..'z').to_a[rand(26)] }.join when 'MultilineQuestion' str = "" (...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/tasks/fake_data.rake
Ruby
mit
47
master
279
namespace :db do desc "Populate DB with Fake Data" task fake: :environment do 1000.times do Survey.create( :name => Forgery(:name).full_name, :expiry_date => 28.days.from_now, :description => Forgery(:basic).text ) end end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/tasks/populate_file_size_from_s3.rake
Ruby
mit
47
master
1,039
require 'ruby-progressbar' namespace :s3 do desc "Populates file size for image assets from s3" task :cache_file_size => :environment do puts "Setting file size for questions" questions = Question.unscoped.where("image IS NOT NULL AND photo_file_size IS NULL") questions_count = questions.count bar ...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/tasks/coverage.rake
Ruby
mit
47
master
309
namespace :coverage do desc "Set up coverage config in enviroment" task :prepare_environment do puts "Preparing coverage environment" ENV["ENABLE_COVERAGE"] = "true" end task :all => :prepare_environment do Rake::Task["parallel:spec"].invoke end end task :coverage => ["coverage:all"]
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/tasks/delete_data_islands.rake
Ruby
mit
47
master
227
namespace :db do desc "Delete all the data islands" task :delete_data_islands => :environment do orphaned_options = Option.where('question_id NOT IN (?)', Question.pluck("id")) orphaned_options.delete_all end end
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/generators/question_type/question_type_generator.rb
Ruby
mit
47
master
1,333
class QuestionTypeGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) def create_rails_model template "rails_model.rb", "app/models/#{file_name}.rb" template "rails_model_spec.rb", "spec/models/#{file_name}_spec.rb" end def create_backbone_model template...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/generators/question_type/templates/backbone_model_spec.rb
Ruby
mit
47
master
1,515
describe "SurveyBuilder.Models.<%= class_name %>Model", -> it "can be instantiated", -> model = new SurveyBuilder.Models.<%= class_name %>Model expect(model).not.toBeNull describe "when setting defaults", -> it "sets type to <%= class_name %>", -> model = new SurveyBuilder.Models.<%= class_name %...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/generators/question_type/templates/rails_model_spec.rb
Ruby
mit
47
master
594
require 'spec_helper' describe <%= class_name %> do it { should respond_to :content } it { should respond_to :mandatory } it { should respond_to :image } it { should respond_to :max_length } it { should belong_to :survey } it { should have_many(:answers).dependent(:destroy) } it { should validate_presenc...
github
nilenso/ashoka-survey-web
https://github.com/nilenso/ashoka-survey-web
lib/generators/question_type/templates/backbone_dummy_template.rb
Ruby
mit
47
master
228
<div class="inline_errors">{{errors}}</div> <label> <img src="{{image_url}}" class="thumb" /> {{content}} <abbr name="mandatory" title="required" style="display:none"> * </abbr> </label> <input type="text" disabled="true" />