Klaus V2.0

This commit is contained in:
Florian Bogenhard
2014-08-11 01:35:48 +02:00
parent 4a1a0937d4
commit cedeffd2c6
55 changed files with 1267 additions and 40 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

+8
View File
@@ -15,3 +15,11 @@
*= require rails_bootstrap_forms
*= require_self
*/
.navbar {
margin-bottom: 0px;
}
.page-header{
margin-top: 0px;
padding-top: 0px;
}
+47
View File
@@ -0,0 +1,47 @@
class DocTypesController < ApplicationController
before_filter :authenticate_user!, :only => [:destroy, :edit, :update ]
def index
@doc_types_grid = initialize_grid(DocType)
end
def new
@doc_type = DocType.new
end
def create
@doc_type = DocType.new(doc_type_param)
if @doc_type.save
redirect_to documents_path, notice: 'DocType was successfully created.'
else
flash.now[:alert] = 'DocType creation failed.'
render 'new'
end
end
def edit
@doc_type = DocType.find(params[:id])
end
def update
@doc_type = DocType.find(params[:id])
if @doc_type.update(doc_type_param)
redirect_to doc_types_path, notice: 'DocType was successfully updated.'
else
flash.now[:alert] = 'DocType update failed.'
render 'new'
end
end
def destroy
@doc_type = DocType.find(params[:id])
@doc_type.destroy
redirect_to doc_types_path, notice: 'DocType was successfully destroyed.'
end
private
def doc_type_param
params.require(:doc_type).permit(:name)
end
end
+31 -3
View File
@@ -1,6 +1,8 @@
class DocumentsController < ApplicationController
before_filter :authenticate_user!, :only => [:destroy, :edit, :update ]
def index
@documents_grid = initialize_grid(Document)
@documents_grid = initialize_grid(Document, include: [:lesson, :doc_type, :semester, :professor])
end
def new
@@ -13,13 +15,39 @@ class DocumentsController < ApplicationController
if @document.save
redirect_to documents_path, notice: 'Document was successfully created.'
else
lash.now[:alert] = 'Document creation failed.'
flash.now[:alert] = 'Document creation failed.'
render 'new'
end
end
def edit
@document = Document.find(params[:id])
end
def update
@document = Document.find(params[:id])
if @document.update(document_update_params)
redirect_to documents_path, notice: 'Document was successfully updated.'
else
flash.now[:alert] = 'Document update failed.'
render 'new'
end
end
def destroy
@document = Document.find(params[:id])
@document.destroy
redirect_to documents_path, notice: 'Document was successfully destroyed.'
end
private
def document_params
params.require(:document).permit(:name)
params.require(:document).permit(:doc_type_id, :semester_id, :professor_id, :file, :file_cache, :lesson_id)
end
def document_update_params
params.require(:document).permit(:doc_type_id, :semester_id, :professor_id, :lesson_id)
end
end
+47
View File
@@ -0,0 +1,47 @@
class LessonsController < ApplicationController
before_filter :authenticate_user!, :only => [:destroy, :edit, :update ]
def index
@lessons_grid = initialize_grid(Lesson)
end
def new
@lesson = Lesson.new
end
def create
@lesson = Lesson.new(lesson_params)
if @lesson.save
redirect_to documents_path, notice: 'Lesson was successfully created.'
else
flash.now[:alert] = 'Lesson creation failed.'
render 'new'
end
end
def edit
@lesson = Lesson.find(params[:id])
end
def update
@lesson = Lesson.find(params[:id])
if @lesson.update(lesson_params)
redirect_to lessons_path, notice: 'Lesson was successfully updated.'
else
flash.now[:alert] = 'Lesson update failed.'
render 'new'
end
end
def destroy
@lesson = Lesson.find(params[:id])
@lesson.destroy
redirect_to lessons_path, notice: 'Lesson was successfully destroyed.'
end
private
def lesson_params
params.require(:lesson).permit(:name, :short_name)
end
end
+46
View File
@@ -0,0 +1,46 @@
class ProfessorsController < ApplicationController
before_filter :authenticate_user!, :only => [:destroy, :edit, :update ]
def index
@professors_grid = initialize_grid(Professor)
end
def new
@professor = Professor.new
end
def create
@professor = Professor.new(professor_params)
if @professor.save
redirect_to documents_path, notice: 'Professor was successfully created.'
else
flash.now[:alert] = 'Professor creation failed.'
render 'new'
end
end
def edit
@professor = Professor.find(params[:id])
end
def update
@professor = Professor.find(params[:id])
if @professor.update(professor_params)
redirect_to professors_path, notice: 'Professor was successfully updated.'
else
flash.now[:alert] = 'Professor update failed.'
render 'new'
end
end
def destroy
@professor = Professor.find(params[:id])
@professor.destroy
redirect_to professors_path, notice: 'Professor was successfully destroyed.'
end
private
def professor_params
params.require(:professor).permit(:first_name, :last_name)
end
end
+47
View File
@@ -0,0 +1,47 @@
class SemestersController < ApplicationController
before_filter :authenticate_user!, :only => [:destroy, :edit, :update ]
def index
@semesters_grid = initialize_grid(Semester)
end
def new
@semester = Semester.new
end
def create
@semester = Semester.new(semester_params)
if @semester.save
redirect_to documents_path, notice: 'Semester was successfully created.'
else
flash.now[:alert] = 'Semester creation failed.'
render 'new'
end
end
def edit
@semester = Semester.find(params[:id])
end
def update
@semester = Semester.find(params[:id])
if @semester.update(semester_params)
redirect_to semesters_path, notice: 'Semester was successfully updated.'
else
flash.now[:alert] = 'Semester update failed.'
render 'new'
end
end
def destroy
@semester = Semester.find(params[:id])
@semester.destroy
redirect_to semesters_path, notice: 'Semester was successfully destroyed.'
end
private
def semester_params
params.require(:semester).permit(:name)
end
end
+13
View File
@@ -0,0 +1,13 @@
module ToDropdown
extend ActiveSupport::Concern
def to_option
[name, id]
end
module ClassMethods
def to_dropdown
all.order(:name).map(&:to_option)
end
end
end
+10
View File
@@ -0,0 +1,10 @@
class DocType < ActiveRecord::Base
include ToDropdown
has_many :documents
auto_strip_attributes :name, squish: true
auto_strip_attributes :name, nullify: true
validates :name, presence: true
validates :name, uniqueness: true
end
+21 -1
View File
@@ -1,3 +1,23 @@
class Document < ActiveRecord::Base
validates :name, presence: true
belongs_to :doc_type
belongs_to :professor
belongs_to :semester
belongs_to :lesson
mount_uploader :file, DocumentUploader
validates :doc_type_id, presence: true
validates :professor_id, presence: true
validates :semester_id, presence: true
validates :lesson_id, presence: true
validates_presence_of :file
validates_integrity_of :file
validates_processing_of :file
before_validation :set_position
private
def set_position
self.position = (Document.where(doc_type: self.doc_type, professor: self.professor, semester: self.semester, lesson: self.lesson).maximum(:position) || 0) + 1
end
end
+13
View File
@@ -0,0 +1,13 @@
class Lesson < ActiveRecord::Base
include ToDropdown
has_many :documents
auto_strip_attributes :name, squish: true
auto_strip_attributes :name, nullify: true
auto_strip_attributes :short_name, squish: true
auto_strip_attributes :short_name, nullify: true
validates :name, presence: true
validates :name, uniqueness: true
end
+28
View File
@@ -0,0 +1,28 @@
class Professor < ActiveRecord::Base
include ToDropdown
has_many :documents
auto_strip_attributes :first_name, squish: true
auto_strip_attributes :first_name, nullify: true
auto_strip_attributes :last_name, squish: true
auto_strip_attributes :last_name, nullify: true
validates :first_name, presence: true
validates :last_name, presence: true
def name_last_first
"#{self.last_name}, #{self.first_name}"
end
def name_first_name
"#{self.first_name} #{self.last_name}"
end
def to_option
[name_last_first, id]
end
def self.to_dropdown
all.order(:last_name, :first_name).map(&:to_option)
end
end
+10
View File
@@ -0,0 +1,10 @@
class Semester < ActiveRecord::Base
include ToDropdown
has_many :documents
auto_strip_attributes :name, squish: true
auto_strip_attributes :name, nullify: true
validates :name, presence: true
validates :name, uniqueness: true
end
+5
View File
@@ -0,0 +1,5 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :trackable, :validatable
end
+51
View File
@@ -0,0 +1,51 @@
# encoding: utf-8
class DocumentUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/document"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :resize_to_fit => [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
def filename
return unless original_filename
"#{model.lesson.name}_#{model.professor.name_first_name}_#{model.semester.name}_#{model.position}.#{model.file.file.extension}".gsub(/[^a-zA-Z0-9ÄÖÜäöüß\.\-\+_]/, '')
end
end
+9
View File
@@ -0,0 +1,9 @@
h2 Sign in
= bootstrap_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
= f.email_field :email, autofocus: true
= f.password_field :password, autocomplete: "off"
- if devise_mapping.rememberable?
= f.check_box :remember_me
= f.submit
+5
View File
@@ -0,0 +1,5 @@
div.well
= bootstrap_form_for(@doc_type) do |f|
= f.text_field :name
= f.submit
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Typ - #{@doc_type.name}
= render 'form'
+18
View File
@@ -0,0 +1,18 @@
<% content_for :page_header do %>
Typ - Index
<% end %>
<%= grid(@doc_types_grid, upper_pagination_panel: true) do |g|
g.blank_slate content_tag(:div, "No records found", class: 'well')
g.column name: 'ID', attribute: 'id'
g.column name: 'Name', attribute: 'name'
g.column do |doc_type|
contant = content_tag(:div, class: 'btn-group') do
link = ''.html_safe
link.concat btn_link_to('Edit', edit_doc_type_path(doc_type), class: 'btn-xs btn-warning') if user_signed_in?
link.concat btn_link_to('Delete', doc_type_path(doc_type), method: "delete", :data => { confirm: 'Are you sure?' }, class: 'btn-xs btn-danger') if user_signed_in?
link
end
end
end
%>
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Neuer Typ
= render 'form'
+16 -4
View File
@@ -1,4 +1,16 @@
= bootstrap_form_for(@document) do |f|
= f.text_field :name
= f.submit
div.well
= bootstrap_form_for(@document, html: {multipart: true}) do |f|
= f.collection_select :doc_type_id, DocType.order(:name).all, :id, :name, prompt: true
= f.collection_select :semester_id, Semester.order(name: :desc).all, :id, :name, prompt: true
= f.collection_select :lesson_id, Lesson.order(:name).all, :id, :name, prompt: true
= f.collection_select :professor_id, Professor.order(:last_name).all, :id, :last_name, prompt: true
- if @document.new_record?
div.row
div.col-lg-6
= f.file_field :file
div.col-lg-6
- if @document.file_cache
= f.static_control label: 'Uploaded file'
= link_to @document.file.filename, @document.file_url
= f.hidden_field :file_cache, readonly: true
= f.submit
+32 -4
View File
@@ -1,5 +1,33 @@
<%= grid(@documents_grid, upper_pagination_panel: true) do |g|
g.column name: 'ID', attribute: 'id'
g.column name: 'Name', attribute: 'name'
<%
define_grid(@documents_grid, upper_pagination_panel: true) do |g|
g.blank_slate content_tag(:div, "No records found", class: 'well')
g.column name: 'Position', attribute: 'position'
g.column name: 'Semester', attribute: 'id', detach_with_id: 'semester_filter', model: 'Semester', custom_filter: Semester.to_dropdown do |document|
document.semester.name if document.semester
end
g.column name: 'Typ', attribute: 'id', detach_with_id: 'doc_type_filter', model: 'DocType', html:{class: 'text-center'}, custom_filter: DocType.to_dropdown do |document|
document.doc_type.name if document.doc_type
end
g.column name: 'Fach', attribute: 'id', detach_with_id: 'lesson_filter', model: 'Lesson', custom_filter: Lesson.to_dropdown do |document|
document.lesson.name if document.lesson
end
g.column name: 'Professor', attribute: 'id', detach_with_id: 'professor_filter', model: 'Professor', custom_filter: Professor.to_dropdown do |document|
document.professor.name_last_first if document.professor
end
g.column html:{class: 'text-center'} do |document|
contant = content_tag(:div, class: 'btn-group') do
link = ''.html_safe
link.concat btn_link_to('Download', document.file_url, class: 'btn-xs btn-primary')
link.concat btn_link_to('Edit', edit_document_path(document), class: 'btn-xs btn-warning') if user_signed_in?
link.concat btn_link_to('Delete', document_path(document), method: "delete", :data => { confirm: 'Are you sure?' }, class: 'btn-xs btn-danger') if user_signed_in?
link
end
end
end
%>
%>
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Dokument - #{@document.semester.name} / #{@document.professor.name} / #{@document.lesson.name} / #{@document.doc_type.name}
= render 'form'
+39 -5
View File
@@ -1,6 +1,40 @@
h1 Index
- content_for :page_header
| Dokumente - Index
- render 'grid'
p
= btn_link_to 'New', new_document_path, class: 'btn-primary'
= render 'grid'
div.col-lg-2.col-md-2.text-center
= image_tag 'QR-FS-Logo_-_fsmni.thm.de.png'
div.col-lg-10.col-md-10
div.panel.panel-default
div.panel-heading
h3.panel-title
| &nbsp;Filter
div
div.panel-body
div.form-horizontal
div.col-lg-6.col-md-11
div.form-group
label for="last_name_filter" class="col-sm-2 control-label" Professor
div class="col-sm-10"
= grid_filter @documents_grid, :professor_filter
div class="form-group"
label for="first_name_filter" class="col-sm-2 control-label" Fach
div class="col-sm-10"
= grid_filter @documents_grid, :lesson_filter
div class="col-lg-5 col-md-11"
div class="form-group"
label for="middle_name_filter" class="col-sm-2 control-label" Semester
div class="col-sm-10"
= grid_filter @documents_grid, :semester_filter
div class="form-group"
label for="id_filter" class="col-sm-2 control-label" Type
div class="col-sm-10"
= grid_filter @documents_grid, :doc_type_filter
div class="col-lg-1 col-md-1"
div class="form-group"
button class="btn btn-primary wg-external-submit-button" data-grid-name='grid' Submit
div class="col-lg-1 col-md-1"
div class="form-group"
button class="btn btn-default wg-external-reset-button" data-grid-name='grid' Reset
div.col-lg-12.col-md-12
== render_grid(@documents_grid)
+2
View File
@@ -1 +1,3 @@
- content_for :page_header
| Neues Dokument
== render 'form'
+22 -3
View File
@@ -10,14 +10,23 @@ html
nav.navbar.navbar-default role="navigation"
div.container-fluid
div.navbar-header
button.navbar-toggle type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
button.navbar-toggle type="button" data-toggle="collapse" data-target="#navbar"
spansr-only Toggle navigation
spanicon-bar
spanicon-bar
spanicon-bar
= link_to 'Klaus', root_path, class: 'navbar-brand'
div.collapse.navbar-collapse#bs-example-navbar-collapse-1
div.collapse.navbar-collapse#navbar
ul.nav.navbar-nav
li = link_to 'Übersicht', documents_path
li = link_to 'Neues Dokument', new_document_path
li = link_to 'Neuer Dokument Typ', new_doc_type_path
li = link_to 'Neuer Professor', new_professor_path
li = link_to 'Neues Semester', new_semester_path
li = link_to 'Neues Fach', new_lesson_path
div.container
div.page-header
h1 = content_for :page_header
- if notice
div.alert.alert-success.alert-dismissable
button type="button" class="close" data-dismiss="alert" aria-hidden="true"
@@ -28,4 +37,14 @@ html
button type="button" class="close" data-dismiss="alert" aria-hidden="true"
| &times;
= alert
= yield
= yield
footer.text-center
p
| CC BY-NC-SA - Fachschaft MNI - Technische Hochschule Mittelhessen
br
== "Index: #{link_to 'Type', doc_types_path} | #{link_to 'Fach', lessons_path} | #{link_to 'Professor', professors_path} | #{link_to 'Semester', semesters_path}"
br
- if user_signed_in?
= link_to 'Logout', destroy_user_session_path, method: :delete
- else
= link_to 'Login', new_user_session_path
+6
View File
@@ -0,0 +1,6 @@
div.well
= bootstrap_form_for(@lesson) do |f|
= f.text_field :name
= f.text_field :short_name
= f.submit
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Fach - #{@lesson.name}
= render 'form'
+19
View File
@@ -0,0 +1,19 @@
<% content_for :page_header do %>
Fach - Index
<% end %>
<%= grid(@lessons_grid, upper_pagination_panel: true) do |g|
g.blank_slate content_tag(:div, "No records found", class: 'well')
g.column name: 'ID', attribute: 'id'
g.column name: 'Name', attribute: 'short_name'
g.column name: 'Name', attribute: 'name'
g.column do |lesson|
contant = content_tag(:div, class: 'btn-group') do
link = ''.html_safe
link.concat btn_link_to('Edit', edit_lesson_path(lesson), class: 'btn-xs btn-warning') if user_signed_in?
link.concat btn_link_to('Delete', lesson_path(lesson), method: "delete", :data => { confirm: 'Are you sure?' }, class: 'btn-xs btn-danger') if user_signed_in?
link
end
end
end
%>
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Neues Fach
= render 'form'
+6
View File
@@ -0,0 +1,6 @@
div.well
= bootstrap_form_for(@professor) do |f|
= f.text_field :first_name
= f.text_field :last_name
= f.submit
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Professor - #{@professor.name}
= render 'form'
+19
View File
@@ -0,0 +1,19 @@
<% content_for :page_header do %>
Professor - Index
<% end %>
<%= grid(@professors_grid, upper_pagination_panel: true) do |g|
g.blank_slate content_tag(:div, "No records found", class: 'well')
g.column name: 'ID', attribute: 'id'
g.column name: 'First Name', attribute: 'first_name'
g.column name: 'Last Name', attribute: 'last_name'
g.column do |professor|
contant = content_tag(:div, class: 'btn-group') do
link = ''.html_safe
link.concat btn_link_to('Edit', edit_professor_path(professor), class: 'btn-xs btn-warning') if user_signed_in?
link.concat btn_link_to('Delete', professor_path(professor), method: "delete", :data => { confirm: 'Are you sure?' }, class: 'btn-xs btn-danger') if user_signed_in?
link
end
end
end
%>
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Neuer Professor
= render 'form'
+5
View File
@@ -0,0 +1,5 @@
div.well
= bootstrap_form_for(@semester) do |f|
= f.text_field :name
= f.submit
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Semester - #{@semester.name}
= render 'form'
+18
View File
@@ -0,0 +1,18 @@
<% content_for :page_header do %>
Semester - Index
<% end %>
<%= grid(@semesters_grid, upper_pagination_panel: true) do |g|
g.blank_slate content_tag(:div, "No records found", class: 'well')
g.column name: 'ID', attribute: 'id'
g.column name: 'Name', attribute: 'name'
g.column do |semester|
contant = content_tag(:div, class: 'btn-group') do
link = ''.html_safe
link.concat btn_link_to('Edit', edit_semester_path(semester), class: 'btn-xs btn-warning') if user_signed_in?
link.concat btn_link_to('Delete', semester_path(semester), method: "delete", :data => { confirm: 'Are you sure?' }, class: 'btn-xs btn-danger') if user_signed_in?
link
end
end
end
%>
+4
View File
@@ -0,0 +1,4 @@
- content_for :page_header
| Neues Semester
= render 'form'