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

Fixing Council pages, #150

Merged
merged 25 commits into from
Apr 6, 2015
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4d62846
Forgot two files
henrikssn Mar 26, 2015
45cd170
Fix post edit
henrikssn Mar 26, 2015
a8ed3f9
Merge current master
davidwessman Mar 29, 2015
6851ffa
Merge with updated cafebokning-branch
davidwessman Mar 29, 2015
83bde66
Fix Ability-model test
davidwessman Mar 29, 2015
0ead96d
Fixing lots on council, pages, posts
davidwessman Mar 30, 2015
49de625
Lots of fixes, removed ALL mentions of moderator?
davidwessman Mar 31, 2015
18bb994
Fixing Hound errors and page-errors
davidwessman Mar 31, 2015
1f09fee
Fixes Hound + errors in Posts
davidwessman Mar 31, 2015
4cd6adb
Fixes RentAbility
davidwessman Mar 31, 2015
194a984
Fixing locales and adding tests
davidwessman Apr 1, 2015
35b4b82
Fixing admin menu, creating more feature tests, reworking councils, p…
davidwessman Apr 1, 2015
004f205
Merge branch 'dev' of https://github.com/fsek/web into dev
davidwessman Apr 5, 2015
3b946eb
Merge branch 'FixCouncilPage' of https://github.com/fsek/web into dev
davidwessman Apr 5, 2015
24a41da
Fixing merge conflicts
davidwessman Apr 5, 2015
1da4464
New remove_profile, not tested
davidwessman Apr 5, 2015
b6cd4b6
Fixed CafeWork view and some abilities
davidwessman Apr 6, 2015
f0c9ea1
Hound fix
davidwessman Apr 6, 2015
75a1591
Merge conflict
davidwessman Apr 6, 2015
7366d2c
Fixing Hound-fixes
davidwessman Apr 6, 2015
5a67f6a
Hound fixes
davidwessman Apr 6, 2015
b45fe9b
Hound fixes
davidwessman Apr 6, 2015
a2a9da4
Fixed post distribution
davidwessman Apr 6, 2015
6de01d4
Hound fixes
davidwessman Apr 6, 2015
f712c89
Hound fixes
davidwessman Apr 6, 2015
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
3 changes: 2 additions & 1 deletion app/assets/javascripts/cafe_works.js.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jQuery ->
$('.datetimepicker').datetimepicker locale: 'sv', format: 'DD/MM/YYYY HH:mm'
$('.datetimepicker').datetimepicker
format: 'DD/MM/YYYY HH:mm'
jQuery ->
$('#date').datepicker()
jQuery ->
Expand Down
7 changes: 6 additions & 1 deletion app/assets/javascripts/rents.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
jQuery ->
$('.datetimepicker1').datetimepicker
format: 'DD/MM/YYYY HH:mm'
$('.datetimepicker2').datetimepicker
format: 'DD/MM/YYYY HH:mm'
loadCalendar = ->
$('#bilkalender').fullCalendar
events: '/bil',
Expand Down Expand Up @@ -35,4 +40,4 @@ $('document').ready ->
else
$('.after_disclaimer').hide()
if $('#rent_disclaimer').is(':checked')
$('.after_disclaimer').show()
$('.after_disclaimer').show()
20 changes: 1 addition & 19 deletions app/controllers/admin/rents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Admin::RentsController < ApplicationController
load_permissions_and_authorize_resource
before_action :set_rent, only: [:show, :update, :destroy, :preview]
before_action :set_councils, only: [:new, :show]

def main
Expand All @@ -18,11 +17,10 @@ def preview
def create
@rent = Rent.new_with_status(rent_params, nil)
flash[:notice] = 'Bokningen skapades' if @rent.save(validate: false)
respond_with @rent
redirect_to @rent
end

def new
@rent = Rent.new
end

def update
Expand All @@ -37,22 +35,6 @@ def destroy

private

def authenticate
flash[:error] = t('the_role.access_denied')
redirect_to(:back) unless (current_user) && (current_user.moderator?(:bil))
rescue ActionController::RedirectBackError
redirect_to root_path
end

# Makes sure that a rent is found, otherwise redirects to admin page
def set_rent
@rent = Rent.find_by_id(params[:id])
if (@rent == nil)
flash[:notice] = 'Hittade ingen bilbokning med det ID:t.'
redirect_to(:admin_car)
end
end

