fassets_core 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/README.md +17 -2
  2. data/app/assets/javascripts/fassets_core/add_asset_box.js +34 -35
  3. data/app/assets/javascripts/fassets_core/application.js.erb +2 -0
  4. data/app/assets/javascripts/fassets_core/edit_box.js +16 -17
  5. data/app/assets/javascripts/fassets_core/facets.js.erb +6 -7
  6. data/app/assets/javascripts/fassets_core/index.js +20 -0
  7. data/app/assets/stylesheets/fassets_core/add_asset_box.css.scss +12 -12
  8. data/app/assets/stylesheets/fassets_core/edit_box.css.scss +1 -2
  9. data/app/assets/stylesheets/fassets_core/forms.css.scss +5 -0
  10. data/app/assets/stylesheets/fassets_core/index.css +15 -0
  11. data/app/assets/stylesheets/fassets_core/labels.css.scss +16 -1
  12. data/app/assets/stylesheets/fassets_core/master.css.scss +4 -0
  13. data/app/controllers/assets_controller.rb +7 -37
  14. data/app/controllers/labels_controller.rb +17 -8
  15. data/app/models/asset.rb +10 -15
  16. data/app/views/assets/new.html.haml +18 -17
  17. data/app/views/catalogs/_facet.html.haml +1 -1
  18. data/app/views/labels/_sidebar.html.haml +15 -15
  19. data/app/views/layouts/fassets_core/application.html.haml +7 -5
  20. data/app/views/shared/_flash_messages.html.haml +6 -0
  21. data/config/routes.rb +3 -4
  22. data/lib/acts_as_asset.rb +1 -8
  23. data/lib/fassets_core/test_helper/acts_as_asset.rb +46 -0
  24. data/lib/fassets_core/test_helper/every_assets_controller.rb +2 -2
  25. data/lib/fassets_core/test_helper.rb +1 -1
  26. data/lib/fassets_core/version.rb +1 -1
  27. data/lib/fassets_core.rb +1 -0
  28. metadata +24 -7
  29. data/lib/authenticated_system.rb +0 -187
  30. data/lib/authenticated_test_helper.rb +0 -20
  31. data/lib/template_manager.rb +0 -27
data/README.md CHANGED
@@ -7,8 +7,7 @@ This project rocks and uses MIT-LICENSE.
7
7
  To use this plugin in your rails project, you need to add the gem to your applications `Gemfile`:
8
8
 
9
9
  ```
10
- # for now the git version of fassets core should be used, since it’s under heavy development
11
- gem 'fassets_core', :git => "git://github.com/fassets/fassets_core.git"
10
+ gem 'fassets_core'
12
11
  ```
13
12
 
14
13
  After that, run the `bundle` command to install all new dependencies.
@@ -20,3 +19,19 @@ bundle exec rake fassets_core_engine:install:migrations
20
19
  bundle exec rake db:migrate
