Class: Integral::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/integral/router.rb

Overview

Handles Integral routing

Class Method Summary collapse

Class Method Details

.draw_backendObject

Draws backend routes



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/integral/router.rb', line 72

def self.draw_backend
  Integral::Engine.routes.draw do
    # Backend [User Only]
    scope Integral.backend_namespace do
      # User Authentication
      devise_for :users, class_name: 'Integral::User', module: :devise
    end

    namespace :backend, path: Integral.backend_namespace do
      get '/', to: 'static_pages#dashboard', as: 'dashboard'

      # User account Profile route
      get 'account', to: 'users#account'

      # User Management
      resources :users do
        get 'list', on: :collection
        member do
          put 'read_all_notifications'
          put 'read_notification'
          get 'notifications'
          put 'block'
          put 'unblock'
          get 'activities', controller: 'users'
          get 'activities/:activity_id', to: 'users#activity', as: :activity
        end
      end

      # Notification subscription management
      resources :notification_subscriptions, only: [:update]

      # File Management
      resources :storage_files, path: :storage do
        get 'list', on: :collection

        member do
          get 'activities', controller: 'storage_files'
          get 'activities/:activity_id', to: 'storage_files#activity', as: :activity
        end
      end

      # Reusable Blocks Management
      resources :block_lists do
        get 'list', on: :collection
        # member do
        #   post 'duplicate'
        #   get 'activities', controller: 'pages'
        #   get 'activities/:activity_id', to: 'pages#activity', as: :activity
        # end
      end

      # Page Management
      resources :pages do
        get 'list', on: :collection
        member do
          post 'duplicate'
          get 'activities', controller: 'pages'
          get 'activities/:activity_id', to: 'pages#activity', as: :activity
        end
      end

      # Activity Management
      resources :activities, only: %i[index] do
        collection do
          post 'widget'
        end
      end

      # Post Management
      if Integral.blog_enabled?
        resources :posts do
          get 'list', on: :collection
          member do
            post 'duplicate'
            get 'activities', controller: 'posts'
            get 'activities/:activity_id', to: 'posts#activity', as: :activity
          end
          # resources :comments, only: [:create, :destroy]
        end
        resources :categories, only: %i[create edit update destroy] do
          member do
            get 'activities', controller: 'categories'
            get 'activities/:activity_id', to: 'categories#activity', as: :activity
          end
        end
      end

      # List Management
      resources :lists do
        get 'list', on: :collection
        member do
          post 'duplicate'
          get 'activities', controller: 'lists'
          get 'activities/:activity_id', to: 'lists#activity', as: :activity
        end
      end

      # Settings Management
      resources :settings, only: %i[index create]
    end

    # Block Editor
    get '/wp/v2/types', to: 'backend/block_lists#wp_types'
    get '/wp/v2/types/wp_block', to: 'backend/block_lists#wp_type'
    get '/wp/v2/block_lists', to: 'backend/block_lists#block_lists'
    get '/wp/v2/block_list/:id', to: 'backend/block_lists#show'
    get '/wp/v2/blocks/:id', to: 'backend/block_lists#show'
    get '/wp/v2/media/:id', to: 'backend/storage_files#show'
  end
end

.draw_frontendObject

Draws frontend routes including dynamic pages and blog routes



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/integral/router.rb', line 33

def self.draw_frontend
  Integral::Engine.routes.draw do
    # Visitor enquiries & newsletter signups
    post 'contact', to: 'contact#contact'
    post 'newsletter_signup', to: 'contact#newsletter_signup'

    # Dynamic pages (URLs are rewritten in Integral::Middleware::AliasRouter)
    if Integral.multilingual_frontend?
      localized do
        resources :pages, only: %i[show]
      end
    else
      resources :pages, only: %i[show]
    end

    # Frontend Blog routes
    if Integral.blog_enabled?
      if Integral.multilingual_frontend?
        localized do
          scope Integral.blog_namespace do
            resources :tags, only: %i[index show]
            resources :categories, only: %i[show]
          end
          # Post Routing must go after tags otherwise it will override
          resources Integral.blog_namespace, only: %i[index show], as: :posts, controller: 'posts'
        end
      else
        scope Integral.blog_namespace do
          resources :tags, only: %i[index show]
          resources :categories, only: %i[show]
        end
        # Post Routing must go after tags otherwise it will override
        resources Integral.blog_namespace, only: %i[index show], as: :posts, controller: 'posts'
      end
    end
  end
end

.draw_rootObject

Draws root route



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/integral/router.rb', line 12

def self.draw_root
  Integral::Engine.routes.draw do
    if Integral.multilingual_frontend?
      localized do
        if Integral.dynamic_homepage_enabled?
          root 'pages#show'
        else
          root Integral.root_path
        end
      end
    else
      if Integral.dynamic_homepage_enabled?
        root 'pages#show'
      else
        root Integral.root_path
      end
    end
  end
end

.loadObject

Loads Integral routes



5
6
7
8
9
# File 'lib/integral/router.rb', line 5

def self.load
  draw_root
  draw_frontend
  draw_backend
end