-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
4d62846
Forgot two files
henrikssn 45cd170
Fix post edit
henrikssn a8ed3f9
Merge current master
davidwessman 6851ffa
Merge with updated cafebokning-branch
davidwessman 83bde66
Fix Ability-model test
davidwessman 0ead96d
Fixing lots on council, pages, posts
davidwessman 49de625
Lots of fixes, removed ALL mentions of moderator?
davidwessman 18bb994
Fixing Hound errors and page-errors
davidwessman 1f09fee
Fixes Hound + errors in Posts
davidwessman 4cd6adb
Fixes RentAbility
davidwessman 194a984
Fixing locales and adding tests
davidwessman 35b4b82
Fixing admin menu, creating more feature tests, reworking councils, p…
davidwessman 004f205
Merge branch 'dev' of https://github.com/fsek/web into dev
davidwessman 3b946eb
Merge branch 'FixCouncilPage' of https://github.com/fsek/web into dev
davidwessman 24a41da
Fixing merge conflicts
davidwessman 1da4464
New remove_profile, not tested
davidwessman b6cd4b6
Fixed CafeWork view and some abilities
davidwessman f0c9ea1
Hound fix
davidwessman 75a1591
Merge conflict
davidwessman 7366d2c
Fixing Hound-fixes
davidwessman 5a67f6a
Hound fixes
davidwessman b45fe9b
Hound fixes
davidwessman a2a9da4
Fixed post distribution
davidwessman 6de01d4
Hound fixes
davidwessman f712c89
Hound fixes
davidwessman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -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]) | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.