geo_labels 0.2.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/README.md +127 -6
  4. data/Rakefile +6 -5
  5. data/app/assets/javascripts/geo_labels/application.coffee +13 -2
  6. data/app/assets/javascripts/geo_labels/ratings.coffee +80 -0
  7. data/app/assets/stylesheets/geo_labels/application.sass +21 -0
  8. data/app/controllers/concerns/geo_labels/shared_template_and_instance_methods.rb +3 -0
  9. data/app/controllers/geo_labels/application_controller.rb +3 -0
  10. data/app/controllers/geo_labels/contacts_controller.rb +18 -0
  11. data/app/controllers/geo_labels/dashboard_controller.rb +14 -9
  12. data/app/controllers/geo_labels/labels_controller.rb +3 -1
  13. data/app/controllers/geo_labels/ratings_controller.rb +30 -0
  14. data/app/helpers/geo_labels/application_helper.rb +73 -44
  15. data/app/helpers/geo_labels/rating_helper.rb +15 -0
  16. data/app/jobs/geo_labels/application_job.rb +1 -0
  17. data/app/mailers/geo_labels/application_mailer.rb +4 -2
  18. data/app/models/concerns/geo_labels/ratings_support.rb +102 -0
  19. data/app/models/geo_labels/application_record.rb +22 -0
  20. data/app/models/geo_labels/contact.rb +62 -20
  21. data/app/models/geo_labels/contact_label.rb +43 -7
  22. data/app/models/geo_labels/label.rb +13 -0
  23. data/app/views/geo_labels/contacts/_form.html.slim +22 -6
  24. data/app/views/geo_labels/contacts/index.html.slim +19 -7
  25. data/app/views/geo_labels/contacts/show.html.slim +24 -2
  26. data/app/views/geo_labels/dashboard/main.html.slim +27 -5
  27. data/app/views/geo_labels/labels/index.html.slim +10 -6
  28. data/app/views/geo_labels/labels/show.html.slim +15 -1
  29. data/app/views/layouts/geo_labels/application.html.slim +2 -0
  30. data/config/environment.rb +2 -0
  31. data/config/initializers/human_plural.rb +8 -5
  32. data/config/locales/geo_labels.en.yml +8 -0
  33. data/config/locales/geo_labels.es.yml +17 -0
  34. data/config/routes.rb +12 -1
  35. data/db/migrate/20221019150722_create_geo_labels_contacts.rb +5 -3
  36. data/db/migrate/20221020180213_create_geo_labels_labels.rb +2 -0
  37. data/db/migrate/20221020195346_create_geo_labels_contact_labels.rb +4 -2
  38. data/db/migrate/20230602182522_geo_labels_contacts_complex_name_to_name.rb +9 -0
  39. data/db/migrate/20230726154822_add_state_to_geo_labels_contacts.rb +8 -0
  40. data/db/migrate/20230801145902_add_food_rating_to_geo_labels_contacts.rb +7 -0
  41. data/lib/geo_labels/engine.rb +17 -7
  42. data/lib/geo_labels/exporter.rb +24 -10
  43. data/lib/geo_labels/importer.rb +31 -27
  44. data/lib/geo_labels/version.rb +3 -1
  45. data/lib/geo_labels.rb +2 -0
  46. data/lib/tasks/geo_labels_tasks.rake +1 -0
  47. metadata +37 -15
@@ -1,17 +1,24 @@
1
1
  .ui.container
2
2
  = page_title :index, record_class
3
- - if @records.any? or @q.conditions.present?
3
+ = render 'button-new-record'
4
+ - if @records.any? or @q.base.conditions.any?
4
5
  = search_form_for(@q, html: {class: 'ui form'}) do |f|
5
6
  = hidden_field_tag :per_page, params[:per_page], id: 'q_per_page'
6
7
  table.ui.compact.top.attached.striped.table
7
8
  thead
8
9
  tr
