Skip to content

Commit

Permalink
Update develop - added access token and versioning with octokit (#19)
Browse files Browse the repository at this point in the history
* Add devise user views and set up stimulus

* Added octokit github version

* Add access_token github
  • Loading branch information
rossme committed Sep 16, 2023
1 parent 189984e commit 421c6f3
Show file tree
Hide file tree
Showing 29 changed files with 319 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ gem 'ruby-openai'
# Use simple_form
gem 'simple_form'

# Github API wrapper
gem 'octokit', '~> 5.0'

# Use Sass to process CSS
# gem "sassc-rails"

Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ GEM
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
octokit (5.6.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
orm_adapter (0.5.0)
parallel (1.23.0)
parser (3.2.2.3)
Expand Down Expand Up @@ -260,6 +263,9 @@ GEM
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
selenium-webdriver (4.9.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
Expand Down Expand Up @@ -324,6 +330,7 @@ DEPENDENCIES
faker
jbuilder
jsbundling-rails
octokit (~> 5.0)
pg
pry-byebug
puma (~> 5.0)
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module ApplicationHelper
alert: 'warning'
}.freeze

def latest_github_release
Octokit.latest_release('rossme/formless')&.tag_name
end

def remote_ip_address
request.remote_ip
end
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/prompts_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module PromptsHelper
end
1 change: 1 addition & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Entry point for the build script in your package.json
import "@hotwired/turbo-rails"
import "./controllers"

import * as bootstrap from "bootstrap"
21 changes: 21 additions & 0 deletions app/javascript/controllers/focus_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="focus"
export default class extends Controller {
static values = {
first: Number
}
connect() {
if (this.firstValue === 0) {
// Focus the element
this.element.focus();
// Add the highlight class to the div
this.element.classList.add('focus-action-element')

// Remove the highlight class after 2 seconds (adjust the time as needed)
setTimeout(() => {
this.element.classList.remove('focus-action-element');
}, 1000);
}
}
}
7 changes: 0 additions & 7 deletions app/javascript/controllers/hello_controller.js

This file was deleted.

7 changes: 5 additions & 2 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName

// $ yarn run build
// running the above helps recompile the controllers

import { application } from "./application"

import HelloController from "./hello_controller"
application.register("hello", HelloController)
import FocusController from "./focus_controller"
application.register("focus", FocusController)
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class User < ApplicationRecord
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable
devise :database_authenticatable, :recoverable, :rememberable, :validatable

has_many :prompts, dependent: :destroy
has_many :clients, dependent: :destroy
Expand Down
14 changes: 14 additions & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row mx-5 pt-5 pb-2">
<p class="col-6 text-secondary fs-6 text-sm-start">
<code class="text-secondary fs-6">
<%#= remote_ip_address %>
</code>
</p>
<div class="col-6 link-underline-opacity-0 text-sm-end">
<code>
<%= link_to("https://www.github.com/rossme/formless", class: 'link-underline-opacity-0 text-secondary text-sm-end link-dark', target: '_blank') do %>
<%= "latest release: #{latest_github_release}" %> <i class="bi bi-github" class="text-secondary"></i>
<% end %>
</code>
</div>
</div>
6 changes: 1 addition & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
</head>

<body class="bg-light-subtle">
<div class="text-secondary text-sm-end container pt-4">
<code>
<%= remote_ip_address %>
</code>
</div>
<!-- Move to _flash partial -->
<div class="text-center">
<% flash.each do |key, value| %>
<div class="alert alert-<%= flash_class(key) %>" role="alert">
Expand Down
4 changes: 3 additions & 1 deletion app/views/prompts/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class="mx-2 mt-5">
<%= render 'layouts/header' %>

<div class="mx-2 mt-2">
<div class="row mx-4">
<div class="col-md-12 mb-4">
<div class="card">
Expand Down
6 changes: 4 additions & 2 deletions app/views/prompts/partials/_action.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

<div class="card-header">
<h6 class="lead text-center pt-2">Rails Application Action</h6>
</div>

<div class="card-body">
<% @prompts.each_with_index do |prompt, index| %>

<% @prompts.each do |prompt| %>
<div class="p-3 m-3">
<!-- Stimulus - a simple controller to focus on the first prompt -->
<div class="p-3 m-3" id="needs-focus" data-controller="focus" data-focus-first-value="<%= index %>">
<p class="my-2 text-secondary">
Prompt: <code><%= prompt.id %></code>
</p>
Expand Down
20 changes: 20 additions & 0 deletions app/views/users/confirmations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h2>Resend confirmation instructions</h2>

<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>
<%= f.full_error :confirmation_token %>

<div class="form-inputs">
<%= f.input :email,
required: true,
autofocus: true,
value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email),
input_html: { autocomplete: "email" } %>
</div>

<div class="form-actions">
<%= f.button :submit, "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "users/shared/links" %>
5 changes: 5 additions & 0 deletions app/views/users/mailer/confirmation_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>Welcome <%= @email %>!</p>

<p>You can confirm your account email through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
7 changes: 7 additions & 0 deletions app/views/users/mailer/email_changed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Hello <%= @email %>!</p>

<% if @resource.try(:unconfirmed_email?) %>
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
<% else %>
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
<% end %>
3 changes: 3 additions & 0 deletions app/views/users/mailer/password_change.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>Hello <%= @resource.email %>!</p>

<p>We're contacting you to notify you that your password has been changed.</p>
8 changes: 8 additions & 0 deletions app/views/users/mailer/reset_password_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
7 changes: 7 additions & 0 deletions app/views/users/mailer/unlock_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>

<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>

<p>Click the link below to unlock your account:</p>

<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
27 changes: 27 additions & 0 deletions app/views/users/passwords/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h2>Change your password</h2>

<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<%= f.input :reset_password_token, as: :hidden %>
<%= f.full_error :reset_password_token %>

<div class="form-inputs">
<%= f.input :password,
label: "New password",
required: true,
autofocus: true,
hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),
input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation,
label: "Confirm your new password",
required: true,
input_html: { autocomplete: "new-password" } %>
</div>

