Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2828 #2

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ gem 'jquery-ui-rails'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'factory_bot_rails'
gem 'faker'
end

group :development do
gem 'rspec-rails', '~> 3.7'
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
Expand Down
30 changes: 29 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
crass (1.0.3)
diff-lcs (1.3)
erubi (1.7.1)
execjs (2.7.0)
factory_bot (4.11.0)
activesupport (>= 3.0.0)
factory_bot_rails (4.11.0)
factory_bot (~> 4.11.0)
railties (>= 3.0.0)
faker (1.9.1)
i18n (>= 0.7)
ffi (1.9.23)
foundation-rails (6.4.3.0)
railties (>= 3.1.0)
Expand Down Expand Up @@ -155,6 +163,23 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
ruby_dep (1.5.0)
rubyzip (1.2.1)
sass (3.4.25)
Expand Down Expand Up @@ -214,6 +239,8 @@ DEPENDENCIES
capybara (~> 2.15)
chromedriver-helper
coffee-rails (~> 4.2)
factory_bot_rails
faker
foundation-rails
jbuilder (~> 2.5)
jquery-rails
Expand All @@ -222,6 +249,7 @@ DEPENDENCIES
pg
puma (~> 3.11)
rails (~> 5.2.0.rc1)
rspec-rails (~> 3.7)
sass-rails (~> 5.0)
selenium-webdriver
spring
Expand All @@ -235,4 +263,4 @@ RUBY VERSION
ruby 2.5.0p0

BUNDLED WITH
1.16.1
1.16.4
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import 'installations';
@import 'foundation_and_overrides';
@import 'consulproject'
13 changes: 13 additions & 0 deletions app/assets/stylesheets/installations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.installations {
.top-bar {
height: auto;

ul {
background-color: unset;

.button {
color: white;
}
}
}
}
25 changes: 24 additions & 1 deletion app/controllers/installations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,27 @@ def show
@installation = Installation.find(params[:id])
end

end
def new
@installation = Installation.new
end

def create
@installation = Installation.new(installation_params)

respond_to do |format|
if @installation.save
format.html { redirect_to @installation, notice: 'installation was successfully created.' }
format.json { render :show, status: :created, location: @installation }
else
format.html { render :new }
format.json { render json: @installation.errors, status: :unprocessable_entity }
end
end
end

private
def installation_params
params.require(:installation).permit(:name, :repo, :website, :contact_name, :conact_email, :location, :organization_type, :status, :notes)
end

end
15 changes: 15 additions & 0 deletions app/helpers/installations_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module InstallationsHelper

def organization_type_for_select
Installation.organization_types.map do |organization_type, _|
[I18n.t("activerecord.attributes.installation.organization_types.#{organization_type}"), organization_type]
end
end

def installation_status_for_select
Installation.installation_statuses.map do |installation_status, _|
[I18n.t("activerecord.attributes.installation.installation_statuses.#{installation_status}"), installation_status]
end
end

end
17 changes: 16 additions & 1 deletion app/models/installation.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
class Installation < ActiveRecord::Base
delegate :last_commit, :lines_diff, :files_changed, :diff_url, to: :github

enum organization_type: {
government: 'government',
ngo: 'ngo',
university: 'university',
school: 'school',
other: 'other',
}
enum installation_status: {
in_progress: 'in_progress',
in_production: 'in_production',
}

validates :name, presence: true
validates :repo, presence: true, uniqueness: true

def github
Installation::Github.new(self)
end

end
end
110 changes: 110 additions & 0 deletions app/views/installations/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<%= form_with(model: installation, local: true) do |form| %>
<% if installation.errors.any? %>
<div id="error_explanation" class="callout alert" data-closable>
<h2><%= pluralize(installation.errors.count, "error") %> prohibited this installation from being saved:</h2>

<ul>
<% installation.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<button class="close-button" aria-label="Dismiss alert" type="button" data-close="">
<span aria-hidden="true">×</span>
</button>
</div>
<% end %>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :name, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.text_field :name %>
</div>
</div>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :repo, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.text_field :repo %>
</div>
</div>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :website, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.text_field :website %>
</div>
</div>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :contact_name, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.text_field :contact_name %>
</div>
</div>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :conact_email, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.text_field :conact_email %>
</div>
</div>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :location, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.text_field :location %>
</div>
</div>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :organization_type, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.select :organization_type, organization_type_for_select %>
</div>
</div>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :status, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.select :status, installation_status_for_select %>
</div>
</div>

<div class="grid-x grid-padding-x">
<div class="small-3 cell">
<%= form.label :notes, class: "text-right middle" %>
</div>

<div class="small-9 cell">
<%= form.text_field :notes %>
</div>
</div>

<div class="actions columns small-offset-9 large-offset-10">
<%= form.submit class: 'button' %>
</div>
<% end %>
39 changes: 25 additions & 14 deletions app/views/installations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
<div class="grid-container" data-equalizer data-equalize-on="medium">
<div class="grid-container installations" data-equalizer data-equalize-on="medium">
<div class="grid-x grid-margin-x">
<div class="cell margin__top">
<nav aria-label="<%= t("breadcrumbs.you_are_here") %>" role="navigation">
<ul class="breadcrumbs">
<li>
<span class="show-for-sr"><%= t("breadcrumbs.current") %></span>
<%= t("installations.index.breadcrumb") %>
</li>
</ul>
</nav>
<div class="cell margin__top margin__bottom">
<div class="top-bar">
<div class="top-bar-left">
<nav aria-label="<%= t("breadcrumbs.you_are_here") %>" role="navigation">
<ul class="breadcrumbs">
<li>
<span class="show-for-sr"><%= t("breadcrumbs.current") %></span>
<%= t("installations.index.breadcrumb") %>
</li>
</ul>
</nav>

<h1 class="title">
<%= image_tag('icons/terminal.svg', alt: "") %>
<%= t("installations.index.title") %>
</h1>
<h1 class="title">
<%= image_tag('icons/terminal.svg', alt: "") %>
<%= t("installations.index.title") %>
</h1>
</div>
<div class="top-bar-right">
<ul class="menu">
<li>
<%= link_to t('helpers.link.new', model: 'Installation'), new_installation_path, class: 'button' %>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions app/views/installations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="grid-container" data-equalizer data-equalize-on="medium">
<div class="grid-x grid-margin-x">
<div class="cell margin__top">
<h1>New Installation</h1>
</div>
</div>

<div class="grid-x page__content">
<div class="cell margin__top">
<%= render 'form', installation: @installation %>
</div>

<div class="cell margin__top">
<%= link_to 'Back', installations_path %>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ class Application < Rails::Application
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.

config.active_record.schema_format = :sql
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Rails.application.routes.draw do
resources :installations, only: [:index, :show]
resources :installations, only: [:index, :show, :new, :create]
root 'installations#index'
get '/dashboard' => 'installations#index'
end
Loading