# Avalanche Avanche is an online plataform where you play the role of an agent and gets assigned to real life missions. 1. Spread the Knoleage 2. Disobey 3. Resist ## Pages - Home Page - System Statistics (Completed Missions | On Going Missions | Number of Agents) - Call To Arms (login) - Game description - About - Introduction - Game Rules - Dev Team - Login - Signup - Missions - Current Missions - Mission Select - Mission Control List - Create new Mission button - Mission Details - Mission Details - Mission Steps - Step Validation - Create/Edit Mission - Mission Control - Agent Profile - Agent Stats - Mission History - Edit Agent Profile ## System - Background Jobs - Hash URLs - No Turbolinks! - Mission Acomplished Email ## Tables #### Users - username - email - password - location - Limites #### Missions - title - description - agent_search_start_date - agent_search_end_date - Status (Initializing -> Launched -> Active -> (Complete, Falied, Canceled or Closed) #### Mission Agent - mission_id - description (if no steps) - location - reward - user_id : int - agent_name : string - anonymous_agent : bool #### Mission Agent Step - mission_agent_id - step_number - description - completed : bool - proof_type - proof - validated : bool - validated_by :user - status (In Progress, Incomplete, Waiting Validation, Completed, Failed, Canceled, Locked) #### Mission Agent Invite - user - status (Waiting, Accepted, Denied, Expired) ## Rails Development Steps ``` bash # Step 1 rails new avalanche_game --database=postgresql # Step 2 - Create databases # Step 3 - Install Gems # Step 4 - Inialize plugins (bootstrap, flatstrap, simpl_form, friendly_id) rails generate bootstrap:install rails generate bootstrap:layout application fluid rails generate bootstrap:layout front_end fixed rails generate bootstrap:layout auth fixed rails generate simple_form:install --bootstrap rails generate friendly_id # Step 5 - Initialize Devise rails generate devise:install rails generate devise user username:string location:string rails g devise:views rake db:migrate # Step 6 - Scaffold rails g scaffold mission title:string description:text status:string agent_search_start:datetime agent_search_end:datetime rails g model mission_agent mission:references description:text location:string reward:text user:references agent_name:string anonymous_agent:bool rails g model mission_agent_step mission_agent:references step:integer description:text completed:bool proof_type:string proof:string rails g controller agent current_missions choose_mission agent_profile rails g controller start index about # Step 7 - Modify rails g model mission_agent_invite user:reference mission_agent:references status:string rails g migration AddInviteToMissionAgent mission_agent_invites:references rails g migration AddOwnerToMission owner:references rails g migration AddValidationToMissionAgentStep validated:boolean validated_by:references ``` ## Badges/Trophies/Perks - Recruiter - Missao Acomplished - Fast Responder - Field Agent - Mission Planner - Beta Tester - Years of service ## Videos * [TED - The case for collaborative consumption](http://www.ted.com/talks/rachel_botsman_the_case_for_collaborative_consumption#) ## Layout References * [Agency Layout](http://startbootstrap.com/templates/agency/) * [FlatStrap](http://flatstrap.org/) * [Timeline 1](http://bootsnipp.com/snippets/featured/timeline-21-with-images-and-responsive), [Timeline 2](http://bootsnipp.com/snippets/featured/timeline-dotted), [Timeline 3](http://bootsnipp.com/snippets/featured/two-column-timeline-not-responsive) * [Comments](http://bootsnipp.com/snippets/featured/recent-comments-admin-panel) * [Carousel](http://bootsnipp.com/snippets/featured/bootstrap-carousel-with-text) * [Blog Post](http://bootsnipp.com/snippets/featured/complete-blog-layout) * [Progress Bar](http://bootsnipp.com/snippets/featured/progress-bar-example) * [User Profile](http://bootsnipp.com/snippets/featured/user-profile-widget) * [Badges](http://bootsnipp.com/snippets/featured/hero-widgets) * [Date Picker](http://bootsnipp.com/snippets/featured/simple-datepicker-with-momentjs) * [Simple Invoice](http://bootsnipp.com/snippets/featured/simple-invoice) * [Ideal Image Slider](http://gilbitron.github.io/Ideal-Image-Slider/) ## Plugins * [Bootstrap Select](http://silviomoreto.github.io/bootstrap-select/) * [Bootstrap Location Picker](https://github.com/abdelilah/bootstrap-locationpicker) * [Bootstrap timepicker rails addon](https://github.com/ywjno/bootstrap-timepicker-rails-addon) * [Bootstrap timepicker rails](https://github.com/tispratik/bootstrap-timepicker-rails) * [bootstrap-tags](https://github.com/Serhioromano/bootstrap-tags) * [awesome_nested_fields](https://github.com/lailsonbm/awesome_nested_fields) * [Chartist.js](http://gionkunz.github.io/chartist-js/) - Simple responsive charts ## Services * [Terms Feed](https://termsfeed.com) - Generate a Free Terms of Service Agreement in minutes. ## Tutorials * [Ruby on Rails Tutorial (3rd Ed.)](http://news.railstutorial.org/rails_tutorial_3rd_edition/) ## Todo List #### Version 0.1 [X] Ajax create/delete agents [X] User List [X] Choose Mission Page [X] Accept/Denie missions [X] Agent Missions [X] Missions List [X] Mission Control / Mission Description [X] Step Validation [X] Mission Completed [X] Mission owner [X] Randomize algorithm [X] User Page [ ] Start Page - add sys statisitcs and how to play text [X] Redirect to missions page after login and signup [ ] Edit Profile Layout [ ] Mission Form [X] Agent Mission History [ ] Access control [X] Run Algorithm every time something changes [X] Sign In Redirect [ ] Heroku Upload [ ] Empty Dashboard #### Version 0.2 [ ] Background Tasks (Redis) [ ] Translations [ ] Invite Timer [ ] Mission Timer [ ] Step Timer [ ] About Page [ ] Email system [ ] New mission email alert ## Bugs **No bugs found for now...* ## Code Clipper ``` ruby # Loop thru all mission_agents and each mission_agent_steps attributes and save them all # Nasty override code for a neste models bug that was resolved in the project @mission.assign_attributes(params[:mission_agents_attributes]) @mission.assign_attributes(params[:mission_agent_steps_attributes]) params[:mission][:mission_agents_attributes].values.each do |a| if a[:mission_agent_steps_attributes] != nil a[:mission_agent_steps_attributes].values.each do |s| @step = MissionAgentStep.where(:id => s[:id]).first_or_create if s[:_destroy] == 1.to_s @step.destroy else @step.mission_agent_id = a[:id] @step.description = s[:description] @step.save end # Update Step Order @steps = MissionAgentStep.order(:step => :asc).find_all_by_mission_agent_id(@step.mission_agent) @step_number = 1 @steps.each do |step| step.step = @step_number step.save @step_number = @step_number + 1 end end end end # Initial Algorithm @users = User.all @mission_agents = @mission.mission_agents.all @users.each do |user| @invited = false @mission_agents.each do |agent| if agent.user != user agent.mission_agent_invites.each do |invite| if invite.user == user # user already invited @invited = true end end else @invited = true end end if @invited == false @mission_agents.each do |agent| if agent.user == nil agent.user_id = user.id agent.mission_agent_invites.create!(:user_id => user.id, :status => 'invited') agent.save end end end end ```