-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc0fcde
commit 8314cfb
Showing
12 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class ProgramsController < ApplicationController | ||
before_action :authenticate_user! | ||
require_permission :can_view_programs? | ||
require_permission :can_edit_programs?, only: %i[create update] | ||
active_tab "inventory" | ||
|
||
def index | ||
@programs = Program.all.to_a | ||
end | ||
|
||
def new | ||
@program = Program.new | ||
end | ||
|
||
def create | ||
@program = Program.new | ||
@program.name = params[:name] | ||
@program.initialized_name = params[:initialized_name] | ||
@program.external_id = params[:external_id] | ||
@program.external_class_id = params[:external_class_id] | ||
@program.save! | ||
redirect_to programs_path, flash: { success: "Program successfully created!" } | ||
rescue ActiveRecord::RecordNotUnique | ||
flash.now[:error] = "Error, duplicate record detected!" | ||
render :new | ||
end | ||
|
||
def show | ||
@program = Program.find(params[:id]) | ||
end | ||
|
||
def update | ||
@program = Program.find(params[:id]) | ||
@program.name = params[:name] | ||
@program.initialized_name = params[:initialized_name] | ||
@program.external_id = params[:external_id] | ||
@program.external_class_id = params[:external_class_id] | ||
@program.save! | ||
redirect_to programs_path, flash: { success: "Program successfully updated!" } | ||
rescue ActiveRecord::RecordNotUnique | ||
flash.now[:error] = "Error, duplicate record detected!" | ||
render :show | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Users | ||
module ProgramManipulator | ||
extend ActiveSupport::Concern | ||
|
||
def can_view_programs? | ||
super_admin? | ||
end | ||
|
||
def can_edit_programs? | ||
super_admin? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<div class="form-group"> | ||
<label class="control-label" for="program-name">Program Name</label> | ||
<input type="text" class="form-control" id="program-name" name="name" placeholder="Program name" value="<%= program.name %>" data-guard="required" autocomplete="off" /> | ||
</div> | ||
</div> | ||
|
||
<div class="col-xs-3"> | ||
<div class="form-group"> | ||
<label class="control-label" for="program-external-id">External Id</label> | ||
<input type="text" class="form-control" id="program-external-id" name="external_id" placeholder="External Id" value="<%= program.external_id %>" data-guard="required int" autocomplete="off" /> | ||
</div> | ||
</div> | ||
|
||
<div class="col-xs-3"> | ||
<div class="form-group"> | ||
<label class="control-label" for="program-external-id">External Class Id</label> | ||
<input type="text" class="form-control" id="program-external-class-id" name="external_class_id" placeholder="External Class Id" value="<%= program.external_class_id %>" data-guard="required int" autocomplete="off" /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-xs-6"> | ||
<div class="form-group"> | ||
<label class="control-label" for="program-initials">Initials</label> | ||
<input type="text" class="form-control" id="program-initials" name="initialized_name" placeholder="Program name initials" value="<%= program.initialized_name %>" data-guard="required string" data-guard-string-max="8" autocomplete="off" /> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<% content_for :title, "Programs" %> | ||
<% content_for :tabs, render("items/tabs") %> | ||
<% content_for :content do %> | ||
<% if current_user.can_edit_programs? %> | ||
<h4 class="button-height"> | ||
<%= link_to "Create Program", new_program_path, class: "btn btn-primary bottom15 pull-right" %> | ||
</h4> | ||
<% end %> | ||
|
||
<table class="table table-hover table-striped data-table"> | ||
<thead> | ||
<tr> | ||
<th class="sort-asc">Name</th> | ||
<th>Initials</th> | ||
<th>External Id</th> | ||
<th>External Class Id</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @programs.each do |program| %> | ||
<tr data-href="<%= program_path(program) %>"> | ||
<td><%= program.name %></td> | ||
<td><%= program.initialized_name %></td> | ||
<td><%= program.external_id %></td> | ||
<td><%= program.external_class_id %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% content_for :title, "Create Program" %> | ||
<% content_for :tabs, render("items/tabs") %> | ||
<% content_for :content do %> | ||
<%= form_for @program, data: { live_guarded: true } do |f| %> | ||
<%= render partial: "programs/program_fields", locals: { fields: f, program: @program } %> | ||
<%= f.submit "Save", class: "btn btn-primary" %> | ||
<%= link_to "Cancel", programs_path, class: "btn btn-link" %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% content_for :title, "Edit Program #{@program.name}" %> | ||
<% content_for :tabs, render("items/tabs") %> | ||
<% content_for :content do %> | ||
<%= form_for @program, data: { live_guarded: true } do |f| %> | ||
<%= render partial: "programs/program_fields", locals: { fields: f, program: @program } %> | ||
<%= f.submit "Save", class: "btn btn-primary" %> | ||
<%= link_to "Cancel", programs_path, class: "btn btn-link" %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
db/migrate/20230510024940_add_initialized_name_to_programs.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class AddInitializedNameToPrograms < ActiveRecord::Migration[5.2] | ||
def up | ||
add_column :programs, :initialized_name, :string, limit: 8 | ||
add_index :programs, :initialized_name, unique: true | ||
|
||
Program.all.to_a.each do |program| | ||
program.initialized_name = program.name.gsub(/\b(\w)\w*?\b/, "\\1").gsub(/[\s\-]/, "") | ||
program.save! | ||
end | ||
|
||
change_column_null :programs, :initialized_name, false | ||
end | ||
|
||
def down | ||
remove_column :programs, :initialized_name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters