From a0f638c10cdc89d0b1bc20724be108645b9222e7 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Fri, 25 Jan 2013 20:49:40 -0500 Subject: [PATCH] added ability to switch what metacodes you are mapping with --- app/assets/javascripts/Jit/loadgraphs.js | 32 ---- .../javascripts/Jit/onCreateLabelHandler.js | 2 +- app/assets/javascripts/application.js | 5 +- app/assets/stylesheets/application.css | 15 +- app/assets/stylesheets/users.css.scss | 62 +++++++ app/controllers/users_controller.rb | 3 + app/models/metacode.rb | 5 + app/models/user.rb | 17 +- app/models/user_preference.rb | 11 ++ app/views/layouts/application.html.erb | 7 + app/views/maps/_newtopic.html.erb | 8 +- app/views/topics/_new.html.erb | 8 +- app/views/users/edit.html.erb | 100 ++++++++++- db/migrate/20120920013446_create_users.rb | 1 + .../20130125194040_add_metacodes_to_user.rb | 9 + db/schema.rb | 163 +++++++++--------- test/fixtures/metacodes.yml | 48 ++++++ 17 files changed, 376 insertions(+), 120 deletions(-) create mode 100644 app/models/user_preference.rb create mode 100644 db/migrate/20130125194040_add_metacodes_to_user.rb diff --git a/app/assets/javascripts/Jit/loadgraphs.js b/app/assets/javascripts/Jit/loadgraphs.js index 8a5f03db..380acbb6 100644 --- a/app/assets/javascripts/Jit/loadgraphs.js +++ b/app/assets/javascripts/Jit/loadgraphs.js @@ -13,38 +13,6 @@ animate = !(iStuff || !nativeCanvasSupport); })(); -var imgArray = new Object(); - -imgArray['Group'] = new Image(); imgArray['Group'].src = '/assets/group.png'; -imgArray['Person'] = new Image(); imgArray['Person'].src = '/assets/person.png'; -imgArray['Bizarre'] = new Image(); imgArray['Bizarre'].src = '/assets/bizarre.png'; -imgArray['Catalyst'] = new Image(); imgArray['Catalyst'].src = '/assets/catalyst.png'; -imgArray['Closed'] = new Image(); imgArray['Closed'].src = '/assets/closed.png'; -imgArray['Experience'] = new Image(); imgArray['Experience'].src = '/assets/experience.png'; -imgArray['Future Dev'] = new Image(); imgArray['Future Dev'].src = '/assets/futuredev.png'; -imgArray['Idea'] = new Image(); imgArray['Idea'].src = '/assets/idea.png'; -imgArray['Implication'] = new Image(); imgArray['Implication'].src = '/assets/implication.png'; -imgArray['Insight'] = new Image(); imgArray['Insight'].src = '/assets/insight.png'; -imgArray['Intention'] = new Image(); imgArray['Intention'].src = '/assets/intention.png'; -imgArray['Knowledge'] = new Image(); imgArray['Knowledge'].src = '/assets/knowledge.png'; -imgArray['Location'] = new Image(); imgArray['Location'].src = '/assets/location.png'; -imgArray['Open Issue'] = new Image(); imgArray['Open Issue'].src = '/assets/openissue.png'; -imgArray['Opinion'] = new Image(); imgArray['Opinion'].src = '/assets/opinion.png'; -imgArray['Opportunity'] = new Image(); imgArray['Opportunity'].src = '/assets/opportunity.png'; -imgArray['Platform'] = new Image(); imgArray['Platform'].src = '/assets/platform.png'; -imgArray['Problem'] = new Image(); imgArray['Problem'].src = '/assets/problem.png'; -imgArray['Question'] = new Image(); imgArray['Question'].src = '/assets/question.png'; -imgArray['Reference'] = new Image(); imgArray['Reference'].src = '/assets/reference.png'; -imgArray['Requirement'] = new Image(); imgArray['Requirement'].src = '/assets/requirement.png'; -imgArray['Resource'] = new Image(); imgArray['Resource'].src = '/assets/resource.png'; -imgArray['Role'] = new Image(); imgArray['Role'].src = '/assets/role.png'; -imgArray['Task'] = new Image(); imgArray['Task'].src = '/assets/task.png'; -imgArray['Tool'] = new Image(); imgArray['Tool'].src = '/assets/tool.png'; -imgArray['Trajectory'] = new Image(); imgArray['Trajectory'].src = '/assets/trajectory.png'; -imgArray['Action'] = new Image(); imgArray['Action'].src = '/assets/action.png'; -imgArray['Activity'] = new Image(); imgArray['Activity'].src = '/assets/activity.png'; - - // init custom node type $jit.ForceDirected.Plot.NodeTypes.implement(nodeSettings); //implement an edge type diff --git a/app/assets/javascripts/Jit/onCreateLabelHandler.js b/app/assets/javascripts/Jit/onCreateLabelHandler.js index c67f6cf7..7284fa80 100644 --- a/app/assets/javascripts/Jit/onCreateLabelHandler.js +++ b/app/assets/javascripts/Jit/onCreateLabelHandler.js @@ -243,7 +243,7 @@ function generateLittleHTML(node) { //logged in, and owner of the topic, thus permission to delete littleHTML += ' \ \ '; } diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 66dc905b..b96ea14a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -226,9 +226,11 @@ function fetchRelatives(node) { url: "/topics/" + node.id + "?format=json", success: function(data) { if (gType == "centered") { + Mconsole.busy = true; Mconsole.op.sum(data, { type: 'fade', - duration: 500 + duration: 500, + hideLabels: false }); Mconsole.graph.eachNode(function (n) { n.eachAdjacency(function (a) { @@ -239,6 +241,7 @@ function fetchRelatives(node) { } }); }); + Mconsole.busy = false; } else { Mconsole.op.sum(data, { diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 6adbf863..c139866a 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -111,7 +111,6 @@ a { .new_session, .new_user, .new_map, -.edit_user, .edit_topic, .edit_synapse, .edit_map, @@ -129,6 +128,20 @@ a { border:2px solid #000; } +.edit_user{ + display: block; + width: 800px; + position:absolute; + left:50%; + top:0; + margin:50px 0 0 -420px; + background: url('bg.png'); + padding: 20px; + border-radius: 15px; + color: #000; + border:2px solid #000; +} + .onConsole .new_map { display:none; } diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss index 1efc835c..ff75b57e 100644 --- a/app/assets/stylesheets/users.css.scss +++ b/app/assets/stylesheets/users.css.scss @@ -1,3 +1,65 @@ // Place all the styles related to the users controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +.allMetacodes { + float:left; +} + +.allMetacodes span { + margin:4px 8px; + color:#67AF9F; +} + +.editMetacodes { + z-index:12; + width:auto; + color: #67AF9F; + padding:10px; + float:left; +} + +.editMetacodes ul { + display:block; +} + +.editMetacodes ul li { + clear:both; + list-style-type:none; + display:block; + padding:3px; +} + +.editMetacodes ul img { + width:40px; + height:40px; + float:left; +} + +.editMetacodes ul p { + float:left; + display: block; + margin: 0; + background: none; + padding: 10px 4px 2px 4px; +} + +.editMetacodes #filters-one { + float:left; +} + +.editMetacodes #filters-two { + float:left; +} + +.editMetacodes #filters-three { + float:left; +} + +.editMetacodes #filters-four { + float:left; +} + +.editMetacodes li.toggledOff { + opacity: 0.4; +} \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5ca2cf36..d80ce66d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -64,6 +64,9 @@ class UsersController < ApplicationController @user = current_user @user.attributes = params[:user] + @m = params[:metacodes][:value] + @user.settings.metacodes=@m.split(',') + @user.save respond_with(@user, location: user_url(@user)) do |format| diff --git a/app/models/metacode.rb b/app/models/metacode.rb index c181a19f..0de248be 100644 --- a/app/models/metacode.rb +++ b/app/models/metacode.rb @@ -2,4 +2,9 @@ class Metacode < ActiveRecord::Base has_many :topics + def hasSelected(user) + return true if user.settings.metacodes.include? self.id.to_s + return false + end + end diff --git a/app/models/user.rb b/app/models/user.rb index 1e4f824c..3af99561 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,6 +15,8 @@ has_many :mappings configuration.merge_validates_length_of_email_field_options unless: Proc.new { |user| user.email.blank? and user.authed? } end + serialize :settings, UserPreference + validates :password, :presence => true, :length => { :maximum => 20, @@ -27,5 +29,18 @@ has_many :mappings :on => :update validates :joinedwithcode, :presence => true, :inclusion => { :in => User.all.map(&:code), :message => "%{value} is not a valid code" }, :on => :create - + + def settings + # make sure we always return a UserPreference instance + if read_attribute(:settings).nil? + write_attribute :settings, UserPreference.new + read_attribute :settings + else + read_attribute :settings + end + end + + def settings=(val) + write_attribute :settings, val + end end diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb new file mode 100644 index 00000000..9c2732a4 --- /dev/null +++ b/app/models/user_preference.rb @@ -0,0 +1,11 @@ +class UserPreference + attr_accessor :metacodes + + def initialize + array = [] + Metacode.all.each do |m| + array.push(m.id.to_s) + end + @metacodes = array + end +end \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 03d66914..c9ae28de 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -20,6 +20,13 @@ var username = null; <% end %> + <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> diff --git a/app/views/maps/_newtopic.html.erb b/app/views/maps/_newtopic.html.erb index 075a9321..c1a8d1ab 100644 --- a/app/views/maps/_newtopic.html.erb +++ b/app/views/maps/_newtopic.html.erb @@ -4,7 +4,13 @@ #%>
<%= form_for Topic.new, url: topics_url, remote: true do |form| %> -
ActionActivityBizarreCatalystClosedExperienceFuture DevGroupIdeaImplicationInsightIntentionKnowledgeLocationOpen IssueOpinionOpportunityPersonPlatformProblemQuestionReferenceRequirementResourceRoleTaskToolTrajectory
+
+ <% @m = user.settings.metacodes %> + <% @m.each do |m| %> + <% metacode = Metacode.find(m.to_i) %> + <%= metacode.name %> + <% end %> +
<%= form.autocomplete_field :name, autocomplete_topic_name_topics_path, :placeholder => "What is the name of your topic?" %> <%= form.hidden_field :metacode, :value => "Action" %> <%= form.hidden_field :x, :value => 0 %> diff --git a/app/views/topics/_new.html.erb b/app/views/topics/_new.html.erb index efb7e91e..faf5c3bc 100644 --- a/app/views/topics/_new.html.erb +++ b/app/views/topics/_new.html.erb @@ -6,7 +6,13 @@
<%= form_for Topic.new, url: topics_url, remote: true do |form| %> -
ActionActivityBizarreCatalystClosedExperienceFuture DevGroupIdeaImplicationInsightIntentionKnowledgeLocationOpen IssueOpinionOpportunityPersonPlatformProblemQuestionReferenceRequirementResourceRoleTaskToolTrajectory
+
+ <% @m = user.settings.metacodes %> + <% @m.each do |m| %> + <% metacode = Metacode.find(m.to_i) %> + <%= metacode.name %> + <% end %> +
<%= form.autocomplete_field :name, autocomplete_topic_name_topics_path, :placeholder => "What is the name of your topic?" %> <%= form.hidden_field :metacode, :value => "Action" %> <%= form.hidden_field :x, :value => 0 %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index fd7ed11a..55d83857 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1,12 +1,110 @@ <%# # @file - # TODO: What URL is this? + # /users/:id/edit # User edit form #%> <%= formula_form_for @user, url: user_url do |form| %> +

