Skip to content

Commit

Permalink
fixed flippy triangles and merging stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
ingridh committed May 2, 2015
2 parents fe2bb6e + ee780cb commit 28a446a
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 178 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jQuery(document).ready(function() {
$('#q' + $(this).attr('id')).find('.answers').toggle();
$('#q' + $(this).attr('id')).find('.additional').toggle();
$('#q' + $(this).attr('id')).find('.text, .toggler').toggleClass("text toggler");
$('#q' + $(this).attr('id')).find('.colname, .toggler2').toggleClass("colname toggler2");
$(this).toggleClass("glyphicon glyphicon-chevron-right icon glyphicon glyphicon-chevron-down icon")
$('#q' + $(this).attr('id')).find('.colname, .toggler2').toggleClass("colname toggler2");
});

Expand Down
27 changes: 21 additions & 6 deletions app/assets/javascripts/problems.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,25 @@


$(document).ready ->
$('#add_tags').on "keypress", (event) ->
$('[id^="add_tags_"]').on "keypress", (event) ->
if event.which == 44
tag = $('#add_tags').val()
console.log(tag)
$("<span class='tags'>" + tag + "</span>").insertAfter("#add_tags");
$('#add_tags').val('');
event.preventDefault();
tag = $(this).val().trim()
tag_id = $(this).parent().attr("id")
problem_id = parseInt(tag_id, 10)
#$("<span class='tag'>" + tag + "</span>").insertAfter(this)
$(this).val('')
event.preventDefault()
$.ajax
url: "add/" + tag + "/to/problem/" + problem_id
success: (data, textStatus, jqXHR) ->
$('#all_tags_' + problem_id).html(data)

@clickHandler = $('body').on "click", '[id^="remove_tag"]', (event) ->
console.log("fn called")
tag_id = parseInt($(this).parent().attr("id"))
pid = parseInt($(this).parent().parent().parent().attr("id"))
$.ajax
url: "remove/" + tag_id + "/from/problem/" + pid
success: (data, textStatus, jqXHR) ->
$('#all_tags_' + pid).html(data)
event.preventDefault()
21 changes: 21 additions & 0 deletions app/assets/stylesheets/_problems.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Place all the styles related to the questions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

.tag {
//background: #5bc0de;
padding: 5px;
//border: 1px solid #DCDCDC;
//border-radius: 3px;
margin: 3px;
//color: #fff;
}

#all_tags {
margin-top: 10px;
}

.remove_tag:hover {
text-decoration: line-through;
color: #ff0000;
}
5 changes: 5 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@import "bootstrap-sprockets";
@import "bootstrap";
@import 'problems';

html, body {
/*font-family: 'Patrick Hand';*/
Expand Down Expand Up @@ -194,6 +195,10 @@ li#navbar {
float: right;
}

.maintable {
margin-top: 10px;
}


ol.questions { list-style-type: none; }
li.question { page-break-inside: avoid; }
Expand Down
32 changes: 0 additions & 32 deletions app/assets/stylesheets/problems.css.scss

This file was deleted.

21 changes: 16 additions & 5 deletions app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ class ProblemsController < ApplicationController
@@defaults = HashWithIndifferentAccess.new({'tags' => "", 'collections' => {}, 'last_exported_begin' => "", 'last_exported_end' => '', 'per_page' => 5 }) #default arguments hash, not sure about the proper styling for this

def set_filter_options
puts "SESSION IS : #{session[:filters]} ----------------------------------------------------------------------------------------"
session[:filters] ||= @@defaults
session[:filters] = @@defaults.merge session[:filters].merge params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :per_page)
puts "SESSION SET TO : #{session[:filters]} ----------------------------------------------------------------------------------------"
puts "PARAMS SLICE: #{params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :per_page)}"
session[:filters] ||= HashWithIndifferentAccess.new(@@defaults)
session[:filters] = session[:filters].merge params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :per_page)
end

def home
Expand All @@ -35,5 +32,19 @@ def remove_from_collection
end

def add_tag
@problem = Problem.find(params[:id])
@tag = @problem.tags.find_by_name(params[:tag])
if !@tag
@tag = Tag.create(name: params[:tag])
@problem.tags << @tag
end
render :partial => "tags", locals: { tags: @problem.tags}
end

def remove_tag
@problem = Problem.find(params[:id])
@tag = Tag.find(params[:tid])
@problem.tags.delete(@tag)
render :partial => "tags", locals: { tags: @problem.tags}
end
end
2 changes: 1 addition & 1 deletion app/models/instructor.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Instructor < ActiveRecord::Base

attr_accessible :privilege, :name, :username, :uid, :provider, :provider_image, :provider_email, :current_collection
attr_accessible :privilege, :name, :username, :uid, :provider, :provider_image, :provider_email, :current_collection
has_many :collections
has_many :problems