<div class="form-actions">
<%= f.button :submit, "Change my password" %>
</div>
<% end %>
<%= render "users/shared/links" %>
18 changes: 18 additions & 0 deletions app/views/users/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h2>Forgot your password?</h2>

<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<%= f.input :email,
required: true,
autofocus: true,
input_html: { autocomplete: "email" } %>
</div>

<div class="form-actions">
<%= f.button :submit, "Send me reset password instructions" %>
</div>
<% end %>
<%= render "users/shared/links" %>
35 changes: 35 additions & 0 deletions app/views/users/registrations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password,
hint: "leave it blank if you don't want to change it",
required: false,
input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation,
required: false,
input_html: { autocomplete: "new-password" } %>
<%= f.input :current_password,
hint: "we need your current password to confirm your changes",
required: true,
input_html: { autocomplete: "current-password" } %>
</div>

<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>

<h3>Cancel my account</h3>

<div>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete %></div>

<%= link_to "Back", :back %>
25 changes: 25 additions & 0 deletions app/views/users/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h2>Sign up</h2>

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<%= f.input :email,
required: true,
autofocus: true,
input_html: { autocomplete: "email" }%>
<%= f.input :password,
required: true,
hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),
input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation,
required: true,
input_html: { autocomplete: "new-password" } %>
</div>

<div class="form-actions">
<%= f.button :submit, "Sign up" %>
</div>
<% end %>
<%= render "users/shared/links" %>
32 changes: 32 additions & 0 deletions app/views/users/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="mx-2 mt-2 d-flex justify-content-center">
<div class="row m-4">
<div class="col-md-12 mb-4">
<div class="card">
<div class="card-header">
<h6 class="lead text-center pt-2">You can find login details on the formless github repo</h6>
</div>
<div class="row card-body m-4">
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email,
placeholder: 'Username',
label: false,
required: false,
autofocus: true,
input_html: { autocomplete: "email", class: 'form-control form-control-md mb-2' } %>
<%= f.input :password,
placeholder: 'Password',
label: false,
required: false,
input_html: { autocomplete: "current-password", class: 'form-control form-control-md' } %>
</div>

<div class="form-actions">
<%= f.button :submit, "Log in", class: 'btn btn-light text-secondary border mt-2' %>
</div>
<% end %>
</div>
</div>
</div>
</div>
</div>
15 changes: 15 additions & 0 deletions app/views/users/shared/_error_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if resource.errors.any? %>
<div id="error_explanation" data-turbo-cache="false">
<h2>
<%= I18n.t("errors.messages.not_saved",
count: resource.errors.count,
resource: resource.class.model_name.human.downcase)
%>
</h2>
<ul>
<% resource.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
Loading

0 comments on commit 421c6f3

Please sign in to comment.