wagn 1.14.4 → 1.14.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/controllers/card_controller.rb +4 -3
- data/db/bootstrap/card_actions.yml +597 -583
- data/db/bootstrap/card_acts.yml +2 -2
- data/db/bootstrap/card_changes.yml +297 -248
- data/db/bootstrap/card_references.yml +3111 -1284
- data/db/bootstrap/cards.yml +1067 -1022
- data/db/migrate_core_cards/20141208132416_partial_reference_type.rb +7 -0
- data/db/migrate_core_cards/20141208162106_add_ace_script.rb +12 -0
- data/db/migrate_core_cards/20141230204340_uri_codename.rb +13 -0
- data/db/version_core_cards.txt +1 -1
- data/features/history.feature +2 -1
- data/features/layouts.feature +4 -0
- data/features/navbox.feature +1 -0
- data/features/step_definitions/wagn_steps.rb +6 -1
- data/features/support/env.rb +1 -1
- data/lib/card/env.rb +1 -1
- data/lib/card/format.rb +35 -48
- data/lib/card/loader.rb +9 -9
- data/lib/card/mailer.rb +0 -2
- data/lib/card/query.rb +8 -8
- data/lib/card/query/{card_spec.rb → card_clause.rb} +42 -42
- data/lib/card/query/{spec.rb → clause.rb} +3 -3
- data/lib/card/query/ref_clause.rb +47 -0
- data/lib/card/query/value_clause.rb +65 -0
- data/lib/card/reference.rb +11 -20
- data/lib/card/set.rb +6 -6
- data/lib/card/set_pattern.rb +5 -1
- data/lib/wagn/commands.rb +28 -14
- data/lib/wagn/config/environments/test.rb +3 -0
- data/lib/wagn/generators/wagn/templates/Gemfile +6 -0
- data/lib/wagn/generators/wagn/templates/Rakefile +1 -0
- data/lib/wagn/generators/wagn/templates/config/application.rb +1 -0
- data/lib/wagn/generators/wagn/templates/spec/javascripts/support/deck_jasmine.yml +56 -0
- data/lib/wagn/generators/wagn/templates/spec/javascripts/support/wagn_jasmine.yml +69 -0
- data/lib/wagn/generators/wagn/wagn_generator.rb +19 -2
- data/lib/wagn/migration.rb +10 -0
- data/lib/wagn/spec_helper.rb +2 -0
- data/lib/wagn/tasks/wagn.rake +9 -16
- data/mod/01_core/chunk/link.rb +2 -2
- data/mod/01_core/chunk/uri.rb +4 -4
- data/mod/01_core/format/html_format.rb +43 -280
- data/mod/01_core/set/all/active_card.rb +2 -0
- data/mod/01_core/set/all/collection.rb +19 -1
- data/mod/01_core/set/all/fetch.rb +5 -0
- data/mod/01_core/set/all/initialize.rb +1 -1
- data/mod/01_core/set/all/references.rb +25 -8
- data/mod/01_core/set/all/templating.rb +1 -1
- data/mod/01_core/set/all/tracked_attributes.rb +1 -1
- data/mod/01_core/set/all/type.rb +1 -1
- data/mod/01_core/set/all/utils.rb +1 -0
- data/mod/01_core/set_pattern/07_type_plus_right.rb +2 -1
- data/mod/01_core/spec/format/html_format_spec.rb +0 -2
- data/mod/01_core/spec/set/all/initialize_spec.rb +4 -4
- data/mod/01_core/spec/set/all/notify_spec.rb +9 -9
- data/mod/02_basic_types/set/type/pointer.rb +19 -8
- data/mod/03_machines/lib/javascript/ace.js +18204 -0
- data/mod/03_machines/lib/javascript/jquery-ui.js +13109 -11440
- data/mod/03_machines/lib/javascript/jquery.autosize.js +52 -33
- data/mod/03_machines/lib/javascript/jquery.fileupload.js +10 -8
- data/mod/03_machines/lib/javascript/jquery.iframe-transport.js +44 -16
- data/mod/03_machines/lib/javascript/jquery.js +4 -9473
- data/mod/03_machines/lib/javascript/jquery_ujs.js +156 -116
- data/mod/03_machines/lib/javascript/jquerymobile.js +14890 -8236
- data/mod/03_machines/lib/javascript/theme-textmate.js +130 -0
- data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +50 -10
- data/mod/03_machines/set/self/script_ace.rb +8 -0
- data/mod/03_machines/set/type/coffee_script.rb +1 -1
- data/mod/03_machines/set/type/css.rb +0 -2
- data/mod/03_machines/set/type/java_script.rb +1 -1
- data/mod/03_machines/spec/lib/{machine_spec.rb → shared_machine_examples.rb} +0 -0
- data/mod/03_machines/spec/lib/{machine_input_spec.rb → shared_machine_input_examples.rb} +0 -0
- data/mod/03_machines/spec/set/type/scss_spec.rb +2 -2
- data/mod/04_settings/set/right/comment.rb +2 -2
- data/mod/04_settings/set/type/setting.rb +2 -2
- data/mod/04_settings/spec/set/right/structure_spec.rb +2 -2
- data/mod/04_settings/spec/set/right/style_spec.rb +1 -1
- data/mod/05_email/set/type/email_template.rb +3 -2
- data/mod/05_standard/set/all/all_css.rb +1 -1
- data/mod/05_standard/set/all/all_js.rb +1 -1
- data/mod/05_standard/set/all/attach.rb +8 -7
- data/mod/05_standard/set/all/base.rb +6 -34
- data/mod/05_standard/set/all/editing.rb +145 -0
- data/mod/05_standard/set/all/error.rb +203 -0
- data/mod/05_standard/set/all/follow.rb +2 -2
- data/mod/05_standard/set/all/form.rb +211 -0
- data/mod/05_standard/set/all/header.rb +60 -0
- data/mod/05_standard/set/all/history.rb +3 -3
- data/mod/05_standard/set/all/links.rb +101 -0
- data/mod/05_standard/set/all/rich_html.rb +14 -392
- data/mod/05_standard/set/all/wrapper.rb +74 -0
- data/mod/05_standard/set/right/account.rb +1 -2
- data/mod/05_standard/set/rstar/rules.rb +5 -5
- data/mod/05_standard/set/self/account_links.rb +8 -4
- data/mod/05_standard/set/self/head.rb +3 -3
- data/mod/05_standard/set/self/signin.rb +5 -3
- data/mod/05_standard/set/type/search_type.rb +25 -25
- data/mod/05_standard/set/type/set.rb +2 -2
- data/mod/05_standard/set/type/signup.rb +0 -2
- data/mod/05_standard/set/type/uri.rb +11 -0
- data/mod/05_standard/spec/set/all/rich_html_spec.rb +6 -6
- data/mod/05_standard/spec/set/all/rss_spec.rb +1 -1
- data/mod/05_standard/spec/set/type/signup_spec.rb +0 -1
- data/mod/05_standard/spec/set/type/uri_spec.rb +41 -0
- data/public/assets/ace/mode-coffee.js +1 -0
- data/public/assets/ace/mode-css.js +1 -0
- data/public/assets/ace/mode-html.js +1 -0
- data/public/assets/ace/mode-javascript.js +1 -0
- data/public/assets/ace/mode-json.js +1 -0
- data/public/assets/ace/mode-scss.js +922 -0
- data/public/assets/ace/theme-github.js +98 -0
- data/public/assets/ace/theme-textmate.js +1 -0
- data/public/assets/ace/worker-coffee.js +1 -0
- data/public/assets/ace/worker-css.js +1 -0
- data/public/assets/ace/worker-html.js +1 -0
- data/public/assets/ace/worker-javascript.js +1 -0
- data/public/assets/ace/worker-json.js +1 -0
- data/spec/controllers/card_controller_spec.rb +0 -1
- data/spec/controllers/location_spec.rb +0 -2
- data/spec/javascripts/helpers/jasmine-jquery.js +812 -0
- data/spec/javascripts/support/jasmine.yml +8 -6
- data/spec/javascripts/support/jasmine_config.rb +1 -1
- data/spec/javascripts/support/jasmine_runner.rb +1 -1
- data/spec/javascripts/wagn_spec.coffee +2 -0
- data/spec/lib/card/content_spec.rb +28 -6
- data/spec/lib/card/format_spec.rb +62 -15
- data/spec/lib/card/reference_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -2
- data/test/fixtures/card_actions.yml +1260 -1239
- data/test/fixtures/card_acts.yml +347 -341
- data/test/fixtures/card_changes.yml +2345 -2276
- data/test/fixtures/card_references.yml +4098 -1606
- data/test/fixtures/cards.yml +1950 -1887
- metadata +39 -13
- data/lib/card/query/ref_spec.rb +0 -37
- data/lib/card/query/value_spec.rb +0 -65
- data/lib/wagn/location.rb +0 -93
- data/spec/javascripts/helpers/jasmine-config.js +0 -2
- data/spec/javascripts/helpers/jasmine-jquery-1.3.1.js +0 -295
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
class AddAceScript < Wagn::CoreMigration
|
4
|
+
def up
|
5
|
+
all_script = Card[:all].fetch :trait=>:script
|
6
|
+
all_script.add_item "script: ace"
|
7
|
+
all_script.save!
|
8
|
+
|
9
|
+
Card.create! :name=>"script: ace",:codename=>"script_ace",:type=>"JavaScript"
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
class UriCodename < Wagn::Migration
|
4
|
+
def up
|
5
|
+
contentedly do
|
6
|
+
cardname = 'URI'
|
7
|
+
codename = cardname.to_name.key
|
8
|
+
okname = Wagn::Migration.find_unused_name(cardname)
|
9
|
+
Card.create! :type_id=>Card::CardtypeID, :name=>okname, :codename=>codename
|
10
|
+
puts "Name #{cardname} was taken, used #{okname}" if okname != cardname
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/db/version_core_cards.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
20141230204340
|
data/features/history.feature
CHANGED
@@ -8,7 +8,8 @@ Feature: History
|
|
8
8
|
Then the card First should not contain "chicken"
|
9
9
|
|
10
10
|
Scenario: view history and rollback
|
11
|
-
When I go to url "/First?view=history"
|
11
|
+
When I go to url "/First?view=history"
|
12
|
+
Then show me the page
|
12
13
|
Then In the main card content I should see a del with content "egg"
|
13
14
|
|
14
15
|
When I expand act 2
|
data/features/layouts.feature
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
@javascript
|
1
2
|
Feature: Layouts
|
2
3
|
In order to have greater control over the look and feel of my website
|
3
4
|
As a User
|
@@ -6,9 +7,12 @@ Feature: Layouts
|
|
6
7
|
Background:
|
7
8
|
Given I am signed in as Joe Admin
|
8
9
|
And I create HTML card "simple layout" with content "Simple Header {{_main}} Simple Footer"
|
10
|
+
And I wait a sec
|
9
11
|
And the card "*all+*layout" contains "[[simple layout]]"
|
10
12
|
And I create Pointer card "User+*type+*layout" with content "[[user layout]]"
|
13
|
+
And I wait a sec
|
11
14
|
And I create HTML card "user layout" with content "User Header {{_main}}"
|
15
|
+
And I wait a sec
|
12
16
|
|
13
17
|
Scenario: I visit a Basic card with the simple layout
|
14
18
|
When I go to card "*account links"
|
data/features/navbox.feature
CHANGED
@@ -94,7 +94,12 @@ end
|
|
94
94
|
|
95
95
|
When /^(.*) creates?\s*a?\s*([^\s]*) card "(.*)" with content "(.*)"$/ do |username, cardtype, cardname, content|
|
96
96
|
create_card(username, cardtype, cardname, content) do
|
97
|
-
|
97
|
+
normal_textarea_card_type = ["JavaScript","CoffeeScript","HTML","CSS","SCS","Search"]
|
98
|
+
if not normal_textarea_card_type.include? cardtype or not page.evaluate_script "typeof ace != 'undefined'"
|
99
|
+
fill_in("card[content]", :with=>content)
|
100
|
+
else
|
101
|
+
page.execute_script %{ace.edit($('.ace_editor').get(0)).getSession().setValue('#{content}')}
|
102
|
+
end
|
98
103
|
end
|
99
104
|
end
|
100
105
|
|
data/features/support/env.rb
CHANGED
@@ -3,7 +3,7 @@ ENV['RAILS_ENV'] = "cucumber"
|
|
3
3
|
|
4
4
|
require File.expand_path( '../../../lib/wagn/simplecov_helper.rb', __FILE__ )
|
5
5
|
require 'simplecov'
|
6
|
-
|
6
|
+
require 'minitest/autorun'
|
7
7
|
|
8
8
|
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
9
9
|
# It is recommended to regenerate this file in the future when you upgrade to a
|
data/lib/card/env.rb
CHANGED
data/lib/card/format.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
class Card
|
4
4
|
class Format
|
5
|
-
include Wagn::Location
|
6
5
|
|
7
6
|
DEPRECATED_VIEWS = { :view=>:open, :card=>:open, :line=>:closed, :bare=>:core, :naked=>:core }
|
8
7
|
INCLUSION_MODES = { :closed=>:closed, :closed_content=>:closed, :edit=>:edit,
|
@@ -468,68 +467,56 @@ class Card
|
|
468
467
|
:name
|
469
468
|
end
|
470
469
|
|
471
|
-
|
472
|
-
pcard = opts.delete(:card) || card
|
473
|
-
base = opts[:action] ? "card/#{ opts.delete :action }/" : ''
|
474
|
-
if pcard && !pcard.name.empty? && !opts.delete(:no_id) && ![:new, :create].member?(opts[:action]) #generalize. dislike hardcoding views/actions here
|
475
|
-
base += ( opts[:id] ? "~#{ opts.delete :id }" : pcard.cardname.url_key )
|
476
|
-
end
|
477
|
-
query = opts.empty? ? '' : "?#{opts.to_param}"
|
478
|
-
wagn_path( base + query )
|
479
|
-
end
|
470
|
+
|
480
471
|
#
|
481
472
|
# ------------ LINKS ---------------
|
482
473
|
#
|
483
474
|
|
484
|
-
def final_link href, opts
|
485
|
-
if text = opts[:text]
|
486
|
-
"#{text}[#{href}]"
|
487
|
-
else
|
488
|
-
href
|
489
|
-
end
|
490
|
-
end
|
491
475
|
|
492
|
-
|
493
|
-
opts = {:text => text }
|
476
|
+
|
494
477
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
478
|
+
|
479
|
+
def add_class options, klass
|
480
|
+
options[:class] = [ options[:class], klass ].flatten.compact * ' '
|
481
|
+
end
|
482
|
+
|
483
|
+
module Location
|
484
|
+
#
|
485
|
+
# page_path takes a Card::Name, adds the format and query string to url_key (site-absolute)
|
486
|
+
# wagn_path makes a relative path site-absolute (if not already)
|
487
|
+
# wagn_url makes it a full url (if not already)
|
488
|
+
|
489
|
+
# TESTME
|
490
|
+
def page_path title, opts={}
|
491
|
+
Rails.logger.warn "Pass only Card::Name to page_path #{title.class}, #{title}" unless Card::Name===title
|
492
|
+
format = opts[:format] ? ".#{opts.delete(:format)}" : ''
|
493
|
+
query = opts.present? ? "?#{opts.to_param}" : ''
|
494
|
+
wagn_path "#{title.to_name.url_key}#{format}#{query}"
|
495
|
+
end
|
496
|
+
|
497
|
+
def wagn_path rel_path
|
498
|
+
Rails.logger.warn "Pass only strings to wagn_path: #{rel_path.class}, #{rel_path}" unless String===rel_path
|
499
|
+
if rel_path =~ /^\//
|
500
|
+
rel_path
|
501
501
|
else
|
502
|
-
|
503
|
-
Rails.logger.debug "build_link mistakenly(?) called on #{href}, #{text}"
|
502
|
+
"#{ Wagn.config.relative_url_root }/#{ rel_path }"
|
504
503
|
end
|
505
|
-
|
506
|
-
final_link href, opts
|
507
|
-
end
|
504
|
+
end
|
508
505
|
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
}
|
516
|
-
if !known
|
517
|
-
link_params = {}
|
518
|
-
link_params['name'] = name.to_s if name.to_s != linkname
|
519
|
-
link_params['type'] = type if type
|
520
|
-
linkname += "?#{ { :card => link_params }.to_param }" if !link_params.empty?
|
506
|
+
def wagn_url rel
|
507
|
+
if rel =~ /^https?\:/
|
508
|
+
rel
|
509
|
+
else
|
510
|
+
"#{ Card::Env[:protocol] }#{ Card::Env[:host] }#{ wagn_path rel }"
|
511
|
+
end
|
521
512
|
end
|
522
|
-
final_link internal_url( linkname ), opts
|
523
513
|
end
|
524
|
-
|
514
|
+
include Location
|
515
|
+
|
525
516
|
def unique_id
|
526
517
|
"#{card.key}-#{Time.now.to_i}-#{rand(3)}"
|
527
518
|
end
|
528
519
|
|
529
|
-
def internal_url relative_path
|
530
|
-
wagn_path relative_path
|
531
|
-
end
|
532
|
-
|
533
520
|
def format_date date, include_time = true
|
534
521
|
# Must use DateTime because Time doesn't support %e on at least some platforms
|
535
522
|
if include_time
|
data/lib/card/loader.rb
CHANGED
@@ -90,7 +90,7 @@ class Card
|
|
90
90
|
load_implicit_sets_from_source set_pattern
|
91
91
|
end
|
92
92
|
if Dir.exists? pattern_tmp_dir
|
93
|
-
load_dir "#{pattern_tmp_dir}
|
93
|
+
load_dir "#{pattern_tmp_dir}/**/*.rb"
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
@@ -100,16 +100,16 @@ class Card
|
|
100
100
|
mod_dirs.each do |mod_dir|
|
101
101
|
dirname = [mod_dir, 'set', set_pattern] * '/'
|
102
102
|
next unless File.exists?( dirname )
|
103
|
-
|
104
|
-
|
105
|
-
Dir.
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
Set.write_tmp_file set_pattern, anchor, filename, seq
|
103
|
+
|
104
|
+
old_pwd = Dir.pwd
|
105
|
+
Dir.chdir dirname
|
106
|
+
Dir.glob( "**/*.rb" ).sort.each do |anchor_path|
|
107
|
+
path_parts = anchor_path.gsub(/\.rb/,'').split(File::SEPARATOR)
|
108
|
+
filename = File.join dirname, anchor_path
|
109
|
+
Set.write_tmp_file set_pattern, path_parts, filename, seq
|
111
110
|
seq = seq + 1
|
112
111
|
end
|
112
|
+
Dir.chdir old_pwd
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
data/lib/card/mailer.rb
CHANGED
data/lib/card/query.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
class Card::Query
|
5
|
-
require_dependency 'card/query/
|
6
|
-
require_dependency 'card/query/
|
7
|
-
require_dependency 'card/query/
|
8
|
-
require_dependency 'card/query/
|
5
|
+
require_dependency 'card/query/clause'
|
6
|
+
require_dependency 'card/query/card_clause'
|
7
|
+
require_dependency 'card/query/value_clause'
|
8
|
+
require_dependency 'card/query/ref_clause'
|
9
9
|
|
10
10
|
MODIFIERS = {}; %w{ conj return sort sort_as group dir limit offset }.each{|key| MODIFIERS[key.to_sym] = nil }
|
11
11
|
|
@@ -15,19 +15,19 @@ class Card::Query
|
|
15
15
|
}.stringify_keys)
|
16
16
|
|
17
17
|
def initialize query
|
18
|
-
@
|
18
|
+
@card_clause = CardClause.build query
|
19
19
|
end
|
20
20
|
|
21
21
|
def query
|
22
|
-
@
|
22
|
+
@card_clause.query
|
23
23
|
end
|
24
24
|
|
25
25
|
def sql
|
26
|
-
@sql ||= @
|
26
|
+
@sql ||= @card_clause.to_sql
|
27
27
|
end
|
28
28
|
|
29
29
|
def run
|
30
|
-
# puts "~~~~~~~~~~~~~~\nCARD SPEC =\n#{@
|
30
|
+
# puts "~~~~~~~~~~~~~~\nCARD SPEC =\n#{@card_clause.rawclause}\n\n-----\n\nSQL=\n#{sql}"
|
31
31
|
rows = ActiveRecord::Base.connection.select_all( sql )
|
32
32
|
retrn = query[:return].present? ? query[:return].to_s : 'card'
|
33
33
|
case retrn
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
class Card
|
3
3
|
class Query
|
4
|
-
class
|
4
|
+
class CardClause < Clause
|
5
5
|
|
6
6
|
ATTRIBUTES = {
|
7
7
|
:basic => %w{ name type_id content id key updater_id left_id right_id creator_id updater_id codename },
|
@@ -16,19 +16,19 @@ class Card
|
|
16
16
|
DEFAULT_ORDER_DIRS = { :update => "desc", :relevance => "desc" }
|
17
17
|
CONJUNCTIONS = { :any=>:or, :in=>:or, :or=>:or, :all=>:and, :and=>:and }
|
18
18
|
|
19
|
-
attr_reader :sql, :query, :
|
19
|
+
attr_reader :sql, :query, :rawclause, :selfname
|
20
20
|
attr_accessor :joins, :join_count
|
21
21
|
|
22
22
|
class << self
|
23
23
|
def build query
|
24
|
-
|
25
|
-
|
24
|
+
cardclause = self.new query
|
25
|
+
cardclause.merge cardclause.rawclause
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def initialize query
|
30
30
|
@mods = MODIFIERS.clone
|
31
|
-
@
|
31
|
+
@clause, @joins = {}, {}
|
32
32
|
@selfname, @parent = '', nil
|
33
33
|
@sql = SqlStatement.new
|
34
34
|
|
@@ -37,7 +37,7 @@ class Card
|
|
37
37
|
@vars = @query.delete(:vars) || {}
|
38
38
|
@vars.symbolize_keys!
|
39
39
|
@query = clean(@query)
|
40
|
-
@
|
40
|
+
@rawclause = @query.deep_clone
|
41
41
|
|
42
42
|
self
|
43
43
|
end
|
@@ -91,7 +91,7 @@ class Card
|
|
91
91
|
s = hashify s
|
92
92
|
translate_to_attributes s
|
93
93
|
ready_to_sqlize s
|
94
|
-
@
|
94
|
+
@clause.merge! s
|
95
95
|
self
|
96
96
|
end
|
97
97
|
|
@@ -100,41 +100,41 @@ class Card
|
|
100
100
|
when String; { :key => s.to_name.key }
|
101
101
|
when Integer; { :id => s }
|
102
102
|
when Hash; s
|
103
|
-
else; raise BadQuery, "Invalid
|
103
|
+
else; raise BadQuery, "Invalid cardclause args #{s.inspect}"
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
def translate_to_attributes
|
107
|
+
def translate_to_attributes clause
|
108
108
|
content = nil
|
109
|
-
|
109
|
+
clause.each do |key,val|
|
110
110
|
if key == :_parent
|
111
|
-
@parent =
|
111
|
+
@parent = clause.delete(key)
|
112
112
|
elsif OPERATORS.has_key?(key.to_s) && !ATTRIBUTES[key]
|
113
|
-
|
113
|
+
clause.delete(key)
|
114
114
|
content = [key,val]
|
115
115
|
elsif MODIFIERS.has_key?(key)
|
116
|
-
next if
|
117
|
-
val =
|
116
|
+
next if clause[key].is_a? Hash
|
117
|
+
val = clause.delete key
|
118
118
|
@mods[key] = Array === val ? val : val.to_s
|
119
119
|
end
|
120
120
|
end
|
121
|
-
|
121
|
+
clause[:content] = content if content
|
122
122
|
end
|
123
123
|
|
124
124
|
|
125
|
-
def ready_to_sqlize
|
126
|
-
|
125
|
+
def ready_to_sqlize clause
|
126
|
+
clause.each do |key,val|
|
127
127
|
keyroot = field_root(key).to_sym
|
128
128
|
if keyroot==:cond # internal SQL cond (already ready)
|
129
129
|
elsif ATTRIBUTES[keyroot] == :basic # sqlize knows how to handle these keys; just process value
|
130
|
-
|
130
|
+
clause[key] = ValueClause.new(val, self)
|
131
131
|
else # keys need additional processing
|
132
|
-
val =
|
132
|
+
val = clause.delete key
|
133
133
|
is_array = Array===val
|
134
134
|
case ATTRIBUTES[keyroot]
|
135
135
|
when :ignore #noop
|
136
136
|
when :relational, :special, :conjunction ; relate is_array, keyroot, val, :send
|
137
|
-
when :ref_relational ; relate is_array, keyroot, val, :
|
137
|
+
when :ref_relational ; relate is_array, keyroot, val, :refclause
|
138
138
|
when :plus_relational
|
139
139
|
# Arrays can have multiple interpretations for these, so we have to look closer...
|
140
140
|
subcond = is_array && ( Array===val.first || conjunction(val.first) )
|
@@ -160,8 +160,8 @@ class Card
|
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
-
def
|
164
|
-
add_join :ref,
|
163
|
+
def refclause key, val
|
164
|
+
add_join :ref, RefClause.new( key, val, self ).to_sql, :id, :ref_id
|
165
165
|
end
|
166
166
|
|
167
167
|
|
@@ -198,11 +198,11 @@ class Card
|
|
198
198
|
end
|
199
199
|
|
200
200
|
def editor_of val
|
201
|
-
|
201
|
+
action_clause :actor_id, "card_actions.card_id", val
|
202
202
|
end
|
203
203
|
|
204
204
|
def edited_by val
|
205
|
-
|
205
|
+
action_clause "card_actions.card_id", :actor_id, val
|
206
206
|
end
|
207
207
|
|
208
208
|
def last_editor_of val
|
@@ -245,8 +245,8 @@ class Card
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def junction side, val
|
248
|
-
|
249
|
-
restrict_by_join :id,
|
248
|
+
part_clause, junction_clause = val.is_a?(Array) ? val : [ val, {} ]
|
249
|
+
restrict_by_join :id, junction_clause, side=>part_clause, :return=>"#{ side==:left ? :right : :left}_id"
|
250
250
|
end
|
251
251
|
|
252
252
|
|
@@ -279,12 +279,12 @@ class Card
|
|
279
279
|
unless c && [SearchTypeID,SetID].include?(c.type_id)
|
280
280
|
raise BadQuery, %{"found_by" value needs to be valid Search, but #{c.name} is a #{c.type_name}}
|
281
281
|
end
|
282
|
-
restrict_by_join :id,
|
282
|
+
restrict_by_join :id, CardClause.new(c.get_query).rawclause
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
286
286
|
def not val
|
287
|
-
subselect =
|
287
|
+
subselect = CardClause.build(:return=>:id, :_parent=>self).merge(val).to_sql
|
288
288
|
join_alias = add_join :not, subselect, :id, :id, :side=>'LEFT'
|
289
289
|
merge field(:cond) => SqlCond.new("#{join_alias}.id is null")
|
290
290
|
end
|
@@ -300,7 +300,7 @@ class Card
|
|
300
300
|
case item
|
301
301
|
when 'referred_to'
|
302
302
|
join_field = 'id'
|
303
|
-
cs =
|
303
|
+
cs = CardClause.build cs_args.merge( field(:cond)=>SqlCond.new("referer_id in #{CardClause.build( val.merge(:return=>'id')).to_sql}") )
|
304
304
|
cs.add_join :wr, :card_references, :id, :referee_id
|
305
305
|
else
|
306
306
|
raise BadQuery, "count with item: #{item} not yet implemented"
|
@@ -311,7 +311,7 @@ class Card
|
|
311
311
|
when 'right' ; 'right_id'
|
312
312
|
else ; raise BadQuery, "sort item: #{item} not yet implemented"
|
313
313
|
end
|
314
|
-
cs =
|
314
|
+
cs = CardClause.build(val)
|
315
315
|
end
|
316
316
|
|
317
317
|
cs.sql.fields << "#{cs.table_alias}.#{join_field} as sort_join_field"
|
@@ -395,27 +395,27 @@ class Card
|
|
395
395
|
|
396
396
|
def subcondition(val, args={})
|
397
397
|
args = { :return=>:condition, :_parent=>self }.merge(args)
|
398
|
-
|
399
|
-
merge field(:cond) =>
|
400
|
-
self.joins.merge!
|
398
|
+
cardclause = CardClause.build( args )
|
399
|
+
merge field(:cond) => cardclause.merge(val)
|
400
|
+
self.joins.merge! cardclause.joins
|
401
401
|
end
|
402
402
|
|
403
|
-
def
|
404
|
-
card_select =
|
403
|
+
def action_clause(field, linkfield, val)
|
404
|
+
card_select = CardClause.build(:_parent=>self, :return=>'id').merge(val).to_sql
|
405
405
|
sql = "(SELECT DISTINCT #{field} AS join_card_id FROM card_acts INNER JOIN card_actions ON card_acts.id = card_act_id "
|
406
406
|
sql += " JOIN (#{card_select}) AS ss ON #{linkfield}=ss.id AND (draft is not true))"
|
407
407
|
add_join :ac, sql, :id, :join_card_id
|
408
408
|
end
|
409
409
|
|
410
|
-
def
|
411
|
-
case
|
412
|
-
when Integer ;
|
413
|
-
when String ; Card.fetch_id(
|
410
|
+
def id_from_clause clause
|
411
|
+
case clause
|
412
|
+
when Integer ; clause
|
413
|
+
when String ; Card.fetch_id(clause)
|
414
414
|
end
|
415
415
|
end
|
416
416
|
|
417
417
|
def restrict id_field, val, opts={}
|
418
|
-
if id =
|
418
|
+
if id = id_from_clause(val)
|
419
419
|
merge field(id_field) => id
|
420
420
|
else
|
421
421
|
restrict_by_join id_field, val, opts
|
@@ -424,7 +424,7 @@ class Card
|
|
424
424
|
|
425
425
|
def restrict_by_join id_field, val, opts={}
|
426
426
|
opts.reverse_merge!(:return=>:id, :_parent=>self)
|
427
|
-
subselect =
|
427
|
+
subselect = CardClause.build(opts).merge(val).to_sql
|
428
428
|
add_join "card_#{id_field}", subselect, id_field, opts[:return]
|
429
429
|
end
|
430
430
|
|
@@ -464,7 +464,7 @@ class Card
|
|
464
464
|
end
|
465
465
|
|
466
466
|
def basic_conditions
|
467
|
-
@
|
467
|
+
@clause.map { |key, val| val.to_sql field_root(key) }.compact.join " #{ current_conjunction } "
|
468
468
|
end
|
469
469
|
|
470
470
|
def current_conjunction
|