Expand Down
13 changes: 6 additions & 7 deletions app/models/problem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ class Problem < ActiveRecord::Base
integer :instructor_id
boolean :is_public
time :last_used
# integer :collection_id

string :tag_names, :multiple => true do
tags.map(&:name)
end

string :coll_names, :multiple => true do
collections.map(&:name)
end

# integer :collection_ids, :multiple => true do
# collections.map(&:id)
# end
end

def html5
Expand Down Expand Up @@ -61,8 +60,8 @@ def self.filter(user, filters = {})
with(:is_public, true)
end
with(:tag_names, filters[:tags]) if filters[:tags].present? #I THOUGHT SUNSPOT SAID THE PRESENCE CHECK WAS UNNECESARY
# with(:coll_names, filters[:collections].keys)
if filters['last_exported_begin']
# with(:collection_ids, filters[:collections].keys)
if filters['last_exported_begin']
with(:last_used).greater_than_or_equal_to(filters['last_exported_begin'])
end
if filters['last_exported_end']
Expand Down
4 changes: 2 additions & 2 deletions app/views/collections/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
= f.check_box :is_public, :class => 'form-control'
%div.form-group
= f.submit 'Update', class: 'btn btn-primary'
=link_to collection_path(collection), :class => 'btn btn-default', method: :delete, :confirm => 'Delete this collection?' do
=link_to collection_path(collection), :class => 'btn btn-default', method: :delete, :confirm => 'Delete this collection?', id: 'Delete' do
%span.glyphicon.glyphicon-trash
Delete Collection
=link_to export_path(:id => collection), :class => 'btn btn-default' do
=link_to export_path(:id => collection), :class => 'btn btn-default', id: 'Export' do
%span.glyphicon.glyphicon-export
Export

Expand Down
4 changes: 2 additions & 2 deletions app/views/collections/finalize_upload.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%div.col-md-12
%h3{:style=>"color: blue; padding:0px;margin:0px;"}
= "Your quiz was successfully uploaded! We found #{@collections.size} collections with #{collections.reduce{|collection, n| collection.size + n}} problems in your quiz. Review them below:"
= "Your quiz was successfully uploaded! We found #{@collections.size} collections with #{@collections.inject(0){|sum, c| c.problems.size + sum}} problems in your quiz. Review them below:"

-@collections.each do |collection|
%tr
=render :partial=> 'form', locals: {collection: collection, :remote => true}
= render :partial => "shared/problems_table", locals: {problems_index: false, collection: collection, problems: collection.problems}
= render :partial => "collections_table", locals: {collection: collection, problems: collection.problems}
7 changes: 2 additions & 5 deletions app/views/problems/_filter.html.haml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

= form_tag problems_path, :method => :get, :id => "filter_form" do
%div.form-group
= label_tag(:search, "Search Keywords:")
= text_field_tag(:search, session[:filters][:search], class: 'form-control', placeholder: "Search")

= text_field_tag(:search, session[:filters][:search], class: 'form-control', placeholder: "Search")
%div.form-group
= label_tag(:tags, "Tags:")
= text_field_tag(:tags, session[:filters][:tags], class: 'form-control', placeholder: "e.g.: tag 1,tag 2")
Expand All @@ -19,5 +17,4 @@
=collection.name
=check_box_tag "collections[0]", 1, !!(session[:filters][:collections].include? 0), class: "checkbox", id: "collections[0]"
All Collections

= submit_tag 'Apply', :id => "filter_submit", :class => 'btn btn-info'
= submit_tag 'Apply', :id => "filter_submit", :class => 'btn btn-info'
17 changes: 8 additions & 9 deletions app/views/problems/_problems_table.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/ <<<<<<< HEAD

/ =form_tag checked_problems_path, class: 'form-inline' do
/ %div.form-group
/ =select_tag 'dropdown', options_from_collection_for_select(Collection.where(instructor_id: @current_user), "id","name"), class: 'form-control'
Expand Down Expand Up @@ -36,11 +36,8 @@
=form_tag checked_problems_path, class: 'form-inline' do
%div.form-group
=select_tag 'dropdown', options_from_collection_for_select(Collection.where(instructor_id: @current_user), "id","name"), class: 'form-control'

=submit_tag 'Add problems to the collection', name: 'add_problems', class: 'btn btn-default'
=submit_tag 'Delete problems', class: 'btn btn-default'
%br
%br
=submit_tag 'Add problems to the collection', name: 'add_problems', class: 'btn btn-default'
=submit_tag 'Delete problems', class: 'btn btn-default'
%div{:class => "maintable"}
%div.table-responsive
%table.table.table-striped#problems
Expand All @@ -61,10 +58,12 @@
%div{:class => "additional"}
= "Created Date: " + problem.created_date.to_s + " | "
= "Created By: " + problem.instructor.name

