Skip to content

Commit 66f5ec3

Browse files
committed
Merge branch 'develop' into 'master'
Develop See merge request !6
2 parents 7a70272 + 44b9151 commit 66f5ec3

File tree

70 files changed

+58489
-57218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+58489
-57218
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source 'https://rubygems.org'
22

33
gem 'deface'
4+
gem 'immutable-struct'
45
gem "rgeo"
56
gem "rgeo-geojson"
67
gem "rgeo-activerecord"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class GttTileSourcesController < ApplicationController
2+
layout 'admin'
3+
4+
before_action :require_admin
5+
6+
self.main_menu = false
7+
8+
def index
9+
@tile_sources = GttTileSource.order name: :asc
10+
end
11+
12+
def new
13+
@tile_source = GttTileSource.new
14+
end
15+
16+
def create
17+
r = RedmineGtt::Actions::CreateTileSource.(tile_source_params)
18+
if r.tile_source_created?
19+
redirect_to gtt_tile_sources_path
20+
else
21+
@tile_source = r.tile_source
22+
render 'new'
23+
end
24+
end
25+
26+
def edit
27+
@tile_source = GttTileSource.find params[:id]
28+
end
29+
30+
def update
31+
ts = GttTileSource.find params[:id]
32+
r = RedmineGtt::Actions::UpdateTileSource.(ts, tile_source_params)
33+
if r.tile_source_updated?
34+
redirect_to gtt_tile_sources_path
35+
else
36+
@tile_source = r.tile_source
37+
render 'edit'
38+
end
39+
end
40+
41+
def destroy
42+
ts = GttTileSource.find params[:id]
43+
ts.destroy
44+
redirect_to gtt_tile_sources_path
45+
end
46+
47+
48+
private
49+
50+
def tile_source_params
51+
return {} unless params[:tile_source]
52+
53+
params[:tile_source].permit( :name, :type, :global,
54+
:default, :options_string )
55+
end
56+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module GttTileSourcesHelper
2+
def pretty_tile_source_options(tile_source)
3+
JSON.pretty_generate tile_source.options if Hash === tile_source.options
4+
end
5+
6+
def tile_source_options(tile_source)
7+
safe_join tile_source.options.to_a.select{
8+
|k,v| v.present?
9+
}.map{|k,v|
10+
"#{k}: #{v}"
11+
}, "<br />".html_safe
12+
end
13+
end

app/models/gtt_configuration.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class GttConfiguration
2+
include ActiveModel::Model
3+
4+
attr_accessor :project, :gtt_tile_source_ids
5+
6+
def self.for(project)
7+
new project: project
8+
end
9+
10+
def gtt_tile_source_ids
11+
project.gtt_tile_source_ids
12+
end
13+
14+
def gtt_tile_source_ids=(ids)
15+
project.gtt_tile_source_ids = ids
16+
end
17+
end

app/models/gtt_tile_source.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Tile source model
2+
#
3+
# Configuration is stored as json
4+
class GttTileSource < ActiveRecord::Base
5+
self.inheritance_column = 'none'
6+
7+
validates :name, presence: true
8+
validates :type, presence: true
9+
validate :take_json_options
10+
11+
# globally available tile sources
12+
scope :global, ->{ where global: true }
13+
14+
# default tile sources for new projects
15+
scope :default, ->{ where default: true }
16+
17+
attr_writer :options_string
18+
def options_string
19+
@options_string ||= JSON.pretty_generate(options || {})
20+
end
21+
22+
private
23+
24+
def take_json_options
25+
self.options = JSON.parse options_string
26+
rescue JSON::ParserError
27+
errors.add :options_string, I18n.t(:error_invalid_json)
28+
end
29+
30+
end
31+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<%= error_messages_for 'tile_source' %>
2+
3+
4+
<div class="box tabular">
5+
<p><%= f.text_field :name, required: true, size: 25 %></p>
6+
<p><%= f.text_field :type, required: true, size: 25 %></p>
7+
<p><%= f.check_box :global %></p>
8+
<p><%= f.check_box :default %></p>
9+
<p> <%= f.text_area :options_string, rows: 10, cols: 80 %> </p>
10+
</div>
11+
12+
13+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<tr class="<%= cycle("odd", "even") %>">
2+
<td><%= tile_source.type %></td>
3+
<td><%= link_to tile_source.name, edit_gtt_tile_source_path(tile_source) %></td>
4+
<td><%= checked_image tile_source.global? %></td>
5+
<td><%= checked_image tile_source.default? %></td>
6+
<td><%= tile_source_options tile_source %></td>
7+
<td class="buttons">
8+
<%= delete_link gtt_tile_source_path(tile_source) %>
9+
</td>
10+
</tr>
11+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%= title [l(:label_gtt_tile_source_plural), gtt_tile_sources_path], @tile_source.name %>
2+
3+
<%= labelled_form_for :tile_source, @tile_source, url: gtt_tile_source_path(@tile_source), method: :patch do |f| %>
4+
<%= render partial: 'form', locals: { f: f } %>
5+
<p>
6+
<%= submit_tag l :button_save %>
7+
</p>
8+
<% end %>
9+
10+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<div class="contextual">
2+
<%= link_to l(:label_gtt_tile_source_new), new_gtt_tile_source_path, :class => 'icon icon-add' %>
3+
</div>
4+
5+
<h2><%= l :label_gtt_tile_source_plural %></h2>
6+
7+
<% if @tile_sources.any? %>
8+
<table class="list">
9+
<thead>
10+
<tr>
11+
<th><%= l :label_type %></th>
12+
<th><%= l :label_name %></th>
13+
<th><%= l :label_global %></th>
14+
<th><%= l :label_default %></th>
15+
<th><%= l :label_config %></th>
16+
<th></th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<%= render collection: @tile_sources, partial: 'tile_source' %>
21+
</tbody>
22+
</table>
23+
24+
<% else %>
25+
<p class="nodata"><%= l :label_no_data %></p>
26+
<% end %>
27+
28+
<% html_title l :label_gtt_tile_source_plural -%>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%= title [l(:label_gtt_tile_source_plural), gtt_tile_sources_path], l(:label_gtt_tile_source_new) %>
2+
3+
<%= labelled_form_for :tile_source, @tile_source, url: gtt_tile_sources_path do |f| %>
4+
<%= render partial: 'form', locals: { f: f } %>
5+
<p>
6+
<%= submit_tag l :button_create %>
7+
<%= submit_tag l(:button_create_and_continue), name: 'continue' %>
8+
</p>
9+
<% end %>
10+

0 commit comments

Comments
 (0)