summaryrefslogtreecommitdiff
path: root/web/viewsjs/tag.js.erb
blob: ebefcc1fa32699dba10ea378ada3439d7fcf84ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<%
    osm = @trans.t.osm
    misc = @trans.t.misc
    taginfo = @trans.t.taginfo
    page = @trans.t.pages.tag
 %>
function link_to_key_or_tag(key, value) {
    var link = link_to_key(key) + '=';
    if (value && value != '') {
        link += link_to_value(key, value, { 'class': 'pref' });
    } else {
        link += '*';
    }
    return link;
}

var create_flexigrid_for = {
    overview: function(key, value, filter_type) {
        create_flexigrid('grid-overview', {
            url: '/api/4/tag/stats?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(value),
            colModel: [
                { display: '<%= h(misc.object_type) %>', name: 'type', width: 100, sortable: true },
                { display: '<%= h(page.number_objects) %>', name: 'count', width: 260, sortable: true, align: 'center' }
            ],
            usepager: false,
            useRp: false,
            preProcess: function(data) {
                return {
                    total: 4,
                    page: 1,
                    rows: jQuery.map(data.data, function(row, i) {
                        return { 'cell': [
                            fmt_type_image(row.type),
                            fmt_value_with_percent(row.count, row.count_fraction)
                        ]};
                    })
                };
            }
        });
    },
    combinations: function(key, value, filter_type) {
        create_flexigrid('grid-combinations', {
            url: '/api/4/tag/combinations?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(value) + '&filter=' + encodeURIComponent(filter_type),
            colModel: [
                { display: '<span title="<%= h(page.other_tags_used.to_count_tooltip) %>"><%= h(misc.count) %> &rarr;</span>', name: 'to_count', width: 260, sortable: true, align: 'center' },
                { display: '<span title="<%= h(page.other_tags_used.other_key_tooltip) %>"><%= h(page.other_tags_used.other) %></span>', name: 'other_tag', width: 400, sortable: true },
                { display: '<span title="<%= h(page.other_tags_used.from_count_tooltip) %>">&rarr; <%= h(misc.count) %></span>', name: 'from_count', width: 260, sortable: true, align: 'center' }
            ],
            searchitems: [
                { display: '<%= h(page.other_tags_used.other) %>', name: 'other_tag' }
            ],
            sortname: 'to_count',
            sortorder: 'desc',
            preProcess: function(data) {
                data.rows = jQuery.map(data.data, function(row, i) {
                    return { 'cell': [
                        fmt_value_with_percent(row.together_count, row.to_fraction),
                        link_to_key_or_tag(row.other_key, row.other_value),
                        fmt_value_with_percent(row.together_count, row.from_fraction),
                    ] };
                });
                return data;
            }
        });
    },
    wiki: function(key, value) {
        create_flexigrid('grid-wiki', {
            url: '/api/4/tag/wiki_pages?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(value),
            colModel: [
                { display: '<%= h(misc.language) %>', name: 'lang', width: 150, sortable: false },
                { display: '<%= h(page.wiki_pages.wiki_page) %>', name: 'title', width: 200, sortable: false, align: 'right' },
                { display: '<%= h(misc.description) %>', name: 'description', width: 400, sortable: false },
                { display: '<%= h(misc.image) %>', name: 'image', width: 120, sortable: false },
                { display: '<%= h(osm.objects) %>', name: 'objects', width:  80, sortable: false },
                { display: '<%= h(page.wiki_pages.implied_tags) %>', name: 'tags_implied', width: 120, sortable: false },
                { display: '<%= h(page.wiki_pages.combined_tags) %>', name: 'tags_combination', width: 120, sortable: false },
                { display: '<%= h(page.wiki_pages.linked_tags) %>', name: 'tags_linked', width: 220, sortable: false }
            ],
            usepager: false,
            useRp: false,
            preProcess: function(data) {
                return {
                    total: data.size,
                    page: 1,
                    rows: jQuery.map(data, function(row, i) {
                        return { 'cell': [
                            fmt_language(row.lang, row.language, row.language_en),
                            link_to_wiki(row.title),
                            html_escape(row.description),
                            fmt_wiki_image_popup(row.image),
                            fmt_type_icon('node',     row.on_node) +
                            fmt_type_icon('way',      row.on_way) +
                            fmt_type_icon('area',     row.on_area) +
                            fmt_type_icon('relation', row.on_relation),
                            fmt_key_or_tag_list(row.tags_implies),
                            fmt_key_or_tag_list(row.tags_combination),
                            fmt_key_or_tag_list(row.tags_linked)
                        ]};
                    })
                };
            }
        });
    },
    projects: function(key, value, filter_type) {
        create_flexigrid('grid-projects', {
            url: '/api/4/tag/projects?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(value) + '&filter=' + encodeURIComponent(filter_type),
            colModel: [
                { display: '<%= h(taginfo.project) %>', name: 'project_name', width: 280, sortable: true },
                { display: '<%= h(osm.tag) %>', name: 'tag', width: 220, sortable: true },
                { display: '<%= h(osm.objects) %>', name: 'objects', width:  80, sortable: false },
                { display: '<%= h(page.projects.description) %>', name: 'description', width: 600, sortable: false, align: 'left' }
            ],
            searchitems: [
                { display: '<%= h(taginfo.project) %>/<%= h(osm.value) %>', name: 'project_value' }
            ],
            sortname: 'tag',
            sortorder: 'asc',
            preProcess: function(data) {
                data.rows = jQuery.map(data.data, function(row, i) {
                    return { 'cell': [
                        link_to_project(row.project_id, row.project_name, row.project_icon_url),
                        row.value ? link_to_tag(row.key, row.value) : (link_to_key(row.key) + '=*'),
                        fmt_type_icon('node',     row.on_node) +
                        fmt_type_icon('way',      row.on_way) +
                        fmt_type_icon('area',     row.on_area) +
                        fmt_type_icon('relation', row.on_relation),
                        project_tag_desc(row.description, row.icon_url, row.doc_url)
                    ] };
                });
                return data;
            }
        });
    }
};

function page_init() {
    activate_josm_button();

    jQuery('#filter').bind('change', function() {
        var value = this.value;

        var qs = jQuery.getQueryString;
        qs['filter'] = value;

        window.location.search = jQuery.param(qs);
    });

    page_init2();
}