9
- th= sort_link @q, :full_name, at(:full_name), default_order: :asc
10
- th.column-filter.actions
10
+ th= sort_link @q, :name, at(:name), default_order: :asc
11
+ th= sort_link @q, :city, at(:city), default_order: :asc
12
+ th= sort_link @q, :department, at(:department), default_order: :asc
13
+ th= sort_link @q, :country, at(:country), default_order: :asc
14
+ th.collapsing.column-filter.actions
11
15
  = search_result_info @records
12
16
  = search_row class: 'ui mini form' do
13
- th= f.text_field :full_name_cont, placeholder: at(:full_name)
14
- th.column-filter.actions
17
+ th= f.search_field :name_cont, placeholder: at(:name)
18
+ th= f.search_field :city_cont, placeholder: at(:city)
19
+ th= f.search_field :department_cont, placeholder: at(:department)
20
+ th= f.search_field :country_cont, placeholder: at(:country)
21
+ th.collapsing.column-filter.actions
15
22
  button.ui.mini.primary.icon.button
16
23
  i.filter.icon
17
24
  = link_to polymorphic_path(record_class, reset_q: true), class: 'clear-filters-button ui mini basic yellow icon button' do
@@ -19,8 +26,13 @@
19
26
  tbody
20
27
  - @records.each do |record|
21
28
  tr
22
- td= link_to record.full_name, record
23
- td.actions
29
+ td
30
+ = link_to record.name, record
31
+ /= address_tag record.address, title: record.description
32
+ td= record.city
33
+ td= record.department
34
+ td= record.country
35
+ td.collapsing.actions
24
36
  = table_show_link record
25
37
  = table_edit_link record
26
38
  .ui.bottom.attached.segment
@@ -1,13 +1,35 @@
1
+ - content_for :head
2
+ javascript:
3
+ setupRatings()
4
+
1
5
  .ui.container
2
6
  = page_title :show, @record, back: [record_class]
3
7
  table.ui.top.attached.compact.definition.table
4
8
  tbody
5
9
  tr
6
10
  td= t 'form.name'
7
- td= @record.full_name
11
+ td
12
+ = @record.name
13
+ = address_tag @record.address, title: @record.description
8
14
  tr
9
15
  td= GeoLabels::Label.model_name.human_plural
10
- td= @record.labels.map(&:name).join(', ')
16
+ td== @record.labels.map{ |label| link_to label.name, label }.join(', ')
17
+ tr
18
+ td Ratings
19
+ td
20
+ = show_rating_for @record, :food
21
+ tr
22
+ td= at :state
23
+ td
24
+ - unless @record.rejected?
25
+ = link_to 'Reject', geo_labels.reject_contact_path(@record.id), method: :put, class: 'ui right floated button negative'
26
+ - unless @record.approved?
27
+ = link_to 'Approve', geo_labels.approve_contact_path(@record.id), method: :put, class: 'ui right floated button positive'
28
+ .ui.basic.label class=(@record.state == 'rejected' ? 'red' : (@record.state == 'approved' ? 'green' : 'yelow'))
29
+ = @record.state
30
+ tr
31
+ td= at :description
32
+ td= @record.description
11
33
  - if @record.geocoded?
12
34
  tr
13
35
  td Location
@@ -4,7 +4,7 @@
4
4
  .field
5
5
  /label Blabla
6
6
  .fields
7
- .eleven.wide.field
7
+ .eight.wide.field
8
8
  .ui.fluid.multiple.search.selection.dropdown
9
9
  = hidden_field_tag 'label_ids', params[:label_ids]
10
10
  i.dropdown.icon
@@ -15,6 +15,16 @@
15
15
  .item data-value=label_id
16
16
  = label_name
17
17
  .four.wide.field
18
+ .ui.fluid.multiple.selection.dropdown
19
+ /input name='q[state][]' value='approved' type='hidden'
20
+ = hidden_field_tag 'states', params[:states].presence || 'approved'
21
+ i.dropdown.icon
22
+ .default.text states
23
+ .menu
24
+ .item data-value='approved' approved
25
+ .item data-value='recommended' recommended
26
+ .item data-value='rejected' rejected
27
+ .three.wide.field
18
28
  .ui.buttons.fluid.and-or-switch-buttons
19
29
  = hidden_field_tag 'predication', params[:predication].presence || 'and'
