From b940c8b01a379519dcfc2ac88c7beca86aa79854 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Thu, 31 Jan 2013 20:35:18 +0100 Subject: Hide unfinished reports. Reports without sources are now "hidden", ie. they are not visible in the list of reports. But if you know the URL you can access them. This allows them to be tested before they are publicly released. Similarly APIs being tested can now use the API version 0, which will make them invisible in the API documentation. --- web/lib/api/test/langtag.rb | 135 ++++++++++++++++++++++++++++++++++++++++++++ web/lib/api/v4/langtag.rb | 135 -------------------------------------------- web/lib/reports.rb | 17 +++++- 3 files changed, 149 insertions(+), 138 deletions(-) create mode 100644 web/lib/api/test/langtag.rb delete mode 100644 web/lib/api/v4/langtag.rb (limited to 'web/lib') diff --git a/web/lib/api/test/langtag.rb b/web/lib/api/test/langtag.rb new file mode 100644 index 0000000..6cc42e5 --- /dev/null +++ b/web/lib/api/test/langtag.rb @@ -0,0 +1,135 @@ +# web/lib/api/v4/langtag.rb +class Taginfo < Sinatra::Base + + api(0, 'keys/name', { + :description => 'Get list of keys from the database that contain the string "name".', + :parameters => { :query => 'Only show keys matching this query (substring match, optional).' }, + :paging => :optional, + :sort => %w( key count_all ), + :result => { + :key => :STRING, + :count_all => :INT, + :in_wiki => :BOOL, + :prefix => :STRING, + :type => :STRING, + :langtag => :STRING, + :langtag_state => :STRING, + :lang => :STRING, + :lang_state => :STRING, + :lang_name => :STRING, + :script => :STRING, + :script_state => :STRING, + :region => :STRING, + :region_state => :STRING, + :notes => :STRING + }, + :example => { :page => 1, :rp => 10, :sortname => 'key', :sortorder => 'asc' }, + :ui => '/reports/name_tags' + }) do + + total = @db.count('db.keys'). + condition("key LIKE '%name%'"). + condition_if("key LIKE '%' || ? || '%'", params[:query]). + get_first_value().to_i + + res = @db.select('SELECT * FROM db.keys'). + condition("key LIKE '%name%'"). + condition_if("key LIKE '%' || ? || '%'", params[:query]). + order_by(@ap.sortname, @ap.sortorder) { |o| + o.key + o.count_all + }. + paging(@ap). + execute() + + return { + :page => @ap.page, + :rp => @ap.results_per_page, + :total => total, + :data => res.map{ |row| + nt = BCP47::Nametag.new(@db, row['key']) + { + :key => row['key'], + :count_all => row['count_all'].to_i, + :in_wiki => row['in_wiki'].to_i == 1 ? true : false, + :prefix => nt.prefix, + :type => nt.type, + :langtag => nt.langtag, + :langtag_state => nt.langtag_state, + :lang => nt.lang, + :lang_state => nt.lang_state, + :lang_note => nt.lang_note, + :script => nt.script, + :script_state => nt.script_state, + :script_note => nt.script_note, + :region => nt.region, + :region_state => nt.region_state, + :region_note => nt.region_note, + :notes => nt.notes + }} + }.to_json + end + + @@bcp47_filters = {}; + BCP47::SUBTAG_TYPES.each do |type| + @@bcp47_filters[type.to_sym] = { :expr => type, :doc => "Show entries of type '#{type}' only." }; + end + + api(0, 'langtags', { + :description => 'Get official subtags from the IETF BCP47 registry.', + :parameters => { :query => 'Only show entries matching this query (case insensitive substring match on subtags and description; optional).' }, + :paging => :optional, + :filter => @@bcp47_filters, + :sort => %w( subtag description added ), + :result => { + :type => :STRING, + :subtag => :STRING, + :description => :STRING, + :added => :STRING, + :notes => :STRING + }, + :example => { :page => 1, :rp => 10, :sortname => :subtag, :sortorder => 'asc' }, + :ui => '/reports/name_tags#bcp47' + }) do + + @filter_type = BCP47.get_filter(params[:filter]) + + total = @db.count('languages.subtags'). + condition_if("stype = ?", @filter_type). + get_first_value().to_i + + res = @db.select('SELECT * FROM languages.subtags'). + condition_if("stype = ?", @filter_type). + condition_if("subtag LIKE '%' || ? || '%' OR description LIKE '%' || ? || '%'", params[:query], params[:query]). + order_by(@ap.sortname, @ap.sortorder) { |o| + o.subtag + o.description + o.added + }. + paging(@ap). + execute() + + return { + :page => @ap.page, + :rp => @ap.results_per_page, + :total => total, + :data => res.map{ |row| + notes = '' + if row['suppress_script'] + notes += "Default script: #{ row['suppress_script'] }" + end + unless row['prefix'].empty? + notes += "Prefixes: #{ row['prefix'] }" + end + { + :type => row['stype'].titlecase, + :subtag => row['subtag'], + :description => row['description'], + :added => row['added'], + :notes => notes + }} + }.to_json + end + +end + diff --git a/web/lib/api/v4/langtag.rb b/web/lib/api/v4/langtag.rb deleted file mode 100644 index a9eadf9..0000000 --- a/web/lib/api/v4/langtag.rb +++ /dev/null @@ -1,135 +0,0 @@ -# web/lib/api/v4/langtag.rb -class Taginfo < Sinatra::Base - - api(4, 'keys/name', { - :description => 'Get list of keys from the database that contain the string "name".', - :parameters => { :query => 'Only show keys matching this query (substring match, optional).' }, - :paging => :optional, - :sort => %w( key count_all ), - :result => { - :key => :STRING, - :count_all => :INT, - :in_wiki => :BOOL, - :prefix => :STRING, - :type => :STRING, - :langtag => :STRING, - :langtag_state => :STRING, - :lang => :STRING, - :lang_state => :STRING, - :lang_name => :STRING, - :script => :STRING, - :script_state => :STRING, - :region => :STRING, - :region_state => :STRING, - :notes => :STRING - }, - :example => { :page => 1, :rp => 10, :sortname => 'key', :sortorder => 'asc' }, - :ui => '/reports/name_tags' - }) do - - total = @db.count('db.keys'). - condition("key LIKE '%name%'"). - condition_if("key LIKE '%' || ? || '%'", params[:query]). - get_first_value().to_i - - res = @db.select('SELECT * FROM db.keys'). - condition("key LIKE '%name%'"). - condition_if("key LIKE '%' || ? || '%'", params[:query]). - order_by(@ap.sortname, @ap.sortorder) { |o| - o.key - o.count_all - }. - paging(@ap). - execute() - - return { - :page => @ap.page, - :rp => @ap.results_per_page, - :total => total, - :data => res.map{ |row| - nt = BCP47::Nametag.new(@db, row['key']) - { - :key => row['key'], - :count_all => row['count_all'].to_i, - :in_wiki => row['in_wiki'].to_i == 1 ? true : false, - :prefix => nt.prefix, - :type => nt.type, - :langtag => nt.langtag, - :langtag_state => nt.langtag_state, - :lang => nt.lang, - :lang_state => nt.lang_state, - :lang_note => nt.lang_note, - :script => nt.script, - :script_state => nt.script_state, - :script_note => nt.script_note, - :region => nt.region, - :region_state => nt.region_state, - :region_note => nt.region_note, - :notes => nt.notes - }} - }.to_json - end - - @@bcp47_filters = {}; - BCP47::SUBTAG_TYPES.each do |type| - @@bcp47_filters[type.to_sym] = { :expr => type, :doc => "Show entries of type '#{type}' only." }; - end - - api(4, 'langtags', { - :description => 'Get official subtags from the IETF BCP47 registry.', - :parameters => { :query => 'Only show entries matching this query (case insensitive substring match on subtags and description; optional).' }, - :paging => :optional, - :filter => @@bcp47_filters, - :sort => %w( subtag description added ), - :result => { - :type => :STRING, - :subtag => :STRING, - :description => :STRING, - :added => :STRING, - :notes => :STRING - }, - :example => { :page => 1, :rp => 10, :sortname => :subtag, :sortorder => 'asc' }, - :ui => '/reports/name_tags#bcp47' - }) do - - @filter_type = BCP47.get_filter(params[:filter]) - - total = @db.count('languages.subtags'). - condition_if("stype = ?", @filter_type). - get_first_value().to_i - - res = @db.select('SELECT * FROM languages.subtags'). - condition_if("stype = ?", @filter_type). - condition_if("subtag LIKE '%' || ? || '%' OR description LIKE '%' || ? || '%'", params[:query], params[:query]). - order_by(@ap.sortname, @ap.sortorder) { |o| - o.subtag - o.description - o.added - }. - paging(@ap). - execute() - - return { - :page => @ap.page, - :rp => @ap.results_per_page, - :total => total, - :data => res.map{ |row| - notes = '' - if row['suppress_script'] - notes += "Default script: #{ row['suppress_script'] }" - end - unless row['prefix'].empty? - notes += "Prefixes: #{ row['prefix'] }" - end - { - :type => row['stype'].titlecase, - :subtag => row['subtag'], - :description => row['description'], - :added => row['added'], - :notes => notes - }} - }.to_json - end - -end - diff --git a/web/lib/reports.rb b/web/lib/reports.rb index 4b1e3d6..398e7da 100644 --- a/web/lib/reports.rb +++ b/web/lib/reports.rb @@ -11,8 +11,14 @@ class Report end end - def self.each_with_index - @@reports.sort_by{ |report| report.title }.each_with_index do |report, idx| + def self.each_visible + @@reports.select{ |report| report.visible? }.sort_by{ |report| report.title }.each do |report| + yield report + end + end + + def self.each_visible_with_index + @@reports.select{ |report| report.visible? }.sort_by{ |report| report.title }.each_with_index do |report, idx| yield report, idx end end @@ -21,6 +27,7 @@ class Report @@reports << self @title = title @sources = Hash.new + @visible = sources.size > 0 sources.each do |id| @sources[id] = 1 end @@ -38,6 +45,10 @@ class Report '/reports/' + name end + def visible? + @visible + end + end Report.new 'Database statistics', :db @@ -48,5 +59,5 @@ Report.new 'Key lengths', :db Report.new 'Language comparison table for keys in the wiki', :wiki Report.new 'Languages', :wiki Report.new 'Wiki pages about non-existing keys', :db, :wiki -#Report.new 'Name tags', :db +Report.new 'Name tags' -- cgit v1.2.3