21
20
  ```
22
21
 
22
+ # Run tests
23
+
24
+ In order to run the tests for the first time, you need to do the following in a clean repository:
25
+
26
+ ```
27
+ bundle
28
+ RAILS_ENV=test rake db:migrate
29
+ bundle exec guard
30
+ ```
31
+
32
+ After the initial setup, it is okay to just start guard:
33
+
34
+ ```
35
+ bundle exec guard
36
+ ```
37
+
@@ -11,8 +11,6 @@ $(document).ready(function(){
11
11
  $.fancybox.showActivity();
12
12
  var f_width = $(window).width()*0.8;
13
13
  var f_height = $(window).height()*0.8;
14
- $("#add_asset_content").css("left",$("#catalog_list").width()+10);
15
- $("#add_asset_content").css("width",$("#fancybox-content").width()-$("#catalog_list").width()-30-$("#facets").width());
16
14
  $.ajaxSetup({cache: false});
17
15
  $.get('/assets/new', { content_only: true }, function(data) {
18
16
  $.fancybox({
@@ -23,7 +21,6 @@ $(document).ready(function(){
23
21
  height: f_height,
24
22
  onComplete: function(){
25
23
  $("#fancybox-content").data("box-type","add_asset");
26
- adjust_links();
27
24
  $.fancybox.resize();
28
25
  }
29
26
  });
@@ -43,40 +40,42 @@ $(document).ready(function(){
43
40
  }
44
41
  break;
45
42
  }
46
- });
47
- var adjust_links = function(){
48
- $("#fancybox-content li.asset_type").click(function(event){
49
- event.preventDefault();
50
- $.fancybox.showActivity();
51
- asset_type = $(event.target).data("asset-type");
52
- $("#fancybox-content").load("/assets/new", {type: asset_type, content_only: true }, function() {
53
- adjust_links();
54
- });
55
- $.fancybox.resize();
56
- $.fancybox.hideActivity();
57
- });
58
- $("#fancybox-content .asset_create_button").click(function(event){
59
- event.preventDefault();
60
- $.fancybox.showActivity();
61
- var action = $("#add_asset_content form").attr("action");
62
- $.post(action, $("#add_asset_content form").serialize(), function(data){
63
- $("#fancybox-content #add_asset_content").load(data[0].edit_box_url+"?type="+data[0].content_type);
64
- });
65
- reload_tray();
66
- $.fancybox.resize();;
67
- $.fancybox.hideActivity();
68
- });
69
- $("#fancybox-content .asset_submit_button").click(function(event){
70
- event.preventDefault();
71
- $.fancybox.showActivity();
72
- //var token = encodeURIComponent(AUTH_TOKEN)
73
- var asset_type = $(event.target).data("asset-type");
74
- reload_tray();
75
- $.fancybox.hideActivity();
43
+ });
44
+ $(document).ajaxComplete(function() {
45
+ adjust_links();
46
+ });
47
+ var adjust_links = function() {
48
+ $("#add_asset_sidebar li.asset_type").click(function(event){
49
+ event.preventDefault();
50
+ $.fancybox.showActivity();
51
+ asset_type = $(event.target).data("asset-type");
52
+ $("div.fassets_core.new").load("/assets/new", {type: asset_type, content_only: true });
53
+ $.fancybox.resize();
54
+ $.fancybox.hideActivity();
55
+ });
56
+ $("#fancybox-content .asset_create_button").click(function(event){
57
+ event.preventDefault();
58
+ $.fancybox.showActivity();
59
+ var action = $("#add_asset_content form").attr("action");
60
+ $.post(action, $("#add_asset_content form").serialize(), function(data){
61
+ $("#fancybox-content #add_asset_content").load(data[0].edit_box_url+"?type="+data[0].content_type);
76
62
  });
77
- $("form.edit_classification input[type=submit][value=Save]").hide();
78
- };
63
+ reload_tray();
64
+ $.fancybox.resize();;
65
+ $.fancybox.hideActivity();
66
+ });
67
+ $("#fancybox-content .asset_submit_button").click(function(event){
68
+ event.preventDefault();
69
+ $.fancybox.showActivity();
70
+ //var token = encodeURIComponent(AUTH_TOKEN)
71
+ var asset_type = $(event.target).data("asset-type");
72
+ reload_tray();
73
+ $.fancybox.hideActivity();
74
+ });
75
+ $("form.edit_classification input[type=submit][value=Save]").hide();
76
+ };
79
77
 
78
+ adjust_links();
80
79
  $("#new_asset_link").click(function(event){
81
80
  event.preventDefault();
82
81
  show_asset_box();
@@ -6,6 +6,8 @@
6
6
  //= require jquery.iframe-transport
7
7
  //= require jquery.collapsiblePanel-0.2.0
8
8
  //= require fancybox
9
+ //= require jquery.purr
10
+ //= require best_in_place
9
11
  //= require_tree .
10
12
  //= require_self
11
13
 
@@ -4,24 +4,23 @@ $(document).ready(function(){
4
4
  $.fancybox.showActivity();
5
5
  var f_width = $(window).width()*0.8;
6
6
  var f_height = $(window).height()*0.8;
7
- $.ajax({
8
- type : "GET",
9
- cache : false,
10
- url : "/asset/"+asset_id+"/edit",
11
- success: function(data) {
12
- $.fancybox({
13
- content: data,
14
- padding: 0,
15
- autoDimensions: false,
16
- width: f_width,
17
- height: f_height,
18
- onComplete: function(){$("#fancybox-content").data("box-type","edit_asset");}
19
- });
20
- adjust_links();
21
- $.fancybox.resize();
22
- }
23
- });
7
+ $.ajaxSetup({cache: false});
8
+ $.get('/assets/'+asset_id+'/edit', { content_only: true }, function(data) {
9
+ $.fancybox({
10
+ content: data,
11
+ padding: 0,
12
+ autoDimensions: false,
13
+ width: f_width,
14
+ height: f_height,
15
+ onComplete: function(){
16
+ $("#fancybox-content").data("box-type","edit_asset");
17
+ adjust_links();
18
+ $.fancybox.resize();
19
+ }
20
+ });
21
+ });
24
22
  };
23
+
25
24
  $("body .edit_button").live("click",function(event){
26
25
  event.preventDefault();
27
26
  show_edit_box(event);
@@ -2,13 +2,10 @@ $(function(){
2
2
  //Sortable Labels
3
3
  $('#labels').sortable({
4
4
  axis: 'y',
5
- start: function() {
6
- $('#labels .handle').bind('click',noEventPropagation);
7
- },
8
- stop:function() {
9
- $('#labels .handle').unbind('click', noEventPropagation);
10
- },
11
- update:function(){
5
+ handle: ".handle",
6
+ update: function(e, ui){
7
+ url = $("ol#labels").data('update_url')
8
+ $.post(url, $(this).sortable('serialize'))
12
9
  }
13
10
  });
14
11
 
@@ -24,6 +21,8 @@ $(function(){
24
21
  });
25
22
  // hide the submit button if JS is enabled (form can be submited by checking the boxes)
26
23
  $("form.edit_classification input[type=submit][value=Save]").hide();
24
+
25
+ $('.best_in_place').best_in_place();
27
26
  });
28
27
 
29
28
  /*$.ajax({
@@ -0,0 +1,20 @@
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require jquery-ui
4
+ //= require jquery.collapsiblePanel-0.2.0
5
+ //= require fancybox
6
+ //= require jquery.purr
7
+ //= require best_in_place
8
+ //= require_self
9
+ //= require ./add_asset_box
10
+ //= require ./assets
11
+ //= require ./catalog_box
12
+ //= require ./catalogs
13
+ //= require ./classification
14
+ //= require ./edit_box
15
+ //= require ./facets
16
+ //= require ./tray
17
+
18
+ $.ajaxSetup({ 'beforeSend': function(xhr) {
19
+ xhr.setRequestHeader("Accept", "text/javascript,text/html");
20
+ }});
@@ -1,12 +1,15 @@
1
1
  #add_asset_sidebar {
2
2
  position: absolute;
3
- left: 0;
4
- top: 0px;
3
+ width: 200px;
5
4
  height: 100%;
6
- min-width: 150px;
7
5
  font-size: 1em;
8
- padding-right: 0;
6
+ margin-right: 1em;
9
7
  background: silver;
8
+
9
+ ul {
10
+ list-style: none;
11
+ }
12
+
10
13
  .asset_type {
11
14
  margin-top: .5em;
12
15
  padding: .5em .0em .5em .5em;
@@ -28,20 +31,17 @@
28
31
  }
29
32
  }
30
33
  }
31
- #content {
32
- position: absolute;
33
- height: 100%;
34
- }
34
+
35
35
  #fancybox-content h1 {
36
36
  border-top: none;
37
37
  background-color: white;
38
38
  }
39
39
  #add_asset_content {
40
40
  position: relative;
41
- top: 5px;
42
- height: 98%;
43
- left: 150px;
44
- width: 88%;
41
+ height: 100%;
42
+ margin-left: 200px;
43
+ padding-left: 1em;
44
+ overflow-y: auto;
45
45
  }
46
46
  #sidebar.box{
47
47
  float: right;
@@ -1,6 +1,5 @@
1
1
  #fancybox-content #main {
2
2
  margin-top: 10px;
3
- margin-left: 10px;
4
3
  height: 95%;
5
4
  }
6
5
  #fancybox-content #sidebar{
@@ -21,7 +20,7 @@
21
20
  color: white;
22
21
  text-shadow: 1px 1px #777777;
23
22
  padding: .5em;
24
- float: left;
23
+ float: left;
25
24
  }
26
25
  #action {
27
26
  float: left;
@@ -10,3 +10,8 @@
10
10
  }
11
11
  }
12
12
 
13
+ .fassets_core.new {
14
+ position: absolute;
15
+ height: 100%;
16
+ width: 100%;
17
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ *= require fancybox
3
+ *= require ./add_asset_box
4
+ *= require ./assets
5
+ *= require ./catalog_box
6
+ *= require ./collapsible
7
+ *= require ./edit_box
8
+ *= require ./facet
9
+ *= require ./filter
10
+ *= require ./forms
11
+ *= require ./labels
12
+ *= require ./master
13
+ *= require ./sidebar
14
+ *= require ./tray
15
+ */
@@ -1,4 +1,4 @@
1
- .fassets_core {
1
+ .fassets_core .labels {
2
2
  .collapsible {
3
3
  text-align: left;
4
4
  }
@@ -10,4 +10,19 @@
10
10
  ul {
11
11
  margin: 0;
12
12
  }
13
+
14
+ span.best_in_place {
15
+ display: inline;
16
+ }
17
+ form {
18
+ display: inline;
19
+
20
+ div {
21
+ display: inline;
22
+ }
23
+
24
+ input {
25
+ display: inline;
26
+ }
27
+ }
13
28
  }
@@ -1,3 +1,7 @@
1
+ body {
2
+ overflow: hidden;
3
+ }
4
+
1
5
  .fassets_core {
2
6
  text-align: left;
3
7
 
@@ -26,7 +26,6 @@ class AssetsController < FassetsCore::ApplicationController
26
26
  if @content.save
27
27
  @classification = Classification.new(:catalog_id => params["classification"]["catalog_id"],:asset_id => @content.asset.id)
28
28
  @classification.save
29
- create_content_labeling(@content.asset.id, params["classification"]["catalog_id"])
30
29
  flash[:notice] = "Created new asset!"
31
30
  format.js { render :json => @content.to_jq_upload.merge({:status => :ok}).to_json }
32
31
  format.html { redirect_to edit_asset_content_path(@content) }
@@ -43,7 +42,7 @@ class AssetsController < FassetsCore::ApplicationController
43
42
  render :template => 'assets/show'
44
43
  end
45
44
  def edit
46
- render :template => 'assets/edit', :locals => {:in_fancybox => false}, :layout => false
45
+ render :template => 'assets/edit', :layout => !(params["content_only"])
47
46
  end
48
47
  def update
49
48
  if @content.update_attributes(content_params) and @content.asset.update_attributes(params["asset"])
@@ -73,43 +72,14 @@ class AssetsController < FassetsCore::ApplicationController
73
72
  params[field_name]
74
73
  end
75
74
  def find_content
76
- if params[:asset_id]
77
- content_id = Asset.find(params[:id]).content_id
78
- else
79
- content_id = params[:id]
75
+ if self.respond_to?(:content_model)
76
+ @content = content_model.find(params[:id])
77
+ elsif !params[:asset_id].nil?
78
+ asset = Asset.find(params[:asset_id])
79
+ @content = asset.content
80
80
  end
81
- content_id = Asset.find(params[:id]).content_id
82
- @content = self.content_model.find(content_id)
83
81
  rescue ActiveRecord::RecordNotFound => e
84
- flash[:error] = "#{self.content_model.to_s} with id #{params[:id]} not found"
82
+ flash[:error] = e.message
85
83
  redirect_to main_app.root_url
86
84
  end
87
- def create_content_labeling(asset_id,catalog_id)
88
- asset = Asset.find(asset_id)
89
- content_facet = Facet.where(:catalog_id => catalog_id, :caption => "Content Type").first
90
- return if content_facet.nil?
91
- content_facet.labels.each do |label|
92
- if asset.content_type == "FileAsset"
93
- if label.caption.downcase == asset.content.media_type
94
- labeling = Labeling.new(:classification_id => @classification.id, :label_id => label.id)
95
- labeling.save
96
- end
97
- elsif asset.content_type == "Url"
98
- if label.caption == "Url"
99
- labeling = Labeling.new(:classification_id => @classification.id, :label_id => label.id)
100
- labeling.save
101
- end
102
- elsif asset.content_type == "Code"
103
- if label.caption == "Code"
104
- labeling = Labeling.new(:classification_id => @classification.id, :label_id => label.id)
105
- labeling.save
106
- end
107
- elsif asset.content_type == "FassetsPresentations::Presentation"
108
- if label.caption == "Presentation"
109
- labeling = Labeling.new(:classification_id => @classification.id, :label_id => label.id)
110
- labeling.save
111
- end
112
- end
113
- end
114
- end
115
85
  end
@@ -1,6 +1,7 @@
1
1
  class LabelsController < FassetsCore::ApplicationController
2
2
  before_filter :authenticate_user!
3
3
  before_filter :find_label, :except => [:create, :sort]
4
+ respond_to :html, :json
4
5
  def create
5
6
  @label = Label.new(params[:label])
6
7
  @label.facet_id = params[:facet_id]
@@ -12,19 +13,27 @@ class LabelsController < FassetsCore::ApplicationController
12
13
  flash[:error] = "Label could not be created! Caption cannot be empty!"
13
14
  else
14
15
  flash[:error] = "Label could not be created!"
15
- end
16
+ end
16
17
  redirect_to :back
17
18
  end
18
19
  end
19
20
  def update
20
- if params[:label][:caption].blank?
21
- flash[:error] = "Label could not be updated! Caption cannot be empty!"
22
- redirect_to :back
23
- return
24
- end
25
21
  @label.update_attributes(params[:label])
26
- flash[:notice] = "Label was successfully updated."
27
- redirect_to edit_catalog_facet_path(params[:catalog_id], params[:facet_id])
22
+ respond_to do |format|
23
+ if @label.save
24
+ format.html do
25
+ flash[:notice] = "Label was successfully updated."
26
+ redirect_to edit_catalog_facet_path(params[:catalog_id], params[:facet_id])
27
+ end
28
+ format.json { respond_with_bip(@label) }
29
+ else
30
+ format.html do
31
+ flash[:error] = "Label could not be updated! Caption cannot be empty!"
32
+ redirect_to :back
33
+ end
34
+ format.json { respond_with_bip(@label) }
35
+ end
36
+ end
28
37
  end
29
38
  def sort
30
39
  params[:label].each_with_index do |id, position|
data/app/models/asset.rb CHANGED
@@ -10,13 +10,6 @@ class Asset < ActiveRecord::Base
10
10
 
11
11
  after_create :put_on_tray
12
12
 
13
- def publish=(test)
14
- end
15
- def published=(test)
16
- end
17
- def published
18
- 1
19
- end
20
13
  def self.filter(filter)
21
14
  options = {:select => "assets.*", :order => "name"}
22
15
  unless filter.empty?
@@ -27,18 +20,19 @@ class Asset < ActiveRecord::Base
27
20
  all options
28
21
  end
29
22
 
23
+ # FIXME: is this used somewhere? should be removed right after the release of 0.3.0 to test if something breaks
30
24
  def self.count_for_labels(filter)
31
25
  options = {:include => [:labelings], :group => "label_id"}
32
26
  unless filter.empty?
33
27
  options[:conditions] = "assets.id IN(
34
- SELECT DISTINCT assets.id
35
- FROM assets
36
- LEFT OUTER JOIN classifications ON (assets.id = classifications.asset_id)
37
- LEFT OUTER JOIN labelings ON (labelings.classification_id=classifications.id)
38
- WHERE (#{filter.to_condition})
39
- GROUP BY assets.id
28
+ SELECT DISTINCT assets.id
29
+ FROM assets
30
+ LEFT OUTER JOIN classifications ON (assets.id = classifications.asset_id)
31
+ LEFT OUTER JOIN labelings ON (labelings.classification_id=classifications.id)
32
+ WHERE (#{filter.to_condition})
33
+ GROUP BY assets.id
40
34
  HAVING COUNT(label_id)=#{filter.size})"
41
- filter.to_condition
35
+ filter.to_condition
42
36
  end
43
37
  count options
44
38
  end
@@ -46,7 +40,8 @@ class Asset < ActiveRecord::Base
46
40
  def put_on_tray
47
41
  return if user.nil?
48
42
 
49
- tray_positions.create(:user_id => user.id, :asset_id => id, :position => user.tray_positions.maximum(:position) ? user.tray_positions.maximum(:position)+1 : 1)
43
+ p = user.tray_positions.maximum(:position) || 0
44
+ tray_positions.create(:user_id => user.id, :asset_id => id, :position => p + 1)
50
45
  end
51
46
  end
52
47
 
@@ -4,22 +4,23 @@
4
4
  #name
5
5
  New
6
6
 
7
- -unless @asset_types.nil?
8
- #add_asset_sidebar
9
- =render :partial => "add_asset_sidebar"
7
+ .fassets_core.new
8
+ -unless @asset_types.nil?
9
+ #add_asset_sidebar
10
+ =render :partial => "add_asset_sidebar"
10
11
 
11
- -unless @content.nil?
12
- #add_asset_content
13
- #main.fassets_core
14
- =form_for @content, :url => asset_content_path(@content),:html => {:multipart => true} do |f|
15
- =render :partial => "shared/error", :locals => {:target => @content}
16
- =fields_for "asset" do |asset|
12
+ -unless @content.nil?
13
+ #add_asset_content
14
+ #main.fassets_core
15
+ =form_for @content, :url => asset_content_path(@content),:html => {:multipart => true} do |f|
16
+ =render :partial => "shared/error", :locals => {:target => @content}
17
+ =fields_for "asset" do |asset|
18
+ %p
19
+ %label{:for => 'name'} Name:
20
+ =asset.text_field :name
21
+ #name_warning
17
22
  %p
18
- %label{:for => 'name'} Name:
19
- =asset.text_field :name
20
- #name_warning
21
- %p
22
- %label{:for => 'catalog_id'} Catalog:
23
- =select("classification", "catalog_id", Catalog.all.inject([]){|m,c| m << [c.title, c.id]})
24
- =render :partial => @content.class.to_s.underscore.pluralize + "/form", :locals => {:new => true}, :object => f
25
- =submit_tag "Create", :class => "asset_create_button"
23
+ %label{:for => 'catalog_id'} Catalog:
24
+ =select("classification", "catalog_id", Catalog.all.inject([]){|m,c| m << [c.title, c.id]})
25
+ =render :partial => @content.class.to_s.underscore.pluralize + "/form", :locals => {:new => true}, :object => f
26
+ =submit_tag "Create", :class => "asset_create_button"
@@ -5,7 +5,7 @@
5
5
  =link_to image_tag("fassets_core/edit.png"), edit_catalog_facet_path(@catalog, facet)
6
6
  %span.handle=image_tag("fassets_core/drag.png")
7
7
  %ul{:class => "#{facet.color}_lite"}
8
- -facet.labels.each do |label|
8
+ -facet.ordered_labels.each do |label|
9
9
  -if @counts[label.id] && !@filter.include?(label.id)
10
10
  %li.label
11
11
  =link_to label.caption, catalog_path(@catalog, :filter => @filter.to_query_include(label.id))
@@ -1,22 +1,22 @@
1
- .collapsible
2
- %h2.title New Label
3
- =form_for [@catalog, @facet, Label.new], :url => catalog_facet_labels_path(@catalog,@facet) do |f|
4
- =render :partial => "labels/form", :object => f
5
- =submit_tag "Create"
6
-
7
- .collapsible
1
+ .labels
8
2
  %h2.title Labels
9
- %ol.collection{:class => @facet.label_order == 'position' ? "sortable" : nil, :id => "catalogs.#{@catalog.id}.facets.#{@facet.id}.labels.sort"}
3
+ .collapsible
4
+ %h2.title New Label
5
+ =form_for [@catalog, @facet, Label.new] do |f|
6
+ =render :partial => "labels/form", :object => f
7
+ =submit_tag "Create"
8
+
9
+ %ol.collection{:class => @facet.label_order == 'position' ? "sortable" : nil,
10
+ :id => "labels",
11
+ :data => {:update_url => sort_catalog_facet_labels_path(@catalog, @facet)}}
10
12
  -@facet.ordered_labels.each do |label|
11
13
  %li{:id => "label_#{label.id}"}
12
- =label.caption
13
- .content
14
- =form_for [@catalog, @facet, label], :url => catalog_facet_label_path(@catalog, @facet, label) do |f|
15
- =render :partial => "labels/form", :object => f
16
- =submit_tag "Save"
17
- =button_to "Drop", catalog_facet_label_path(@catalog, @facet, label),
14
+ %span.content
15
+ =best_in_place label, :caption, :path => catalog_facet_label_path(@catalog, @facet, label)
16
+ =button_to "Delete", catalog_facet_label_path(@catalog, @facet, label),
18
17
  :confirm => 'Are you sure?',
19
18
  :method => "delete",
20
19
  :remote => true,
21
20
  :disable_with => 'loading...'
22
-
21
+ - if @facet.label_order == 'position'
22
+ %span.handle= image_tag "fassets_core/drag.png"
@@ -4,11 +4,13 @@
4
4
  =yield :core_head
5
5
 
6
6
  - content_for :catalogs_selector do
7
- =collection_select :catalog,
8
- :id, Catalog.all,
9
- :id, :title,
10
- options ={:prompt => "Catalogs ..."},
11
- :onchange => "javascript:window.location= '/catalogs/' + this.value"
7
+ %select{ :onchange => "javascript:window.location= this.value"}
8
+ %option{ :value => "/" }= "Catalogs..."
9
+ =Catalog.all.each do |c|
10
+ - if params[:id].to_i == c.id
11
+ %option{ :value => '/catalogs/' + c.id.to_s, :selected => 'selected'}= c.title
12
+ - else
13
+ %option{ :value => '/catalogs/' + c.id.to_s}= c.title
12
14
 
13
15
  - content_for :tray do
14
16
  =render :partial => "shared/tray"
@@ -0,0 +1,6 @@
1
+ -if flash[:notice]
2
+ #message=flash[:notice]
3
+ -if flash[:error]
4
+ #error_message=flash[:error]
5
+ -if flash[:alert]
6
+ #error_message=flash[:alert]
data/config/routes.rb CHANGED
@@ -3,10 +3,10 @@ Rails.application.routes.draw do
3
3
  resources :facets do
4
4
  collection do
5
5
  post :sort
6
- end
6
+ end
7
7
  resources :labels do
8
8
  collection do
9
- put :sort
9
+ post :sort
10
10
  end
11
11
  end
12
12
  end
@@ -24,11 +24,10 @@ Rails.application.routes.draw do
24
24
  end
25
25
 
26
26
  match 'asset/:id/preview' => 'Assets#preview'
27
- match 'asset/:id/edit' => 'Assets#edit'
28
27
  match 'asset/:id/classifications' => 'Assets#classifications'
29
28
  match 'catalog_box' => 'Catalogs#catalog_box'
30
29
  match 'box_content' => 'Catalogs#box_content'
31
30
  match 'box_facet' => 'Catalogs#box_facet'
32
- match 'edit_box/:id' => 'Assets#edit_box'
31
+ match 'assets/:asset_id/edit' => 'assets#edit'
33
32
  match 'assets/new' => 'assets#new'
34
33
  end
data/lib/acts_as_asset.rb CHANGED
@@ -2,7 +2,7 @@ module ActiveRecord
2
2
  module Acts
3
3
  module Asset
4
4
  def self.included(base)
5
- base.extend(ClassMethods)
5
+ base.extend(ClassMethods)
6
6
  end
7
7
  module ClassMethods
8
8
  def acts_as_asset
@@ -15,19 +15,12 @@ module ActiveRecord
15
15
  def name
16
16
  asset.name
17
17
  end
18
- def class_underscore
19
- self.class.to_s.underscore
20
- end
21
18
  def media_type
22
19
  "generic"
23
20
  end
24
21
  def icon
25
22
  "/images/#{media_type}.png"
26
23
  end
27
- protected
28
- def put_on_tray
29
- tray_positions.create(:user_id => self.user_id)
30
- end
31
24
  end
32
25
  end
33
26
  end
@@ -0,0 +1,46 @@
1
+ require "rspec"
2
+
3
+ shared_examples_for "ActsAsAsset" do
4
+ before(:each) do
5
+ begin
6
+ @the_asset = Asset.create!(:name => "Test Asset", :content => asset)
7
+ rescue NameError
8
+ raise "May be you need to define an asset! Use \"let(:asset){ #your code here }\" in your specs."
9
+ end
10
+ end
11
+
12
+ context "associations for the model" do
13
+ it "should have an asset object" do
14
+ asset.asset.should == @the_asset
15
+ end
16
+
17
+ it "should destroy the asset model when deleted" do
18
+ asset.destroy
19
+ begin
20
+ @the_asset.reload
21
+ raise "RecordNotFound exception should have been raised!"
22
+ rescue ActiveRecord::RecordNotFound
23
+ end
24
+ end
25
+
26
+ it "should be possible to set the name for an asset through the object itself" do
27
+ asset.asset.name="New name"
28
+ asset.save!
29
+ @the_asset.reload.name.should == "New name"
30
+ end
31
+ end
32
+
33
+ context "instance methods for the model" do
34
+ it "should provide a name method" do
35
+ asset.name.should == "Test Asset"
36
+ end
37
+
38
+ it "should provide a media type" do
39
+ asset.media_type.should_not be_nil
40
+ end
41
+
42
+ it "should provide an icon" do
43
+ asset.icon.should_not be_nil
44
+ end
45
+ end
46
+ end
@@ -79,13 +79,13 @@ shared_examples_for "Every AssetsController" do
79
79
  it "should redirect to root with error message on error" do
80
80
  get 'show', additional_request_params.merge({ :id => asset.id })
81
81
  response.should redirect_to(root_path)
82
- request.flash[:error].should =~ /not found$/
82
+ request.flash[:error].should =~ /^Couldn't find/
83
83
  end
84
84
 
85
85
  it "should delete the asset and show a notice" do
86
86
  delete "destroy", additional_request_params.merge({ :id => asset.id })
87
87
  response.should redirect_to(root_path)
88
- request.flash[:error].should =~ /not found$/
88
+ request.flash[:error].should =~ /^Couldn't find/
89
89
  end
90
90
 
91
91
  describe "create asset" do
@@ -1,3 +1,3 @@
1
1
  require "fassets_core/test_helper/every_assets_controller.rb"
2
2
  require "fassets_core/test_helper/every_authenticated_controller.rb"
3
-
3
+ require "fassets_core/test_helper/acts_as_asset.rb"
@@ -1,3 +1,3 @@
1
1
  module FassetsCore
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/fassets_core.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "fassets_core/engine"
2
2
  require "fassets_core/plugins"
3
3
  require "fancybox-rails"
4
+ require "best_in_place"
4
5
 
5
6
  module FassetsCore
6
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fassets_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-23 00:00:00.000000000 Z
13
+ date: 2012-10-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -108,6 +108,22 @@ dependencies:
108
108
  - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: best_in_place
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
111
127
  - !ruby/object:Gem::Dependency
112
128
  name: devise
113
129
  requirement: !ruby/object:Gem::Requirement
@@ -231,6 +247,7 @@ files:
231
247
  - app/views/facets/edit.html.haml
232
248
  - app/views/facets/_form.html.haml
233
249
  - app/views/shared/_asset_form.html.haml
250
+ - app/views/shared/_flash_messages.html.haml
234
251
  - app/views/shared/_clipboard.html.haml
235
252
  - app/views/shared/_classification.html.haml
236
253
  - app/views/shared/_error.html.haml
@@ -261,6 +278,7 @@ files:
261
278
  - app/assets/stylesheets/fassets_core/facet.css.scss
262
279
  - app/assets/stylesheets/fassets_core/forms.css.scss
263
280
  - app/assets/stylesheets/fassets_core/application.css
281
+ - app/assets/stylesheets/fassets_core/index.css
264
282
  - app/assets/stylesheets/fassets_core/add_asset_box.css.scss
265
283
  - app/assets/stylesheets/fassets_core/tray.css.scss
266
284
  - app/assets/stylesheets/fassets_core/edit_box.css.scss
@@ -273,6 +291,7 @@ files:
273
291
  - app/assets/stylesheets/fassets_core/sidebar.css.scss
274
292
  - app/assets/javascripts/fassets_core/assets.js
275
293
  - app/assets/javascripts/fassets_core/tray.js
294
+ - app/assets/javascripts/fassets_core/index.js
276
295
  - app/assets/javascripts/fassets_core/catalog_box.js
277
296
  - app/assets/javascripts/fassets_core/add_asset_box.js
278
297
  - app/assets/javascripts/fassets_core/application.js.erb
@@ -308,13 +327,11 @@ files:
308
327
  - lib/fassets_core/version.rb
309
328
  - lib/fassets_core/engine.rb
310
329
  - lib/fassets_core/plugins.rb
330
+ - lib/fassets_core/test_helper/acts_as_asset.rb
311
331
  - lib/fassets_core/test_helper/every_assets_controller.rb
312
332
  - lib/fassets_core/test_helper/every_authenticated_controller.rb
313
333
  - lib/fassets_core/test_helper.rb
314
- - lib/authenticated_system.rb
315
334
  - lib/fassets_core.rb
316
- - lib/authenticated_test_helper.rb
317
- - lib/template_manager.rb
318
335
  - lib/tasks/cucumber.rake
319
336
  - lib/tasks/fassets-core_tasks.rake
320
337
  - MIT-LICENSE
@@ -384,7 +401,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
384
401
  version: '0'
385
402
  segments:
386
403
  - 0
387
- hash: -4486109871585801178
404
+ hash: -1017598728477094860
388
405
  required_rubygems_version: !ruby/object:Gem::Requirement
389
406
  none: false
390
407
  requirements:
@@ -393,7 +410,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
393
410
  version: '0'
394
411
  segments:
395
412
  - 0
396
- hash: -4486109871585801178
413
+ hash: -1017598728477094860
397
414
  requirements: []
398
415
  rubyforge_project:
399
416
  rubygems_version: 1.8.24
@@ -1,187 +0,0 @@
1
- module AuthenticatedSystem
2
- protected
3
- # Returns true or false if the user is logged in.
4
- # Preloads @current_user with the user model if they're logged in.
5
- def logged_in?
6
- !!current_user
7
- end
8
-
9
- # Accesses the current user from the session.
10
- # Future calls avoid the database because nil is not equal to false.
11
- def current_user
12
- @current_user ||= (login_from_session || login_from_basic_auth || login_from_cookie) unless @current_user == false
13
- end
14
-
15
- # Store the given user id in the session.
16
- def current_user=(new_user)
17
- session[:user_id] = new_user ? new_user.id : nil
18
- @current_user = new_user || false
19
- end
20
-
21
- # Check if the user is authorized
22
- #
23
- # Override this method in your controllers if you want to restrict access
24
- # to only a few actions or if you want to check if the user
25
- # has the correct rights.
26
- #
27
- # Example:
28
- #
29
- # # only allow nonbobs
30
- # def authorized?
31
- # current_user.login != "bob"
32
- # end
33
- #
34
- def authorized?(action=nil, resource=nil, *args)
35
- user_signed_in??
36
- end
37
-
38
- # Filter method to enforce a login requirement.
39
- #
40
- # To require logins for all actions, use this in your controllers:
41
- #
42
- # before_filter :login_required
43
- #
44
- # To require logins for specific actions, use this in your controllers:
45
- #
46
- # before_filter :login_required, :only => [ :edit, :update ]
47
- #
48
- # To skip this in a subclassed controller:
49
- #
50
- # skip_before_filter :login_required
51
- #
52
- def login_required
53
- authorized? || access_denied
54
- end
55
-
56
- # Redirect as appropriate when an access request fails.
57
- #
58
- # The default action is to redirect to the login screen.
59
- #
60
- # Override this method in your controllers if you want to have special
61
- # behavior in case the user is not authorized
62
- # to access the requested action. For example, a popup window might
63
- # simply close itself.
64
- def access_denied
65
- respond_to do |format|
66
- format.html do
67
- store_location
68
- redirect_to new_session_path
69
- end
70
- # format.any doesn't work in rails version < http://dev.rubyonrails.org/changeset/8987
71
- # you may want to change format.any to e.g. format.any(:js, :xml)
72
- format.any do
73
- request_http_basic_authentication 'Web Password'
74
- end
75
- end
76
- end
77
-
78
- # Store the URI of the current request in the session.
79
- #
80
- # We can return to this location by calling #redirect_back_or_default.
81
- def store_location
82
- session[:return_to] = request.request_uri
83
- end
84
-
85
- # Redirect to the URI stored by the most recent store_location call or
86
- # to the passed default. Set an appropriately modified
87
- # after_filter :store_location, :only => [:index, :new, :show, :edit]
88
- # for any controller you want to be bounce-backable.
89
- def redirect_back_or_default(default)
90
- redirect_to(session[:return_to] || default)
91
- session[:return_to] = nil
92
- end
93
-
94
- # Inclusion hook to make #current_user and #logged_in?
95
- # available as ActionView helper methods.
96
- def self.included(base)
97
- base.send :helper_method, :current_user, :user_signed_in?, :authorized? if base.respond_to? :helper_method
98
- end
99
-
100
- #
101
- # Login
102
- #
103
-
104
- # Called from #current_user. First attempt to login by the user id stored in the session.
105
- def login_from_session
106
- self.current_user = User.find_by_id(session[:user_id]) if session[:user_id]
107
- end
108
-
109
- # Called from #current_user. Now, attempt to login by basic authentication information.
110
- def login_from_basic_auth
111
- authenticate_with_http_basic do |login, password|
112
- self.current_user = User.authenticate(login, password)
113
- end
114
- end
115
-
116
- #
117
- # Logout
118
- #
119
-
120
- # Called from #current_user. Finaly, attempt to login by an expiring token in the cookie.
121
- # for the paranoid: we _should_ be storing user_token = hash(cookie_token, request IP)
122
- def login_from_cookie
123
- user = cookies[:auth_token] && User.find_by_remember_token(cookies[:auth_token])
124
- if user && user.remember_token?
125
- self.current_user = user
126
- handle_remember_cookie! false # freshen cookie token (keeping date)
127
- self.current_user
128
- end
129
- end
130
-
131
- # This is ususally what you want; resetting the session willy-nilly wreaks
132
- # havoc with forgery protection, and is only strictly necessary on login.
133
- # However, **all session state variables should be unset here**.
134
- def logout_keeping_session!
135
- # Kill server-side auth cookie
136
- @current_user.forget_me if @current_user.is_a? User
137
- @current_user = false # not logged in, and don't do it for me
138
- kill_remember_cookie! # Kill client-side auth cookie
139
- session[:user_id] = nil # keeps the session but kill our variable
140
- # explicitly kill any other session variables you set
141
- end
142
-
143
- # The session should only be reset at the tail end of a form POST --
144
- # otherwise the request forgery protection fails. It's only really necessary
145
- # when you cross quarantine (logged-out to logged-in).
146
- def logout_killing_session!
147
- logout_keeping_session!
148
- reset_session
149
- end
150
-
151
- #
152
- # Remember_me Tokens
153
- #
154
- # Cookies shouldn't be allowed to persist past their freshness date,
155
- # and they should be changed at each login
156
-
157
- # Cookies shouldn't be allowed to persist past their freshness date,
158
- # and they should be changed at each login
159
-
160
- def valid_remember_cookie?
161
- return nil unless @current_user
162
- (@current_user.remember_token?) &&
163
- (cookies[:auth_token] == @current_user.remember_token)
164
- end
165
-
166
- # Refresh the cookie auth token if it exists, create it otherwise
167
- def handle_remember_cookie! new_cookie_flag
168
- return unless @current_user
169
- case
170
- when valid_remember_cookie? then @current_user.refresh_token # keeping same expiry date
171
- when new_cookie_flag then @current_user.remember_me
172
- else @current_user.forget_me
173
- end
174
- send_remember_cookie!
175
- end
176
-
177
- def kill_remember_cookie!
178
- cookies.delete :auth_token
179
- end
180
-
181
- def send_remember_cookie!
182
- cookies[:auth_token] = {
183
- :value => @current_user.remember_token,
184
- :expires => @current_user.remember_token_expires_at }
185
- end
186
-
187
- end
@@ -1,20 +0,0 @@
1
- module AuthenticatedTestHelper
2
- # Sets the current user in the session from the user fixtures.
3
- def login_as(user)
4
- @request.session[:user_id] = user ? users(user).id : nil
5
- end
6
-
7
- def authorize_as(user)
8
- @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials(users(user).login, 'monkey') : nil
9
- end
10
-
11
- # rspec
12
- def mock_user
13
- user = mock_model(User, :id => 1,
14
- :login => 'user_name',
15
- :name => 'U. Surname',
16
- :to_xml => "User-in-XML", :to_json => "User-in-JSON",
17
- :errors => [])
18
- user
19
- end
20
- end
@@ -1,27 +0,0 @@
1
- module TemplateManager
2
- extend self
3
-
4
- def outer_templates
5
- templates.keys
6
- end
7
- def inner_templates(outer)
8
- templates[outer].keys
9
- end
10
- def inner_template(outer, name)
11
- templates[outer][name]
12
- end
13
- private
14
- def templates
15
- Dir.chdir(TEMPLATE_PATH) do
16
- @templates ||= Dir.entries(".").inject({}) do |templates, entry|
17
- yml_path = File.join(entry, "template.yml")
18
- if entry != '.' &&
19
- entry != '..' &&
20
- File.exists?(yml_path)
21
- templates[entry] = YAML.load_file(yml_path)
22
- end
23
- templates
24
- end
25
- end
26
- end
27
- end