20
30
  /= text_field_tag 'predication', 'and'
@@ -25,11 +35,23 @@
25
35
  button.ui.blue.icon.button
26
36
  i.search.icon
27
37
 
28
-
38
+ - if params[:label_ids].blank?
39
+ .ui.basic.pointing.label= t 'geo_labels.select_labels_text', models: GeoLabels::Label.model_name.human_plural
29
40
  - if @contacts.present?
30
- .ui.horizontal.divider= GeoLabels::Contact.model_name.human_plural
31
- .ui.segment
41
+ .ui.top.attached.tabular.menu
42
+ a.item.active data-tab='contacts'= GeoLabels::Contact.model_name.human_plural
43
+ a.item data-tab='map' Map
44
+ .ui.bottom.attached.tab.segment.active data-tab='contacts'
45
+ .ui.list
46
+ - @contacts.each do |contact|
47
+ .ui.item
48
+ = link_to contact.name, contact
49
+ = address_tag contact.address, title: contact.description
50
+ .ui.bottom.attached.tab.segment data-tab='map'
51
+ #map-canvas
52
+ /.ui.horizontal.divider= GeoLabels::Contact.model_name.human_plural
53
+ /.ui.segment
32
54
  #map-canvas
33
55
  javascript:
34
56
  window.map_points = #{@contacts.map(&:map_attributes).to_json.html_safe};
35
- script src="https://maps.googleapis.com/maps/api/js?key=#{Rails.application.config.x.geo_labels.google_api_key}&callback=initMap&v=weekly" defer
57
+ script src="https://maps.googleapis.com/maps/api/js?key=#{Rails.application.config.x.geo_labels.google_api_key}&v=weekly" defer
@@ -1,17 +1,21 @@
1
1
  .ui.container
2
2
  = page_title :index, record_class
3
- - if @records.any? or @q.conditions.present?
3
+ span   
4
+ = link_to new_label_path
5
+ i.plus.icon
6
+ = link_to_labels_tree
7
+ /- if @records.any? or @q.base.conditions.any?
4
8
  = search_form_for(@q, html: {class: 'ui form'}) do |f|
5
9
  = hidden_field_tag :per_page, params[:per_page], id: 'q_per_page'
6
10
  table.ui.compact.top.attached.striped.table
7
11
  thead
8
12
  tr
9
13
  th= sort_link @q, :name, at(:name), default_order: :asc
10
- th.column-filter.actions
14
+ th.collapsing.column-filter.actions
11
15
  = search_result_info @records
12
16
  = search_row class: 'ui mini form' do
13
17
  th= f.text_field :name_cont, placeholder: at(:name)
14
- th.column-filter.actions
18
+ th.collapsing.column-filter.actions
15
19
  button.ui.mini.primary.icon.button
16
20
  i.filter.icon
17
21
  = link_to polymorphic_path(record_class, reset_q: true), class: 'clear-filters-button ui mini basic yellow icon button' do
@@ -20,17 +24,17 @@
20
24
  - @records.each do |record|
21
25
  tr
22
26
  td= link_to record.name, record
23
- td.actions
27
+ td.collapsing.actions
24
28
  = table_show_link record
25
29
  = table_edit_link record
26
30
  .ui.bottom.attached.segment
27
31
  = render 'button-new-record'
28
32
  = paginate @records
29
- - else
33
+ /- else
30
34
  p= t 'collection.empty', models: record_class.model_name.human_plural
31
35
  = render 'button-new-record'
32
36
 
33
- .ui.styled.accordion
37
+ /.ui.styled.accordion
34
38
  .title.active
35
39
  i.dropdown.icon
36
40
  = t 'geo_labels.tree_title'
@@ -7,6 +7,20 @@
7
7
  td= @record.name
8
8
  tr
9
9
  td Parents
