Module: Adminix::Setup::Views

Defined in:
lib/adminix/setup/views.rb

Class Method Summary collapse

Class Method Details

.complete_view(_assigns) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/adminix/setup/views.rb', line 99

def self.complete_view(_assigns)
  layout do
    panel(title: 'Application setup process completed') do
      %{
        <p>Your application setup is completed.
      }
    end
  end
end

.connect_service_view(assigns) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/adminix/setup/views.rb', line 79

def self.connect_service_view(assigns)
  layout do
    panel(title: 'Connect existing service') do
      %{
        <form method="POST" action="/connect-service?t=#{assigns[:token]}">
          <div class="form-group">
            <label for="service_id">Please select service to connect</label>
            <select class="form-control" name="service[id]" id="service_id">
              #{(assigns[:services].map { |s| "<option value='#{s['id']}'>#{s['name']}</option>" }).join('')}
            </select>
          </div>
          <button type="submit" class="btn btn-primary">Launch your service</button>
          <br/><br/>
          <a href="/create-service?t=#{assigns[:token]}" title="Connect service">Want to create a new one? Create service</a>
        </form>
      }
    end
  end
end

.create_service_view(assigns) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/adminix/setup/views.rb', line 64

def self.create_service_view(assigns)
  layout do
    panel(title: 'Create service') do
      %{
        <form method="POST" action="/create-service?t=#{assigns[:token]}">
          #{form_group('name', type: 'text', name: 'service[name]', label: 'Service name', placeholder: 'Please enter your service name')}
          <button type="submit" class="btn btn-primary" onclick="location.href='/complete';">Launch your service</button>
          <br/><br/>
          #{assigns[:service_exists] ? "<a href=\"/connect-service?t=#{assigns[:token]}\" title=\"Connect service\">Already have an existing service? Choose it</a>" : ''} 
        </form>
      }
    end
  end
end

.error_view(_assigns) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/adminix/setup/views.rb', line 109

def self.error_view(_assigns)
  layout do
    panel(title: 'Something went wrong') do
      %{
        <p>Something went wrong please retry a process.</p>
      }
    end
  end
end

.flash(text, type = 'danger') ⇒ Object



169
170
171
# File 'lib/adminix/setup/views.rb', line 169

def self.flash(text, type='danger')
  %{<div class="alert alert-#{type}">#{text}</div>}
end

.form_group(id, assigns) ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/adminix/setup/views.rb', line 173

def self.form_group(id, assigns)
  %{
    <div class="form-group">
      <label for="#{id}">#{assigns[:label]}</label>
      <input type="#{assigns[:type]}" name="#{assigns[:name]}" value="#{assigns[:value]}" class="form-control" id="#{id}" placeholder="#{assigns[:placeholder]}">
    </div>
  } 
end

.layoutObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/adminix/setup/views.rb', line 121

def self.layout
  %{
    <html>
      <head>
        <title>Adminix setup</title>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
      </head>
      <body>
        <div class="container">
          #{yield}
        </div>
          <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
      </body>
    </html>
  }
end

.login_view(assigns) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/adminix/setup/views.rb', line 24

def self.(assigns)
  session = assigns[:session] || {}
  errors = assigns[:errors] || []
  layout do
    panel(title: 'Login') do
      %{
        <form method="POST" action="/login">
          #{form_group('email', type: 'email', name: 'session[email]', label: 'Email', placeholder: 'Please enter your email', value: session[:email])}
          #{form_group('password', type: 'password', name: 'session[password]', label: 'Password', placeholder: 'Please enter your password')}
          #{errors.count != 0 ? render_errors(errors) : ''}
          <button type="submit" class="btn btn-primary">Login</button>
          <br/><br/>
          <a href="/sign-up" title="Sign up">New to Adminix? Create a FREE account</a>
        </form>
      }
    end
  end
end

.panel(assigns) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/adminix/setup/views.rb', line 139

def self.panel(assigns)
  %{
    <div class="row">
      <div class="col-md-offset-2 col-md-8">
        <div class="panel panel-default">
          <div class="panel-heading clearfix">
            <i class="icon-calendar"></i>
            <h3 class="panel-title">#{assigns[:title]}</h3>
          </div>
        <div class="panel-body">
          <div class="row">
            <div class="col-md-6 col-md-offset-3">
              #{yield}
            </div>
          </div>
        </div>
      </div>
    </div>
  }
end

.render_errors(errors) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/adminix/setup/views.rb', line 160

def self.render_errors(errors)
  flash (errors.map { |k,v| "#{v}<br/>" }).join('<br/>')
  text = errors.map do |attr, errors|
    (errors.map { |err| "#{attr} #{err}" }).join('<br/>')
  end.join('<br/>')

  flash(text)
end

.root_view(_assigns) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/adminix/setup/views.rb', line 3

def self.root_view(_assigns)
  layout do
    %{
      <div class="row">
        <div class="col-md-6 col-md-offset-3">
          <br/>
          <a href="http://adminix.io" title="Adminix website" target="_blank">
            <img src="http://www.adminix.io/images/logo_square.jpg" alt="Adminix logo" class="img-responsive center-block" style="width: 130px" />
          </a>
          <br/>
          <p>Thank you for using Adminix image!</p>
          <p>Your application is almost deployed, please click on "Continue" button to finish setup process.</p>
          <button type="button" class="btn btn-primary" onclick="location.href='/sign-up';">Continue</button>
          <br/><br/>
          <a href="http://adminix.io" title="Adminix website" target="_blank">Click to visit our website</a>
        </div>
      </div>
    }
  end
end

.sign_up_view(assigns) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/adminix/setup/views.rb', line 43

def self.(assigns)
  user = assigns[:user] || {}
  errors = assigns[:errors] || []
  layout do
    panel(title: 'Create a FREE Adminix account') do
      %{
        <form method="POST" action="/sign-up">
          #{form_group('first_name', type: 'text', name: 'user[first_name]', label: 'First name', placeholder: 'Please enter your first name', value: user[:first_name])}
          #{form_group('last_name', type: 'text', name: 'user[last_name]', label: 'Last name', placeholder: 'Please enter your last name', value: user[:last_name])}
          #{form_group('email', type: 'email', name: 'user[email]', label: 'Email', placeholder: 'Please enter your email', value: user[:email])}
          #{form_group('password', type: 'password', name: 'user[password]', label: 'Password', placeholder: 'Please enter your password')}
          #{errors.count != 0 ? render_errors(errors) : ''}
          <button type="submit" class="btn btn-primary">Sign up</button>
          <br/><br/>
          <a href="/login" title="Login">Already have an account? Login</a>
        </form>
      }
    end
  end
end