Skip to content

Commit

Permalink
Andet commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0Truck committed Mar 21, 2014
1 parent 5e303d5 commit a4ad834
Show file tree
Hide file tree
Showing 25 changed files with 433 additions and 89 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ end
# Use ActiveModel has_secure_password
gem 'bcrypt-ruby', :require => "bcrypt"

#uploads
gem 'carrierwave'
gem 'rmagick'
gem 'mini_magick'

# Use unicorn as the app server
# gem 'unicorn'

Expand Down
20 changes: 20 additions & 0 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ImagesController < ApplicationController

def index
@images = Image.all
end

def create
@upload = Image.new(params[:uploads])

respond_to do |format|
if @upload.save
format.html { redirect_to upload_path(@upload), notice: 'Upload Lykkedes.' }
format.json { render action: 'show', status: :created, location: @upload }
else
format.html { render action: 'new' }
format.json { render json: @upload.errors, status: :unprocessable_entity }
end
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create

respond_to do |format|
if @setting.save
format.html { redirect_to @setting, notice: 'Setting was successfully created.' }
format.html { redirect_to root_path, notice: 'Setting was successfully created.' }
format.json { render action: 'show', status: :created, location: @setting }
else
format.html { render action: 'new' }
Expand All @@ -43,7 +43,7 @@ def create
def update
respond_to do |format|
if @setting.update(setting_params)
format.html { redirect_to @setting, notice: 'Setting was successfully updated.' }
format.html { redirect_to root_path, notice: 'Setting was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
Expand Down
74 changes: 74 additions & 0 deletions app/controllers/upload_sections_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
class UploadSectionsController < ApplicationController
before_action :set_upload_section, only: [:show, :edit, :update, :destroy]

# GET /upload_sections
# GET /upload_sections.json
def index
@upload_sections = UploadSection.all
end

# GET /upload_sections/1
# GET /upload_sections/1.json
def show
end

# GET /upload_sections/new
def new
@upload_section = UploadSection.new
end

# GET /upload_sections/1/edit
def edit
end

# POST /upload_sections
# POST /upload_sections.json
def create
@upload_section = UploadSection.new(upload_section_params)

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

# PATCH/PUT /upload_sections/1
# PATCH/PUT /upload_sections/1.json
def update
respond_to do |format|
if @upload_section.update(upload_section_params)
format.html { redirect_to @upload_section, notice: 'Upload section was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @upload_section.errors, status: :unprocessable_entity }
end
end
end

# DELETE /upload_sections/1
# DELETE /upload_sections/1.json
def destroy
@upload_section.destroy
respond_to do |format|
format.html { redirect_to upload_sections_url }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_upload_section
@upload_section = UploadSection.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def upload_section_params
params.require(:upload_section).permit(:section_id, :upload_id)
end
end
8 changes: 5 additions & 3 deletions app/controllers/uploads_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
class UploadsController < ApplicationController
before_action :set_upload, only: [:show, :edit, :update, :destroy]

Expand All @@ -24,11 +25,12 @@ def edit
# POST /uploads
# POST /uploads.json
def create
@upload = Upload.new(upload_params)

@upload = Upload.new(params[:uploads])

respond_to do |format|
if @upload.save
format.html { redirect_to @upload, notice: 'Upload was successfully created.' }
format.html { redirect_to @upload, notice: 'Upload Lykkedes.' }
format.json { render action: 'show', status: :created, location: @upload }
else
format.html { render action: 'new' }
Expand All @@ -42,7 +44,7 @@ def create
def update
respond_to do |format|
if @upload.update(upload_params)
format.html { redirect_to @upload, notice: 'Upload was successfully updated.' }
format.html { redirect_to @upload, notice: 'Ændringer gemt.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
Expand Down
7 changes: 7 additions & 0 deletions app/models/image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Image < ActiveRecord::Base
self.table_name = 'uploads'
has_many :sections, through: :upload_sections

attr_accessible :title, :size, :filetype, :file
mount_uploader :file, ImageUploader
end
2 changes: 1 addition & 1 deletion app/models/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Page < ActiveRecord::Base
has_many :users, through: :user_pages
belongs_to :page
has_many :pages

has_many :sections
attr_accessible :name, :order, :page_id

def self.first_level
Expand Down
2 changes: 2 additions & 0 deletions app/models/section.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Section < ActiveRecord::Base

has_many :users, through: :user_sections
has_many :uploads, through: :upload_sections
belongs_to :page

end
5 changes: 5 additions & 0 deletions app/models/upload.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
class Upload < ActiveRecord::Base

has_many :sections, through: :upload_sections

attr_accessible :title, :size, :filetype, :file
mount_uploader :file, UploadUploader
end
66 changes: 66 additions & 0 deletions app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class ImageUploader < CarrierWave::Uploader::Base
require 'carrierwave/processing/mini_magick'
include CarrierWave::MiniMagick

# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
# include Sprockets::Helpers::RailsHelper
# include Sprockets::Helpers::IsolatedHelper

# 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/upload/#{mounted_as}/#{model.id}"
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:
# # 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_fill => [75, 75]
end

version :small do
process :resize_to_limit => [100, 100]
end

version :medium do
process :resize_to_limit => [300, 300]
end

version :large do
process :resize_to_limit => [800, 600]
end

version :gallery do
process :resize_to_fill => [972, 350]
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
# "something.jpg" if original_filename
# end

end
44 changes: 44 additions & 0 deletions app/uploaders/upload_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class UploadUploader < CarrierWave::Uploader::Base

# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
# include Sprockets::Helpers::RailsHelper
# include Sprockets::Helpers::IsolatedHelper

# 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/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
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:
# # 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

# 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(doc docx xlsx odt pdf)
end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end

end
7 changes: 7 additions & 0 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
%h1
Velkommen til
= @setting.name
%section
%article
= raw @setting.info

- if current_user.admin?
.row
.col-xs-4
= link_to 'Redigér', edit_setting_path(1), class: 'btn btn-primary'
2 changes: 1 addition & 1 deletion app/views/pages/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
.form-group
.col-xs-12
.btn-group
= submit_tag 'Opret', :class => 'btn btn-primary'
= submit_tag 'Gem', :class => 'btn btn-primary'
= link_to 'Annuller', root_path, class: 'btn btn-default'
65 changes: 35 additions & 30 deletions app/views/settings/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
= form_for @setting do |f|
= simple_form_for @setting do |f|
- if @setting.errors.any?
#error_explanation
%h2= "#{pluralize(@setting.errors.count, "error")} prohibited this setting from being saved:"
%ul
- @setting.errors.full_messages.each do |msg|
%li= msg

.field
= f.label :domain
= f.text_field :domain
.field
= f.label :name
= f.text_field :name
.field
= f.label :login
= f.number_field :login
.field
= f.label :footer
= f.number_field :footer
.field
= f.label :info
= f.text_area :info
.field
= f.label :analytics_api
= f.text_field :analytics_api
.field
= f.label :facebook
= f.text_field :facebook
.field
= f.label :googleplus
= f.text_field :googleplus
.field
= f.label :linkedin
= f.text_field :linkedin
.actions
= f.submit 'Save'
.row
.form-group
.col-xs-6
= f.input :domain, label: 'Domæne', as: :string, input_html: {size: 40, class: 'form-control'}
.col-xs-6
= f.input :name, label: 'Navn', as: :string, input_html: {size: 40, class: 'form-control'}
.row
.form-group
.col-xs-6
= f.input :login, label: 'Aktivér login', as: :boolean, input_html: {class: 'form-control'}
.col-xs-6
= f.input :footer, label: 'Aktivér footer', as: :boolean, input_html: {class: 'form-control'}
.row
.form-group
.col-xs-12
= f.input :info, label: 'Forside', as: :text, input_html: {size: 40, class: 'form-control'}
.row
.form-group
.col-xs-3
= f.input :analytics_api, label: 'Google Analytics API', as: :string, input_html: {size: 40, class: 'form-control'}
.col-xs-3
= f.input :googleplus, label: 'Google+ API', as: :string, input_html: {size: 40, class: 'form-control'}
.col-xs-3
= f.input :facebook, label: 'Facebook API', as: :string, input_html: {size: 40, class: 'form-control'}
.col-xs-3
= f.input :linkedin, label: 'LinkedIn API', as: :string, input_html: {size: 40, class: 'form-control'}
.row
%hr
.row
.form-group
.col-xs-12
.btn-group
= submit_tag 'Gem', :class => 'btn btn-primary'
= link_to 'Annuller', root_path, class: 'btn btn-default'
Loading

0 comments on commit a4ad834

Please sign in to comment.