10
- td= @record.ancestors.map(&:name).join(' -> ')
10
+ td== @record.ancestors.map{ |label| link_to label.name, label }.join(' -> ')
11
+ tr
12
+ td Children
13
+ td
14
+ .ui.horizontal.bulleted.list
15
+ - @record.children.each do |child|
16
+ .item= link_to child.name, child
17
+ tr
18
+ td= GeoLabels::Contact.model_name.human_plural
19
+ td
20
+ .ui.list
21
+ - @record.associated_contacts.each do |contact|
22
+ .item
23
+ = link_to(contact.name, contact)
24
+ = address_tag contact.address, title: contact.description
11
25
  .ui.bottom.attached.segment
12
26
  = render 'button-edit-record', record: @record
@@ -11,6 +11,8 @@ html lang="en"
11
11
 
12
12
  = stylesheet_link_tag 'geo_labels/application', media: 'all'
13
13
  = javascript_include_tag 'geo_labels/application'
14
+ javascript:
15
+ window.geo_labels = #{{paths: GeoLabels::Engine.client_paths}.to_json.html_safe};
14
16
  = content_for :head
15
17
  body
16
18
  header= render 'navigation'
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ### NOTE:
2
4
  # This is a dummy file to let the vim-rails vim plugin work with the rails engine
@@ -1,16 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveModel
2
4
  class Name
5
+
3
6
  def human_plural
4
7
  # Try to find the plural name of a model. If none can be found try to find a non namespaced version and return that one
5
- default = Proc.new do |path|
6
- if path.present? and path['/'] # non namespaced model a/b/c => a
7
- unnamespaced_path = path.sub(/\.(\w+)\/[\w\\]+/, '.\1')
8
- I18n.t(unnamespaced_path, default: Proc.new{ human.pluralize })
8
+ default = proc do |path|
9
+ if path.present? and path['/'] # non namespaced model a.b.c/d/e => a.b.c
10
+ unnamespaced_path = path.sub(%r{\.(\w+)/[\w\\]+}, '.\1')
11
+ I18n.t(unnamespaced_path, default: proc{ human.pluralize })
9
12
  else
10
13
  human.pluralize
11
14
  end
12
15
  end
13
- I18n.t("#{@klass.i18n_scope}.models.plural.#{i18n_key}", default: default )
16
+ I18n.t("#{@klass.i18n_scope}.models.plural.#{i18n_key}", default: default)
14
17
  end
15
18
  end
16
19
  end
@@ -3,3 +3,11 @@ en:
3
3
  export: Export
4
4
  import: Import
5
5
  tree_title: Tree
6
+ select_labels_text: Select %{models} and search...
7
+ manual_lat_lng:
8
+ title: Manual location
9
+ explanation: >
10
+ Sometimes an address cannot be geocoded.<br>
11
+ Then a Google maps can give a location string <br>
12
+ That can be copy pasted here. Example&colon;<br>
13
+ <code>4.973122, -75.623981</code>
@@ -1,5 +1,22 @@
1
1
  es:
2
+ activerecord:
3
+ models:
4
+ geo_labels/contact: Contacto
5
+ geo_labels/label: Etiqueta
6
+ plural:
7
+ geo_labels/contact: Contactos
8
+ geo_labels/label: Etiquetas
9
+
2
10
  geo_labels:
3
11
  export: Exportar
4
12
  import: Importar
5
13
  tree_title: Árbol
14
+ select_labels_text: Seleccionar %{models} y busca...
15
+ manual_lat_lng:
16
+ title: Ubicación manuál
17
+ explanation: >
18
+ A veces una dirección no se puede convertir en
19
+ una ubicación. <br>
20
+ Pues en Google maps se puede copiar y pegar<br>
21
+ coordinatos manuál. Ejemplo&colon;<br>
22
+ <code>4.973122, -75.623981</code>
data/config/routes.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  GeoLabels::Engine.routes.draw do
2
3
  root 'dashboard#main'
3
4
 
@@ -8,6 +9,16 @@ GeoLabels::Engine.routes.draw do
8
9
  post :import_file
9
10
  end
10
11
 
11
- resources :contacts
12
+ scope 'ratings', controller: :ratings do
13
+ post :set, as: :set_rating # post because of.. well.. $.post
14
+ get :get, as: :get_rating
15
+ end
16
+
17
+ resources :contacts do
18
+ member do
19
+ put :approve
20
+ put :reject
21
+ end
22
+ end
12
23
  resources :labels
