ecoportal-api-v2 0.8.7 → 0.8.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +82 -1
 - data/lib/ecoportal/api/common/content/array_model.rb +8 -6
 - data/lib/ecoportal/api/common/content/collection_model.rb +45 -20
 - data/lib/ecoportal/api/common/content/double_model.rb +94 -5
 - data/lib/ecoportal/api/common/content/hash_diff_patch.rb +44 -22
 - data/lib/ecoportal/api/common/content/model_helpers.rb +36 -0
 - data/lib/ecoportal/api/common/content.rb +1 -0
 - data/lib/ecoportal/api/v2/page/component/action.rb +17 -8
 - data/lib/ecoportal/api/v2/page/component/action_field.rb +37 -2
 - data/lib/ecoportal/api/v2/page/component/chart_field/benchmark.rb +30 -0
 - data/lib/ecoportal/api/v2/page/component/chart_field/config.rb +23 -0
 - data/lib/ecoportal/api/v2/page/component/chart_field/frequency.rb +3 -4
 - data/lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb +1 -3
 - data/lib/ecoportal/api/v2/page/component/chart_field/indicator.rb +4 -5
 - data/lib/ecoportal/api/v2/page/component/chart_field/multiseries.rb +3 -5
 - data/lib/ecoportal/api/v2/page/component/chart_field/sankey.rb +1 -3
 - data/lib/ecoportal/api/v2/page/component/chart_field/serie.rb +3 -4
 - data/lib/ecoportal/api/v2/page/component/chart_field/series_config.rb +5 -7
 - data/lib/ecoportal/api/v2/page/component/chart_field.rb +43 -5
 - data/lib/ecoportal/api/v2/page/component/chart_fr_field.rb +7 -5
 - data/lib/ecoportal/api/v2/page/component/checklist_field.rb +1 -1
 - data/lib/ecoportal/api/v2/page/component/checklist_item.rb +7 -5
 - data/lib/ecoportal/api/v2/page/component/date_field.rb +71 -4
 - data/lib/ecoportal/api/v2/page/component/file.rb +14 -3
 - data/lib/ecoportal/api/v2/page/component/files_field.rb +37 -1
 - data/lib/ecoportal/api/v2/page/component/gauge_field.rb +2 -2
 - data/lib/ecoportal/api/v2/page/component/gauge_stop.rb +5 -5
 - data/lib/ecoportal/api/v2/page/component/geo_coordinates.rb +13 -0
 - data/lib/ecoportal/api/v2/page/component/geo_field.rb +4 -1
 - data/lib/ecoportal/api/v2/page/component/image.rb +2 -1
 - data/lib/ecoportal/api/v2/page/component/images_field.rb +57 -1
 - data/lib/ecoportal/api/v2/page/component/number_field.rb +1 -0
 - data/lib/ecoportal/api/v2/page/component/people_field.rb +115 -5
 - data/lib/ecoportal/api/v2/page/component/people_viewable_field.rb +14 -0
 - data/lib/ecoportal/api/v2/page/component/plain_text_field.rb +34 -2
 - data/lib/ecoportal/api/v2/page/component/reference_field.rb +32 -3
 - data/lib/ecoportal/api/v2/page/component/selection_field.rb +65 -7
 - data/lib/ecoportal/api/v2/page/component/selection_option.rb +16 -5
 - data/lib/ecoportal/api/v2/page/component/signature_field.rb +3 -2
 - data/lib/ecoportal/api/v2/page/component/tag_field.rb +31 -1
 - data/lib/ecoportal/api/v2/page/component.rb +44 -10
 - data/lib/ecoportal/api/v2/page/components.rb +8 -3
 - data/lib/ecoportal/api/v2/page/permission_flags.rb +67 -0
 - data/lib/ecoportal/api/v2/page/permit.rb +15 -0
 - data/lib/ecoportal/api/v2/page/section.rb +70 -9
 - data/lib/ecoportal/api/v2/page/sections.rb +64 -6
 - data/lib/ecoportal/api/v2/page/stage.rb +12 -4
 - data/lib/ecoportal/api/v2/page/stages.rb +7 -7
 - data/lib/ecoportal/api/v2/page.rb +19 -2
 - data/lib/ecoportal/api/v2/pages/page_stage.rb +9 -3
 - data/lib/ecoportal/api/v2/pages.rb +6 -2
 - data/lib/ecoportal/api/v2/registers/search_results.rb +13 -0
 - data/lib/ecoportal/api/v2/registers.rb +13 -0
 - data/lib/ecoportal/api/v2_version.rb +1 -1
 - metadata +10 -2
 
| 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Ecoportal
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                class V2
         
     | 
| 
      
 4 
     | 
    
         
            +
                  class Page
         
     | 
| 
      
 5 
     | 
    
         
            +
                    class Permit < Common::Content::DoubleModel
         
     | 
| 
      
 6 
     | 
    
         
            +
                      passkey     :id
         
     | 
| 
      
 7 
     | 
    
         
            +
                      passforced  :patch_ver, default: 1
         
     | 
| 
      
 8 
     | 
    
         
            +
                      passthrough :user_id, :user_name
         
     | 
| 
      
 9 
     | 
    
         
            +
                      passthrough :editable, :flags
         
     | 
