From 19ec1d7e4325df4b802acf1c0b57f6e447601b92 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Fri, 16 May 2014 20:08:00 +0200 Subject: Add cookie-base comparison list. --- README | 1 + web/i18n/de.yml | 8 +++ web/i18n/en.yml | 8 +++ web/lib/javascript.rb | 1 + web/lib/ui/comparison.rb | 2 +- web/lib/ui/keys.rb | 2 +- web/lib/ui/tags.rb | 2 +- web/public/css/taginfo.css | 11 +++ web/public/js/jquery.cookie-minified.js | 8 +++ web/public/js/jquery.cookie.js | 117 ++++++++++++++++++++++++++++++++ web/public/js/taginfo.js | 66 +++++++++++++++++- web/views/key.erb | 15 ++++ web/views/tag.erb | 15 ++++ 13 files changed, 252 insertions(+), 4 deletions(-) create mode 100644 web/public/js/jquery.cookie-minified.js create mode 100644 web/public/js/jquery.cookie.js diff --git a/README b/README index c22248a..0df88cf 100644 --- a/README +++ b/README @@ -66,6 +66,7 @@ Taginfo uses the following Javascript libraries: * jQuery UI 1.9.2 * customSelect (http://adam.co/lab/jquery/customselect/) * tipsy (http://onehackoranother.com/projects/jquery/tipsy/) +* jQuery Cookie (https://github.com/carhartl/jquery-cookie/) * Flexigrid (Originally from http://code.google.com/p/flexigrid/ http://www.flexigrid.info/ , the version used and included has some changes and bugfixes.) diff --git a/web/i18n/de.yml b/web/i18n/de.yml index b3ae308..574715b 100644 --- a/web/i18n/de.yml +++ b/web/i18n/de.yml @@ -317,6 +317,14 @@ flexigrid: nomsg: Keine Einträge errormsg: Fehler in der Verbindung +comparison: + list: Vergleichsliste + items: Einträge + add_key: Diesen Key hinzufügen + add_tag: Diesen Tag hinzufügen + clear: Vergleichsliste löschen + compare: Keys/Tags vergleichen + sources: master: name: Master diff --git a/web/i18n/en.yml b/web/i18n/en.yml index c8356a3..eba5c97 100644 --- a/web/i18n/en.yml +++ b/web/i18n/en.yml @@ -313,6 +313,14 @@ flexigrid: nomsg: No items errormsg: Connection Error +comparison: + list: Comparison list + items: items + add_key: Add this key to list + add_tag: Add this tag to list + clear: Clear comparison list + compare: Compare keys/tags + sources: master: name: Master diff --git a/web/lib/javascript.rb b/web/lib/javascript.rb index 5cf0a5a..cb73ff7 100644 --- a/web/lib/javascript.rb +++ b/web/lib/javascript.rb @@ -18,6 +18,7 @@ class Javascript @@js_files = { # :common => [ 'jquery-1.9.0.min', 'jquery-ui-1.9.2.custom.min', 'customSelect.jquery.min', 'jquery.tipsy-minified' ], :common => [ 'common' ], + :cookie => [ 'jquery.cookie-minified' ], :taginfo => [ 'taginfo' ], :flexigrid => [ 'jquery-migrate-1.0.0.min', 'flexigrid-minified' ], :d3 => [ 'd3/d3.v3.min' ], diff --git a/web/lib/ui/comparison.rb b/web/lib/ui/comparison.rb index 611d62e..4bc5d46 100644 --- a/web/lib/ui/comparison.rb +++ b/web/lib/ui/comparison.rb @@ -15,7 +15,7 @@ class Taginfo < Sinatra::Base params[:key].each_with_index do |key, index| @data << { :key => key, - :value => (params[:value].is_a?(Array) ? params[:value][index] : nil) + :value => (params[:value].is_a?(Array) ? (params[:value][index] == '' ? nil : params[:value][index]) : nil) } end end diff --git a/web/lib/ui/keys.rb b/web/lib/ui/keys.rb index 1ffc8eb..5b8af23 100644 --- a/web/lib/ui/keys.rb +++ b/web/lib/ui/keys.rb @@ -52,7 +52,7 @@ class Taginfo < Sinatra::Base @img_width = TaginfoConfig.get('geodistribution.width') * TaginfoConfig.get('geodistribution.scale_image') @img_height = TaginfoConfig.get('geodistribution.height') * TaginfoConfig.get('geodistribution.scale_image') - javascript_for(:flexigrid, :d3) + javascript_for(:flexigrid, :cookie, :d3) javascript "#{ r18n.locale.code }/key" erb :key end diff --git a/web/lib/ui/tags.rb b/web/lib/ui/tags.rb index 4250b33..4ba184c 100644 --- a/web/lib/ui/tags.rb +++ b/web/lib/ui/tags.rb @@ -60,7 +60,7 @@ class Taginfo < Sinatra::Base @img_width = TaginfoConfig.get('geodistribution.width') * TaginfoConfig.get('geodistribution.scale_image') @img_height = TaginfoConfig.get('geodistribution.height') * TaginfoConfig.get('geodistribution.scale_image') - javascript_for(:flexigrid) + javascript_for(:flexigrid, :cookie) javascript "#{ r18n.locale.code }/tag" erb :tag end diff --git a/web/public/css/taginfo.css b/web/public/css/taginfo.css index 7dd4e2f..84a1f14 100644 --- a/web/public/css/taginfo.css +++ b/web/public/css/taginfo.css @@ -338,6 +338,17 @@ span.char { border-radius: 4px; } +form#list-form { + margin: 0 20px 0 0; + float: right; +} + +select#list { + background-color: #ffffff; + color: #083e76; + width: 200px; +} + form#filter-form { margin-top: 0px; clear: both; diff --git a/web/public/js/jquery.cookie-minified.js b/web/public/js/jquery.cookie-minified.js new file mode 100644 index 0000000..b8b4c70 --- /dev/null +++ b/web/public/js/jquery.cookie-minified.js @@ -0,0 +1,8 @@ +/* + * jQuery Cookie Plugin v1.4.1 + * https://github.com/carhartl/jquery-cookie + * + * Copyright 2013 Klaus Hartl + * Released under the MIT license + */ +(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a)}else{if(typeof exports==="object"){a(require("jquery"))}else{a(jQuery)}}}(function(f){var a=/\+/g;function d(i){return b.raw?i:encodeURIComponent(i)}function g(i){return b.raw?i:decodeURIComponent(i)}function h(i){return d(b.json?JSON.stringify(i):String(i))}function c(i){if(i.indexOf('"')===0){i=i.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{i=decodeURIComponent(i.replace(a," "));return b.json?JSON.parse(i):i}catch(j){}}function e(j,i){var k=b.raw?j:c(j);return f.isFunction(i)?i(k):k}var b=f.cookie=function(q,p,v){if(p!==undefined&&!f.isFunction(p)){v=f.extend({},b.defaults,v);if(typeof v.expires==="number"){var r=v.expires,u=v.expires=new Date();u.setTime(+u+r*86400000)}return(document.cookie=[d(q),"=",h(p),v.expires?"; expires="+v.expires.toUTCString():"",v.path?"; path="+v.path:"",v.domain?"; domain="+v.domain:"",v.secure?"; secure":""].join(""))}var w=q?undefined:{};var s=document.cookie?document.cookie.split("; "):[];for(var o=0,m=s.length;o><%= h(t.pages.key.filter.relations) %> +
+ +
<% if @count_all_values <= TaginfoConfig.get('xapi.max_results', 1000) %> <%= xapi_link(@filter_xapi, @key) %> <%= josm_link(@filter_xapi, @key) %> @@ -113,6 +121,13 @@ function page_init2() { var filter = #{ @filter_type.to_json }, key = #{ @key.to_json }; jQuery('h1').html(fmt_key(key)); + + jQuery.cookie.json = true; + comparison_list_update(); + jQuery('#list').bind('change', function() { + comparison_list_change(key); + }); + jQuery('#level0_button').bind('click', function() { return level0_editor('#{ TaginfoConfig.get('level0.overpass_url_prefix') }', '#{ TaginfoConfig.get('level0.level0_url_prefix') }', filter, key, undefined); }); diff --git a/web/views/tag.erb b/web/views/tag.erb index b1758fa..9397d91 100644 --- a/web/views/tag.erb +++ b/web/views/tag.erb @@ -8,6 +8,14 @@ +
+ +
<% if @count_all < TaginfoConfig.get('xapi.max_results', 1000) %> <%= xapi_link(@filter_xapi, @key, @value) %> <%= josm_link(@filter_xapi, @key, @value) %> @@ -112,6 +120,13 @@ function page_init2() { value = #{ @value.to_json }; up = function() { window.location = url_for_key(key); }; jQuery('h1').html(link_to_key(key) + '=' + fmt_value(value)); + + jQuery.cookie.json = true; + comparison_list_update(); + jQuery('#list').bind('change', function() { + comparison_list_change(key, value); + }); + jQuery('span#keylink').html(link_to_key(key)); jQuery('span#relationlink').html(link_to_rtype(value)); jQuery('#level0_button').bind('click', function() { -- cgit v1.2.3