13
24
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class CreateGeoLabelsContacts < ActiveRecord::Migration[7.0]
3
+
2
4
  def change
3
5
  create_table :geo_labels_contacts do |t|
4
6
  t.string :first_name
@@ -10,11 +12,11 @@ class CreateGeoLabelsContacts < ActiveRecord::Migration[7.0]
10
12
  t.string :state
11
13
  t.string :country
12
14
  t.text :description
13
- t.float :latitude
14
- t.float :longitude
15
+ t.decimal :latitude, precision: 15, scale: 13
16
+ t.decimal :longitude, precision: 15, scale: 13
15
17
 
16
18
  t.timestamps
17
- t.index [:latitude, :longitude]
19
+ t.index %i[latitude longitude]
18
20
  end
19
21
  end
20
22
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class CreateGeoLabelsLabels < ActiveRecord::Migration[7.0]
3
+
2
4
  def change
3
5
  create_table :geo_labels_labels do |t|
4
6
  t.string :name
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  class CreateGeoLabelsContactLabels < ActiveRecord::Migration[7.0]
3
+
2
4
  def change
3
5
  create_table :geo_labels_contact_labels, id: false do |t|
4
- #t.belongs_to :contact, null: false, foreign_key: true
5
- #t.belongs_to :label, null: false, foreign_key: true
6
+ # t.belongs_to :contact, null: false, foreign_key: true
7
+ # t.belongs_to :label, null: false, foreign_key: true
6
8
  t.integer :contact_id, index: true
7
9
  t.integer :label_id, index: true
8
10
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ class GeoLabelsContactsComplexNameToName < ActiveRecord::Migration[7.0]
3
+
4
+ def change
5
+ rename_column :geo_labels_contacts, :first_name, :name
6
+ remove_column :geo_labels_contacts, :middle_name
7
+ remove_column :geo_labels_contacts, :last_name
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ class AddStateToGeoLabelsContacts < ActiveRecord::Migration[7.0]
3
+
4
+ def change
5
+ rename_column :geo_labels_contacts, :state, :department
6
+ add_column :geo_labels_contacts, :state, :string, default: 'approved'
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ class AddFoodRatingToGeoLabelsContacts < ActiveRecord::Migration[7.0]
3
+
4
+ def change
5
+ add_column :geo_labels_contacts, :food_rating, :integer, default: 0, null: false
6
+ end
7
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'geocoder'
2
3
  require 'slim-rails'
3
4
  require 'coffee-rails'
@@ -11,24 +12,33 @@ require 'awesome_nested_set'
11
12
 
12
13
  module GeoLabels
13
14
  class Engine < ::Rails::Engine
15
+
14
16
  isolate_namespace GeoLabels
15
17
 
16
- initializer "geo_labels.assets.precompile" do |main_app|
17
- #app.config.assets.precompile << "config/engine_name_manifest.js"
18
- main_app.config.assets.precompile << "geo_labels/application.css"
19
- main_app.config.assets.precompile << "geo_labels/application.js"
18
+ initializer 'geo_labels.assets.precompile' do |main_app|
19
+ # app.config.assets.precompile << "config/engine_name_manifest.js"
20
+ main_app.config.assets.precompile << 'geo_labels/application.css'
21
+ main_app.config.assets.precompile << 'geo_labels/application.js'
20
22
 
21
23
  # Engine specific config
22
24
  main_app.config.x.geo_labels.application_title ||= -> { 'GEO-labels' }
23
25
  main_app.config.x.geo_labels.link_home_content ||= -> { '<i class="arrow left icon"></i> Back' }
24
- main_app.config.x.geo_labels.google_api_key ||= "GOOGLE_API_KEY"
26
+ main_app.config.x.geo_labels.google_api_key ||= ENV['GOOGLE_API_KEY'] || 'GOOGLE_API_KEY'
27
+ end
28
+
29
+ def self.client_paths
30
+ {
31
+ mount: routes.find_script_name({}),
32
+ get_rating: routes.url_helpers.get_rating_path,
33
+ set_rating: routes.url_helpers.set_rating_path
34
+ }
25
35
  end