# To set the councils
def set_councils
@councils = Council.all
Expand Down
226 changes: 50 additions & 176 deletions app/controllers/albums_controller.rb
Original file line number Diff line number Diff line change
@@ -1,214 +1,88 @@
# encoding:UTF-8
class AlbumsController < ApplicationController
load_permissions_and_authorize_resource
load_and_authorize_resource :image, through: :album
before_action :set_edit
before_action :set_album, except: [:index,:new,:create,:settings]
before_action :categories

def index
@albums = Album.order('start_date asc')
@albums_latest = Album.order('created_at desc LIMIT 4')

if (params[:id] != nil) && (params[:datum] != "")
@id = params[:id]
@datum = Date.parse(params[:datum])
if @datum < Date.today
if @kategorier.find_by_id(@id)
@searched = Album.where(:start_date => @datum..Date.today).all
else
@searched = Album.where(:category => @kategorier.find(@id).name, :start_date => @datum...Date.today).all
end
end
elsif (params[:id]) && (params[:datum] == "" )
@id = params[:id]
@searched = Album.where(:category => @kategorier.find(@id).name)
end

@albums_latest = Album.order('created_at desc LIMIT 4')
end

def edit
if(params[:commit]) && (current_user) && (current_user.moderator?(:galleri))
if(params[:commit] == 'Markera alla')
@mark = true
elsif(params[:commit] == 'Ta bort markerade') && (params[:image_ids])
params[:image_ids].each { |img_id|
img = Image.find_by_id(img_id)
if(img)
img.destroy
end
}
flash.now[:notice] = 'De markerade bilderna togs bort.'
elsif(params[:commit] == 'Byt kategori') && (params[:image_ids]) && (params[:image_category])
params[:image_ids].each { |img_id|
img = Image.find_by_id(img_id)
if(img)
img.subcategory_id = params[:image_category]
img.save()
end
}
flash.now[:notice] = 'De markerade bilderna har nu kategorin: '+Subcategory.find_by_id(params[:image_category]).text
end
end


end

def settings
unless @kategori
@kategori = AlbumCategory.new
end
unless @kategorier
@kategorier = AlbumCategory.order('name desc')
end

if (params[:commit] == "Spara ny kategori") && (params[:album_category][:name] != nil)
@kategori.update(name: params[:album_category][:name],text: params[:album_category][:text],visible: params[:album_category][:visible])
if @kategori.save
flash.now[:notice] = 'Kategorin '[email protected]+' skapades till Bildgalleriet'
@kategorier = AlbumCategory.order('name desc')
@kategori = AlbumCategory.new
end
end

if (params[:commit] == 'Spara kategori') && (params[:album_category][:id].nil? == false)
@kategorin = AlbumCategory.find(params[:album_category][:id])
@kategorin.update(name: params[:album_category][:name],text: params[:album_category][:text],visible: params[:album_category][:visible])
if @kategorin.save
@kategorier = AlbumCategory.unscoped.order('name desc')
flash.now[:notice] = 'Kategorin '[email protected]+' uppdaterades till Bildgalleriet'
end
end

if (params[:commit] == 'Ta bort kategori')&&(params[:album_category])
@category = AlbumCategory.find_by_id(params[:album_category][:id]).destroy
@kategorier = AlbumCategory.all
flash.now[:notice] = 'Kategorin togs bort'
end

unless @subcategory
@subcategory = Subcategory.new
end
unless @subcategories
@subcategories = Subcategory.order('text desc')
end

if (params[:commit] == "Spara ny underkategori") && (params[:subcategory][:text] != nil)
@subcategory.update(text: params[:subcategory][:text])
if @subcategory.save
flash.now[:notice] = 'Underkategorin '[email protected]+' skapades till Bildgalleriet'
@subcategory = Subcategory.new()

end
end

if (params[:commit] == 'Spara underkategori') && (params[:subcategory][:id].nil? == false)
@subcategory = Subcategory.find(params[:subcategory][:id].nil? == false)
@subcategory.update(text: params[:subcategory][:text])
if @subcategory.save
@subcategories = Subcategory.unscoped.order('text desc')
flash.now[:notice] = 'Underkategorin '[email protected]+' uppdaterades till Bildgalleriet'
end
end

if (params[:commit] == 'Ta bort underkategori')&&(params[:subcategory][:id].nil? == false)
@category = Subcategory.find(params[:subcategory][:id]).destroy
@subcategories = Subcategory.unscoped.order('text desc')
flash.now[:notice] = 'Kategorin togs bort'
end
end

def show

# TODO add Settings somewhere else

def show
if (@album.images)
@images = @album.images.order('foto_file_name asc')
else
@images = nil
end
@images = nil
end
end

def new
@album = Album.new
end

