biovision-regions 0.1.180222 → 0.1.180316

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a79b81c7e1d6d771c1594476d4930a890fa9f8e47a7baad03b7444839109a60
4
- data.tar.gz: 36f5a1f865a16424ef771ad0c201e47c1b1f8e7f935de6f7c7e5dbfc6e8cec70
3
+ metadata.gz: 2fb6438d3fe3a89b3c390f468b6418aa7f2afd8085a81097d3d113799421d7e6
4
+ data.tar.gz: 9d6fe63322491f8c3b2e32f63291468d1a3600bb3cab18cf8977c1a0c641f0b6
5
5
  SHA512:
6
- metadata.gz: c5974037f36ac1524d0735fa521cfeef8bcea5a63cac8be5e57a352ea7f42da3f36e41d0910b85ce006a9c32e7373b6471707ec89194c853fa0f30e0c3d96030
7
- data.tar.gz: 5d780758299aeef479e00756f069223b752d923ed9f301c6c1d0aa749d251c499ae840df50ebf3e46f674ee2f26fa4d0b85d6aba2d20021fc857a255a54636bd
6
+ metadata.gz: 638a7c6aff83aa3f85f4150013208c586fe03f1e51c3cee699f7041e5157759b7d0464ccaed7e3ef8ab69499b2f9d6662a446399a56fce602d04bc706a91b275
7
+ data.tar.gz: 77bc866cacac56908b051e42bd6d8d168a88b5acc32b1e2bd266099bef741b99717617c9e07b2086867efa031db03f590e7b3ff6c49737705a87928ee79aff9f
@@ -1,19 +1,29 @@
1
- class RegionsController < AdminController
2
- before_action :set_entity, only: [:edit, :update, :destroy]
1
+ class RegionsController < ApplicationController
2
+ before_action :restrict_access, except: [:index, :show, :children]
3
+ before_action :set_entity, except: [:index, :new, :create]
3
4
  before_action :restrict_editing, only: [:edit, :update, :destroy]
4
5
 
6
+ layout 'admin', except: [:index, :show, :children]
7
+
8
+ # get /regions
9
+ def index
10
+ @collection = Region.visible.for_tree
11
+ end
12
+
5
13
  # post /regions
6
14
  def create
7
15
  @entity = Region.new(creation_parameters)
8
16
  if @entity.save
9
- next_page = admin_region_path(@entity.id)
10
- respond_to do |format|
11
- format.html { redirect_to next_page }
12
- format.json { render json: { links: { self: next_page } } }
13
- format.js { render js: "document.location.href = '#{next_page}'" }
14
- end
17
+ form_processed_ok(admin_region_path(@entity.id))
15
18
  else
16
- render :new, status: :bad_request
19
+ form_processed_with_error(:new)
20
+ end
21
+ end
22
+
23
+ # get /regions/:id
24
+ def show
25
+ unless @entity.visible
26
+ handle_http_404('Region is not visible')
17
27
  end
18
28
  end
19
29
 
@@ -24,18 +34,13 @@ class RegionsController < AdminController
24
34
  # patch /regions/:id
25
35
  def update
26
36
  if @entity.update(entity_parameters)
27
- next_page = admin_region_path(@entity.id)
28
- respond_to do |format|
29
- format.html { redirect_to next_page, notice: t('regions.update.success') }
30
- format.json { render json: { links: { self: next_page } } }
31
- format.js { render js: "document.location.href = '#{next_page}'" }
32
- end
37
+ form_processed_ok(admin_region_path(@entity.id))
33
38
  else
34
- render :edit, status: :bad_request
39
+ form_processed_with_error(:edit)
35
40
  end
36
41
  end
37
42
 
38
- # delete /post_categories/:id
43
+ # delete /regions/:id
39
44
  def destroy
40
45
  if @entity.destroy
41
46
  flash[:notice] = t('regions.destroy.success')
@@ -43,6 +48,13 @@ class RegionsController < AdminController
43
48
  redirect_to admin_regions_path
44
49
  end
45
50
 
51
+ # get /regions/:id/children
52
+ def children
53
+ @collection = Region.visible.for_tree(@entity.country_id, @entity.id)
54
+
55
+ render :index
56
+ end
57
+
46
58
  protected
47
59
 
48
60
  def restrict_access
data/app/models/region.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  class Region < ApplicationRecord
2
2
  include Toggleable
3
3
 
