Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'settingcards' into develop

  • Loading branch information...
commit 35798d2806e562ca7829951ea521748ee7ecec86 2 parents 2fb6caf + b2f31f8
@ethn ethn authored
View
16 app/assets/stylesheets/settings.css
@@ -6,14 +6,18 @@
.set-select {
margin: 10px;
}
+.setting-rules,
.set-rules {
width: 100%;
}
+.setting-rules th,
.set-rules th {
background: #aaa;
color: #eee;
padding: 5px 0;
}
+.setting-rules th,
+.setting-rules td,
.set-rules th,
.set-rules td.rule-cell {
text-align: left;
@@ -23,6 +27,7 @@
.set-rules td.rule-cell {
border-bottom: 1px solid #eee;
}
+.setting-klass,
.rule-setting {
font-weight: bold;
}
@@ -103,3 +108,14 @@ td.missing-rule {
.show-rule .rule-set {
margin-bottom: 10px;
}
+.klass-row {
+ background: #eee;
+ border-top: 1px solid #ddd;
+}
+tr.rule-changeover td {
+ border-top: 1px solid #eee;
+ padding-top: 5px;
+}
+td.rule-anchor {
+ padding-left: 30px;
+}
View
3  app/helpers/location_helper.rb
@@ -75,7 +75,8 @@ def wagn_url rel #should be in smartname?
def link_to_page( text, title=nil, options={})
title ||= text
- url_options = (options[:type]) ? {:type=>options[:type]} : {}
+ url_options = {}
+ [:type, :view].each { |k| url_options[k] = options.delete(k) if options[k] }
url = wagn_path page_path( title, url_options )
link_to text, url, options
end
View
18 lib/cardlib/pattern.rb
@@ -131,8 +131,8 @@ def register key, opt_keys, opts={}
def method_key_from_opts opts
method_key || ((opt_keys.map do |opt_key|
- opts[opt_key].to_s.gsub('+', '-')
- end << key) * '_')
+ opts[opt_key].to_s.gsub('+', '-')
+ end << key) * '_' )
end
def pattern_applies? card
@@ -170,7 +170,7 @@ def set_const
def get_method_key
if self.class.anchorless?
self.class.method_key
- else
+ elsif self.class.opt_keys.size == opt_vals.size
opts = {}
self.class.opt_keys.each_with_index do |key, index|
return nil unless opt_vals[index]
@@ -182,13 +182,17 @@ def get_method_key
def opt_vals
if @opt_vals.nil?
- @opt_vals = self.class.anchorless? ? [] :
- @anchor_name.parts.map do |part|
- card=Card.fetch(part, :skip_virtual=>true, :skip_modules=>true) and Wagn::Codename[card.id.to_i]
- end
+ @opt_vals = self.class.anchorless? ? [] : find_opt_vals
end
@opt_vals
end
+
+ def find_opt_vals
+ @anchor_name.parts.map do |part|
+ card = Card.fetch part, :skip_virtual=>true, :skip_modules=>true
+ card && Wagn::Codename[card.id.to_i] or return []
+ end
+ end
def key_name
@key_name ||= self.class.key_name
View
71 lib/wagn/set/type/setting.rb
@@ -17,26 +17,73 @@ module Set::Type::Setting
format :base
define_view :core, :type=>'setting' do |args|
- _render_closed_content(args) +
- Cardlib::Pattern.subclasses.reverse.map do |set_class|
+ klasses = Cardlib::Pattern.subclasses.reverse.map do |set_class|
wql = { :left => { :type =>Card::SetID },
:right => card.id,
- :sort => 'name',
+ #:sort => 'content',
+
+ :sort => ['content', 'name'],
:limit => 0
}
wql[:left][ (set_class.anchorless? ? :id : :right_id )] = set_class.key_id
- search_card = Card.new :type =>Card::SearchTypeID, :content=>wql.to_json
- next if search_card.count == 0
+ rules = Card.search wql
+ [ set_class, rules ] unless rules.empty?
+ end.compact
- %{
- <div class="set-class set-class-#{set_class.key}">
- <h2>#{ set_class.key_name }</h2>
- #{ subrenderer(search_card)._render_content }
- </div>
- }
- end.compact * "\n"
+
+
+ %{
+ #{ _render_closed_content args }
+ <table class="setting-rules">
+ <tr><th>Set</th><th>Rule</th></tr>
+ #{
+ klasses.map do |klass, rules|
+ %{
+ <tr class="klass-row anchorless-#{ klass.anchorless? }">
+ <td class="setting-klass">#{ klass.key_name }</td>
+ <td class="rule-content-container">
+ <span class="closed-content content">#{ subrenderer(rules[0])._render_closed_content if klass.anchorless? }</span>
+ </td>
+ </tr>
+ #{
+ unless klass.anchorless?
+ previous_content = nil
+ rules.map do |rule|
+ current_content = rule.content.strip
+ duplicate = previous_content == current_content
+ changeover = previous_content && !duplicate
+ previous_content = current_content
+ %{
+ <tr class="#{ 'rule-changeover' if changeover }">
+ <td class="rule-anchor">#{ link_to_page rule.cardname.trunk_name.trunk_name, rule.cardname.trunk_name }</td>
+
+ #{
+ if duplicate
+ %{ <td></td> }
+ else
+ %{
+ <td class="rule-content-container">
+ <span class="closed-content content">#{ subrenderer(rule)._render_closed_content }</span>
+ </td>
+ }
+ end
+ }
+ </tr>
+ }
+
+ end * "\n"
+ end
+
+ }
+ }
+ end * "\n"
+
+ }
+ <th>
+ </table>
+ }
end
View
25 lib/wql.rb
@@ -186,7 +186,8 @@ def merge(spec)
content = [key,val]
elsif MODIFIERS.has_key?(key)
next if spec[key].is_a? Hash
- @mods[key] = spec.delete(key).to_s
+ val = spec.delete key
+ @mods[key] = Array === val ? val : val.to_s
end
end
spec[:content] = content if content
@@ -401,11 +402,21 @@ def fields_to_sql
end
def sort_to_sql
+ #fail "order_key = #{@mods[:sort]}, class = #{order_key.class}"
+
return nil if @parent or @mods[:return]=='count'
order_key ||= @mods[:sort].blank? ? "update" : @mods[:sort]
- dir = @mods[:dir].blank? ? (DEFAULT_ORDER_DIRS[order_key.to_sym]||'asc') : safe_sql(@mods[:dir])
+
+ order_directives = [order_key].flatten.map do |key|
+ dir = @mods[:dir].blank? ? (DEFAULT_ORDER_DIRS[key.to_sym]||'asc') : safe_sql(@mods[:dir]) #wonky
+ sort_field key, @mods[:sort_as], dir
+ end.join ', '
+ "ORDER BY #{order_directives}"
- order_field = case order_key
+ end
+
+ def sort_field key, as, dir
+ order_field = case key
when "id"; "#{table_alias}.id"
when "update"; "#{table_alias}.updated_at"
when "create"; "#{table_alias}.created_at"
@@ -421,11 +432,11 @@ def sort_to_sql
"#{table_alias}.updated_at"
end
else
- safe_sql(order_key)
+ safe_sql(key)
end
- order_field = "CAST(#{order_field} AS #{cast_type(@mods[:sort_as])})" if @mods[:sort_as]
- "ORDER BY #{order_field} #{dir}"
-
+ order_field = "CAST(#{order_field} AS #{cast_type(as)})" if as
+ "#{order_field} #{dir}"
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.