26
36
 
27
37
  # add migrations to containing application
28
38
  initializer 'geo_labels.append_migrations' do |app|
29
39
  unless app.root.to_s.match root.to_s
30
- config.paths["db/migrate"].expanded.each do |expanded_path|
31
- app.config.paths["db/migrate"] << expanded_path
40
+ config.paths['db/migrate'].expanded.each do |expanded_path|
41
+ app.config.paths['db/migrate'] << expanded_path
32
42
  end
33
43
  end
34
44
  end
@@ -1,16 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  require 'yaml'
2
3
  module GeoLabels
3
4
  class Exporter
5
+
4
6
  def self.export_h
5
- obj = {
7
+ {
6
8
  'labels' => labels_tree,
7
- 'contacts' => GeoLabels::Contact.includes(:labels).map{ |contact|
8
- contact.attributes.merge('labels' => contact.labels.map(&:name)).select{ |attr, val|
9
- val.present? and not %w[id created_at updated_at].include?(attr)
10
- }
11
- }
9
+ 'contacts' => contacts_h
12
10
  }
13
- obj
14
11
  end
15
12
 
16
13
  def self.export_str
@@ -20,11 +17,11 @@ module GeoLabels
20
17
  # Formats the tree structure from labels_tree_h to a string output
21
18
  # can be called with add_punctuation: '-' to add dashes
22
19
  def self.labels_tree(add_punctuation: nil)
23
- output = ""
24
- tree_formatter = Proc.new do |items, lead_space|
20
+ output = ''
21
+ tree_formatter = proc do |items, lead_space|
25
22
  items.each do |item|
26
23
  output += "#{lead_space}#{item[:name]}\n"
27
- tree_formatter.call(item[:children], lead_space + ' ') if item[:children].present?
24
+ tree_formatter.call(item[:children], "#{lead_space} ") if item[:children].present?
28
25
  end
29
26
  end
30
27
  tree_formatter.call(labels_tree_h, '')
@@ -32,6 +29,23 @@ module GeoLabels
32
29
  output
33
30
  end
34
31
 
32
+ def self.contacts_h
33
+ GeoLabels::Contact.includes(:labels).map do |contact|
34
+ contact
35
+ .attributes
36
+ .slice(*%w[name street subsection city department country state description latitude longitude])
37
+ .merge('labels' => contact.labels.map(&:name))
38
+ .select { |_, v| v.present? }
39
+ .transform_values do |value|
40
+ case value
41
+ when Date, Time then value.iso8601
42
+ when BigDecimal then value.to_f
43
+ else value
44
+ end
45
+ end
46
+ end
47
+ end
48
+
35
49
  # Returns an array having the tree structure as ruby objects
36
50
  def self.labels_tree_h
37
51
  labels = GeoLabels::Label.order(:name).to_a
@@ -1,27 +1,28 @@
1
+ # frozen_string_literal: true
1
2
  module GeoLabels
2
3
  module Importer
3
4
  def self.import(subject)
4
- yaml_h = case subject
5
- when String
6
- if subject.start_with?('/') or subject.start_with?('./')
7
- YAML.load_file(subject)
8
- else
9
- YAML.load(subject)
10
- end
11
- when File then YAML.load(subject.read)
12
- when Pathname then YAML.load(subject.read)
13
- when ActionDispatch::Http::UploadedFile then YAML.load(subject.read)
14
- else
15
- raise "Argument not recognized"
16
- end
5
+ yaml_h = case subject
6
+ when String
7
+ if subject.start_with?('/') or subject.start_with?('./')
8
+ YAML.load_file(subject)
9
+ else
10
+ YAML.safe_load(subject)
11
+ end
12
+ when File then YAML.safe_load(subject.read)
13
+ when Pathname then YAML.safe_load(subject.read)
14
+ when ActionDispatch::Http::UploadedFile then YAML.safe_load(subject.read)
15
+ else
16
+ raise 'Argument not recognized'
17
+ end
17
18
  GeoLabels::Contact.delete_all
18
19
  GeoLabels::Label.delete_all
19
20
  GeoLabels::ContactLabel.delete_all
20
21
  labels_dict = persist_labels_tree yaml_h['labels']
21
22
  yaml_h['contacts'].each do |contact_attributes|
22
- label_names = Array(contact_attributes.delete 'labels')
23
+ label_names = Array(contact_attributes.delete('labels'))
23
24
  contact = GeoLabels::Contact.new(contact_attributes)
24
- contact.labels = label_names.map{labels_dict[_1]}.compact
25
+ contact.labels = label_names.map{ labels_dict[_1] }.compact
25
26
  contact.save
26
27
  end
27
28
  GeoLabels::Contact.count
@@ -29,13 +30,13 @@ module GeoLabels
29
30
 
30
31
  def self.labels_text_to_tree(tree_text)
31
32
  txt = tree_text.gsub("\n\u0001", "\n") # remove START OF HEADING TRASH
32
- txt.gsub! /^(\s*)[\-\*] /, '\1 ' # remove list punctuations and interpret just the spaces
33
+ txt.gsub! /^(\s*)[-*] /, '\1 ' # remove list punctuations and interpret just the spaces
33
34
  lines = txt.split("\n")
34
35
  root_label, current_indentation = ImportLabel.new('root'), -1
35
36
  working_object = root_label
36
37
  lines.each do |line|
37
38
  line_indentation = (line.match(/\s+/).try(:[], 0).try(:size) || 0) / 2
38
- #name = line[(2*line_indentation)..] # strip the leading spaces
39
+ # name = line[(2*line_indentation)..] # strip the leading spaces
39
40
  name = line.strip
40
41
  label = ImportLabel.new(name)
41
42
  if line_indentation > current_indentation # level deeper
@@ -55,13 +56,13 @@ module GeoLabels
55
56
 
56
57
  def self.persist_labels_tree(tree_or_text = nil)
57
58
  tree = case tree_or_text
58
- when ImportLabel then tree_or_text
59
- when String then labels_text_to_tree(tree_or_text)
60
- else
61
- raise "Must provide a tree label object or tree text"
62
- end
59
+ when ImportLabel then tree_or_text
60
+ when String then labels_text_to_tree(tree_or_text)
61
+ else
62
+ raise 'Must provide a tree label object or tree text'
63
+ end
63
64
  record_lookup_dict = {}
64
- persister = Proc.new do |items, parent|
65
+ persister = proc do |items, parent|
65
66
  items.each do |item|
66
67
  record = Label.create name: item.name, parent: parent
67
68
  record_lookup_dict[item.name] = record
@@ -73,11 +74,14 @@ module GeoLabels
73
74
  end
74
75
 
75
76
  class LabelList < Array
77
+
76
78
  attr_accessor :parent
77
79
  end
78
80
 
79
81
  class ImportLabel
80
- attr_accessor :name, :children, :parent
82
+
83
+ attr_accessor :name, :parent
84
+
81
85
  def initialize(name)
82
86
  @name = name
83
87
  end
@@ -103,9 +107,9 @@ module GeoLabels
103
107
  end
104
108
 
105
109
  def inspect
106
- #"#{name} => #{children.inspect}"
107
- #children.any? ? "<#{name}> => #{children.inpsect}" : "#{name}"
108
- base = "#{name}"
110
+ # "#{name} => #{children.inspect}"
111
+ # children.any? ? "<#{name}> => #{children.inpsect}" : "#{name}"
112
+ base = name.to_s
109
113
  base = "#{base} => #{children.inspect}" if children.any?
110
114
  base
111
115
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GeoLabels
2
- VERSION = "0.2.0"
4
+ VERSION = '0.3.2'
3
5
  end
data/lib/geo_labels.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require 'geo_labels/version'
2
3
  require 'geo_labels/engine'
3
4
  require 'geo_labels/importer'
4
5
  require 'geo_labels/exporter'
6
+ require 'fomantic-ui-sass'
5
7
 
6
8
  module GeoLabels
7
9
  # Your code goes here...
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # desc "Explaining what the task does"
2
3
  # task :geo_labels do
3
4
  # # Task goes here