def create
@album = Album.new(album_params)
@album.update(author: current_user.profile)
respond_to do |format|
if @album.save
format.html { redirect_to @album, notice: 'Albumet skapades!' }
format.json { render :json => @album, :status => :created, :location => @album }
else
format.html { render action: "new" }
format.json { render json: @album.errors, status: :unprocessable_entity }
end
end
@album.author = current_user.profile
if @album.save
redirect_to @album, notice: 'Albumet skapades!'
else
render action: :new
end
end
def destroy

def destroy
@album.destroy
respond_to do |format|
format.html { redirect_to albums_url,notice: 'Albumet raderades.' }
format.json { head :no_content }
end
redirect_to albums_url, notice: 'Albumet raderades.'
end

def destroy_images
for image in @album.images
image.destroy
end
respond_to do |format|
format.html { redirect_to @album, notice: 'Bilderna tog borts!' }
format.json { render :json => @album, :location => @album }
end
redirect_to @album, notice: 'Bilderna tog borts!'
end

def upload_images
if (params[:fotos]) && (params[:subcategory_id])
#===== The magic is here ;)
@count = 1
@total = params[:fotos].count
params[:fotos].each { |foto|
flash[:notice] =("Laddar upp "+@count.to_s+"/"+@total.to_s)
@album.images.create(foto: foto,subcategory_id: params[:subcategory_id])
@count = @count+1;
}
flash[:notice] =("Färdig! Laddat upp "+@total.to_s+" bilder.")
end
#===== The magic is here ;)
@count = 1
@total = params[:fotos].count
params[:fotos].each do |foto|
flash[:notice] = %(Laddar upp #{@count}/#{@total})
@album.images.create(foto: foto, subcategory_id: params[:subcategory_id])
@count = @count + 1
end
flash[:notice] = %(Färdig! Laddat upp #{@total} bilder.)
end
end

def update
respond_to do |format|
if @album.update_attributes(album_params)
format.html { redirect_to edit_album_path(@album), :notice => 'Albumet uppdaterades!' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @album.errors, :status => :unprocessable_entity }
end
if @album.update(album_params)
redirect_to edit_album_path(@album), notice: 'Albumet uppdaterades!'
else
render action: :edit
end
end
private
def authenticate

redirect_to(:back) unless (current_user) && (current_user.moderator?(:galleri))

rescue ActionController::RedirectBackError
redirect_to root_path
end

private

def categories
@kategorier = AlbumCategory.order('name desc')
@subcategories = Subcategory.order('text desc')
end
def set_album
@album = Album.find(params[:id])
@kategorier = AlbumCategory.order('name desc')
@subcategories = Subcategory.order('text desc')
end

def set_edit
if (current_user) && (current_user.moderator?(:galleri))
@edit = true
else
@edit = false
end
end
def image_params
params.fetch(:image,{}).permit(:album_id,:subcategory_id)
@edit = can? :manage, Album
end

def album_params
params.fetch(:album,{}).permit(:title,:description,:author,:location,:public,:start_date,:end_date,:album_category_ids => [],:subcategory_ids => [],images_parameters: [:id, :foto])
params.require(:album).permit(:title, :description, :author, :location,
:public, :start_date, :end_date, album_category_ids: [],
subcategory_ids: [], images_parameters: [:id, :foto])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align the elements of a hash literal if they span more than one line.

end
end
7 changes: 5 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ class ApplicationController < ActionController::Base
before_action :set_locale

rescue_from CanCan::AccessDenied do |ex|
flash[:error] = ex.message
render text: '', layout: true, status: :forbidden
if current_user.nil?
redirect_to :new_user_session, alert: ex.message
else
redirect_to :root, alert: ex.message
end
end

rescue_from ActiveRecord::RecordInvalid do |ex|
Expand Down
10 changes: 2 additions & 8 deletions app/controllers/councils_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# encoding:UTF-8
class CouncilsController < ApplicationController
load_permissions_and_authorize_resource find_by: :url
before_action :set_page, only: :show
load_and_authorize_resource :post, through: :council
before_action :set_page, only: [:show, :edit]
before_action :set_councils

def index
end

def show
if @page
@mainelements = @page.page_elements.where(visible: true,
sidebar: false).order(:displayIndex, :asc)
@sidebarelements = @page.page_elements.where(visible: true,
sidebar: true).order(:displayIndex, :asc)
end
@poster = @council.posts
end

Expand All @@ -26,7 +21,6 @@ def edit

def create
if @council.save
@council.build_page!(council_id: @council.id)
redirect_to edit_council_path(@council), notice: 'Utskott skapades, success.'
else
render action: 'new'
Expand Down
Loading