Choose Active Metacodes

+
Show AllHide All
+
+
+
    + <% $i = 0 %> + <% @m = Metacode.order("name").all %> + <% while $i < 10 do %> +
  • class="toggledOff"<% end %> > + <%= @m[$i].name %> +

    <%= @m[$i].name.downcase %>

    +
    +
  • + <% $i += 1 %> + <% end %> +
+
    + <% while $i < 20 do %> +
  • class="toggledOff"<% end %> > + <%= @m[$i].name %> +

    <%= @m[$i].name.downcase %>

    +
    +
  • + <% $i += 1 %> + <% end %> +
+
    + <% while $i < 30 do %> +
  • class="toggledOff"<% end %> > + <%= @m[$i].name %> +

    <%= @m[$i].name.downcase %>

    +
    +
  • + <% $i += 1 %> + <% end %> +
+
    + <% while $i < 40 do %> +
  • class="toggledOff"<% end %> > + <%= @m[$i].name %> +

    <%= @m[$i].name.downcase %>

    +
    +
  • + <% $i += 1 %> + <% end %> +
+
+

Edit Account

<%= form.input :name, label: "Name", class: "name" %> <%= form.input :email, label: "Email", class: "email" %> <%= form.input :password, label: "Password", class: "password" %> + <%= hidden_field(:metacodes, :value, {:value => 0}) %> <%= form.submit "Update", class: "update" %> <% end %> + + diff --git a/db/migrate/20120920013446_create_users.rb b/db/migrate/20120920013446_create_users.rb index 6c603cd0..b120c2ff 100644 --- a/db/migrate/20120920013446_create_users.rb +++ b/db/migrate/20120920013446_create_users.rb @@ -3,6 +3,7 @@ class CreateUsers < ActiveRecord::Migration create_table :users do |t| t.string :name t.string :email + t.text :settings t.string :code, :limit => 8 t.string :joinedwithcode, :limit => 8 t.string :crypted_password diff --git a/db/migrate/20130125194040_add_metacodes_to_user.rb b/db/migrate/20130125194040_add_metacodes_to_user.rb new file mode 100644 index 00000000..6c395caa --- /dev/null +++ b/db/migrate/20130125194040_add_metacodes_to_user.rb @@ -0,0 +1,9 @@ +class AddMetacodesToUser < ActiveRecord::Migration + def self.up + add_column :users, :settings, :text + end + + def self.down + remove_column :users, :settings + end +end diff --git a/db/schema.rb b/db/schema.rb index 5779a0e1..2aab361a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,81 +1,82 @@ -# 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 source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended to check this file into your version control system. - -ActiveRecord::Schema.define(:version => 20130101194424) do - - create_table "mappings", :force => true do |t| - t.text "category" - t.integer "xloc" - t.integer "yloc" - t.integer "topic_id" - t.integer "synapse_id" - t.integer "map_id" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "maps", :force => true do |t| - t.text "name" - t.boolean "arranged" - t.text "desc" - t.text "permission" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "metacodes", :force => true do |t| - t.text "name" - t.string "icon" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "synapses", :force => true do |t| - t.text "desc" - t.text "category" - t.text "weight" - t.text "permission" - t.integer "node1_id" - t.integer "node2_id" - t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "topics", :force => true do |t| - t.text "name" - t.text "desc" - t.text "link" - t.text "permission" - t.integer "user_id" - t.integer "metacode_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "users", :force => true do |t| - t.string "name" - t.string "email" - t.string "code", :limit => 8 - t.string "joinedwithcode", :limit => 8 - t.string "crypted_password" - t.string "password_salt" - t.string "persistence_token" - t.string "perishable_token" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - -end +# 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 source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 20130125210014) do + + create_table "mappings", :force => true do |t| + t.text "category" + t.integer "xloc" + t.integer "yloc" + t.integer "topic_id" + t.integer "synapse_id" + t.integer "map_id" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "maps", :force => true do |t| + t.text "name" + t.boolean "arranged" + t.text "desc" + t.text "permission" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "metacodes", :force => true do |t| + t.text "name" + t.string "icon" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "synapses", :force => true do |t| + t.text "desc" + t.text "category" + t.text "weight" + t.text "permission" + t.integer "node1_id" + t.integer "node2_id" + t.integer "user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "topics", :force => true do |t| + t.text "name" + t.text "desc" + t.text "link" + t.text "permission" + t.integer "user_id" + t.integer "metacode_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "users", :force => true do |t| + t.string "name" + t.string "email" + t.string "code", :limit => 8 + t.string "joinedwithcode", :limit => 8 + t.string "crypted_password" + t.string "password_salt" + t.string "persistence_token" + t.string "perishable_token" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.text "settings" + end + +end diff --git a/test/fixtures/metacodes.yml b/test/fixtures/metacodes.yml index 4af9d7ea..e2cdfbfa 100644 --- a/test/fixtures/metacodes.yml +++ b/test/fixtures/metacodes.yml @@ -115,3 +115,51 @@ twenty-seven: twenty-eight: name: Trajectory icon: trajectory.png + +twenty-nine: + name: Argument + icon: argument.png + +thirty: + name: Con + icon: con_icon.png + +thirty-one: + name: Decision + icon: decision.png + +thirty-two: + name: Example + icon: example.png + +thirty-three: + name: Foresight + icon: foresight.png + +thirty-four: + name: Good Practice + icon: goodpractice.png + +thirty-five: + name: List + icon: list.png + +thirty-six: + name: Movie Map + icon: moviemap.png + +thirty-seven: + name: Note + icon: note.png + +thirty-eight: + name: Pro + icon: pro.png + +thirty-nine: + name: Research + icon: research.png + +forty: + name: Wildcard + icon: wildcard.png