%td
- problem.collections.each do |collection|
%p{:class => "colname"}
= link_to "#{collection.name} \n", collection_path(:id => collection.id)
%td= problem.tags.map {|tags| tags.name + ', '}.join
/ >>>>>>> truncate
%td{:id => "#{problem.id}_tag"}
= text_field_tag(:tag, "", class: 'form-control', id: "add_tags_#{problem.id}", placeholder: "Add tags")
%div{:id => "all_tags_#{problem.id}"}
= render :partial => "tags", locals: { tags: problem.tags}

2 changes: 2 additions & 0 deletions app/views/problems/_tags.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- tags.each do |tag|
%span.tag{:id => tag.id.to_s + "_tag"}= link_to tag.name, '', class: 'remove_tag', id: 'remove_tag'
1 change: 0 additions & 1 deletion app/views/problems/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
%div.col-md-2#sidebar-filter
= render "filter"
%div.col-md-10

%div.container-fluid
= render :partial => "problems_table", locals: { problems: @problems}
%div.container-fluid
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
get 'profile' => 'instructors#show', :as => 'profile'
get 'add_problem' => 'problems#add_to_collection', :as => 'add_problem'
get 'remove_problem' => 'problems#remove_from_collection'
get 'add/:tag/to/problem' => 'problems#add_tag', :as => 'add_tag'
get 'add/:tag/to/problem/:id' => 'problems#add_tag', :as => 'add_tag'
get 'remove/:tid/from/problem/:id' => 'problems#remove_tag', :as => 'remove_tag'
resources :collections
get 'mark_as_current' => 'instructors#mark_as_current'
get 'admin' => 'instructors#show_unauthorized', :as => 'admin'
Expand Down
10 changes: 5 additions & 5 deletions features/collections.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: collections that we can add problems to
Scenario: create a new collection
When I follow "start a new collection"
And I fill in "collection_name" with "yolo"
And I press "Create Collection"
And I press "Create"
Then I should be on the dashboard
And I add problem containing 'Raffi' to collection 'yolo'
And I should see Collection 'yolo' in the database
Expand All @@ -21,14 +21,14 @@ Feature: collections that we can add problems to
Scenario: create a new collection
When I follow "start a new collection"
And I fill in "collection_name" with ""
And I press "Create Collection"
And I press "Create"
Then I should see "can't be blank"


Scenario: remove a problem
When I follow "start a new collection"
And I fill in "collection_name" with "yolo"
And I press "Create Collection"
And I press "Create"
Then I should be on the dashboard
And I add problem containing 'lifetime' to collection 'yolo'
And I should see Collection 'yolo' in the database
Expand All @@ -43,14 +43,14 @@ Feature: collections that we can add problems to
Scenario: update a collection name
When I follow "start a new collection"
And I fill in "collection_name" with "yolo"
And I press "Create Collection"
And I press "Create"
And I update 'yolo' to 'swag'
Then I should see Collection 'swag' in the database

Scenario: attempt to update a collection with invalid name
When I follow "start a new collection"
And I fill in "collection_name" with "yolo"
And I press "Create Collection"
And I press "Create"
And I update 'yolo' to ''
Then I should see Collection 'yolo' in the database

Expand Down
7 changes: 1 addition & 6 deletions features/step_definitions/login_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


Given /^I am signed in with provider "([^\"]*)"$/ do |provider|
visit login_path
visit "/auth/#{provider.downcase}"
Expand All @@ -11,8 +9,6 @@
Instructor.stub(:find_by_provider_and_uid).and_return(@instructor)
Instructor.stub(:create_with_omniauth).and_return(@instructor)
visit "/auth/#{provider.downcase}"


end

Given /I am not logged in/ do
Expand All @@ -21,5 +17,4 @@

Given /login was unsuccessful/ do
visit auth_failure_path
end

end
10 changes: 4 additions & 6 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def with_scope(locator)
steps %Q{
Given I am on the upload page
And I attach the file "features/test_files/#{file}" to "file_upload"
And I press "upload"
Then I should see "Quiz successfully uploaded"
And I press "Upload File"
Then I should see "successfully uploaded"
}
end

Expand All @@ -69,7 +69,7 @@ def with_scope(locator)
Given I am on the dashboard
And I follow "start a new collection"
And I fill in "collection_name" with "#{name}"
And I press "Create Collection"
And I press "Create"
}
if optional.strip == 'and mark it as current'
visit mark_as_current_path(:id => Collection.find_by_name(name).id)
Expand Down Expand Up @@ -116,9 +116,7 @@ def with_scope(locator)
When /^I press the trash icon at '(.*)'/ do |collection|
collection = Collection.find_by_name(collection)
visit edit_collection_path(:id => collection)
steps %Q{
Then I follow "trash_can_icon"
}
click_link 'Delete'
end

Given /^(?:|I )am on (.+)$/ do |page_name|
Expand Down
Loading

0 comments on commit 28a446a

Please sign in to comment.