4
- SLUG_PATTERN = /\A[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?\z/
5
- PER_PAGE = 20
6
- NAME_LIMIT = 70
7
- SLUG_LIMIT = 63
8
- PRIORITY_RANGE = (1..32767)
4
+ SLUG_PATTERN = /\A[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?\z/
5
+ SLUG_PATTERN_HTML = '^[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?$'
6
+ PER_PAGE = 20
7
+ NAME_LIMIT = 70
8
+ SLUG_LIMIT = 63
9
+ PRIORITY_RANGE = (1..32767)
9
10
 
10
11
  toggleable :visible
11
12
 
@@ -1,4 +1,4 @@
1
- <%= form_with(model: entity, html: { id: 'region-form' }) do |f| %>
1
+ <%= form_with(model: entity, html: { id: "#{entity.class.to_s.underscore}-form" }) do |f| %>
2
2
  <%= render partial: 'shared/list_of_errors', locals: { entity: entity } %>
3
3
 
4
4
  <dl>
@@ -15,9 +15,9 @@
15
15
  <%=
16
16
  f.file_field(
17
17
  :image,
18
- id: :region_image,
18
+ id: :region_image,
19
19
  accept: 'image/jpeg,image/png',
20
- data: { image: 'region-image' }
20
+ data: { image: 'region-image' }
21
21
  )
22
22
  %>
23
23
  </figcaption>
@@ -36,9 +36,9 @@
36
36
  <%=
37
37
  f.file_field(
38
38
  :header_image,
39
- id: :region_header_image,
39
+ id: :region_header_image,
40
40
  accept: 'image/jpeg,image/png',
41
- data: { image: 'region-header-image' }
41
+ data: { image: 'region-header-image' }
42
42
  )
43
43
  %>
44
44
  <div class="guideline"><%= t('.guidelines.header_image') %></div>
@@ -51,9 +51,9 @@
51
51
  <%=
52
52
  f.text_field(
53
53
  :name,
54
- id: :region_name,
55
- required: true,
56
- size: nil,
54
+ id: :region_name,
55
+ required: true,
56
+ size: nil,
57
57
  maxlength: Region::NAME_LIMIT
58
58
  )
59
59
  %>
@@ -64,9 +64,9 @@
64
64
  <%=
65
65
  f.text_field(
66
66
  :short_name,
67
- id: :region_short_name,
68
- required: true,
69
- size: nil,
67
+ id: :region_short_name,
68
+ required: true,
69
+ size: nil,
70
70
  maxlength: Region::NAME_LIMIT
71
71
  )
72
72
  %>
@@ -80,10 +80,10 @@
80
80
  <%=
81
81
  f.text_field(
82
82
  :locative,
83
- id: :region_locative,
84
- required: true,
85
- size: nil,
86
- maxlength: Region::NAME_LIMIT,
83
+ id: :region_locative,
84
+ required: true,
85
+ size: nil,
86
+ maxlength: Region::NAME_LIMIT,
87
87
  placeholder: t('.placeholders.locative')
88
88
  )
89
89
  %>
@@ -97,9 +97,9 @@
97
97
  <%=
98
98
  f.text_field(
99
99
  :slug,
100
- id: :region_slug,
101
- required: true,
102
- size: nil,
100
+ id: :region_slug,
101
+ required: true,
102
+ size: nil,
103
103
  maxlength: Region::SLUG_LIMIT
104
104
  )
105
105
  %>
@@ -0,0 +1,12 @@
1
+ json.id region.id
2
+ json.type region.class.table_name
3
+ json.attributes do
4
+ json.(region, :parent_id, :name, :short_name, :priority, :slug, :long_slug)
5
+ end
6
+ json.links do
7
+ json.self region_path(region.id, format: :json)
8
+ json.children children_region_path(region.id)
9
+ end
10
+ json.meta do
11
+ json.child_count region.children_cache.count
12
+ end
@@ -0,0 +1,3 @@
1
+ json.data @collection do |entity|
2
+ json.partial! entity
3
+ end
@@ -0,0 +1,3 @@
1
+ json.data do
2
+ json.partial! @entity
3
+ end
data/config/routes.rb CHANGED
@@ -13,5 +13,9 @@ Rails.application.routes.draw do
13
13
  # get 'privileges/:id/regions' => 'privileges#regions', as: :regions_admin_privilege, defaults: { format: :json }
14
14
  end
15
15
 
16
- resources :regions, except: [:index, :show]
16
+ resources :regions do
17
+ member do
18
+ get 'children', defaults: { format: :json }
19
+ end
20
+ end
17
21
  end
@@ -1,5 +1,5 @@
1
1
  module Biovision
2
2
  module Regions
3
- VERSION = '0.1.180222'
3
+ VERSION = '0.1.180316'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biovision-regions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.180222
4
+ version: 0.1.180316
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Khan-Magomedov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-22 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -201,10 +201,11 @@ files:
201
201
  - app/views/admin/regions/show.html.erb
202
202
  - app/views/layouts/biovision/regions/application.html.erb
203
203
  - app/views/regions/_form.html.erb
204
+ - app/views/regions/_region.jbuilder
204
205
  - app/views/regions/edit.html.erb
205
- - app/views/regions/edit.js.erb
206
+ - app/views/regions/index.jbuilder
206
207
  - app/views/regions/new.html.erb
207
- - app/views/regions/new.js.erb
208
+ - app/views/regions/show.jbuilder
208
209
  - config/locales/regions-en.yml
209
210
  - config/locales/regions-ru.yml
210
211
  - config/routes.rb
@@ -1 +0,0 @@
1
- <%= render partial: 'shared/forms/list_of_errors', locals: { entity: @entity, form_id: 'region-form' } %>
@@ -1 +0,0 @@
1
- <%= render partial: 'shared/forms/list_of_errors', locals: { entity: @entity, form_id: 'region-form' } %>