| 
      
 10 
     | 
    
         
            +
                      embeds_one  :flags, klass: "Ecoportal::API::V2::Page::PermissionFlags"
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -6,9 +6,9 @@ module Ecoportal 
     | 
|
| 
       6 
6 
     | 
    
         
             
                      class << self
         
     | 
| 
       7 
7 
     | 
    
         
             
                        def new_doc(split: false)
         
     | 
| 
       8 
8 
     | 
    
         
             
                          {
         
     | 
| 
       9 
     | 
    
         
            -
                            "id" 
     | 
| 
       10 
     | 
    
         
            -
                            "type" 
     | 
| 
       11 
     | 
    
         
            -
                            "weight" 
     | 
| 
      
 9 
     | 
    
         
            +
                            "id"         => new_uuid,
         
     | 
| 
      
 10 
     | 
    
         
            +
                            "type"       => split ? "split" : "content",
         
     | 
| 
      
 11 
     | 
    
         
            +
                            "weight"     => 800
         
     | 
| 
       12 
12 
     | 
    
         
             
                          }.tap do |out|
         
     | 
| 
       13 
13 
     | 
    
         
             
                            component_ids = if split
         
     | 
| 
       14 
14 
     | 
    
         
             
                                {
         
     | 
| 
         @@ -26,10 +26,11 @@ module Ecoportal 
     | 
|
| 
       26 
26 
     | 
    
         
             
                      end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
                      passkey     :id
         
     | 
| 
       29 
     | 
    
         
            -
                       
     | 
| 
      
 29 
     | 
    
         
            +
                      passforced  :patch_ver, default: 1
         
     | 
| 
      
 30 
     | 
    
         
            +
                      passthrough :weight, :type
         
     | 
| 
       30 
31 
     | 
    
         
             
                      passthrough :heading, :left_heading, :right_heading
         
     | 
| 
       31 
32 
     | 
    
         
             
                      passarray   :component_ids, :left_component_ids, :right_component_ids
         
     | 
| 
       32 
     | 
    
         
            -
                       
     | 
| 
      
 33 
     | 
    
         
            +
                      passboolean :minimized
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
35 
     | 
    
         
             
                      def split?
         
     | 
| 
       35 
36 
     | 
    
         
             
                        doc && doc["type"] == "split"
         
     | 
| 
         @@ -44,10 +45,70 @@ module Ecoportal 
     | 
|
| 
       44 
45 
     | 
    
         
             
                        all_component_ids.include?(id)
         
     | 
| 
       45 
46 
     | 
    
         
             
                      end
         
     | 
| 
       46 
47 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
                      def components
         
     | 
| 
       48 
     | 
    
         
            -
                         
     | 
| 
       49 
     | 
    
         
            -
                         
     | 
| 
       50 
     | 
    
         
            -
                           
     | 
| 
      
 48 
     | 
    
         
            +
                      def components(side: nil)
         
     | 
| 
      
 49 
     | 
    
         
            +
                        case side
         
     | 
| 
      
 50 
     | 
    
         
            +
                        when :right
         
     | 
| 
      
 51 
     | 
    
         
            +
                          components_right
         
     | 
| 
      
 52 
     | 
    
         
            +
                        when :left
         
     | 
| 
      
 53 
     | 
    
         
            +
                          components_left
         
     | 
| 
      
 54 
     | 
    
         
            +
                        when NilClass
         
     | 
| 
      
 55 
     | 
    
         
            +
                          components_by_id(*all_component_ids)
         
     | 
| 
      
 56 
     | 
    
         
            +
                        else
         
     | 
| 
      
 57 
     | 
    
         
            +
                          raise "Side should be one of [nil, :right, :left]. Given: #{side}"
         
     | 
| 
      
 58 
     | 
    
         
            +
                        end
         
     | 
| 
      
 59 
     | 
    
         
            +
                      end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                      def components_left
         
     | 
| 
      
 62 
     | 
    
         
            +
                        raise "You are trying to retrieve side components in a Split Section" unless split?
         
     | 
| 
      
 63 
     | 
    
         
            +
                        components_by_id(*left_component_ids)
         
     | 
| 
      
 64 
     | 
    
         
            +
                      end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                      def components_right
         
     | 
| 
      
 67 
     | 
    
         
            +
                        raise "You are trying to retrieve side components in a Split Section" unless split?
         
     | 
| 
      
 68 
     | 
    
         
            +
                        components_by_id(*right_component_ids)
         
     | 
| 
      
 69 
     | 
    
         
            +
                      end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                      # Adds `field` to the section
         
     | 
| 
      
 72 
     | 
    
         
            +
                      # @note
         
     | 
| 
      
 73 
     | 
    
         
            +
                      #   - To the specified `side`, when split section (default `:left`)
         
     | 
| 
      
 74 
     | 
    
         
            +
                      #   - To the end if `after` is not specified
         
     | 
| 
      
 75 
     | 
    
         
            +
                      #   - If `after` is specified, it searches field
         
     | 
| 
      
 76 
     | 
    
         
            +
                      #     - On the specific `side`, if specified (and split section)
         
     | 
| 
      
 77 
     | 
    
         
            +
                      #     - And adds the `field` after it, when found, or at the end if `after` is not found
         
     | 
| 
      
 78 
     | 
    
         
            +
                      # @param field [Ecoportal::API::V2::Page::Component] the field to be added.
         
     | 
| 
      
 79 
     | 
    
         
            +
                      def add_component(field, after: nil, side: nil)
         
     | 
| 
      
 80 
     | 
    
         
            +
                        raise "field should be a Ecoportal::API::V2::Page::Component. Given: #{field.class}" unless field.is_a?(Ecoportal::API::V2::Page::Component)
         
     | 
| 
      
 81 
     | 
    
         
            +
                        if field.section == self
         
     | 
| 
      
 82 
     | 
    
         
            +
                          raise "Field with id '#{field.id}' already belongs to this section"
         
     | 
| 
      
 83 
     | 
    
         
            +
                        elsif sec = field.section
         
     | 
| 
      
 84 
     | 
    
         
            +
                          # Field belongs to another section
         
     | 
| 
      
 85 
     | 
    
         
            +
                          raise "Field with id '#{field.id}' belongs to section '#{sec.heading || "Unnamed"}' (id: '#{sec.id}')"
         
     | 
| 
      
 86 
     | 
    
         
            +
                        end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                        if split?
         
     | 
| 
      
 89 
     | 
    
         
            +
                          ids_ary = side == :right ? right_component_ids : left_component_ids
         
     | 
| 
      
 90 
     | 
    
         
            +
                          fields  = components(side: side || :left)
         
     | 
| 
      
 91 
     | 
    
         
            +
                        else
         
     | 
| 
      
 92 
     | 
    
         
            +
                          ids_ary = component_ids
         
     | 
| 
      
 93 
     | 
    
         
            +
                          fields  = components
         
     | 
| 
      
 94 
     | 
    
         
            +
                        end
         
     | 
| 
      
 95 
     | 
    
         
            +
                        if after
         
     | 
| 
      
 96 
     | 
    
         
            +
                          after_fld = fields.find do |fld|
         
     | 
| 
      
 97 
     | 
    
         
            +
                            found   = nil
         
     | 
| 
      
 98 
     | 
    
         
            +
                            found ||= !!after if after.is_a?(Ecoportal::API::V2::Page::Component)
         
     | 
| 
      
 99 
     | 
    
         
            +
                            found ||= fld.id == after
         
     | 
| 
      
 100 
     | 
    
         
            +
                            found ||= same_string?(fld.label, after)
         
     | 
| 
      
 101 
     | 
    
         
            +
                          end
         
     | 
| 
      
 102 
     | 
    
         
            +
                        end
         
     | 
| 
      
 103 
     | 
    
         
            +
                        ids_ary.insert_one(field.id, after: after_fld&.id)
         
     | 
| 
      
 104 
     | 
    
         
            +
                        self
         
     | 
| 
      
 105 
     | 
    
         
            +
                      end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                      private
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                      def components_by_id(*ids)
         
     | 
| 
      
 110 
     | 
    
         
            +
                        root.components.values_at(*ids).select.with_index do |fld, i|
         
     | 
| 
      
 111 
     | 
    
         
            +
                          puts "Warning: field id #{ids[i]} points to missing field" if !fld
         
     | 
| 
       51 
112 
     | 
    
         
             
                          fld && (!block_given? || yield(fld))
         
     | 
| 
       52 
113 
     | 
    
         
             
                        end
         
     | 
| 
       53 
114 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -7,26 +7,84 @@ module Ecoportal 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
                      self.klass = :section_class
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
                      # Creates a new `section`
         
     | 
| 
       10 
11 
     | 
    
         
             
                      def add(name: nil, split: false, pos: NOT_USED, before: NOT_USED, after: NOT_USED)
         
     | 
| 
       11 
12 
     | 
    
         
             
                        sec_doc = section_class.new_doc(split: split)
         
     | 
| 
       12 
     | 
    
         
            -
                        upsert!(sec_doc 
     | 
| 
      
 13 
     | 
    
         
            +
                        upsert!(sec_doc) do |section| #, pos: pos, before: before, after: after) do |section|
         
     | 
| 
       13 
14 
     | 
    
         
             
                          section.heading  = name
         
     | 
| 
       14 
     | 
    
         
            -
                          if  
     | 
| 
       15 
     | 
    
         
            -
                            section.weight =  
     | 
| 
      
 15 
     | 
    
         
            +
                          if weight = scope_weight(pos: pos, before: before, after: after)
         
     | 
| 
      
 16 
     | 
    
         
            +
                            section.weight = weight
         
     | 
| 
       16 
17 
     | 
    
         
             
                          end
         
     | 
| 
      
 18 
     | 
    
         
            +
                          fix_weights!
         
     | 
| 
       17 
19 
     | 
    
         
             
                          yield(section) if block_given?
         
     | 
| 
       18 
     | 
    
         
            -
                          #fix_weights! # a server bug prevents to set the weight of existing sections
         
     | 
| 
       19 
20 
     | 
    
         
             
                        end
         
     | 
| 
       20 
21 
     | 
    
         
             
                      end
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
      
 23 
     | 
    
         
            +
                      def get_by_type(type)
         
     | 
| 
      
 24 
     | 
    
         
            +
                        ordered.select do |sec|
         
     | 
| 
      
 25 
     | 
    
         
            +
                          sec.type == type
         
     | 
| 
      
 26 
     | 
    
         
            +
                        end
         
     | 
| 
      
 27 
     | 
    
         
            +
                      end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                      def get_by_heading(heading)
         
     | 
| 
      
 30 
     | 
    
         
            +
                        ordered.select do |sec|
         
     | 
| 
      
 31 
     | 
    
         
            +
                          value = heading == :unnamed ? nil : heading
         
     | 
| 
      
 32 
     | 
    
         
            +
                          same_string?(sec.heading, value)
         
     | 
| 
      
 33 
     | 
    
         
            +
                        end
         
     | 
| 
      
 34 
     | 
    
         
            +
                      end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                      # Gets all the sections between `sec1` and `sec2`
         
     | 
| 
      
 37 
     | 
    
         
            +
                      def between(sec1, sec2, included: false)
         
     | 
| 
      
 38 
     | 
    
         
            +
                        sorted_secs = ordered
         
     | 
| 
      
 39 
     | 
    
         
            +
                        pos1 = (sec1 = to_section(sec1)) && sorted_secs.index(sec1)
         
     | 
| 
      
 40 
     | 
    
         
            +
                        pos2 = (sec2 = to_section(sec2)) && sorted_secs.index(sec2)
         
     | 
| 
      
 41 
     | 
    
         
            +
                        if included
         
     | 
| 
      
 42 
     | 
    
         
            +
                          pos1 = pos1 ? pos1 : 0
         
     | 
| 
      
 43 
     | 
    
         
            +
                          pos2 = pos2 ? pos2 : -1
         
     | 
| 
      
 44 
     | 
    
         
            +
                        else
         
     | 
| 
      
 45 
     | 
    
         
            +
                          pos1 = pos1 ? (pos1 + 1) : 0
         
     | 
| 
      
 46 
     | 
    
         
            +
                          pos2 = pos2 ? (pos2 - 1) : -1
         
     | 
| 
      
 47 
     | 
    
         
            +
                        end
         
     | 
| 
      
 48 
     | 
    
         
            +
                        sorted_secs[pos1..pos2]
         
     | 
| 
      
 49 
     | 
    
         
            +
                      end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                      # Gets the sections ordered by `weight` (as they appear in the page)
         
     | 
| 
       22 
52 
     | 
    
         
             
                      def ordered
         
     | 
| 
       23 
     | 
    
         
            -
                         
     | 
| 
      
 53 
     | 
    
         
            +
                        self.sort_by.with_index do |section, index|
         
     | 
| 
       24 
54 
     | 
    
         
             
                          (section.weight >= 9999) ? [index, index] : [section.weight, index]
         
     | 
| 
       25 
     | 
    
         
            -
                        end 
     | 
| 
      
 55 
     | 
    
         
            +
                        end
         
     | 
| 
       26 
56 
     | 
    
         
             
                      end
         
     | 
| 
       27 
57 
     | 
    
         | 
| 
       28 
58 
     | 
    
         
             
                      private
         
     | 
| 
       29 
59 
     | 
    
         | 
| 
      
 60 
     | 
    
         
            +
                      def scope_weight(pos: NOT_USED, before: NOT_USED, after: NOT_USED)
         
     | 
| 
      
 61 
     | 
    
         
            +
                        case
         
     | 
| 
      
 62 
     | 
    
         
            +
                        when used_param?(pos)
         
     | 
| 
      
 63 
     | 
    
         
            +
                          if pos    = to_section(pos)
         
     | 
| 
      
 64 
     | 
    
         
            +
                            pos.weight - 1
         
     | 
| 
      
 65 
     | 
    
         
            +
                          end
         
     | 
| 
      
 66 
     | 
    
         
            +
                        when used_param?(before)
         
     | 
| 
      
 67 
     | 
    
         
            +
                          if before = to_section(before)
         
     | 
| 
      
 68 
     | 
    
         
            +
                            before.weight - 1
         
     | 
| 
      
 69 
     | 
    
         
            +
                          end
         
     | 
| 
      
 70 
     | 
    
         
            +
                        when used_param?(after)
         
     | 
| 
      
 71 
     | 
    
         
            +
                          if after  = to_section(after)
         
     | 
| 
      
 72 
     | 
    
         
            +
                            after.weight
         
     | 
| 
      
 73 
     | 
    
         
            +
                          end
         
     | 
| 
      
 74 
     | 
    
         
            +
                        end
         
     | 
| 
      
 75 
     | 
    
         
            +
                      end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                      def to_section(value)
         
     | 
| 
      
 78 
     | 
    
         
            +
                        case value
         
     | 
| 
      
 79 
     | 
    
         
            +
                        when Ecoportal::API::V2::Page::Section
         
     | 
| 
      
 80 
     | 
    
         
            +
                          value
         
     | 
| 
      
 81 
     | 
    
         
            +
                        when Numeric
         
     | 
| 
      
 82 
     | 
    
         
            +
                          ordered[value]
         
     | 
| 
      
 83 
     | 
    
         
            +
                        else
         
     | 
| 
      
 84 
     | 
    
         
            +
                          get_by_heading(value).first
         
     | 
| 
      
 85 
     | 
    
         
            +
                        end
         
     | 
| 
      
 86 
     | 
    
         
            +
                      end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
       30 
88 
     | 
    
         
             
                      def fix_weights!
         
     | 
| 
       31 
89 
     | 
    
         
             
                        ordered.each_with_index do |section, index|
         
     | 
| 
       32 
90 
     | 
    
         
             
                          section.weight = index
         
     | 
| 
         @@ -4,10 +4,17 @@ module Ecoportal 
     | 
|
| 
       4 
4 
     | 
    
         
             
                  class Page
         
     | 
| 
       5 
5 
     | 
    
         
             
                    class Stage < Common::Content::DoubleModel
         
     | 
| 
       6 
6 
     | 
    
         
             
                      passkey     :id
         
     | 
| 
       7 
     | 
    
         
            -
                       
     | 
| 
       8 
     | 
    
         
            -
                      passthrough :name
         
     | 
| 
      
 7 
     | 
    
         
            +
                      passforced  :patch_ver, default: 1
         
     | 
| 
      
 8 
     | 
    
         
            +
                      passthrough :name, :ordering
         
     | 
| 
       9 
9 
     | 
    
         
             
                      passarray   :subtags, order_matters: false
         
     | 
| 
       10 
10 
     | 
    
         
             
                      passarray   :section_ids
         
     | 
| 
      
 11 
     | 
    
         
            +
                      passthrough :status
         
     | 
| 
      
 12 
     | 
    
         
            +
                      passboolean :complete, :lock_after_completion
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                      embeds_many :permits, klass: "Ecoportal::API::V2::Page::Permit"
         
     | 
| 
      
 15 
     | 
    
         
            +
                      passboolean :disable_direct_permissions
         
     | 
| 
      
 16 
     | 
    
         
            +
                      passboolean :creator_enabled, :creator_editable
         
     | 
| 
      
 17 
     | 
    
         
            +
                      embeds_one  :creator_flags, klass: "Ecoportal::API::V2::Page::PermissionFlags"
         
     | 
| 
       11 
18 
     | 
    
         
             
                      passthrough :can
         
     | 
| 
       12 
19 
     | 
    
         | 
| 
       13 
20 
     | 
    
         
             
                      def sections
         
     | 
| 
         @@ -18,8 +25,9 @@ module Ecoportal 
     | 
|
| 
       18 
25 
     | 
    
         
             
                        end.sort_by {|sec| sec.weight}
         
     | 
| 
       19 
26 
     | 
    
         
             
                      end
         
     | 
| 
       20 
27 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                      def  
     | 
| 
       22 
     | 
    
         
            -
                        section_ids.insert_one( 
     | 
| 
      
 28 
     | 
    
         
            +
                      def add_section(*secs)
         
     | 
| 
      
 29 
     | 
    
         
            +
                        secs.each {|sec| section_ids.insert_one(sec.id)}
         
     | 
| 
      
 30 
     | 
    
         
            +
                        self
         
     | 
| 
       23 
31 
     | 
    
         
             
                      end
         
     | 
| 
       24 
32 
     | 
    
         | 
| 
       25 
33 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -8,16 +8,16 @@ module Ecoportal 
     | 
|
| 
       8 
8 
     | 
    
         
             
                      self.klass = :stage_class
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                      def get_by_name(name)
         
     | 
| 
       11 
     | 
    
         
            -
                        find do |stage|
         
     | 
| 
       12 
     | 
    
         
            -
                          stage.name 
     | 
| 
      
 11 
     | 
    
         
            +
                        self.find do |stage|
         
     | 
| 
      
 12 
     | 
    
         
            +
                          same_string?(stage.name, name)
         
     | 
| 
       13 
13 
     | 
    
         
             
                        end
         
     | 
| 
       14 
14 
     | 
    
         
             
                      end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                      def  
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                      end
         
     | 
| 
      
 16 
     | 
    
         
            +
                      #def ordered
         
     | 
| 
      
 17 
     | 
    
         
            +
                      #  self.each_with_index.sort_by do |stage, index|
         
     | 
| 
      
 18 
     | 
    
         
            +
                      #    (stage.ordering >= 9999) ? [index, index] : [stage.ordering, index]
         
     | 
| 
      
 19 
     | 
    
         
            +
                      #  end.map(&:first)
         
     | 
| 
      
 20 
     | 
    
         
            +
                      #end
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                    end
         
     | 
| 
       23 
23 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -2,9 +2,19 @@ module Ecoportal 
     | 
|
| 
       2 
2 
     | 
    
         
             
              module API
         
     | 
| 
       3 
3 
     | 
    
         
             
                class V2
         
     | 
| 
       4 
4 
     | 
    
         
             
                  class Page < Common::Content::DoubleModel
         
     | 
| 
       5 
     | 
    
         
            -
                    ALLOWED_KEYS  =  
     | 
| 
      
 5 
     | 
    
         
            +
                    ALLOWED_KEYS  = [
         
     | 
| 
      
 6 
     | 
    
         
            +
                      "id", "patch_ver", "name", "template_id",
         
     | 
| 
      
 7 
     | 
    
         
            +
                      "base_tags", "tags",
         
     | 
| 
      
 8 
     | 
    
         
            +
                      "time_zone", "created_at", "updated_at",
         
     | 
| 
      
 9 
     | 
    
         
            +
                      "components", "sections", "stages",
         
     | 
| 
      
 10 
     | 
    
         
            +
                      "permits", "mould_counter", "mould",
         
     | 
| 
      
 11 
     | 
    
         
            +
                      "state", "task_priority",
         
     | 
| 
      
 12 
     | 
    
         
            +
                      "votes_enabled", "upvotes", "downvotes",
         
     | 
| 
      
 13 
     | 
    
         
            +
                      "force_errors", "subtags"
         
     | 
| 
      
 14 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       6 
16 
     | 
    
         
             
                    passkey     :id
         
     | 
| 
       7 
     | 
    
         
            -
                     
     | 
| 
      
 17 
     | 
    
         
            +
                    passforced  :patch_ver, default: 1
         
     | 
| 
       8 
18 
     | 
    
         
             
                    passthrough :name, :template_id
         
     | 
| 
       9 
19 
     | 
    
         
             
                    passarray   :base_tags, :tags, order_matters: false
         
     | 
| 
       10 
20 
     | 
    
         
             
                    passthrough :time_zone
         
     | 
| 
         @@ -25,15 +35,22 @@ module Ecoportal 
     | 
|
| 
       25 
35 
     | 
    
         
             
                          hash["data"].select! do |key, value|
         
     | 
| 
       26 
36 
     | 
    
         
             
                            ALLOWED_KEYS.include?(key)
         
     | 
| 
       27 
37 
     | 
    
         
             
                          end
         
     | 
| 
      
 38 
     | 
    
         
            +
                          return nil if (hash["data"].keys - ["patch_ver"]).empty?
         
     | 
| 
       28 
39 
     | 
    
         
             
                        end
         
     | 
| 
       29 
40 
     | 
    
         
             
                      end
         
     | 
| 
       30 
41 
     | 
    
         
             
                    end
         
     | 
| 
       31 
42 
     | 
    
         | 
| 
      
 43 
     | 
    
         
            +
                    def stages?
         
     | 
| 
      
 44 
     | 
    
         
            +
                      self.stages.count > 0
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
       32 
47 
     | 
    
         
             
                  end
         
     | 
| 
       33 
48 
     | 
    
         
             
                end
         
     | 
| 
       34 
49 
     | 
    
         
             
              end
         
     | 
| 
       35 
50 
     | 
    
         
             
            end
         
     | 
| 
       36 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
            require 'ecoportal/api/v2/page/permission_flags'
         
     | 
| 
      
 53 
     | 
    
         
            +
            require 'ecoportal/api/v2/page/permit'
         
     | 
| 
       37 
54 
     | 
    
         
             
            require 'ecoportal/api/v2/page/component'
         
     | 
| 
       38 
55 
     | 
    
         
             
            require 'ecoportal/api/v2/page/components'
         
     | 
| 
       39 
56 
     | 
    
         
             
            require 'ecoportal/api/v2/page/section'
         
     | 
| 
         @@ -4,11 +4,17 @@ module Ecoportal 
     | 
|
| 
       4 
4 
     | 
    
         
             
                  class Pages
         
     | 
| 
       5 
5 
     | 
    
         
             
                    class PageStage < V2::Page
         
     | 
| 
       6 
6 
     | 
    
         
             
                      passthrough :mould_counter, :archive
         
     | 
| 
       7 
     | 
    
         
            -
                      passthrough :task_priority, :state
         
     | 
| 
      
 7 
     | 
    
         
            +
                      passthrough :task_priority, :state, :status
         
     | 
| 
       8 
8 
     | 
    
         
             
                      passthrough :votes_enabled, :upvotes, :downvotes
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                       
     | 
| 
       11 
     | 
    
         
            -
                       
     | 
| 
      
 10 
     | 
    
         
            +
                      embeds_many :permits, klass: "Ecoportal::API::V2::Page::Permit"
         
     | 
| 
      
 11 
     | 
    
         
            +
                      passarray   :force_errors, :subtags, order_matters: false
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                      # `id` of the stage we got the data of.
         
     | 
| 
      
 14 
     | 
    
         
            +
                      def current_stage_id
         
     | 
| 
      
 15 
     | 
    
         
            +
                        doc.dig("active_stage", "id") || doc["current_stage_id"]
         
     | 
| 
      
 16 
     | 
    
         
            +
                      end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       12 
18 
     | 
    
         
             
                    end
         
     | 
| 
       13 
19 
     | 
    
         
             
                  end
         
     | 
| 
       14 
20 
     | 
    
         
             
                end
         
     | 
| 
         @@ -47,12 +47,16 @@ module Ecoportal 
     | 
|
| 
       47 
47 
     | 
    
         
             
                    end
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
49 
     | 
    
         
             
                    # Requests to update an existing page via api.
         
     | 
| 
      
 50 
     | 
    
         
            +
                    # @note It won't launch the update unless there are changes
         
     | 
| 
       50 
51 
     | 
    
         
             
                    # @param doc [Hash, Page] data that at least contains an `id` (internal or external) of the target page.
         
     | 
| 
       51 
52 
     | 
    
         
             
                    # @return [Response] an object with the api response.
         
     | 
| 
       52 
53 
     | 
    
         
             
                    def update(doc)
         
     | 
| 
       53 
54 
     | 
    
         
             
                      body = get_body(doc) # , level: "page"
         
     | 
| 
       54 
     | 
    
         
            -
                       
     | 
| 
       55 
     | 
    
         
            -
                       
     | 
| 
      
 55 
     | 
    
         
            +
                      # Launch only if there are changes
         
     | 
| 
      
 56 
     | 
    
         
            +
                      if body && body["page"]
         
     | 
| 
      
 57 
     | 
    
         
            +
                        id   = get_id(doc)
         
     | 
| 
      
 58 
     | 
    
         
            +
                        client.patch("/pages/#{CGI.escape(id)}", data: body)
         
     | 
| 
      
 59 
     | 
    
         
            +
                      end
         
     | 
| 
       56 
60 
     | 
    
         
             
                    end
         
     | 
| 
       57 
61 
     | 
    
         | 
| 
       58 
62 
     | 
    
         
             
                    # Gets a `new` non-existing page via api with all the ids initialized.
         
     | 
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Ecoportal
         
     | 
| 
      
 2 
     | 
    
         
            +
              module API
         
     | 
| 
      
 3 
     | 
    
         
            +
                class V2
         
     | 
| 
      
 4 
     | 
    
         
            +
                  class Registers
         
     | 
| 
      
 5 
     | 
    
         
            +
                    class SearchResults < Common::Content::DoubleModel
         
     | 
| 
      
 6 
     | 
    
         
            +
                      passthrough :total, :total_before_filtering
         
     | 
| 
      
 7 
     | 
    
         
            +
                      passarray   :tags, order_matters: false
         
     | 
| 
      
 8 
     | 
    
         
            +
                      embeds_many :results, klass: "Ecoportal::API::V2::Registers::PageResult"
         
     | 
| 
      
 9 
     | 
    
         
            +
                    end
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -9,6 +9,7 @@ module Ecoportal 
     | 
|
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                    class_resolver :register_class,  "Ecoportal::API::V2::Registers::Register"
         
     | 
| 
       11 
11 
     | 
    
         
             
                    class_resolver :register_search_result_class, "Ecoportal::API::V2::Registers::PageResult"
         
     | 
| 
      
 12 
     | 
    
         
            +
                    class_resolver :register_search_results, "Ecoportal::API::V2::Registers::SearchResults"
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
14 
     | 
    
         
             
                    attr_reader :client
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
         @@ -35,7 +36,12 @@ module Ecoportal 
     | 
|
| 
       35 
36 
     | 
    
         
             
                    # @param options [Hash] the search options
         
     | 
| 
       36 
37 
     | 
    
         
             
                    # @option options [Hash<Symbol, String>] :query plain search (like the search box in register).
         
     | 
| 
       37 
38 
     | 
    
         
             
                    # @option options [Hash<Symbol, Array<Object>>] :filters the set of filters.
         
     | 
| 
      
 39 
     | 
    
         
            +
                    # @option options [Boolean] if `true`, it only performs the first search and results `Ecoportal::API::V2::Registers::SearchResults`.
         
     | 
| 
      
 40 
     | 
    
         
            +
                    # @yield [result]  something to do with search page-result.
         
     | 
| 
      
 41 
     | 
    
         
            +
                    # @yieldparam result [Ecoportal::V2::Registers::PageResult] a page result.
         
     | 
| 
      
 42 
     | 
    
         
            +
                    # @return [Ecoportal::API::V2::Registers, Ecoportal::API::V2::Registers::SearchResults]
         
     | 
| 
       38 
43 
     | 
    
         
             
                    def search(register_id, options = {})
         
     | 
| 
      
 44 
     | 
    
         
            +
                      only_first = options.delete(:only_first)
         
     | 
| 
       39 
45 
     | 
    
         
             
                      # supply a query string
         
     | 
| 
       40 
46 
     | 
    
         
             
                      # or a filter array (copy/paste from dev tools in the browser)
         
     | 
| 
       41 
47 
     | 
    
         
             
                      options = {query: nil, filters: []}.update(options)
         
     | 
| 
         @@ -49,6 +55,12 @@ module Ecoportal 
     | 
|
| 
       49 
55 
     | 
    
         
             
                        end
         
     | 
| 
       50 
56 
     | 
    
         
             
                      end
         
     | 
| 
       51 
57 
     | 
    
         | 
| 
      
 58 
     | 
    
         
            +
                      if only_first
         
     | 
| 
      
 59 
     | 
    
         
            +
                        response = client.get("/registers/#{register_id}/search", params: options)
         
     | 
| 
      
 60 
     | 
    
         
            +
                        raise "Request failed - Status #{response.status}: #{response.body}" unless response.success?
         
     | 
| 
      
 61 
     | 
    
         
            +
                        return register_search_results.new(response.body["data"])
         
     | 
| 
      
 62 
     | 
    
         
            +
                      end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       52 
64 
     | 
    
         
             
                      cursor_id = nil
         
     | 
| 
       53 
65 
     | 
    
         
             
                      results = 0
         
     | 
| 
       54 
66 
     | 
    
         
             
                      loop do
         
     | 
| 
         @@ -87,3 +99,4 @@ require 'ecoportal/api/v2/registers/register' 
     | 
|
| 
       87 
99 
     | 
    
         
             
            require 'ecoportal/api/v2/registers/stage_result'
         
     | 
| 
       88 
100 
     | 
    
         
             
            require 'ecoportal/api/v2/registers/stages_result'
         
     | 
| 
       89 
101 
     | 
    
         
             
            require 'ecoportal/api/v2/registers/page_result'
         
     | 
| 
      
 102 
     | 
    
         
            +
            require 'ecoportal/api/v2/registers/search_results'
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: ecoportal-api-v2
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.8. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.8.11
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Oscar Segura
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2021- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-08-27 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -176,6 +176,7 @@ files: 
     | 
|
| 
       176 
176 
     | 
    
         
             
            - lib/ecoportal/api/common/content/doc_helpers.rb
         
     | 
| 
       177 
177 
     | 
    
         
             
            - lib/ecoportal/api/common/content/double_model.rb
         
     | 
| 
       178 
178 
     | 
    
         
             
            - lib/ecoportal/api/common/content/hash_diff_patch.rb
         
     | 
| 
      
 179 
     | 
    
         
            +
            - lib/ecoportal/api/common/content/model_helpers.rb
         
     | 
| 
       179 
180 
     | 
    
         
             
            - lib/ecoportal/api/common/content/string_digest.rb
         
     | 
| 
       180 
181 
     | 
    
         
             
            - lib/ecoportal/api/common/content/wrapped_response.rb
         
     | 
| 
       181 
182 
     | 
    
         
             
            - lib/ecoportal/api/v2.rb
         
     | 
| 
         @@ -184,6 +185,8 @@ files: 
     | 
|
| 
       184 
185 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/action.rb
         
     | 
| 
       185 
186 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/action_field.rb
         
     | 
| 
       186 
187 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/chart_field.rb
         
     | 
| 
      
 188 
     | 
    
         
            +
            - lib/ecoportal/api/v2/page/component/chart_field/benchmark.rb
         
     | 
| 
      
 189 
     | 
    
         
            +
            - lib/ecoportal/api/v2/page/component/chart_field/config.rb
         
     | 
| 
       187 
190 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/chart_field/frequency.rb
         
     | 
| 
       188 
191 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/chart_field/heatmap.rb
         
     | 
| 
       189 
192 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/chart_field/indicator.rb
         
     | 
| 
         @@ -199,12 +202,14 @@ files: 
     | 
|
| 
       199 
202 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/files_field.rb
         
     | 
| 
       200 
203 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/gauge_field.rb
         
     | 
| 
       201 
204 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/gauge_stop.rb
         
     | 
| 
      
 205 
     | 
    
         
            +
            - lib/ecoportal/api/v2/page/component/geo_coordinates.rb
         
     | 
| 
       202 
206 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/geo_field.rb
         
     | 
| 
       203 
207 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/image.rb
         
     | 
| 
       204 
208 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/images_field.rb
         
     | 
| 
       205 
209 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/law_field.rb
         
     | 
| 
       206 
210 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/number_field.rb
         
     | 
| 
       207 
211 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/people_field.rb
         
     | 
| 
      
 212 
     | 
    
         
            +
            - lib/ecoportal/api/v2/page/component/people_viewable_field.rb
         
     | 
| 
       208 
213 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/plain_text_field.rb
         
     | 
| 
       209 
214 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/reference_field.rb
         
     | 
| 
       210 
215 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/rich_text_field.rb
         
     | 
| 
         @@ -213,6 +218,8 @@ files: 
     | 
|
| 
       213 
218 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/signature_field.rb
         
     | 
| 
       214 
219 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/component/tag_field.rb
         
     | 
| 
       215 
220 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/components.rb
         
     | 
| 
      
 221 
     | 
    
         
            +
            - lib/ecoportal/api/v2/page/permission_flags.rb
         
     | 
| 
      
 222 
     | 
    
         
            +
            - lib/ecoportal/api/v2/page/permit.rb
         
     | 
| 
       216 
223 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/section.rb
         
     | 
| 
       217 
224 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/sections.rb
         
     | 
| 
       218 
225 
     | 
    
         
             
            - lib/ecoportal/api/v2/page/stage.rb
         
     | 
| 
         @@ -224,6 +231,7 @@ files: 
     | 
|
| 
       224 
231 
     | 
    
         
             
            - lib/ecoportal/api/v2/registers.rb
         
     | 
| 
       225 
232 
     | 
    
         
             
            - lib/ecoportal/api/v2/registers/page_result.rb
         
     | 
| 
       226 
233 
     | 
    
         
             
            - lib/ecoportal/api/v2/registers/register.rb
         
     | 
| 
      
 234 
     | 
    
         
            +
            - lib/ecoportal/api/v2/registers/search_results.rb
         
     | 
| 
       227 
235 
     | 
    
         
             
            - lib/ecoportal/api/v2/registers/stage_result.rb
         
     | 
| 
       228 
236 
     | 
    
         
             
            - lib/ecoportal/api/v2/registers/stages_result.rb
         
     | 
| 
       229 
237 
     | 
    
         
             
            - lib/ecoportal/api/v2/registers/template.rb
         
     |