From 4d628465b07a3c472f1bf4ec71f36c430b9840d7 Mon Sep 17 00:00:00 2001 From: Erik Henriksson Date: Thu, 26 Mar 2015 15:07:10 +0100 Subject: [PATCH 01/19] Forgot two files --- .../20410822171447_create_permission_posts.rb | 10 ++++++ spec/models/ability_spec.rb | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 db/migrate/20410822171447_create_permission_posts.rb create mode 100644 spec/models/ability_spec.rb diff --git a/db/migrate/20410822171447_create_permission_posts.rb b/db/migrate/20410822171447_create_permission_posts.rb new file mode 100644 index 000000000..e4e9b1645 --- /dev/null +++ b/db/migrate/20410822171447_create_permission_posts.rb @@ -0,0 +1,10 @@ +class CreatePermissionPosts < ActiveRecord::Migration + def change + create_table :permission_posts do |t| + t.integer :permission_id + t.integer :post_id + + t.timestamps null: false + end + end +end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb new file mode 100644 index 000000000..ebf905f4b --- /dev/null +++ b/spec/models/ability_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' +require 'cancan/matchers' + +describe Ability do + context 'default user' do + let(:user) { FactoryGirl.create(:user) } + let(:ability) { FactoryGirl.create(:user) } + subject(:ability) { Ability.new(user) } + + # Stuff everyone can do + it { should be_able_to :read, News.new } + + # Stuff everyone must not be able to do + it { should_not be_able_to :read, Constant.new } + it { should_not be_able_to :read, Album.new } + it { should_not be_able_to :read, Candidate.new } + it { should_not be_able_to :read, Event.new } + it { should_not be_able_to :read, Permission.new } + it { should_not be_able_to :read, Post.new } + it { should_not be_able_to :read, Profile.new } + it { should_not be_able_to :read, User.new } + end + + context 'admin user' do + let(:user) { FactoryGirl.create(:admin) } + let(:ability) { FactoryGirl.create(:user) } + subject(:ability) { Ability.new(user) } + + # Can do anything + it { should be_able_to :manage, :all } + end + +end From 45cd1703cb4aebdbce3e2e8f832c8f5a7389089c Mon Sep 17 00:00:00 2001 From: Erik Henriksson Date: Thu, 26 Mar 2015 16:09:42 +0100 Subject: [PATCH 02/19] Fix post edit --- app/controllers/councils_controller.rb | 26 ++++++++++---------------- app/controllers/posts_controller.rb | 2 +- app/models/council.rb | 7 ------- app/models/user.rb | 2 +- app/views/posts/_form.html.erb | 2 +- app/views/posts/index.html.erb | 3 ++- 6 files changed, 15 insertions(+), 27 deletions(-) diff --git a/app/controllers/councils_controller.rb b/app/controllers/councils_controller.rb index 9551b3ec8..092652115 100644 --- a/app/controllers/councils_controller.rb +++ b/app/controllers/councils_controller.rb @@ -2,22 +2,22 @@ class CouncilsController < ApplicationController load_permissions_and_authorize_resource before_action :set_council, only: [:show, :edit, :update, :destroy] + before_action :set_councils # GET /councils # GET /councils.json def index - @councils = Council.all end # GET /councils/1 # GET /councils/1.json def show - if (@page) + if @page @mainelements = @page.page_elements.where(visible: true,sidebar: false) @sidebarelements = @page.page_elements.where(visible:true,sidebar: true) - end - if(@mainelemnents) && (@mainelements.count > 1) - @mainelements = @mainelements.sort_by{ |x| x[:displayIndex]} + if @mainelements.count > 1 + @mainelements = @mainelements.sort_by{ |x| x[:displayIndex]} + end end @poster = @council.posts end @@ -80,20 +80,14 @@ def destroy private # Use callbacks to share common setup or constraints between actions. def set_council - @council = Council.find_by_url(params[:id]) - if(@council == nil) - @council = Council.find_by_id(params[:id]) - if(@council == nil) - flash[:notice] = 'Hittade inget utskott med ID/URL ' + params[:id]+'.' - redirect_to(:utskott) - else - flash[:notice] = 'Utskotten hittas med dess URL istället för ett ID' - redirect_to(council_path(@council.url)) - end - end + @council = Council.find_by_id(params[:id]) @page = @council.page end + def set_councils + @councils = Council.all + end + # Never trust parameters from the scary internet, only allow the white list through. def council_params params.require(:council).permit(:title,:url,:description,:president,:vicepresident,:public) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index ce65c664b..916f1f634 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -123,7 +123,7 @@ def set_post @post = Post.find(params[:id]) end def set_council - @council = Council.find_by_url(params[:council_id]) + @council = Council.find_by_id(params[:council_id]) end end diff --git a/app/models/council.rb b/app/models/council.rb index 20475e084..b3a0d184f 100644 --- a/app/models/council.rb +++ b/app/models/council.rb @@ -12,11 +12,4 @@ class Council < ActiveRecord::Base def to_s self.title end - def to_param - if (self.url) - self.url - else - self.id - end - end end diff --git a/app/models/user.rb b/app/models/user.rb index 56851ee31..4f2f3c60d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -34,7 +34,7 @@ def check_f_membership(civic) def is? role_name profile.posts.each do |post| - return true if post.name == role_name + return true if post.title == role_name end false end diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb index 5b584ac50..413c7eae3 100644 --- a/app/views/posts/_form.html.erb +++ b/app/views/posts/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for([@council,@post]) do |f| %> +<%= form_for(council_post_path(@council,@post)) do |f| %> <%= render 'shared/form_errors', current: @post%>
<%= f.label 'Titel', :class => 'reg-label'%> diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index 52fd20049..8adf8aa1f 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -27,7 +27,7 @@ g.column name: "Väljs av:", attribute: "elected_by",filter: false g.column name: "HT/VT?",attribute: "elected_at",filter: false - if @edit + if can? :edit, @post g.column do |post| link_to('Redigera', edit_council_post_path(post.council,post)) end @@ -41,6 +41,7 @@

<%=@post.title%>

<% if can? :edit, @post %> + <%= link_to 'Ändra posten', edit_council_post_path(@post.council, @post) %> <% if @post.profiles.size > 0 %>

Ta bort någon från posten.

<%= form_tag remove_profile_council_post_path(@post.council,@post), :method => :patch do%> From 83bde66661af2f9c7ae0442db2a39d19e2acc3a9 Mon Sep 17 00:00:00 2001 From: davidwessman Date: Mon, 30 Mar 2015 00:44:24 +0200 Subject: [PATCH 03/19] Fix Ability-model test --- spec/models/ability_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 9af7ef2ff..74720c513 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -28,9 +28,7 @@ it { should_not be_able_to :read, Constant.new } it { should_not be_able_to :read, Album.new } it { should_not be_able_to :read, Candidate.new } - it { should_not be_able_to :read, Event.new } it { should_not be_able_to :read, Permission.new } - it { should_not be_able_to :read, Post.new } it { should_not be_able_to :read, Profile.new } it { should_not be_able_to :read, User.new } end From 0ead96d47863e5c0075d65a599828aa88643f485 Mon Sep 17 00:00:00 2001 From: davidwessman Date: Tue, 31 Mar 2015 00:57:23 +0200 Subject: [PATCH 04/19] Fixing lots on council, pages, posts --- app/controllers/councils_controller.rb | 10 +-- app/controllers/old_gallery_controller.rb | 2 +- app/controllers/page_elements_controller.rb | 77 ++++------------- app/controllers/pages_controller.rb | 66 +++------------ app/controllers/posts_controller.rb | 78 +++++------------ app/helpers/application_helper.rb | 2 +- app/models/council.rb | 15 +++- app/models/page.rb | 22 ++++- app/models/page_element.rb | 18 ++-- app/models/post.rb | 44 ++++++---- app/models/profile.rb | 4 +- app/views/admin/cafe_works/new.html.erb | 4 +- app/views/admin/elections/edit.html.erb | 34 ++++---- app/views/albums/_form.html.erb | 32 +++---- app/views/albums/edit.html.erb | 6 +- app/views/albums/new.html.erb | 4 +- app/views/albums/upload_images.html.erb | 12 +-- app/views/cafe_works/_authorization.html.erb | 4 +- app/views/contacts/_form.html.erb | 18 ++-- app/views/contacts/edit.html.erb | 4 +- app/views/contacts/new.html.erb | 4 +- app/views/contacts/show.html.erb | 8 +- app/views/councils/_form.html.erb | 84 +++++++++---------- app/views/councils/_menu.html.erb | 8 ++ app/views/councils/edit.html.erb | 38 ++++----- app/views/councils/new.html.erb | 4 +- app/views/councils/show.html.erb | 10 ++- app/views/councils/show.json.jbuilder | 1 - app/views/devise/registrations/edit.html.erb | 36 ++++---- app/views/devise/registrations/new.html.erb | 18 ++-- app/views/devise/sessions/new.html.erb | 12 +-- app/views/documents/_form.html.erb | 20 ++--- app/views/documents/edit.html.erb | 4 +- app/views/documents/new.html.erb | 4 +- app/views/election/candidates/_form.html.erb | 22 ++--- .../election/candidates/candidate.html.erb | 8 +- app/views/election/candidates/index.html.erb | 6 +- app/views/election/candidates/new.html.erb | 4 +- app/views/election/candidates/show.html.erb | 4 +- app/views/election/nominations/_form.html.erb | 20 ++--- app/views/election/nominations/new.html.erb | 2 +- app/views/events/_form.html.erb | 36 ++++---- app/views/events/edit.html.erb | 4 +- app/views/events/new.html.erb | 4 +- app/views/faqs/edit.html.erb | 4 +- app/views/faqs/new.html.erb | 4 +- app/views/images/_form.html.erb | 14 ++-- app/views/images/new.html.erb | 4 +- app/views/images/show.html.erb | 4 +- app/views/layouts/_utskottmenu.html.erb | 8 -- app/views/layouts/application.html.erb | 2 +- app/views/menus/_form.html.erb | 81 ++++++++---------- app/views/news/_form.html.erb | 14 ++-- app/views/news/edit.html.erb | 4 +- app/views/news/new.html.erb | 4 +- app/views/notices/_form.html.erb | 6 +- app/views/notices/edit.html.erb | 2 +- app/views/notices/new.html.erb | 4 +- app/views/page_elements/_form.html.erb | 49 +++++------ .../page_elements/_page_element.html.erb | 26 ++++++ app/views/page_elements/edit.html.erb | 22 ++--- app/views/page_elements/index.html.erb | 54 ++++++------ app/views/page_elements/index.json.jbuilder | 4 - app/views/page_elements/new.html.erb | 4 +- app/views/page_elements/show.html.erb | 4 +- app/views/page_elements/show.json.jbuilder | 1 - app/views/pages/_form.html.erb | 38 +++++---- app/views/pages/_main.html.erb | 57 ------------- app/views/pages/_page.html.erb | 11 +++ app/views/pages/_sidebar.html.erb | 40 --------- app/views/pages/edit.html.erb | 4 +- app/views/pages/index.html.erb | 52 ++++++++---- app/views/pages/index.json.jbuilder | 4 - app/views/pages/new.html.erb | 4 +- app/views/pages/show.html.erb | 12 +-- app/views/pages/show.json.jbuilder | 1 - app/views/posts/_table.html.erb | 35 ++++++++ app/views/posts/edit.html.erb | 4 +- app/views/posts/new.html.erb | 4 +- app/views/profiles/_form.html.erb | 30 +++---- app/views/profiles/edit.html.erb | 4 +- app/views/proposals/form.html.haml | 4 +- app/views/short_links/_form.html.haml | 12 +-- app/views/work_posts/_form.html.erb | 48 +++++------ app/views/work_posts/edit.html.erb | 4 +- app/views/work_posts/new.html.erb | 4 +- config/routes.rb | 10 +-- .../20410822171449_add_fields_to_page.rb | 9 ++ ...171450_change_president_column_councils.rb | 8 ++ db/schema.rb | 12 ++- lib/tasks/tests_data.rake | 1 + spec/features/visit_a_council.rb | 13 +++ spec/models/council_spec.rb | 0 93 files changed, 744 insertions(+), 817 deletions(-) create mode 100644 app/views/councils/_menu.html.erb delete mode 100644 app/views/councils/show.json.jbuilder delete mode 100644 app/views/layouts/_utskottmenu.html.erb create mode 100644 app/views/page_elements/_page_element.html.erb delete mode 100644 app/views/page_elements/index.json.jbuilder delete mode 100644 app/views/page_elements/show.json.jbuilder delete mode 100644 app/views/pages/_main.html.erb create mode 100644 app/views/pages/_page.html.erb delete mode 100644 app/views/pages/_sidebar.html.erb delete mode 100644 app/views/pages/index.json.jbuilder delete mode 100644 app/views/pages/show.json.jbuilder create mode 100644 app/views/posts/_table.html.erb create mode 100644 db/migrate/20410822171449_add_fields_to_page.rb create mode 100644 db/migrate/20410822171450_change_president_column_councils.rb create mode 100644 spec/features/visit_a_council.rb create mode 100644 spec/models/council_spec.rb diff --git a/app/controllers/councils_controller.rb b/app/controllers/councils_controller.rb index bcd4da06b..cf645ca1f 100644 --- a/app/controllers/councils_controller.rb +++ b/app/controllers/councils_controller.rb @@ -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 @@ -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' diff --git a/app/controllers/old_gallery_controller.rb b/app/controllers/old_gallery_controller.rb index 303d52624..0b3bb028a 100644 --- a/app/controllers/old_gallery_controller.rb +++ b/app/controllers/old_gallery_controller.rb @@ -1,5 +1,5 @@ class OldGalleryController < ApplicationController - authorize_resource :class => false + authorize_resource class: false def index end end diff --git a/app/controllers/page_elements_controller.rb b/app/controllers/page_elements_controller.rb index c2362485f..751022b32 100644 --- a/app/controllers/page_elements_controller.rb +++ b/app/controllers/page_elements_controller.rb @@ -1,92 +1,45 @@ # encoding:UTF-8 class PageElementsController < ApplicationController - before_action :set_page_element, only: [:show, :edit, :update, :destroy] - before_action :set_council + before_action :load_permissions + load_and_authorize_resource :page, parent: true, find_by: :url + load_and_authorize_resource :page_element, through: :page - # GET /page_elements - # GET /page_elements.json def index - @page_elements = @page.page_elements - if (@page) - @mainelements = @page.page_elements.where(visible: true,sidebar: false) - @sidebarelements = @page.page_elements.where(visible:true,sidebar: true) - end - if(@mainelemnents) && (@mainelements.count > 1) - @mainelements = @mainelements.sort_by{ |x| x[:displayIndex]} - end - @poster = @council.posts - @rest = @page.page_elements.where(visible: false) end - # GET /page_elements/1 - # GET /page_elements/1.json def show end - # GET /page_elements/new def new - @page_element = PageElement.new() - @path = council_page_page_elements_path(@council) end - # GET /page_elements/1/edit def edit - - @path = council_page_page_element_path(@council,@page_element) end - # POST /page_elements - # POST /page_elements.json def create - @page_element = @page.page_elements.build(page_element_params) - - respond_to do |format| - if @page_element.save - format.html { redirect_to council_page_page_elements_path(@council), notice: 'Elementet skapades.' } - format.json { render action: 'show', status: :created, location: @page_element } - else - format.html { render action: 'new' } - format.json { render json: @page_element.errors, status: :unprocessable_entity } - end + if @page_element.save + redirect_to edit_page_page_element_path[@page, @page_element], notice: 'Elementet skapades' + else + render action: :new end end - # PATCH/PUT /page_elements/1 - # PATCH/PUT /page_elements/1.json def update - respond_to do |format| - if @page_element.update(page_element_params) - format.html { redirect_to council_page_page_elements_path(@council), notice: 'Elementet uppdaterades.' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @page_element.errors, status: :unprocessable_entity } - end + if @page_element.update(page_element_params) + redirect_to edit_page_page_element_path(@page, @page_element), notice: 'Elementet uppdaterades.' + else + render action: :edit end end - # DELETE /page_elements/1 - # DELETE /page_elements/1.json def destroy @page_element.destroy - respond_to do |format| - format.html { redirect_to council_page_page_elements_path(@council) } - format.json { head :no_content } - end + redirect_to @page end private - # Use callbacks to share common setup or constraints between actions. - def set_page_element - @page_element = PageElement.find(params[:id]) - end - def set_council - @council = Council.find_by_url(params[:council_id]) - @page = @council.page - end - # Never trust parameters from the scary internet, only allow the white list through. - def page_element_params - params.fetch(:page_element).permit(:page_id,:displayIndex, :sidebar, :visible,:text, :headline, :border, :name, :pictureR,:picture) - end + def page_element_params + params.fetch(:page_element).permit(:page_id, :displayIndex, :sidebar, :visible, :text, :headline, :border, :name, :pictureR, :picture) + end end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index c9f727db1..8475c802c 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,84 +1,40 @@ # encoding:UTF-8 class PagesController < ApplicationController - before_action :set_page, only: [:show, :edit, :update, :destroy] + load_permissions_and_authorize_resource find_by: :url - # GET /pages - # GET /pages.json def index - @pages = @page.page_elements end - # GET /pages/1 - # GET /pages/1.json def show - if (@page) - @mainelements = @page.page_elements.where(visible: true,sidebar: false) - @sidebarelements = @page.page_elements.where(visible:true,sidebar: true) - end - if(@mainelemnents) && (@mainelements.count > 1) - @mainelements = @mainelements.sort_by{ |x| x[:displayIndex]} - end - @poster = @council.posts end - # GET /pages/new def new - @page = Page.new end - # GET /pages/1/edit def edit end - # POST /pages - # POST /pages.json def create - @page = Page.new(page_params) - - respond_to do |format| - if @page.save - format.html { redirect_to @page, notice: 'Sidan skapades, success!.' } - format.json { render action: 'show', status: :created, location: @page } - else - format.html { render action: 'new' } - format.json { render json: @page.errors, status: :unprocessable_entity } - end - end + flash[:notice] = 'Sidan skapades, success!.' if @page.save + redirect_to @page end - # PATCH/PUT /pages/1 - # PATCH/PUT /pages/1.json def update - respond_to do |format| - if @page.update(page_params) - format.html { redirect_to @page, notice: 'Sidan uppdaterades, great!' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @page.errors, status: :unprocessable_entity } - end + if @page.update(page_params) + redirect_to @page, notice: 'Sidan uppdaterades, great!' + else + render action: :edit end end - # DELETE /pages/1 - # DELETE /pages/1.json def destroy @page.destroy - respond_to do |format| - format.html { redirect_to pages_url } - format.json { head :no_content } - end + redirect_to pages_url end private - # Use callbacks to share common setup or constraints between actions. - def set_page - @council = Council.find_by_url(params[:council_id]) - @page = @council.page - end - # Never trust parameters from the scary internet, only allow the white list through. - def page_params - params.fetch(:page).permit(:council_id) - end + def page_params + params.fetch(:page).permit(:council_id, :url, :visible, :title) + end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 988c4acb2..112302b81 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,27 +1,19 @@ # encoding:UTF-8 class PostsController < ApplicationController load_permissions_and_authorize_resource - before_action :set_council + load_resource :council, find_by: :url def remove_profile - @profile = Profile.find_by_id(params[:profile_id]) - @post.profiles.delete(@profile) - respond_to do |format| - format.html { redirect_to council_posts_path(@council), notice: @profile.name.to_s + ' har inte längre posten ' + @post.title.to_s + '.' } - end + profile = Profile.find_by_id(params[:profile_id]) + @post.remove_profile(profile) + redirect_to council_posts_path(@council), + notice: %(#{profile.full_name} har inte längre posten #{@post.title}.) end def add_profile_username @user = User.find_by(username: params[:username]) - if @user != nil - @profile = @user.profile - end - if @profile == nil - respond_to do |format| - format.html { redirect_to council_posts_path(@council), flash: {alert: 'Hittade ingen användare med det användarnamnet.'} } - end - elsif @profile.name.blank? - redirect_to council_posts_path(@council), flash: {alert: 'Användaren :"' + @user.username.to_s + '" måste fylla i fler uppgifter i sin profil.'} + if @post.add_profile(@user) + redirect_to council_posts_path(@council), flash: {alert: 'Hittade ingen användare med det användarnamnet.'} elsif @profile.posts.include?(@post) redirect_to council_posts_path(@council), flash: {alert: @profile.name.to_s + '(' + @user.username.to_s + ') har redan posten '+@post.title.to_s + '.'} elsif (@post.limit != nil) && (@post.profiles.size >= @post.limit) @@ -29,18 +21,11 @@ def add_profile_username else @post.profiles << @profile redirect_to council_posts_path(@council), notice: @profile.name.to_s + ' (' + @profile.user.username.to_s + ') tilldelades posten '+@post.title.to_s + '.' - if (@profile.first_post == nil) - @profile.update(first_post: @post.id) - end end end def index - if (@council) - @posts = @council.posts - else - @posts = Post.all - end + @posts = (@council.present?) ? @council.posts : Post.all @post_grid = initialize_grid(@posts) end @@ -58,45 +43,27 @@ def edit def create @councils = Council.order(title: :asc) @post = @council.posts.build(post_params) - respond_to do |format| - if @post.save - format.html { redirect_to council_posts_path(@council), notice: 'Posten skapades!' } - format.json { render action: 'show', status: :created, location: @post } - else - format.html { render action: 'new' } - format.json { render json: @posts.errors, status: :unprocessable_entity } - end + if @post.save + redirect_to council_posts_path(@council), notice: 'Posten skapades!' + else + render action: 'new' end end def update - respond_to do |format| - @post.attributes = post_params - @post.permissions = [] - @post.set_permissions(params[:permissions]) if params[:permissions] - if @post.save - @council2 = Council.find_by_id(params[:post][:council]) - if (@council2) && (@council2.equal?(@council) == false) - @council2.posts << @post - @council = @council2 - end - format.html { redirect_to edit_council_post_path(@council, @post), notice: 'Posten uppdaterades!' } - format.json { head :no_content } - else - @councils = Council.order(title: :asc) - format.html { render action: 'edit' } - format.json { render json: @post.errors, status: :unprocessable_entity } - end + @post.attributes = post_params + @post.permissions = [] + @post.set_permissions(params[:permissions]) if params[:permissions] + if @post.save + redirect_to edit_council_post_path(@post.council, @post), notice: 'Posten uppdaterades!' + else + render action: 'edit' end end def destroy - @post.profiles.clear @post.destroy - respond_to do |format| - format.html { redirect_to council_posts_path(@council) } - format.json { head :no_content } - end + redirect_to council_posts_path(@council) end def display @@ -112,9 +79,4 @@ def post_params :description, :elected_by, :elected_at, :styrelse, :car_rent, :council_id, :permissions) end - - def set_council - @council = Council.find_by_url(params[:council_id]) - end end - diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1d43c0a2a..fdc444e24 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -24,6 +24,6 @@ def form_group &block e['class'] = 'form-control ' end end - content_tag :div, raw(html.to_html), :class => 'form-group' + content_tag :div, raw(html.to_html), class: 'form-group' end end diff --git a/app/models/council.rb b/app/models/council.rb index bb9777431..1e3cce4e4 100644 --- a/app/models/council.rb +++ b/app/models/council.rb @@ -3,8 +3,8 @@ class Council < ActiveRecord::Base # Associations has_one :page, dependent: :destroy - belongs_to :president, foreign_key: :president, class_name: :Post - belongs_to :vice_president, foreign_key: :vice_president, class_name: :Post + belongs_to :president, foreign_key: :president_id, class_name: :Post + belongs_to :vice_president, foreign_key: :vicepresident_id, class_name: :Post has_many :posts has_many :profiles, through: :posts @@ -15,6 +15,17 @@ class Council < ActiveRecord::Base validates :title, :url, presence: true validates :url, uniqueness: true + after_update :check_page + + def check_page + if page.nil? + build_page(url: url,visible: true, title: title).save! + elsif page.url.nil? + page.update!(url: url, visible: true, title: title) + end + + end + def to_s title end diff --git a/app/models/page.rb b/app/models/page.rb index dd736bc20..306f14a82 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -1,5 +1,23 @@ # encoding: UTF-8 class Page < ActiveRecord::Base -belongs_to :council -has_many :page_elements + # Associations + belongs_to :council + has_many :page_elements + + # Validations + validates :url, uniqueness: true, if: 'url.present?' + + # Scopes + + def main + page_elements.main + end + + def side + page_elements.side + end + + def to_param + url.present? ? url : id + end end diff --git a/app/models/page_element.rb b/app/models/page_element.rb index fa1042717..fed045397 100644 --- a/app/models/page_element.rb +++ b/app/models/page_element.rb @@ -1,9 +1,15 @@ # encoding: UTF-8 class PageElement < ActiveRecord::Base - belongs_to :page - has_attached_file :picture, - :styles => { original: "4000x4000>", large: "1500x1500>", small: "250x250>",thumb: "100x100>" }, - :path => ":rails_root/public/system/images/sidor/element/:id/:style/:filename", - :url => "/system/images/sidor/element/:id/:style/:filename" - validates_attachment_content_type :picture, :content_type => /\Aimage\/.*\Z/ + belongs_to :page + has_attached_file :picture, + styles: {original: "4000x4000>", large: "1500x1500>", small: "250x250>", thumb: "100x100>"}, + path: ":rails_root/public/system/images/sidor/element/:id/:style/:filename", + url: "/system/images/sidor/element/:id/:style/:filename" + validates_attachment_content_type :picture, content_type: /\Aimage\/.*\Z/ + + scope :visible, -> { where(visible: true) } + scope :main, -> { visible.where(sidebar: false).index } + scope :side, -> { visible.where(sidebar: true).index } + scope :index, -> { order(:displayIndex) } + scope :rest, -> { where(visible: false) } end diff --git a/app/models/post.rb b/app/models/post.rb index c38e69a66..7a2ff6a06 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -4,33 +4,47 @@ class Post < ActiveRecord::Base belongs_to :council has_and_belongs_to_many :profiles has_many :nominations - has_many :candidates + has_many :candidates has_many :permission_posts has_many :permissions, through: 'permission_posts' # Scopes - scope :studierad, -> {where(elected_by: "Studierådet").order(council_id: :asc)} - scope :termins, -> {where(elected_by: "Terminsmötet").order(council_id: :asc)} + scope :studierad, -> { where(elected_by: "Studierådet").order(council_id: :asc) } + scope :termins, -> { where(elected_by: "Terminsmötet").order(council_id: :asc) } - scope :not_termins, -> {where.not(elected_by: "Terminsmötet").order(council_id: :asc)} + scope :not_termins, -> { where.not(elected_by: "Terminsmötet").order(council_id: :asc) } # Validations - validates_presence_of :limit,:recLimit, :description + validates :limit, :recLimit, :description, presence: true # Scopes - scope :renters, -> {where(car_rent:true)} - + scope :renters, -> { where(car_rent: true) } + def printLimit - if((recLimit == 0) && (limit == 0)) || (recLimit > limit ) + if recLimit == 0 && limit == 0 || recLimit > limit "*" - elsif(recLimit == limit) && (recLimit > 0) - limit.to_s + " (x)" - elsif(limit > 0) && (recLimit == 0) - limit.to_s - elsif(limit > recLimit) - recLimit.to_s + "-" + limit.to_s + elsif recLimit == limit && recLimit > 0 + %(#{limit} (x)) + elsif limit > 0 && recLimit == 0 + limit + elsif limit > recLimit + %(#{recLimit}- #{limit}) end - end + end + + def limited? + + end + def add_profile(profile) + if limited? + + end + end + + def remove_profile(profile) + profiles.delete(profile) + end + def set_permissions(permissions) permissions.each do |id| #find the main permission assigned from the UI diff --git a/app/models/profile.rb b/app/models/profile.rb index b21016f9e..37fb5412e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -6,6 +6,8 @@ class Profile < ActiveRecord::Base has_many :candidates has_many :rents has_many :councils, through: :posts + # TODO Change the first_post field to first_post_id + #belongs_to :first_post, foreign_key: first_post_id, class: Post # Attachment has_attached_file :avatar, @@ -26,7 +28,7 @@ def full_name # allowed to rent the car # /d.wessman def car_councils - self.councils.merge(Post.renters) + councils.merge(Post.renters) end # Check if profile has user data (name and lastname) diff --git a/app/views/admin/cafe_works/new.html.erb b/app/views/admin/cafe_works/new.html.erb index 2d2ffb2a4..5067eec97 100644 --- a/app/views/admin/cafe_works/new.html.erb +++ b/app/views/admin/cafe_works/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Cafejobb',nil, :class => 'reg-header'%> + <%= label_tag 'Cafejobb',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till cafebokning', :admin_cafe_works %>
-
\ No newline at end of file +
diff --git a/app/views/admin/elections/edit.html.erb b/app/views/admin/elections/edit.html.erb index 21159312f..18288535f 100644 --- a/app/views/admin/elections/edit.html.erb +++ b/app/views/admin/elections/edit.html.erb @@ -3,37 +3,37 @@
<%= form_for([:admin,@election]) do |f| %> - <%= label_tag 'Redigera val',nil, :class => 'reg-header'%>
- <%= f.label 'Huvudtext i nomineringsmejl', :class => 'reg-label'%> + <%= label_tag 'Redigera val',nil, class: 'reg-header'%>
+ <%= f.label 'Huvudtext i nomineringsmejl', class: 'reg-label'%>
- <%= f.text_area :nominate_mail,:class => 'form-control', size: "180x4" %> + <%= f.text_area :nominate_mail,class: 'form-control', size: "180x4" %>
- <%= f.label 'Huvudtext i valberedningens kandidaturmejl', :class => 'reg-label'%> + <%= f.label 'Huvudtext i valberedningens kandidaturmejl', class: 'reg-label'%>
- <%= f.text_area :candidate_mail,:class => 'form-control', size: "180x4" %> + <%= f.text_area :candidate_mail,class: 'form-control', size: "180x4" %>
- <%= f.label 'Huvudtext i kandidaturmejl för stjärnposter', :class => 'reg-label'%> + <%= f.label 'Huvudtext i kandidaturmejl för stjärnposter', class: 'reg-label'%>
- <%= f.text_area :candidate_mail_star,:class => 'form-control', size: "180x4" %> + <%= f.text_area :candidate_mail_star,class: 'form-control', size: "180x4" %>
- <%= f.label 'Extratext i styrelsemejl', :class => 'reg-label'%> + <%= f.label 'Extratext i styrelsemejl', class: 'reg-label'%>
- <%= f.text_area :extra_text,:class => 'form-control', size: "180x4" %> + <%= f.text_area :extra_text,class: 'form-control', size: "180x4" %>
- <%= f.label 'Text innan valet är öppet', :class => 'reg-label'%> + <%= f.label 'Text innan valet är öppet', class: 'reg-label'%>
- <%= f.text_area :text_before,:class => 'form-control', size: "180x4" %> + <%= f.text_area :text_before,class: 'form-control', size: "180x4" %>
- <%= f.label 'Text under valet', :class => 'reg-label'%> + <%= f.label 'Text under valet', class: 'reg-label'%>
- <%= f.text_area :text_during,:class => 'form-control', size: "180x4" %> + <%= f.text_area :text_during,class: 'form-control', size: "180x4" %>
- <%= f.label 'Text efter valet', :class => 'reg-label'%> + <%= f.label 'Text efter valet', class: 'reg-label'%>
- <%= f.text_area :text_after,:class => 'form-control', size: "180x4" %> + <%= f.text_area :text_after,class: 'form-control', size: "180x4" %>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
<%end%> <%= link_to 'Redigera inställningar', admin_election_path(@election) %>
@@ -94,4 +94,4 @@ Valberedningen

-
\ No newline at end of file + diff --git a/app/views/albums/_form.html.erb b/app/views/albums/_form.html.erb index d3fca1ccd..b496f27fd 100644 --- a/app/views/albums/_form.html.erb +++ b/app/views/albums/_form.html.erb @@ -11,35 +11,35 @@ <% end %>
- <%= f.label 'Titel', :class => 'reg-label'%> + <%= f.label 'Titel', class: 'reg-label'%>
- <%= f.text_field :title, :class => 'form-control',:placeholder => 'Titel'%> + <%= f.text_field :title, class: 'form-control',:placeholder => 'Titel'%>
- <%= f.label 'Beskrivning', :class => 'reg-label'%> + <%= f.label 'Beskrivning', class: 'reg-label'%>
- <%= f.text_area :description, :class => 'form-control',:placeholder => 'Beskrivning',size: "40x5" %> + <%= f.text_area :description, class: 'form-control',:placeholder => 'Beskrivning',size: "40x5" %>
- <%= f.label 'Plats', :class => 'reg-label'%> + <%= f.label 'Plats', class: 'reg-label'%>
- <%= f.text_field :location, :class => 'form-control',:placeholder => 'Plats',:autocomplete => 'off' %> + <%= f.text_field :location, class: 'form-control',:placeholder => 'Plats',:autocomplete => 'off' %>
- <%= f.label 'Start', :class => 'reg-label'%> + <%= f.label 'Start', class: 'reg-label'%>
- <%= f.date_field :start_date, :class => 'form-control' %> + <%= f.date_field :start_date, class: 'form-control' %>
- <%= f.label 'Slut', :class => 'reg-label'%> + <%= f.label 'Slut', class: 'reg-label'%>
- <%= f.date_field :end_date, :class => 'form-control' %> + <%= f.date_field :end_date, class: 'form-control' %>
- <%= f.label 'Kategori', :class => 'reg-label'%> + <%= f.label 'Kategori', class: 'reg-label'%> <%if @kategorier%>
<%for @cat in @kategorier%>
- <%= f.check_box(:album_category_ids,{multiple: true},@cat.id,nil)%><%= f.label :album_category_id, @cat.name, :value => false,:class => 'reg-label' %> + <%= f.check_box(:album_category_ids,{multiple: true},@cat.id,nil)%><%= f.label :album_category_id, @cat.name, :value => false,class: 'reg-label' %>
<%end%> Just nu kan man välja flera, men bara för att man kan, så behöver man inte göra det! :)
@@ -47,18 +47,18 @@
<%end%> <%if @subcategories%> - <%= f.label 'Underkategorier', :class => 'reg-label'%> + <%= f.label 'Underkategorier', class: 'reg-label'%> <%for @subcat in @subcategories%>
- <%= f.check_box(:subcategory_ids,{multiple: true},@subcat.id,nil)%><%= f.label :subcategory_id, @subcat.text, :value => false,:class => 'reg-label' %> + <%= f.check_box(:subcategory_ids,{multiple: true},@subcat.id,nil)%><%= f.label :subcategory_id, @subcat.text, :value => false,class: 'reg-label' %>
<%end%> <%= link_to 'Lägg till fler underkategorier?', settings_albums_path, target: "blank" %>
<%end%>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
<% end %> - \ No newline at end of file + diff --git a/app/views/albums/edit.html.erb b/app/views/albums/edit.html.erb index af4e9ff31..5c0d237c0 100644 --- a/app/views/albums/edit.html.erb +++ b/app/views/albums/edit.html.erb @@ -1,7 +1,7 @@
- <%= label_tag 'Redigera album',nil, :class => 'reg-header'%>
+ <%= label_tag 'Redigera album',nil, class: 'reg-header'%>
<% if @album.title %> <%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Visa album"), @album,class: 'btn btn-u' %> @@ -23,7 +23,7 @@ <%= select_tag :image_category, options_from_collection_for_select(@album.subcategories,:id,:text), include_blank: true, - :class => " listBox"%>

+ class: " listBox"%>

<%=submit_tag 'Byt kategori',class: "btn btn-u"%>
    <%for @image in @album.images%> @@ -38,4 +38,4 @@
<%end-%>
-
\ No newline at end of file +
diff --git a/app/views/albums/new.html.erb b/app/views/albums/new.html.erb index db63d52a3..94777add2 100644 --- a/app/views/albums/new.html.erb +++ b/app/views/albums/new.html.erb @@ -1,10 +1,10 @@
- <%= label_tag 'Nytt album',nil, :class => 'reg-header'%> + <%= label_tag 'Nytt album',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Visa album', @album %>
<%= link_to 'Tillbaka', :back %>
-
\ No newline at end of file +
diff --git a/app/views/albums/upload_images.html.erb b/app/views/albums/upload_images.html.erb index ab9d5092e..bc51be19c 100644 --- a/app/views/albums/upload_images.html.erb +++ b/app/views/albums/upload_images.html.erb @@ -1,7 +1,7 @@
- <%= label_tag 'Lägg till bilder i '+@album.title,nil, :class => 'reg-header'%> + <%= label_tag 'Lägg till bilder i '+@album.title,nil, class: 'reg-header'%> <%= form_for(@album,url: upload_images_album_path(@album), html: {multipart: true}) do |f| %> <% if @album.errors.any? %>
@@ -15,17 +15,17 @@ <% end %>
- <%= f.label 'Underkategori', :class => 'reg-label'%> + <%= f.label 'Underkategori', class: 'reg-label'%>
- <%= select_tag :subcategory_id, options_from_collection_for_select(@album.subcategories,:id,:text,@subcategory),{:class => 'form-control',include_blank: true}%> + <%= select_tag :subcategory_id, options_from_collection_for_select(@album.subcategories,:id,:text,@subcategory),{class: 'form-control',include_blank: true}%>
- <%= f.label 'Bilder', :class => 'reg-label'%> + <%= f.label 'Bilder', class: 'reg-label'%>
<%= file_field_tag "fotos[]", type: :file, multiple: true %>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
<% end %> @@ -36,4 +36,4 @@
<% # jquery image template # %> - \ No newline at end of file + diff --git a/app/views/cafe_works/_authorization.html.erb b/app/views/cafe_works/_authorization.html.erb index cdbdd9409..bae6835cf 100644 --- a/app/views/cafe_works/_authorization.html.erb +++ b/app/views/cafe_works/_authorization.html.erb @@ -1,5 +1,5 @@ <%=form_for(@cwork, url: authorize_cafe_work_url(@cwork), remote: true ) do |f|%> - <%= f.label 'Kod', :class => 'reg-label'%> + <%= f.label 'Kod', class: 'reg-label'%>
<%= f.text_field :access_code, value: nil, class: 'form-control'%> @@ -7,4 +7,4 @@
<%= f.submit "Auktorisera",class: 'btn-u pull-right' %>
-<%end%> \ No newline at end of file +<%end%> diff --git a/app/views/contacts/_form.html.erb b/app/views/contacts/_form.html.erb index 78a80d1d3..d8cb0eb4f 100644 --- a/app/views/contacts/_form.html.erb +++ b/app/views/contacts/_form.html.erb @@ -9,25 +9,25 @@
<% end %> - <%= f.label 'Titel', :class => "reg-label"%> + <%= f.label 'Titel', class: "reg-label"%>
- <%= f.text_field :name, :class => 'form-control',:placeholder => 'Titel'%> + <%= f.text_field :name, class: 'form-control',:placeholder => 'Titel'%>
- <%= f.label 'Beskrivning', :class => 'reg-label'%> + <%= f.label 'Beskrivning', class: 'reg-label'%>
- <%= f.text_area :text, :class => 'form-control',:placeholder => 'Varför ska man kontakta er?',:size => "45x4" %> + <%= f.text_area :text, class: 'form-control',:placeholder => 'Varför ska man kontakta er?',:size => "45x4" %>
- <%= f.label 'E-post', :class => 'reg-label'%> + <%= f.label 'E-post', class: 'reg-label'%>
Delas inte ut till någon. - <%= f.text_field :email, :class => 'form-control',:placeholder => 'Epost',:autocomplete => 'off' %> + <%= f.text_field :email, class: 'form-control',:placeholder => 'Epost',:autocomplete => 'off' %>
- <%= f.label 'Publik?', :class => 'reg-label'%> + <%= f.label 'Publik?', class: 'reg-label'%>
- <%= f.check_box :public, :class => 'form-control'%> + <%= f.check_box :public, class: 'form-control'%> Innebär att även de som inte är inloggade kan kontakta.
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
<% end %> diff --git a/app/views/contacts/edit.html.erb b/app/views/contacts/edit.html.erb index e6689e566..216fa33e7 100644 --- a/app/views/contacts/edit.html.erb +++ b/app/views/contacts/edit.html.erb @@ -1,10 +1,10 @@
- <%= label_tag "Redigera kontakt",nil, :class => 'reg-header'%> + <%= label_tag "Redigera kontakt",nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to (content_tag(:i, nil, class: "fa fa-trash-o") + " Förinta"), @contact, method: :delete, data: {confirm: "Är du säker?"}, class: "btn-u btn-u-small" %>
<%= link_to 'Tillbaka till start', root_url %>
-
\ No newline at end of file +
diff --git a/app/views/contacts/new.html.erb b/app/views/contacts/new.html.erb index 9569fbcf4..eb92b7911 100644 --- a/app/views/contacts/new.html.erb +++ b/app/views/contacts/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Ny kontakt',nil, :class => 'reg-header'%> + <%= label_tag 'Ny kontakt',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till start', root_url %>
-
\ No newline at end of file +
diff --git a/app/views/contacts/show.html.erb b/app/views/contacts/show.html.erb index 131464b0c..8abaca833 100644 --- a/app/views/contacts/show.html.erb +++ b/app/views/contacts/show.html.erb @@ -17,18 +17,18 @@
<%= label_tag "E-post"%>
- <%= text_field_tag :email, nil, :required => true, :pattern => '[^@]+@[^@]+\.[a-zA-Z]{2,6}',:class => 'form-control' %>
+ <%= text_field_tag :email, nil, :required => true, :pattern => '[^@]+@[^@]+\.[a-zA-Z]{2,6}',class: 'form-control' %>
<%= label_tag "Meddelande"%>
- <%= text_area_tag :msg,nil, :required => true , :class => 'form-control', :size => '100x10'%>
+ <%= text_area_tag :msg,nil, :required => true , class: 'form-control', :size => '100x10'%>
- <%= submit_tag "Skicka", :class => 'form-control btn-u btn-u-orange'%> + <%= submit_tag "Skicka", class: 'form-control btn-u btn-u-orange'%>
<% end %> - \ No newline at end of file + diff --git a/app/views/councils/_form.html.erb b/app/views/councils/_form.html.erb index a61ca2800..9814c1f0a 100644 --- a/app/views/councils/_form.html.erb +++ b/app/views/councils/_form.html.erb @@ -1,45 +1,39 @@ -<%= form_for(@council, :html => { :autocomplete => 'off' }) do |f| %> - <% if @council.errors.any? %> -
-

<%= pluralize(@council.errors.count, "error") %> gör att utskottet inte kan sparas:

-
    - <% @council.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> - <%= f.label 'Titel', :class => "reg-label"%> -
- <%= f.text_field :title, :class => 'form-control',:placeholder => 'Titel'%> -
- <%= f.label 'Beskrivning', :class => 'reg-label'%> -
- <%= f.text_area :description, :class => 'form-control',:placeholder => 'Beskrivning' %> -
- <%= f.label 'Url - små bokstäver, a-z, till exempel "pryl"', :class => 'reg-label'%> -
- <%= f.text_field :url, :class => 'form-control',:placeholder => 'Url',:autocomplete => 'off' %> -
- <%= f.label 'Publik?', :class => 'reg-label'%> -
- Innebär att även de som inte är inloggade kan
- läsa om utskottet. - <%= f.check_box :public, :class => 'form-control'%> -
- <%if @council.posts.count > 0 %> - <%= f.label 'Ordförande', :class => 'reg-label'%> -
- <%= f.select :president, options_for_select(@council.posts.collect{ |r| [r.title, r.id] },selected: @council.president),{include_blank: true},:class => 'form-control'%> -
- <%elsif @council.new_record? == false%> - Detta utskott har inga poster, lägg till en post och välj sedan här vilken post som är utskottets ordförande. -
- <%end%> -
- <%= f.submit "Spara",:class => 'btn-u pull-right btn-u-small' %> - <%if @council.id.nil? == false%> - <%= link_to (content_tag(:i, nil, class: "fa fa-trash-o") + " Förinta"), @council, method: :delete, data: {confirm: "Är du säker?"}, class: "btn-u btn-u-small" %> - <%end%> -
-<% end %> \ No newline at end of file +<%= form_for(@council) do |f| %> + <%= render 'shared/form_errors', current: @council %> + <%= f.label 'Titel', class: "reg-label" %> +
+ <%= f.text_field :title, class: 'form-control', placeholder: 'Titel' %> +
+ <%= f.label 'Beskrivning', class: 'reg-label' %> +
+ <%= f.text_area :description, class: 'form-control', placeholder: 'Beskrivning', size: '40x5' %> +
+ <%= f.label 'Url - små bokstäver, a-z, till exempel "pryl"', class: 'reg-label' %> +
+ <%= f.text_field :url, class: 'form-control', placeholder: 'Url' %> +
+ <%= f.label 'Publik?', class: 'reg-label' %> +
+ Innebär att även de som inte är inloggade kan
+ läsa om utskottet. + <%= f.check_box :public, class: 'form-control' %> +
+ <% if @council.posts.count > 0 %> + <%= f.label 'Ordförande', class: 'reg-label' %> +
+ <%= f.collection_select(:president_id, @council.posts, :id, :title, include_blank: true, + class: 'form-control')%> +
+ <% elsif not @council.new_record? %> + Detta utskott har inga poster, lägg till en post och välj sedan här vilken post som är utskottets ordförande. +
+ <% end %> +
+ <%= f.submit "Spara", class: 'btn-u pull-right btn-u-small' %> + <% if not @council.new_record? %> + <%= link_to (content_tag(:i, nil, class: "fa fa-trash-o") + " Förinta"), + @council, method: :delete, data: {confirm: "Är du säker?"}, + class: "btn-u btn-u-small" %> + <% end %> +
+<% end %> diff --git a/app/views/councils/_menu.html.erb b/app/views/councils/_menu.html.erb new file mode 100644 index 000000000..b14868806 --- /dev/null +++ b/app/views/councils/_menu.html.erb @@ -0,0 +1,8 @@ + diff --git a/app/views/councils/edit.html.erb b/app/views/councils/edit.html.erb index 2be53f8fa..b45001083 100644 --- a/app/views/councils/edit.html.erb +++ b/app/views/councils/edit.html.erb @@ -1,22 +1,18 @@
-
-
- <%= label_tag 'Redigera utskott',nil, :class => 'reg-header'%> - <%= render 'form'%> -
- <%= link_to 'Lägg till post', new_council_post_path(@council),class:"btn-u" %> <%= link_to 'Visa poster', council_posts_path(@council),class:"btn-u" %> - <%= link_to 'Redigera sida', council_page_path(@council),class:"btn-u" %> -
- <%= link_to 'Visa utskott', @council,class:"btn-u" %> -
- <%if @council.page%> -
- <%if @contact %> - <%= label_tag 'Redigera kontakt',nil, :class => 'reg-header'%> - <%=render partial: "contacts/form",object: @contact%> - <%end%> -
- <%end%> -
-
- \ No newline at end of file +
+
+ <%= label_tag 'Redigera utskott', nil, class: 'reg-header' %> + <%= render 'form' %> +
+ <%= link_to 'Lägg till post', new_council_post_path(@council), class: "btn-u" %> + <%= link_to 'Visa poster', council_posts_path(@council), class: "btn-u" %> + <% if @council.page.present?%> + <%= link_to 'Redigera sida', page_path(@page), class: "btn-u" %> + <% end %> +
+ <%= link_to 'Visa utskott', @council, class: "btn-u" %> +
+ +
+ + diff --git a/app/views/councils/new.html.erb b/app/views/councils/new.html.erb index 9569fbcf4..eb92b7911 100644 --- a/app/views/councils/new.html.erb +++ b/app/views/councils/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Ny kontakt',nil, :class => 'reg-header'%> + <%= label_tag 'Ny kontakt',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till start', root_url %>
-
\ No newline at end of file + diff --git a/app/views/councils/show.html.erb b/app/views/councils/show.html.erb index 55286adf9..5bb46c280 100644 --- a/app/views/councils/show.html.erb +++ b/app/views/councils/show.html.erb @@ -4,5 +4,11 @@ <%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Redigera"), edit_council_path(@council), class: "btn-u btn-u-small"%> <%end%> -
-<%=render partial: "pages/main"%> +
+ <% if @page.present? %> + <%=render @page%> + <%end%> + <% if @council.posts.present? %> + <%= render 'posts/table', collection: @council.posts %> + <%end%> +
diff --git a/app/views/councils/show.json.jbuilder b/app/views/councils/show.json.jbuilder deleted file mode 100644 index 1949648a2..000000000 --- a/app/views/councils/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @page, :id, :created_at, :updated_at diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index de50d98b4..4f7b02af2 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -1,53 +1,53 @@
- <%= form_for(resource, :as => resource_name, :url => update_user_registration_path(resource), :html => { :method => :patch,:class => "reg-page" }) do |f| %> + <%= form_for(resource, :as => resource_name, :url => update_user_registration_path(resource), :html => { :method => :patch,class: "reg-page" }) do |f| %> - <%= f.label 'Redigera användare', :class => 'reg-header'%>
- <%= f.label 'Användarnamn', :class => 'reg-label'%> + <%= f.label 'Redigera användare', class: 'reg-header'%>
+ <%= f.label 'Användarnamn', class: 'reg-label'%>
<%= fa_icon('user')%> - <%= f.text_field :username, :class => 'form-control',:placeholder => 'Användarnamn'%> + <%= f.text_field :username, class: 'form-control',:placeholder => 'Användarnamn'%>
- <%= f.label 'E-post', :class => 'reg-label'%> + <%= f.label 'E-post', class: 'reg-label'%>
<%= fa_icon('envelope')%> - <%= f.email_field :email, :class => 'form-control',:placeholder => 'E-postadress' %> + <%= f.email_field :email, class: 'form-control',:placeholder => 'E-postadress' %>
- <%= f.label 'Fyll i nytt lösenord för att byta.', :class => 'reg-header'%>
- <%= f.label 'Nytt lösenord', :class => 'reg-label'%> + <%= f.label 'Fyll i nytt lösenord för att byta.', class: 'reg-header'%>
+ <%= f.label 'Nytt lösenord', class: 'reg-label'%>
<%= fa_icon('lock')%> - <%= f.password_field :password, :class => 'form-control',:placeholder => 'Nytt lösenord',:autocomplete => 'off' %> + <%= f.password_field :password, class: 'form-control',:placeholder => 'Nytt lösenord',:autocomplete => 'off' %>
- <%= f.label 'Bekräfta lösenord', :class => 'reg-label'%> + <%= f.label 'Bekräfta lösenord', class: 'reg-label'%>
<%= fa_icon('lock')%> - <%= f.password_field :password_confirmation, :class => 'form-control',:placeholder => 'Bekräfta lösenord' %> + <%= f.password_field :password_confirmation, class: 'form-control',:placeholder => 'Bekräfta lösenord' %>
- <%= f.label 'Bekräfta ändringar med nuvarande lösenord', :class => 'reg-header'%> + <%= f.label 'Bekräfta ändringar med nuvarande lösenord', class: 'reg-header'%>
<%= fa_icon('lock')%> - <%= f.password_field :current_password, :class => 'form-control',:placeholder => 'Nuvarande lösenord' %> + <%= f.password_field :current_password, class: 'form-control',:placeholder => 'Nuvarande lösenord' %>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
<% end %>

- <%= form_for(resource, :as => resource_name, :url => admin_destroy_user_path(resource), :html => { :method => :delete,:class => "reg-page" }) do |f| %> + <%= form_for(resource, :as => resource_name, :url => admin_destroy_user_path(resource), :html => { :method => :delete,class: "reg-page" }) do |f| %> <%= devise_error_messages! %> - <%= f.label 'Ta bort användare', :class => 'reg-header'%>
+ <%= f.label 'Ta bort användare', class: 'reg-header'%>
<%= fa_icon('lock')%> - <%= f.password_field :currrent_password, :class => 'form-control',:placeholder => 'Nuvarande lösenord'%> + <%= f.password_field :currrent_password, class: 'form-control',:placeholder => 'Nuvarande lösenord'%>
- <%= f.submit "Ta bort mitt konto", :data => { :confirm => "Är du säker?" },:class => 'btn-u pull-right'%> + <%= f.submit "Ta bort mitt konto", :data => { :confirm => "Är du säker?" },class: 'btn-u pull-right'%>
<%= link_to "Tillbaka", :back %> <% end %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 5993a4773..37509b553 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -2,34 +2,34 @@
<%= devise_error_messages! %>
- <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => "reg-page", autofill: 'off'}, options: {autocomplete: 'off'}) do |f| %> + <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {class: "reg-page", autofill: 'off'}, options: {autocomplete: 'off'}) do |f| %> - <%= f.label 'Registrera ny användare', :class => 'reg-header'%>
+ <%= f.label 'Registrera ny användare', class: 'reg-header'%>
<%= fa_icon('user')%> - <%= f.text_field :username, :class => 'form-control',:placeholder => 'Användarnamn', :autofocus => true%> + <%= f.text_field :username, class: 'form-control',:placeholder => 'Användarnamn', :autofocus => true%>
<%= fa_icon('envelope')%> - <%= f.email_field :email, :class => 'form-control',:placeholder => 'E-postadress' %> + <%= f.email_field :email, class: 'form-control',:placeholder => 'E-postadress' %>
<%= fa_icon('lock')%> - <%= f.password_field :password, :class => 'form-control',:placeholder => 'Nytt lösenord'%> + <%= f.password_field :password, class: 'form-control',:placeholder => 'Nytt lösenord'%>
<%= fa_icon('lock')%> - <%= f.password_field :password_confirmation, :class => 'form-control',:placeholder => 'Bekräfta lösenord' %> + <%= f.password_field :password_confirmation, class: 'form-control',:placeholder => 'Bekräfta lösenord' %>
- <%= f.label 'Personnummer', :class => 'reg-label'%>
+ <%= f.label 'Personnummer', class: 'reg-label'%>
För att kolla medlemskap - sparas ej.
<%= fa_icon('bolt')%> - <%= text_field_tag :civic, nil, :class => 'form-control',:placeholder => 'Personnummer (10 siffor i följd)'%> + <%= text_field_tag :civic, nil, class: 'form-control',:placeholder => 'Personnummer (10 siffor i följd)'%>
- <%= f.submit "Registrera",:class => 'btn-u pull-right' %> + <%= f.submit "Registrera",class: 'btn-u pull-right' %>
<%= render "devise/shared/links" %> <% end %> diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index af0dc8ef1..186d93786 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,17 +1,17 @@
- <%= form_for(resource,:html => {:class => "reg-page"}, :as => resource_name, :url => session_path(resource_name)) do |f| %> + <%= form_for(resource,:html => {class: "reg-page"}, :as => resource_name, :url => session_path(resource_name)) do |f| %> - <%= f.label 'Logga in', :class => 'reg-header'%>
+ <%= f.label 'Logga in', class: 'reg-header'%>
<%= fa_icon('user')%> - <%= f.text_field :username, :autofocus => true, :class => 'form-control',:placeholder => 'Användarnamn'%> + <%= f.text_field :username, :autofocus => true, class: 'form-control',:placeholder => 'Användarnamn'%>
<%= fa_icon('lock')%> - <%= f.password_field :password, :class => 'form-control',:placeholder => 'Lösenord' %> + <%= f.password_field :password, class: 'form-control',:placeholder => 'Lösenord' %>
@@ -20,7 +20,7 @@ <% end -%>
- <%= f.submit "Logga in",:class => 'btn-u pull-right' %> + <%= f.submit "Logga in",class: 'btn-u pull-right' %>
@@ -36,4 +36,4 @@
-
\ No newline at end of file +
diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb index b65ccc59f..8c34d72b2 100644 --- a/app/views/documents/_form.html.erb +++ b/app/views/documents/_form.html.erb @@ -9,28 +9,28 @@
<% end %> - <%= f.label 'Titel', :class => "reg-label"%> + <%= f.label 'Titel', class: "reg-label"%>
- <%= f.text_field :title, :class => 'form-control',:placeholder => 'Titel'%> + <%= f.text_field :title, class: 'form-control',:placeholder => 'Titel'%>
- <%= f.label 'Kategori', :class => 'reg-label'%> + <%= f.label 'Kategori', class: 'reg-label'%>
- <%= f.select :category,options_for_select(["Styrdokument", "Protokoll", "Sektionsmöten", "Övrigt"],@dokument.category), :class => 'form-control'%> + <%= f.select :category,options_for_select(["Styrdokument", "Protokoll", "Sektionsmöten", "Övrigt"],@dokument.category), class: 'form-control'%>
- <%= f.label 'PDF', :class => 'reg-label'%> + <%= f.label 'PDF', class: 'reg-label'%>
<%if @dokument.pdf_file_name.blank?%> - <%= f.file_field :pdf, :class => 'form-control'%> + <%= f.file_field :pdf, class: 'form-control'%> <%else%> <%=@dokument.pdf_file_name%> <%end%>
- <%= f.label 'Publik?', :class => 'reg-label'%> + <%= f.label 'Publik?', class: 'reg-label'%>
- <%= f.check_box :public, :class => 'form-control'%> + <%= f.check_box :public, class: 'form-control'%> Innebär att även de som inte är inloggade kan se dokument.
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
- <% end %> \ No newline at end of file + <% end %> diff --git a/app/views/documents/edit.html.erb b/app/views/documents/edit.html.erb index 803c7705d..209a0f9f7 100644 --- a/app/views/documents/edit.html.erb +++ b/app/views/documents/edit.html.erb @@ -1,10 +1,10 @@
- <%= label_tag "Redigera dokument",nil, :class => 'reg-header'%> + <%= label_tag "Redigera dokument",nil, class: 'reg-header'%> <%=render partial: "form"%> <%= link_to (content_tag(:i, nil, class: "fa fa-trash-o") + " Förinta"), @dokument, method: :delete, data: {confirm: "Är du säker?"}, class: "btn-u btn-u-small" %>
<%= link_to 'Tillbaka till start', root_url %>
-
\ No newline at end of file +
diff --git a/app/views/documents/new.html.erb b/app/views/documents/new.html.erb index 69c152902..84a7c3934 100644 --- a/app/views/documents/new.html.erb +++ b/app/views/documents/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Nytt dokument',nil, :class => 'reg-header'%> + <%= label_tag 'Nytt dokument',nil, class: 'reg-header'%> <%=render partial: "form"%> <%= link_to 'Tillbaka till start', root_url %>
-
\ No newline at end of file +
diff --git a/app/views/election/candidates/_form.html.erb b/app/views/election/candidates/_form.html.erb index 35423e703..c9bd0de22 100644 --- a/app/views/election/candidates/_form.html.erb +++ b/app/views/election/candidates/_form.html.erb @@ -2,37 +2,37 @@ <%= render 'shared/form_errors',current: @candidate %> Uppgifter ifylls i <%= link_to('profilen', edit_profile_path(current_user.profile)) %>.
- <%= f.label :name, :class => 'reg-label' %> & <%= f.label :lastname, :class => 'reg-label' %> + <%= f.label :name, class: 'reg-label' %> & <%= f.label :lastname, class: 'reg-label' %>
-
<%= f.text_field :name, :class => 'form-control', placeholder: "Förnamn" %>
-
<%= f.text_field :lastname, :class => 'form-control', placeholder: "Efternamn" %>
+
<%= f.text_field :name, class: 'form-control', placeholder: "Förnamn" %>
+
<%= f.text_field :lastname, class: 'form-control', placeholder: "Efternamn" %>
- <%= f.label :email, :class => 'reg-label' %> & <%= f.label :phone, :class => 'reg-label' %> + <%= f.label :email, class: 'reg-label' %> & <%= f.label :phone, class: 'reg-label' %>
-
<%= f.email_field :email, :class => 'form-control', placeholder: "E-post" %>
-
<%= f.phone_field :phone, :class => 'form-control', placeholder: "Telefon" %>
+
<%= f.email_field :email, class: 'form-control', placeholder: "E-post" %>
+
<%= f.phone_field :phone, class: 'form-control', placeholder: "Telefon" %>
- <%= f.label :stil_id, :class => 'reg-label' %> + <%= f.label :stil_id, class: 'reg-label' %>
<%= f.text_field :stil_id, class: 'form-control',placeholder: 'Stil-ID' %>
- <%= f.label 'Post', :class => 'reg-label' %>
+ <%= f.label 'Post', class: 'reg-label' %>
<% if @candidate.new_record?%> <%= f.select :post_id, options_from_collection_for_select(@election.current_posts, :id, :title, @candidate.post_id), include_blank: true, - :class => "form-control listBox" %> + class: "form-control listBox" %> <%else%>

<%= @candidate.post.title%>

Det går inte att byta post, har du valt fel får du ta bort denna kandidaturen och skapa en ny.

<%end%>
- <%= f.submit :class => 'btn btn-u' %> + <%= f.submit class: 'btn btn-u' %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/election/candidates/candidate.html.erb b/app/views/election/candidates/candidate.html.erb index 2db397487..5f0a548a2 100644 --- a/app/views/election/candidates/candidate.html.erb +++ b/app/views/election/candidates/candidate.html.erb @@ -10,7 +10,7 @@
-

<%= label_tag 'Kandidera!', nil, :class => 'reg-header' %>

+

<%= label_tag 'Kandidera!', nil, class: 'reg-header' %>

<% if @done %>

Tack för din kandidering

Det kanske finns en post till att söka?

@@ -25,12 +25,12 @@
<% elsif @before %>
-

<%= label_tag 'Kandideringar öppnar: ' + @valet.start.to_date.to_s, nil, :class => 'reg-header' %>

+

<%= label_tag 'Kandideringar öppnar: ' + @valet.start.to_date.to_s, nil, class: 'reg-header' %>

<%= link_to image_tag("layout/f.svg", class: "val-logo"), elections_path %>
<% else %>
-

<%= label_tag 'Kandideringar har stängt.', nil, :class => 'reg-header' %>

+

<%= label_tag 'Kandideringar har stängt.', nil, class: 'reg-header' %>

Du kan inte längre kandidera på nya poster eller ändra dina kandidaturer.

<%= link_to image_tag("layout/f.svg", class: "val-logo"), elections_path %> <%= grid(@candidates_grid) do |g| @@ -48,4 +48,4 @@ end end -%>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/election/candidates/index.html.erb b/app/views/election/candidates/index.html.erb index 2d03c7c24..1fb3a3fa6 100644 --- a/app/views/election/candidates/index.html.erb +++ b/app/views/election/candidates/index.html.erb @@ -12,12 +12,12 @@
<% elsif @election.view_status == 1 %>
-

<%= label_tag 'Kandideringar öppnar: ' + @election.start.to_date.to_s, nil, :class => 'reg-header' %>

+

<%= label_tag 'Kandideringar öppnar: ' + @election.start.to_date.to_s, nil, class: 'reg-header' %>

<%= link_to image_tag("layout/f.svg", class: "val-logo"), elections_path %>
<% elsif @election.view_status == 3 %>
-

<%= label_tag 'Kandideringar har stängt.', nil, :class => 'reg-header' %>

+

<%= label_tag 'Kandideringar har stängt.', nil, class: 'reg-header' %>

Du kan inte längre kandidera på nya poster eller ändra dina kandidaturer.

<%= link_to image_tag("layout/f.svg", class: "val-logo"), elections_path %> <%= grid(@candidates_grid) do |g| @@ -35,4 +35,4 @@ end end -%>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/election/candidates/new.html.erb b/app/views/election/candidates/new.html.erb index f19e38612..1e6e2252f 100644 --- a/app/views/election/candidates/new.html.erb +++ b/app/views/election/candidates/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Ny kandidatur',nil, :class => 'reg-header'%> + <%= label_tag 'Ny kandidatur',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka', election_candidates_path %>
-
\ No newline at end of file +
diff --git a/app/views/election/candidates/show.html.erb b/app/views/election/candidates/show.html.erb index cee0c5cdb..3bd41149c 100644 --- a/app/views/election/candidates/show.html.erb +++ b/app/views/election/candidates/show.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Redigera kandidatur',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera kandidatur',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka', election_candidates_path,class: "btn-u btn-u-small" %> <%= link_to 'Ta bort', election_candidate_path(@candidate), method: :delete, class: "btn-u btn-u-small" %>
-
\ No newline at end of file + diff --git a/app/views/election/nominations/_form.html.erb b/app/views/election/nominations/_form.html.erb index 856e34d1f..f0074ba80 100644 --- a/app/views/election/nominations/_form.html.erb +++ b/app/views/election/nominations/_form.html.erb @@ -1,27 +1,27 @@ <%= form_for([:election,nomination], remote: true) do |f| %> <%= render 'shared/form_errors', current: @nomination %> - <%= f.label 'Namn', :class => 'reg-label' %> + <%= f.label 'Namn', class: 'reg-label' %>
- <%= f.text_field :name, :class => 'form-control' %> + <%= f.text_field :name, class: 'form-control' %>
- <%= f.label 'E-post', :class => 'reg-label' %> + <%= f.label 'E-post', class: 'reg-label' %>
- <%= f.email_field :email, :class => 'form-control' %> + <%= f.email_field :email, class: 'form-control' %>
- <%= f.label 'Post', :class => 'reg-label' %>
+ <%= f.label 'Post', class: 'reg-label' %>
<%= f.select :post_id, options_from_collection_for_select(election.current_posts, :id, :title, params[:post].to_i), include_blank: true, - :class => "form-control listBox" %> + class: "form-control listBox" %>
- <%= f.label 'Motivering', :class => 'reg-label' %>
+ <%= f.label 'Motivering', class: 'reg-label' %>
Frivillig - den nominerade kan se den i ett mejl.
- <%= f.text_area :motivation, :class => 'form-control' %> + <%= f.text_area :motivation, class: 'form-control' %>
- <%= f.submit "Spara", :class => 'btn-u' %> + <%= f.submit "Spara", class: 'btn-u' %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/election/nominations/new.html.erb b/app/views/election/nominations/new.html.erb index 666cb0a44..abdb654dd 100644 --- a/app/views/election/nominations/new.html.erb +++ b/app/views/election/nominations/new.html.erb @@ -22,7 +22,7 @@ <% else %>
-

<%= label_tag 'Nomineringar:', nil, :class => 'reg-header' %>

+

<%= label_tag 'Nomineringar:', nil, class: 'reg-header' %>

<%= render 'elections/countdown' %> <%= link_to image_tag("layout/f.svg", class: "val-logo"), elections_path %>
diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index 097e80266..2d1bf2f25 100644 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -9,47 +9,47 @@ <% end %> - <%= f.label 'Titel', :class => 'reg-label'%> + <%= f.label 'Titel', class: 'reg-label'%>
- <%= f.text_field :title, :class => 'form-control',:placeholder => 'Titel'%> + <%= f.text_field :title, class: 'form-control',:placeholder => 'Titel'%>
- <%= f.label 'Beskrivning', :class => 'reg-label'%> + <%= f.label 'Beskrivning', class: 'reg-label'%>
- <%= f.text_area :description, :class => 'form-control',:placeholder => 'Beskrivning' %> + <%= f.text_area :description, class: 'form-control',:placeholder => 'Beskrivning' %>
- <%= f.label 'Plats', :class => 'reg-label'%> + <%= f.label 'Plats', class: 'reg-label'%>
- <%= f.text_field :location, :class => 'form-control',:placeholder => 'Plats',:autocomplete => 'off' %> + <%= f.text_field :location, class: 'form-control',:placeholder => 'Plats',:autocomplete => 'off' %>
- <%= f.label 'Visningsbild', :class => 'reg-label'%> + <%= f.label 'Visningsbild', class: 'reg-label'%>
<% if @event.image_file_name != nil%> <%= image_tag(@event.image(:thumb))%> <% end %> - <%= f.file_field :image, :class => 'form-control' %> + <%= f.file_field :image, class: 'form-control' %>
- <%= f.label 'Heldagsevent', :class => 'reg-label'%> + <%= f.label 'Heldagsevent', class: 'reg-label'%>
- <%= f.check_box :all_day, :class => '' %> + <%= f.check_box :all_day, class: '' %>
- <%= f.label 'Startar', :class => 'reg-label'%> + <%= f.label 'Startar', class: 'reg-label'%>
- <%= f.datetime_select :starts_at, :minute_step => 15, :class => 'form-control' %> + <%= f.datetime_select :starts_at, :minute_step => 15, class: 'form-control' %>
- <%= f.label 'Slutar', :class => 'reg-label'%> + <%= f.label 'Slutar', class: 'reg-label'%>
- <%= f.datetime_select :ends_at, :minute_step => 15, :class => 'form-control' %> + <%= f.datetime_select :ends_at, :minute_step => 15, class: 'form-control' %>
- <%= f.label 'Ansvarigt utskott', :class => 'reg-label'%> + <%= f.label 'Ansvarigt utskott', class: 'reg-label'%>
<%= f.select :category, options_from_collection_for_select(@utskott,:title,:title,@event.category), include_blank: true, - :class => "form-control listBox"%> + class: "form-control listBox"%>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/events/edit.html.erb b/app/views/events/edit.html.erb index bffd68324..2468b6d9a 100644 --- a/app/views/events/edit.html.erb +++ b/app/views/events/edit.html.erb @@ -1,10 +1,10 @@
- <%= label_tag 'Redigera event',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera event',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Visa event', @event %>
<%= link_to 'Tillbaka', :back %>
-
\ No newline at end of file + diff --git a/app/views/events/new.html.erb b/app/views/events/new.html.erb index 80e56bac7..d19d29aaa 100644 --- a/app/views/events/new.html.erb +++ b/app/views/events/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Lägg till event',nil, :class => 'reg-header'%> + <%= label_tag 'Lägg till event',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka', :back %>
-
\ No newline at end of file + diff --git a/app/views/faqs/edit.html.erb b/app/views/faqs/edit.html.erb index 24131bcd1..4651f21bf 100644 --- a/app/views/faqs/edit.html.erb +++ b/app/views/faqs/edit.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Redigera fråga',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera fråga',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till faq', faqs_path %>
-
\ No newline at end of file + diff --git a/app/views/faqs/new.html.erb b/app/views/faqs/new.html.erb index 1febda4e0..314170fd4 100644 --- a/app/views/faqs/new.html.erb +++ b/app/views/faqs/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Ny fråga',nil, :class => 'reg-header'%> + <%= label_tag 'Ny fråga',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till faq', faqs_path %>
-
\ No newline at end of file + diff --git a/app/views/images/_form.html.erb b/app/views/images/_form.html.erb index 21804abe4..36953af71 100644 --- a/app/views/images/_form.html.erb +++ b/app/views/images/_form.html.erb @@ -9,20 +9,20 @@ <% end %> - <%= f.label 'Titel', :class => 'reg-label'%> + <%= f.label 'Titel', class: 'reg-label'%>
<%= image_tag(@image.foto(:small),class: 'img-responsive')%>
- <%= f.label 'Beskrivning', :class => 'reg-label'%> + <%= f.label 'Beskrivning', class: 'reg-label'%>
- <%= f.text_area :description, :class => 'form-control',:placeholder => 'Beskrivning' %> + <%= f.text_area :description, class: 'form-control',:placeholder => 'Beskrivning' %>
- <%= f.label 'Plats', :class => 'reg-label'%> + <%= f.label 'Plats', class: 'reg-label'%>
- <%= f.select :subcategory_id, options_from_collection_for_select(@album.subcategories,:id,:text,@image.subcategory_id),{:class => 'form-control',include_blank: true}%> + <%= f.select :subcategory_id, options_from_collection_for_select(@album.subcategories,:id,:text,@image.subcategory_id),{class: 'form-control',include_blank: true}%>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
<% end %> - \ No newline at end of file + diff --git a/app/views/images/new.html.erb b/app/views/images/new.html.erb index 3c128607f..4fc1b2c2f 100644 --- a/app/views/images/new.html.erb +++ b/app/views/images/new.html.erb @@ -1,10 +1,10 @@
- <%= label_tag 'Lägg till bilder i '+@album.title,nil, :class => 'reg-header'%> + <%= label_tag 'Lägg till bilder i '+@album.title,nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Visa album', @album %>
<%= link_to 'Tillbaka', :root %>
-
\ No newline at end of file + diff --git a/app/views/images/show.html.erb b/app/views/images/show.html.erb index d2130166a..3b41d1a2e 100644 --- a/app/views/images/show.html.erb +++ b/app/views/images/show.html.erb @@ -1,10 +1,10 @@
- <%= label_tag 'Visa bild',nil, :class => 'reg-header'%> + <%= label_tag 'Visa bild',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Visa album', @album %>
<%= link_to 'Tillbaka', :back %>
-
\ No newline at end of file + diff --git a/app/views/layouts/_utskottmenu.html.erb b/app/views/layouts/_utskottmenu.html.erb deleted file mode 100644 index a182baaf5..000000000 --- a/app/views/layouts/_utskottmenu.html.erb +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 63039c4fc..9dc7e0007 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -75,7 +75,7 @@ <% if yield(:title) == 'Utskott' %>
- <%= render "layouts/utskottmenu" %> + <%= render "councils/menu" %>
<% end %> diff --git a/app/views/menus/_form.html.erb b/app/views/menus/_form.html.erb index 2d8ff6699..f075d9b74 100644 --- a/app/views/menus/_form.html.erb +++ b/app/views/menus/_form.html.erb @@ -1,46 +1,37 @@ -<%= form_for(@menu, :html => { :autocomplete => 'off' }) do |f| %> - <% if @menu.errors.any? %> -
-

<%= pluralize(@menu.errors.count, "error") %> gör att menyn inte kan sparas:

-
    - <% @menu.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> - <%= f.label 'Meny', :class => 'reg-label'%> -
- <%= f.select :location, - options_for_select(["Sektionen","För medlemmar","För företag","Kontakt"],@menu.location), - include_blank: true, - :class => "form-control listBox"%> -
- <%= f.label 'Sorteringsindex', :class => 'reg-label'%> -
- <%= f.number_field :index,:class => 'form-control' %> -
- <%= f.label 'Text', :class => 'reg-label'%> -
- <%= f.text_field :name, :class => 'form-control',:placeholder => 'Text',:autocomplete => 'off' %> -
- <%= f.label 'Länk', :class => 'reg-label'%> -
- <%= f.text_field :link, :class => 'form-control',:placeholder => 'Länk',:autocomplete => 'off' %> -
- <%= f.label 'Synlig', :class => 'reg-label'%> -
- <%= f.check_box :visible, checked: @menu.visible %> -
- <%= f.label 'Turbolinks', :class => 'reg-label'%> -
- <%= f.check_box :turbolinks, checked: @menu.turbolinks %> -
- <%= f.label 'Öppna i ny tab', :class => 'reg-label'%> -
- <%= f.check_box :blank_p, checked: @menu.blank_p %> -
-
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> -
+<%= form_for(@menu) do |f| %> + <%= render 'shared/form_errors', current: @menu %> + <%= f.label 'Meny', class: 'reg-label' %> +
+ <%= f.select :location, + options_for_select(["Sektionen", "För medlemmar", "För företag", "Kontakt"], @menu.location), + include_blank: true, + class: "form-control listBox" %> +
+ <%= f.label 'Sorteringsindex', class: 'reg-label' %> +
+ <%= f.number_field :index, class: 'form-control' %> +
+ <%= f.label 'Text', class: 'reg-label' %> +
+ <%= f.text_field :name, class: 'form-control', placeholder: 'Text', autocomplete: 'off' %> +
+ <%= f.label 'Länk', class: 'reg-label' %> +
+ <%= f.text_field :link, class: 'form-control', placeholder: 'Länk', autocomplete: 'off' %> +
+ <%= f.label 'Synlig', class: 'reg-label' %> +
+ <%= f.check_box :visible, checked: @menu.visible %> +
+ <%= f.label 'Turbolinks', class: 'reg-label' %> +
+ <%= f.check_box :turbolinks, checked: @menu.turbolinks %> +
+ <%= f.label 'Öppna i ny tab', class: 'reg-label' %> +
+ <%= f.check_box :blank_p, checked: @menu.blank_p %> +
+
+ <%= f.submit "Spara", class: 'btn-u pull-right' %> +
<% end %> diff --git a/app/views/news/_form.html.erb b/app/views/news/_form.html.erb index 2909981c2..afe9b18ad 100644 --- a/app/views/news/_form.html.erb +++ b/app/views/news/_form.html.erb @@ -1,21 +1,21 @@ <%= form_for(@news, :html => { :autocomplete => 'off' }) do |f| %> <%= render 'shared/form_errors',current: @news%> - <%= f.label 'Titel', :class => 'reg-label'%> + <%= f.label 'Titel', class: 'reg-label'%>
- <%= f.text_field :title, :class => 'form-control',:placeholder => 'Titel'%> + <%= f.text_field :title, class: 'form-control',:placeholder => 'Titel'%>
- <%= f.label 'Innehåll', :class => 'reg-label'%> + <%= f.label 'Innehåll', class: 'reg-label'%>
- <%= f.text_area :content, :class => 'form-control',:placeholder => 'Innehåll', size: "120x15" %> + <%= f.text_area :content, class: 'form-control',:placeholder => 'Innehåll', size: "120x15" %>
- <%= f.label 'Visningsbild', :class => 'reg-label'%> + <%= f.label 'Visningsbild', class: 'reg-label'%>
<% if @news.image != nil%> <%= image_tag(@news.image(:thumb))%> <% end %> - <%= f.file_field :image, :class => 'form-control' %> + <%= f.file_field :image, class: 'form-control' %>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
<% end %> diff --git a/app/views/news/edit.html.erb b/app/views/news/edit.html.erb index 1b2aa7e68..3de55a0cf 100644 --- a/app/views/news/edit.html.erb +++ b/app/views/news/edit.html.erb @@ -1,10 +1,10 @@
- <%= label_tag 'Redigera nyhet',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera nyhet',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Visa nyhet', @news %>
<%= link_to 'Tillbaka till nyheter', news_index_path %>
-
\ No newline at end of file + diff --git a/app/views/news/new.html.erb b/app/views/news/new.html.erb index deffba945..6fd167a3b 100644 --- a/app/views/news/new.html.erb +++ b/app/views/news/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Ny nyhet',nil, :class => 'reg-header'%> + <%= label_tag 'Ny nyhet',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till nyheter', news_index_path %>
-
\ No newline at end of file + diff --git a/app/views/notices/_form.html.erb b/app/views/notices/_form.html.erb index 5919d3773..a42417b5d 100644 --- a/app/views/notices/_form.html.erb +++ b/app/views/notices/_form.html.erb @@ -30,14 +30,14 @@
<%= f.number_field :sort ,class: 'form-control'%>
- <%= f.label :image, :class => 'reg-label'%> + <%= f.label :image, class: 'reg-label'%>
<% if @notice.image?%> <%= image_tag(image_notice_path(@notice, style: 'small'))%>
<% end %> - <%= f.file_field :image, :class => 'form-control' %> + <%= f.file_field :image, class: 'form-control' %>
<%= f.submit class:"btn btn-u" %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/notices/edit.html.erb b/app/views/notices/edit.html.erb index 26e6f799b..f8d15dc21 100644 --- a/app/views/notices/edit.html.erb +++ b/app/views/notices/edit.html.erb @@ -2,7 +2,7 @@
- <%= label_tag 'Redigera notis',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera notis',nil, class: 'reg-header'%> <%= render 'form'%>
<%= link_to('Visa alla notiser',notices_path, class: "btn btn-u")%> diff --git a/app/views/notices/new.html.erb b/app/views/notices/new.html.erb index 298240d17..deda52051 100644 --- a/app/views/notices/new.html.erb +++ b/app/views/notices/new.html.erb @@ -2,11 +2,11 @@
- <%= label_tag 'Ny notis',nil, :class => 'reg-header'%> + <%= label_tag 'Ny notis',nil, class: 'reg-header'%> <%= render 'form'%>
<%= link_to('Visa alla notiser',notices_path, class: "btn btn-u")%> <%= link_to('Tillbaka till startsida', root_url, class: "btn btn-u")%>
-
\ No newline at end of file +
diff --git a/app/views/page_elements/_form.html.erb b/app/views/page_elements/_form.html.erb index 8b89d1206..e4ed1603f 100644 --- a/app/views/page_elements/_form.html.erb +++ b/app/views/page_elements/_form.html.erb @@ -1,52 +1,43 @@ -<%= form_for(@page_element,url: @path) do |f| %> - <% if @page_element.errors.any? %> -
-

<%= pluralize(@page_element.errors.count, "error") %> gör att sidan inte kan sparas:

-
    - <% @page_element.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> - <%= f.label 'Namn', :class => 'reg-label'%> +<%= form_for([@page,@page_element]) do |f| %> + <%= render 'shared/form_errors', current: @page_element%> + <%= f.label 'Namn', class: 'reg-label'%>
För att ni ska kunna skilja på olika element. - <%= f.text_field :name,:class => 'form-control' %> + <%= f.text_field :name,class: 'form-control' %>
- <%= f.label 'Synlig?', :class => 'reg-label'%> - <%= f.check_box :visible,:class => 'form-control' %> + <%= f.label 'Synlig?', class: 'reg-label'%> + <%= f.check_box :visible,class: 'form-control' %> - <%= f.label 'Text', :class => 'reg-label'%> + <%= f.label 'Text', class: 'reg-label'%>
- <%= f.text_area :text,:class => 'form-control', size: "60x8" %> + <%= f.text_area :text,class: 'form-control', size: "60x8" %>
- <%= f.label 'Rubrik', :class => 'reg-label'%> + <%= f.label 'Rubrik', class: 'reg-label'%>
Lämnas tomt för element utan rubrik - <%= f.text_field :headline,:class => 'form-control' %> + <%= f.text_field :headline,class: 'form-control' %>
<%if 1 == 0%> - <%= f.label 'Ram?', :class => 'reg-label'%> - <%= f.check_box :border,:class => 'form-control' %> + <%= f.label 'Ram?', class: 'reg-label'%> + <%= f.check_box :border,class: 'form-control' %> <%end%> - <%= f.label 'Position?', :class => 'reg-label'%>
+ <%= f.label 'Position?', class: 'reg-label'%>
<%= f.radio_button :sidebar, false,checked: true %> - <%= f.label :sidebar, 'Huvudfält', :value => false,:class => 'reg-label' %> + <%= f.label :sidebar, 'Huvudfält', :value => false,class: 'reg-label' %> <%= f.radio_button :sidebar, true %> - <%= f.label :sidebar, 'Sidofält', :value => true,:class => 'reg-label' %>
+ <%= f.label :sidebar, 'Sidofält', :value => true,class: 'reg-label' %>
- <%= f.label 'Sorteringsindex', :class => 'reg-label'%> + <%= f.label 'Sorteringsindex', class: 'reg-label'%>
Elementen i sidofältet och huvudfältet sorteras efter detta nummer. - <%= f.number_field :displayIndex,:class => 'form-control' %> + <%= f.number_field :displayIndex,class: 'form-control' %>
- <%= f.label 'Bild', :class => 'reg-label'%> + <%= f.label 'Bild', class: 'reg-label'%>
- <%= f.file_field :picture,:class => 'form-control' %> + <%= f.file_field :picture,class: 'form-control' %>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
<%end%> diff --git a/app/views/page_elements/_page_element.html.erb b/app/views/page_elements/_page_element.html.erb new file mode 100644 index 000000000..63601dc7a --- /dev/null +++ b/app/views/page_elements/_page_element.html.erb @@ -0,0 +1,26 @@ +<% if @edit %> +
+<% end %> +<% if page_element.headline.present? %> +

<%= page_element.headline %>

+<% end %> +<% if page_element.text.present? %> + <%= simple_format(page_element.text) %> +<% end %> + +<% if @edit %> +
+ +<% end %> +<% if @edit %> +
+<% end %> + diff --git a/app/views/page_elements/edit.html.erb b/app/views/page_elements/edit.html.erb index 92b8857d9..93b4a234b 100644 --- a/app/views/page_elements/edit.html.erb +++ b/app/views/page_elements/edit.html.erb @@ -1,11 +1,13 @@
-
-
- <%= label_tag 'Redigera element',nil, :class => 'reg-header'%> - <%= render 'form'%> - <%= link_to 'Visa sida', council_page_path(@council)%>
- <%= link_to (content_tag(:i, nil, class: "fa fa-trash-o") + " Förinta"), council_page_page_element_path(@council,@page_element), method: :delete, data: {confirm: "Är du säker?"}, class: "btn-u btn-u-small" %> - <%= link_to 'Tillbaka till startsida', root_url %> -
-
-
\ No newline at end of file +
+
+ <%= label_tag 'Redigera element', nil, class: 'reg-header' %> + <%= render 'form' %> + <%= link_to 'Visa sida', @page %>
+ <%= link_to (content_tag(:i, nil, class: "fa fa-trash-o") + " Förinta"), + page_page_element_path(@page, @page_element), method: :delete, + data: {confirm: "Är du säker?"}, class: "btn-u btn-u-small" %> + <%= link_to 'Tillbaka till startsida', root_url %> +
+
+
diff --git a/app/views/page_elements/index.html.erb b/app/views/page_elements/index.html.erb index a9361dbec..c89dca045 100644 --- a/app/views/page_elements/index.html.erb +++ b/app/views/page_elements/index.html.erb @@ -1,26 +1,30 @@ -<%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Visa sida"), council_page_path(@council), class: "btn-u btn-u-small"%> -<%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Visa alla element"), council_page_page_elements_path(@council), class: "btn-u btn-u-small"%> +<%= link_to(fa_icon('edit') +' Redigera sida' , + page_path(@page), class: "btn-u btn-u-small")%> +<%= link_to(fa_icon('edit') + ' Lägg till nytt element', + new_page_page_element_path(@page,@page_element), + class: "btn-u btn-u-small")%>
-
-

Sida

-
-
-
    - <% @page_elements.each do |p| %> -
  • -
    -
    -

    <%=p.name%>

    -
    -
    -
    <%=simple_format(p.text)%> - <%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Redigera"), edit_council_page_page_element_path(@council,p), class: "btn-u btn-u-small"%> -
    -
    -
  • - <% end %> -
-
-
-
-
\ No newline at end of file +
+

Sida

+
+
+
    + <% @page_elements.each do |p| %> +
  • +
    +
    +

    <%= p.name %>

    +
    +
    +
    <%= simple_format(p.text) %> + <%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Redigera"), + edit_page_page_element_path(@page, p), class: "btn-u btn-u-small" %> +
    +
    +
  • + <% end %> +
+
+
+
+
diff --git a/app/views/page_elements/index.json.jbuilder b/app/views/page_elements/index.json.jbuilder deleted file mode 100644 index ed1cbcf14..000000000 --- a/app/views/page_elements/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@pages) do |page| - json.extract! page, :id - json.url page_url(page, format: :json) -end diff --git a/app/views/page_elements/new.html.erb b/app/views/page_elements/new.html.erb index 476f62154..736464f6d 100644 --- a/app/views/page_elements/new.html.erb +++ b/app/views/page_elements/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Nytt element',nil, :class => 'reg-header'%> + <%= label_tag 'Nytt element',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till start', root_url %>
-
\ No newline at end of file +
diff --git a/app/views/page_elements/show.html.erb b/app/views/page_elements/show.html.erb index 0350aa16a..e1f51266d 100644 --- a/app/views/page_elements/show.html.erb +++ b/app/views/page_elements/show.html.erb @@ -1,7 +1,7 @@
-

<%= "Titel" +@page_element.to_s %>

+

<%= %("Titel" +@page_element.name) %>

-
\ No newline at end of file + diff --git a/app/views/page_elements/show.json.jbuilder b/app/views/page_elements/show.json.jbuilder deleted file mode 100644 index 1949648a2..000000000 --- a/app/views/page_elements/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @page, :id, :created_at, :updated_at diff --git a/app/views/pages/_form.html.erb b/app/views/pages/_form.html.erb index 2d761b41d..7ddbfc956 100644 --- a/app/views/pages/_form.html.erb +++ b/app/views/pages/_form.html.erb @@ -1,16 +1,24 @@ -<%= form_for(@page, :html => { :autocomplete => 'off' }) do |f| %> - <% if @page.errors.any? %> -
-

<%= pluralize(@page.errors.count, "error") %> gör att sidan inte kan sparas:

- -
    - <% @page.errors.full_messages.each do |msg| %> -
  • <%= msg %>
  • - <% end %> -
-
- <% end %> -
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> -
+<%= form_for(@page) do |f| %> + <%= render 'shared/form_errors', current: @page %> + <%= f.label :title, class: 'reg-label' %> +
+ <%= f.text_field :title, class: 'form-control', placeholder: 'Titel' %> +
+ <% if @page.council.present? %> + <%= f.label 'Sida', class: 'reg-label' %> +
+ <%= link_to(@page.council, @page.council) %> +
+ <% end %> + <%= f.label :url, class: 'reg-label' %> +
+ <%= f.text_field :url, class: 'form-control', placeholder: 'Url' %> +
+ <%= f.label :visible, class: 'reg-label' %> +
+ <%= f.check_box :visible, checked: @page.visible %> +
+
+ <%= f.submit "Spara", class: 'btn-u pull-right' %> +
<% end %> diff --git a/app/views/pages/_main.html.erb b/app/views/pages/_main.html.erb deleted file mode 100644 index 157592be9..000000000 --- a/app/views/pages/_main.html.erb +++ /dev/null @@ -1,57 +0,0 @@ -

<%= @council.title %>

-
-
-
- - <%if @mainelements%> - <%@mainelements.each do |p|%> -
- <%@main = p%> - <%=render partial: "pages/element"%> -
-
- <%end%> - <%end%> -
- <%= render partial: "pages/sidebar"%> - -
-
- - <%if (@poster) && (@poster.count > 0)%> -
-

Poster

- -
- <%@first = true%> - <% @poster.each do |post|%> - <%if @first%> -
- <%else%> -
- <%end%> -
-
- <%=simple_format(post.description)%> -
-
-
- <%@first = false%> - <%end%> -
-
- - <%end%> -
diff --git a/app/views/pages/_page.html.erb b/app/views/pages/_page.html.erb new file mode 100644 index 000000000..234d4c571 --- /dev/null +++ b/app/views/pages/_page.html.erb @@ -0,0 +1,11 @@ +

<%= page.title %>

+
+
+ + <%= render page.main %> +
+ +
+ <%= render page.side %> +
+
diff --git a/app/views/pages/_sidebar.html.erb b/app/views/pages/_sidebar.html.erb deleted file mode 100644 index 4326f2cde..000000000 --- a/app/views/pages/_sidebar.html.erb +++ /dev/null @@ -1,40 +0,0 @@ -
- -
- <%= render 'pages/president'%> -
- - <%if @sidebarelements%> - <%@sidebarelements.each do |p|%> -
- <%@main = p%> - <%=render partial: "pages/element"%> -
-
- <%end%> - <%end%> - <%if 1 == 0%> - - - <%end%> -
\ No newline at end of file diff --git a/app/views/pages/edit.html.erb b/app/views/pages/edit.html.erb index 982480656..334f4f2ab 100644 --- a/app/views/pages/edit.html.erb +++ b/app/views/pages/edit.html.erb @@ -1,10 +1,10 @@
- <%= label_tag 'Redigera sida',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera sida',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Visa sida', @page %>
<%= link_to 'Tillbaka till startsida', root_url %>
-
\ No newline at end of file + diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb index 648ca814d..b29039d7c 100644 --- a/app/views/pages/index.html.erb +++ b/app/views/pages/index.html.erb @@ -1,17 +1,35 @@ -%h1 Listing pages - -%table - %tr - %th - %th - %th - - - @pages.each do |page| - %tr - %td= link_to 'Show', page - %td= link_to 'Edit', edit_page_path(page) - %td= link_to 'Destroy', page, :method => :delete, :data => { :confirm => 'Are you sure?' } - -%br - -= link_to 'New Page', new_page_path +
+
+
+
+

+ Sidor

+ <%= link_to('Skapa ny', new_page_path, class: 'btn btn-u') %> +
+ + + + + + + + + + + + + <% @pages.each do |page| %> + + + + + + + + + <% end %> + +
IdUrlSynligUtskottUppdateradRedigera
<%= page.id %><%= page.url %><%= page.visible %><%= (page.council.nil?) ? link_to(page.council, page.council) : 'Inget' %><%= page.updated_at %><%= link_to('Redigera', edit_page_path(page), class: "btn btn-u") %>
+
+
+
diff --git a/app/views/pages/index.json.jbuilder b/app/views/pages/index.json.jbuilder deleted file mode 100644 index ed1cbcf14..000000000 --- a/app/views/pages/index.json.jbuilder +++ /dev/null @@ -1,4 +0,0 @@ -json.array!(@pages) do |page| - json.extract! page, :id - json.url page_url(page, format: :json) -end diff --git a/app/views/pages/new.html.erb b/app/views/pages/new.html.erb index 32cc97609..c575b48b1 100644 --- a/app/views/pages/new.html.erb +++ b/app/views/pages/new.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Ny sida',nil, :class => 'reg-header'%> + <%= label_tag 'Ny sida',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till start', root_url %>
-
\ No newline at end of file + diff --git a/app/views/pages/show.html.erb b/app/views/pages/show.html.erb index c0ff47f65..4fc010edc 100644 --- a/app/views/pages/show.html.erb +++ b/app/views/pages/show.html.erb @@ -1,8 +1,8 @@ -<% @edit = true%> -<%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Lägg till element"), new_council_page_page_element_path(@council), class: "btn-u btn-u-small"%> -<%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Visa alla element"), council_page_page_elements_path(@council), class: "btn-u btn-u-small"%>
+<%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Lägg till element"), + new_page_page_element_path(@page), class: "btn-u btn-u-small" %> +<%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Visa alla element"), + page_page_elements_path(@page), class: "btn-u btn-u-small" %> +
Den här sidan visas endast för de med rättighet att redigera. För att se hur sidan faktiskt se ut gå till: -

<%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Visa utskottssida"), council_path(@council), class: "btn-u btn-u-small"%>
-
-<%=render partial: "main"%> \ No newline at end of file +<%= render @page %> diff --git a/app/views/pages/show.json.jbuilder b/app/views/pages/show.json.jbuilder deleted file mode 100644 index 1949648a2..000000000 --- a/app/views/pages/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @page, :id, :created_at, :updated_at diff --git a/app/views/posts/_table.html.erb b/app/views/posts/_table.html.erb new file mode 100644 index 000000000..c9607a946 --- /dev/null +++ b/app/views/posts/_table.html.erb @@ -0,0 +1,35 @@ +
+

Poster

+ +
+ <% first = true %> + <% collection.each do |post| %> +
+
+
+ Beskrivning: <%= simple_format(post.description) %> +
+
+ Vem har posten just nu? +
    + <% post.profiles.each do |profile|%> +
  • <%=profile.full_name%>
  • + <%end%> +
+ +
+
+
+ <% first = false %> + <% end %> +
+
+ diff --git a/app/views/posts/edit.html.erb b/app/views/posts/edit.html.erb index bc39d0cb8..78f86c3ed 100644 --- a/app/views/posts/edit.html.erb +++ b/app/views/posts/edit.html.erb @@ -1,7 +1,7 @@
- <%= label_tag 'Redigera post',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera post',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Radera post', council_post_path(@council,@post),method: :delete %>
<%= link_to 'Visa utskottets poster', council_posts_path(@council) %>
@@ -9,4 +9,4 @@ <%= link_to 'Tillbaka till startsida', root_url %>
-
\ No newline at end of file + diff --git a/app/views/posts/new.html.erb b/app/views/posts/new.html.erb index f840ecd4d..57f728de8 100644 --- a/app/views/posts/new.html.erb +++ b/app/views/posts/new.html.erb @@ -1,10 +1,10 @@
- <%= label_tag 'Ny post',nil, :class => 'reg-header'%> + <%= label_tag 'Ny post',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Visa utskott', @council %>
<%= link_to 'Tillbaka till startsida', root_url %>
-
\ No newline at end of file + diff --git a/app/views/profiles/_form.html.erb b/app/views/profiles/_form.html.erb index f993e135f..fc3f76e52 100644 --- a/app/views/profiles/_form.html.erb +++ b/app/views/profiles/_form.html.erb @@ -1,51 +1,51 @@ <%= form_for(@profile) do |f| %> <%= render 'shared/form_errors', current: @profile%> - <%= f.label 'Namn och efternamn', :class => 'reg-label'%> + <%= f.label 'Namn och efternamn', class: 'reg-label'%>
- <%= f.text_field :name, :class => 'form-control',:placeholder => 'Namn'%> - <%= f.text_field :lastname, :class => 'form-control',:placeholder => 'Efternamn'%> + <%= f.text_field :name, class: 'form-control',:placeholder => 'Namn'%> + <%= f.text_field :lastname, class: 'form-control',:placeholder => 'Efternamn'%>
- <%= f.label 'Program', :class => 'reg-label'%> + <%= f.label 'Program', class: 'reg-label'%>
<%= f.select :program, options_for_select([ [" ","Oklart"], ["Teknisk Fysik"], ["Teknisk Matematik"], - ["Teknisk Nanovetenskap"]],@profile.program),{}, html_options = {:class => "listBox form-control",:selected => :program , :style=>"float:left;"} %> + ["Teknisk Nanovetenskap"]],@profile.program),{}, html_options = {class: "listBox form-control",:selected => :program , :style=>"float:left;"} %>
- <%= f.label 'Började på programmet', :class => 'reg-label'%> + <%= f.label 'Började på programmet', class: 'reg-label'%>
<%= f.select( :start_year, (1954..(Time.zone.now.year+1)).to_a.reverse!, class: "form-control")%>
- <%= f.label 'Profilbild', :class => 'reg-label'%> + <%= f.label 'Profilbild', class: 'reg-label'%>
<% if @profile.avatar_file_name%> <%= image_tag(@profile.avatar(:thumb))%> <% end %> - <%= f.file_field :avatar, :class => 'form-control' %> + <%= f.file_field :avatar, class: 'form-control' %>
<% if @profile.posts.count > 0%> - <%= f.label 'Visningspost', :class => 'reg-label'%> + <%= f.label 'Visningspost', class: 'reg-label'%>
- <%= f.select :first_post, options_for_select(@profile.posts.collect{ |r| [r.title, r.id] }),:class => 'form-control'%> + <%= f.select :first_post, options_for_select(@profile.posts.collect{ |r| [r.title, r.id] }),class: 'form-control'%>
<% end %>
Nedanstående fält är till för t.ex. sektionsval,
uppgifterna i fälten kan endast ses av dig själv,styrelsen och valberedningen.
- <%= f.label 'STIL-id', :class => 'reg-label'%> + <%= f.label 'STIL-id', class: 'reg-label'%>
<%= f.text_field :stil_id, placeholder: "Stil-id", class: "form-control"%>
- <%= f.label 'E-post', :class => 'reg-label'%> + <%= f.label 'E-post', class: 'reg-label'%>
<%= f.text_field :email, placeholder: "E-post", class: "form-control"%>
- <%= f.label 'Telefonnummer', :class => 'reg-label'%> + <%= f.label 'Telefonnummer', class: 'reg-label'%>
<%= f.text_field :phone, placeholder: "Telefonnumer", class: "form-control"%>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/profiles/edit.html.erb b/app/views/profiles/edit.html.erb index 8b43ee94a..d47b4e248 100644 --- a/app/views/profiles/edit.html.erb +++ b/app/views/profiles/edit.html.erb @@ -1,9 +1,9 @@
- <%= label_tag 'Redigera din användarprofil',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera din användarprofil',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Tillbaka till profilen', @profile %>
-
\ No newline at end of file + diff --git a/app/views/proposals/form.html.haml b/app/views/proposals/form.html.haml index 529078648..e0f3e819a 100644 --- a/app/views/proposals/form.html.haml +++ b/app/views/proposals/form.html.haml @@ -13,7 +13,7 @@ skulle råka ladda om sidan. = form_for @proposal, :url => proposals_generate_path(:format => :pdf), - :html => { :class => 'proposal-form' }do |f| + :html => { class: 'proposal-form' }do |f| %fieldset %legend Grundläggande information @@ -50,5 +50,5 @@ Yrka mindre! %hr - = f.submit 'Skapa motion!', :class => 'btn btn-default' + = f.submit 'Skapa motion!', class: 'btn btn-default' diff --git a/app/views/short_links/_form.html.haml b/app/views/short_links/_form.html.haml index 9c02caa0b..48c8e7af1 100644 --- a/app/views/short_links/_form.html.haml +++ b/app/views/short_links/_form.html.haml @@ -1,19 +1,19 @@ = form_for @short_link, - :html => { :class => 'form-inline shortlink-check' } do |f| + :html => { class: 'form-inline shortlink-check' } do |f| .form-group - = f.label :link, :class => 'sr-only' - = f.text_field :link, :class => 'form-control shortlink-field', + = f.label :link, class: 'sr-only' + = f.text_field :link, class: 'form-control shortlink-field', :placeholder => ShortLink.human_attribute_name(:link) %span ⟶ .form-group - = f.label :target, :class => 'sr-only' - = f.text_field :target, :class => 'form-control', + = f.label :target, class: 'sr-only' + = f.text_field :target, class: 'form-control', :placeholder => ShortLink.human_attribute_name(:target) - = f.submit 'Skapa ny snabblänk', :class => 'btn btn-default' + = f.submit 'Skapa ny snabblänk', class: 'btn btn-default' %p.shortlink-notice{ :style => 'display: none' } En snabblänk med det namnet finns redan. Du kommer att spara över diff --git a/app/views/work_posts/_form.html.erb b/app/views/work_posts/_form.html.erb index fc157d0db..45946c811 100644 --- a/app/views/work_posts/_form.html.erb +++ b/app/views/work_posts/_form.html.erb @@ -11,57 +11,57 @@ <% end %>
- <%= f.label 'Titel', :class => 'reg-label'%> + <%= f.label 'Titel', class: 'reg-label'%>
- <%= f.text_field :title,:class => 'form-control' %> + <%= f.text_field :title,class: 'form-control' %>
- <%= f.label 'Text', :class => 'reg-label'%> + <%= f.label 'Text', class: 'reg-label'%>
- <%= f.text_area :description,:class => 'form-control', size: "60x8" %> + <%= f.text_area :description,class: 'form-control', size: "60x8" %>
- <%= f.label 'Företag', :class => 'reg-label'%> + <%= f.label 'Företag', class: 'reg-label'%>
- <%= f.text_field :company,:class => 'form-control' %> + <%= f.text_field :company,class: 'form-control' %>
- <%= f.label 'Område', :class => 'reg-label'%> + <%= f.label 'Område', class: 'reg-label'%>
- <%= f.text_field :category,:class => 'form-control' %> + <%= f.text_field :category,class: 'form-control' %>
- <%= f.label 'Typ', :class => 'reg-label'%> + <%= f.label 'Typ', class: 'reg-label'%>
- <%= f.text_field :kind,:class => 'form-control' %> + <%= f.text_field :kind,class: 'form-control' %>
- <%= f.label 'Målgrupp', :class => 'reg-label'%> + <%= f.label 'Målgrupp', class: 'reg-label'%>
- <%= f.text_field :for,:class => 'form-control' %> + <%= f.text_field :for,class: 'form-control' %>
- <%= f.label 'Länk', :class => 'reg-label'%> + <%= f.label 'Länk', class: 'reg-label'%>
- <%= f.text_field :link,:class => 'form-control' %> + <%= f.text_field :link,class: 'form-control' %>
- <%= f.label 'Synlig?', :class => 'reg-label'%> - <%= f.check_box :visible,:class => 'form-control' %> - <%= f.label 'Deadline', :class => 'reg-label'%>
+ <%= f.label 'Synlig?', class: 'reg-label'%> + <%= f.check_box :visible,class: 'form-control' %> + <%= f.label 'Deadline', class: 'reg-label'%>
Fulfix: för ingen deadline, sätt ett datum efter
2100-03-25
- <%= f.date_field :deadline, :class => 'form-control' %> + <%= f.date_field :deadline, class: 'form-control' %>
- <%= f.label 'Publicera', :class => 'reg-label'%>
+ <%= f.label 'Publicera', class: 'reg-label'%>
Måste sättas, sätt idag för att visa direkt.
- <%= f.date_field :publish, :class => 'form-control' %> + <%= f.date_field :publish, class: 'form-control' %>
- <%= f.label 'Bild', :class => 'reg-label'%> + <%= f.label 'Bild', class: 'reg-label'%> <% if @work_post.picture_file_name%> <%= image_tag(@work_post.picture(:view),class: "img-responsive")%>
<% end %>
- <%= f.file_field :picture,:class => 'form-control' %> + <%= f.file_field :picture,class: 'form-control' %>
- <%= f.submit "Spara",:class => 'btn-u pull-right' %> + <%= f.submit "Spara",class: 'btn-u pull-right' %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/work_posts/edit.html.erb b/app/views/work_posts/edit.html.erb index bdab12c6e..c8c70cf65 100644 --- a/app/views/work_posts/edit.html.erb +++ b/app/views/work_posts/edit.html.erb @@ -1,11 +1,11 @@
- <%= label_tag 'Redigera jobbpost',nil, :class => 'reg-header'%> + <%= label_tag 'Redigera jobbpost',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Radera post', work_post_path(@work_post),method: :delete %>
<%= link_to 'Visa poster', work_posts_path %>
<%= link_to 'Tillbaka till startsida', root_url %>
-
\ No newline at end of file + diff --git a/app/views/work_posts/new.html.erb b/app/views/work_posts/new.html.erb index 9452170fe..9f77e2ecb 100644 --- a/app/views/work_posts/new.html.erb +++ b/app/views/work_posts/new.html.erb @@ -1,10 +1,10 @@
- <%= label_tag 'Ny jobbpost',nil, :class => 'reg-header'%> + <%= label_tag 'Ny jobbpost',nil, class: 'reg-header'%> <%= render 'form'%> <%= link_to 'Visa jobbposter',work_posts_path %>
<%= link_to 'Tillbaka till startsida', root_url %>
-
\ No newline at end of file + diff --git a/config/routes.rb b/config/routes.rb index 2ea047523..f6b1496d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,7 +39,6 @@ resources :notices - scope :hilbertcafe do namespace :admin do resources :cafe_works, path: :jobb, controller: :cafe_works, except: :index do @@ -83,6 +82,10 @@ resources :menus, path: :meny, except: :show + resources :pages, path: :sida do + resources :page_elements, path: :element, on: :member, except: :show + end + resources :posts, path: :poster, only: :index do get :display, on: :member get :collapse, on: :collection @@ -93,9 +96,6 @@ patch :remove_profile, on: :member patch :add_profile_username, on: :member end - resource :page, path: :sida do - resources :page_elements, path: :element, on: :member - end end resources :faqs, path: :faq @@ -148,7 +148,7 @@ end post '' => 'albums#index', as: :index_albums - resources :short_links, except: [ :show, :update, :edit ] do + resources :short_links, except: [:show, :update, :edit] do collection do get 'go' => 'short_links#go' get 'check' => 'short_links#check' diff --git a/db/migrate/20410822171449_add_fields_to_page.rb b/db/migrate/20410822171449_add_fields_to_page.rb new file mode 100644 index 000000000..145936da4 --- /dev/null +++ b/db/migrate/20410822171449_add_fields_to_page.rb @@ -0,0 +1,9 @@ +class AddFieldsToPage < ActiveRecord::Migration + def change + add_column :pages, :url, :string + add_column :pages, :visible, :boolean + add_column :pages, :title, :string + add_index :pages, :url + add_index :pages, :council_id + end +end diff --git a/db/migrate/20410822171450_change_president_column_councils.rb b/db/migrate/20410822171450_change_president_column_councils.rb new file mode 100644 index 000000000..3ef8bacf8 --- /dev/null +++ b/db/migrate/20410822171450_change_president_column_councils.rb @@ -0,0 +1,8 @@ +class ChangePresidentColumnCouncils < ActiveRecord::Migration + def change + remove_column :councils, :president, :integer + remove_column :councils, :vicepresident, :integer + add_column :councils, :president_id, :integer + add_column :councils, :vicepresident_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 74634ac4f..c601e4b61 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20410822171448) do +ActiveRecord::Schema.define(version: 20410822171450) do create_table "album_categories", force: :cascade do |t| t.string "name", limit: 255 @@ -117,8 +117,6 @@ t.string "title", limit: 255 t.string "url", limit: 255 t.text "description", limit: 65535 - t.integer "president", limit: 4 - t.integer "vicepresident", limit: 4 t.string "logo_file_name", limit: 255 t.string "logo_content_type", limit: 255 t.integer "logo_file_size", limit: 4 @@ -127,6 +125,8 @@ t.datetime "created_at" t.datetime "updated_at" t.integer "contact_id", limit: 4 + t.integer "president_id", limit: 4 + t.integer "vicepresident_id", limit: 4 end create_table "documents", force: :cascade do |t| @@ -293,8 +293,14 @@ t.datetime "created_at" t.datetime "updated_at" t.integer "council_id", limit: 4 + t.string "url", limit: 255 + t.boolean "visible", limit: 1 + t.string "title", limit: 255 end + add_index "pages", ["council_id"], name: "index_pages_on_council_id", using: :btree + add_index "pages", ["url"], name: "index_pages_on_url", using: :btree + create_table "permission_posts", force: :cascade do |t| t.integer "permission_id", limit: 4 t.integer "post_id", limit: 4 diff --git a/lib/tasks/tests_data.rake b/lib/tasks/tests_data.rake index 5a2cc9eb2..69b7ae042 100644 --- a/lib/tasks/tests_data.rake +++ b/lib/tasks/tests_data.rake @@ -4,6 +4,7 @@ namespace :load_database do # Councils pryl = Council.find_or_create_by!(title: 'Prylmästeriet', url: 'pryl', description: 'Detta är Prylmästeriet', public: true) + sexm = Council.find_or_create_by!(title: 'Sexmästeriet', url: 'sex', description: 'Detta är Sexmästeriet', public: true) cafem = Council.find_or_create_by!(title: 'Cafemästeriet', diff --git a/spec/features/visit_a_council.rb b/spec/features/visit_a_council.rb new file mode 100644 index 000000000..e373e6b43 --- /dev/null +++ b/spec/features/visit_a_council.rb @@ -0,0 +1,13 @@ +require 'rails_helper' +feature 'admin tries to login' do + let(:user) { create(:user) } + let(:council) { create(:council, :with_page, public: true) } + scenario 'they get alert with text "Loggade in"' do + visit %(/utskott/#{council.to_param}) + fill_in 'user_username', with: user.username + fill_in 'user_password', with: '12345678' + click_button 'Logga in' + page.should have_css('div.alert.alert-info') # Verify we get an alert + find('div.alert.alert-info').text.should include('Loggade in.') # Verify that the alert states we are signed in + end +end diff --git a/spec/models/council_spec.rb b/spec/models/council_spec.rb new file mode 100644 index 000000000..e69de29bb From 49de625d49c5b29b7529c074bc4315e9fe915c5d Mon Sep 17 00:00:00 2001 From: davidwessman Date: Tue, 31 Mar 2015 11:56:15 +0200 Subject: [PATCH 05/19] Lots of fixes, removed ALL mentions of moderator? --- app/controllers/admin/rents_controller.rb | 9 - app/controllers/albums_controller.rb | 227 +++++----------------- app/controllers/faqs_controller.rb | 57 ++---- app/controllers/notices_controller.rb | 71 ++----- app/controllers/users_controller.rb | 77 +++----- app/controllers/work_posts_controller.rb | 83 +++----- app/models/ability.rb | 6 +- app/views/notices/_form.html.erb | 30 +-- app/views/notices/_notice.html.erb | 24 +-- app/views/notices/index.html.erb | 5 +- config/routes.rb | 14 +- lib/tasks/tests_data.rake | 4 + spec/factories/notice.rb | 11 ++ spec/features/admin_notice_spec.rb | 30 +++ 14 files changed, 210 insertions(+), 438 deletions(-) create mode 100644 spec/factories/notice.rb create mode 100644 spec/features/admin_notice_spec.rb diff --git a/app/controllers/admin/rents_controller.rb b/app/controllers/admin/rents_controller.rb index 07ad8a57a..f38588665 100644 --- a/app/controllers/admin/rents_controller.rb +++ b/app/controllers/admin/rents_controller.rb @@ -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 @@ -37,14 +36,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) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index ff572adef..af57f84a8 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -1,214 +1,89 @@ # 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 '+@kategori.name+' 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 '+@kategorin.name+' 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 '+@subcategory.text+' 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 '+@subcategory.text+' 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 { |foto| + flash[:notice] = %(Laddar upp #{@count}/#{@total}) + @album.images.create(foto: foto, subcategory_id: params[:subcategory_id]) + @count = @count+1; + } + 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.fetch(:album, {}).permit(:title, :description, :author, :location, + :public, :start_date, :end_date, album_category_ids: [], + subcategory_ids: [], images_parameters: [:id, :foto]) end end diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb index ed2787f71..fc6c47180 100644 --- a/app/controllers/faqs_controller.rb +++ b/app/controllers/faqs_controller.rb @@ -1,10 +1,7 @@ # encoding:UTF-8 class FaqsController < ApplicationController - - before_action :authenticate_editor, only: [:edit, :update, :destroy] + load_permissions_and_authorize_resource before_action :set_editor, only: [:new, :show, :edit, :index] - before_action :set_faq, only: [:show, :edit, :update, :destroy] - def index @faq = Faq.where.not(answer: '').where(category: 'main') @@ -17,7 +14,6 @@ def show end def new - @faq = Faq.new if params[:category].present? @faq.category = params[:category] end @@ -27,63 +23,36 @@ def edit end def destroy - @faq.destroy() - respond_to do |format| - format.html { redirect_to :faqs } - format.json { head :no_content } - end + @faq.destroy + redirect_to :faqs end def update - respond_to do |format| - if @faq.update(faq_params) - format.html { redirect_to @faq, notice: 'FAQ uppdaterades!' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @faq.errors, status: :unprocessable_entity } - end + if @faq.update(faq_params) + redirect_to @faq, notice: 'FAQ uppdaterades!' + else + render action: 'edit' end end def create - @faq = Faq.new(faq_params) - if @faq.answer == nil + if @faq.answer.nil? @faq.answer = '' end - respond_to do |format| - if @faq.save - format.html { redirect_to @faq, notice: 'Frågan skapades!' } - format.json { render action: 'show', status: :created, location: @faq } - else - format.html { render action: 'new' } - format.json { render json: @faq.errors, status: :unprocessable_entity } - end + if @faq.save + redirect_to @faq, notice: 'Frågan skapades!' + else + render action: 'new' end end private - def set_faq - @faq = Faq.find(params[:id]) - end - - def authenticate_editor - if !(current_user) || !(current_user.moderator?(:faq)) - flash[:error] = "Funkar inte" - redirect_to :faq - end - end def set_editor - if (current_user) && (current_user.moderator?(:faq)) - @editor = true - else - @editor = false - end + @editor = can? :manage, Faq end def faq_params params.require(:faq).permit(:question, :answer, :category) end - end diff --git a/app/controllers/notices_controller.rb b/app/controllers/notices_controller.rb index f9b4f8754..895a73338 100644 --- a/app/controllers/notices_controller.rb +++ b/app/controllers/notices_controller.rb @@ -1,92 +1,53 @@ class NoticesController < ApplicationController - before_action :authenticate, except: [:image] - before_action :set_notice, only: [:show, :edit, :update, :destroy,:hide,:display,:image] + load_permissions_and_authorize_resource def index - @notices = Notice.all @notice_grid = initialize_grid(@notices) end def show - end def new - @notice = Notice.new end def edit - end def create - @notice = Notice.new(notice_params) - respond_to do |format| - if @notice.save - format.html { redirect_to @notice, notice: %(#{t(:notice)} #{t(:success_create)}.)} - format.json { render action: 'show', status: :created, location: @notice } - else - format.html { render action: 'new' } - format.json { render json: @notice.errors, status: :unprocessable_entity } - end + if @notice.save + redirect_to @notice, notice: %(#{t(:notice)} #{t(:success_create)}.) + else + render action: :new end end def update - respond_to do |format| - if @notice.update(notice_params) - format.html { redirect_to @notice, notice: %(#{t(:notice)} #{t(:success_update)}.) } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @notice.errors, status: :unprocessable_entity } - end + if @notice.update(notice_params) + redirect_to @notice, notice: %(#{t(:notice)} #{t(:success_update)}.) + else + render action: :edit end end def destroy @notice.destroy - respond_to do |format| - format.html { redirect_to notices_url } - format.json { head :no_content } - end - end - - # Requested to hide the current Notice - # /d.wessman - def hide - @notice.display(false) - end - - # Requested to display the current Notice - # /d.wessman - def display - @notice.display(true) + redirect_to notices_url end - # Action to show profile picture only already authenticated def image if @notice.image? - if(params[:style] == "original" || params[:style] == "large" || params[:style] == "small") - send_file(@notice.image.path(params[:style]), filename:@notice.image_file_name, type: "image/jpg",disposition: 'inline',x_sendfile: true) + if (params[:style] == "original" || params[:style] == "large" || params[:style] == "small") + send_file(@notice.image.path(params[:style]), filename: @notice.image_file_name, type: "image/jpg", disposition: 'inline', x_sendfile: true) else - send_file(@notice.image.path(:large), filename:@notice.image_file_name, type: "image/jpg",disposition: 'inline',x_sendfile: true) + send_file(@notice.image.path(:large), filename: @notice.image_file_name, type: "image/jpg", disposition: 'inline', x_sendfile: true) end end end private - def authenticate - redirect_to root_path unless current_user && (current_user.moderator?(:notiser)) - end - # Use callbacks to share common setup or constraints between actions. - def set_notice - @notice = Notice.find_by_id(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def notice_params - params.require(:notice).permit(:title, :description, :public, :d_publish, :d_remove, :sort,:image) - end + def notice_params + params.require(:notice).permit(:title, :description, :public, :d_publish, :d_remove, :sort, :image) + end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b6ef1164d..9013171ea 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,70 +1,41 @@ # encoding:UTF-8 -class UsersController < ApplicationController +class UsersController < ApplicationController load_permissions_and_authorize_resource - before_filter :find_user, :only => [:edit, :update,:destroy,:update_password] - before_filter :owner_required, :only => [:edit, :update] - - def change_role - @user = User.find params[:user_id] - @role = Role.find params[:role_id] - @user.update_attribute(:role, @role) - redirect_to users_path + + def index end - - def index - @users = User.all + + def update_password + if @user.update_with_password(user_params) + redirect_to :edit_user_registration, notice: 'Användaruppgifter uppdaterades.' + else + redirect_to :edit_user_registration, notice: 'Lösenord måste fyllas i för att ändra uppgifter.' + end end - def update_password - respond_to do |format| - if @user.update_with_password(user_params) - format.html { redirect_to :edit_user_registration, notice: 'Användaruppgifter uppdaterades.' } - format.json { head :no_content } - else - format.html{ redirect_to :edit_user_registration , notice: 'Lösenord måste fyllas i för att ändra uppgifter.' } - format.json { head :no_content } - end - end - end + def update + if @user.update(user_params) + flash[:notice] = 'Användare uppdaterades.' + redirect_to edit_user_path @user + else - def update - @user.update(user_params) - flash[:notice] = 'Användare uppdaterades.' - redirect_to edit_user_path @users + end end def destroy - respond_to do |format| - if @user.update_with_password(user_params) - @user.profile.posts.clear - if @user.destroy - - format.html { redirect_to root_url, notice: 'Användare togs bort..' } - format.json { head :no_content } - end - else - format.html{ redirect_to :edit_user_registration , notice: 'Lösenord måste fyllas i för att radera användare.' } - format.json { head :no_content } + if @user.update_with_password(user_params) + @user.profile.posts.clear + if @user.destroy + redirect_to root_url, notice: 'Användare togs bort..' end + else + redirect_to :edit_user_registration, notice: 'Lösenord måste fyllas i för att radera användare.' end end - private + private + def user_params params.require(:user).permit(:username, :email, :password, :password_confirmation, :current_password) end - def authenticate_admin! - flash[:error] = t('the_role.access_denied') - redirect_to(:back) unless current_user && current_user.moderator?(:users) - rescue ActionController::RedirectBackError - redirect_to root_path - end - def find_user - @user = User.find(params[:id]) - - # TheRole: You should define OWNER CHECK OBJECT - # When editable object was found - - @owner_check_object = @user - end end diff --git a/app/controllers/work_posts_controller.rb b/app/controllers/work_posts_controller.rb index f50c9ae6e..160434454 100644 --- a/app/controllers/work_posts_controller.rb +++ b/app/controllers/work_posts_controller.rb @@ -1,92 +1,55 @@ # encoding:UTF-8 -class WorkPostsController < ApplicationController - - before_filter :authenticate_user! - before_filter :authenticate, only: [:new, :create,:edit,:destroy,:update] +class WorkPostsController < ApplicationController + load_permissions_and_authorize_resource before_action :set_edit - before_action :set_work_post, except: [:index,:new,:create] - - def index @work_posts = WorkPost.publish @work_post_grid = initialize_grid(WorkPost.publish) @not_published_grid = initialize_grid(WorkPost.unpublish) - if(WorkPost.unpublish.count > 0) + if (WorkPost.unpublish.count > 0) @edit_grid = true end end - - def show + def show end - + def new - @work_post = WorkPost.new end - + def edit end - + def create - @work_post = WorkPost.new(work_post_params) @work_post.responsible = current_user.profile.id - respond_to do |format| - if @work_post.save - format.html { redirect_to work_posts_path, notice: 'Jobbposten skapades, success!.' } - format.json { render action: 'show', status: :created, location: @work_post } - else - format.html { render action: 'new' } - format.json { render json: @work_post.errors, status: :unprocessable_entity } - end + if @work_post.save + redirect_to work_posts_path, notice: 'Jobbposten skapades, success!.' + else + render action: 'new' end end def update - respond_to do |format| - if @work_post.update(work_post_params) - format.html { redirect_to work_posts_path, notice: 'Jobbposten uppdaterades, gött' } - format.json { head :no_content } - else - format.html { render action: 'edit' } - format.json { render json: @work_post.errors, status: :unprocessable_entity } - end + if @work_post.update(work_post_params) + redirect_to work_posts_path, notice: 'Jobbposten uppdaterades, gött' + else + render action: 'edit' end end def destroy @work_post.destroy - respond_to do |format| - format.html { redirect_to work_posts_path,notice: 'Jobbposten raderades.' } - format.json { head :no_content } - end + redirect_to work_posts_path, notice: 'Jobbposten raderades.' end private - def authenticate - flash[:error] = t('the_role.access_denied') - redirect_to(:back) unless current_user.moderator?(:jobbportal) - - rescue ActionController::RedirectBackError - redirect_to root_path - end - def set_edit - if(current_user) && (current_user.moderator?(:jobbportal)) - @edit = true - else - @edit = false - end - end - # Use callbacks to share common setup or constraints between actions. - def set_work_post - @work_post = WorkPost.find_by_id(params[:id]) - if(@work_post == nil) - @work_post = WorkPost.new() - end - end - # Never trust parameters from the scary internet, only allow the white list through. - def work_post_params - params.fetch(:work_post).permit(:title,:description,:company,:deadline,:kind,:for,:visible,:publish,:picture,:category,:link) - end + def set_edit + @edit = can?(:manage, WorkPost) + end + + def work_post_params + params.fetch(:work_post).permit(:title, :description, :company, :deadline, :kind, :for, :visible, :publish, :picture, :category, :link) + end end diff --git a/app/models/ability.rb b/app/models/ability.rb index ce5a8cfb1..b63767adc 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -7,10 +7,9 @@ def initialize(user) user.profile ||= Profile.new # Abilities that everyone get. - can :read, News - can :read, Council - can :read, Election + can :read, [News, Council, Post, Page, Election] can :read, Document, public: true + can :image, Notice # TODO Should be removed when everyone is required to log in. # /d.wessman 2015-03-28 @@ -19,6 +18,7 @@ def initialize(user) # Abilities all signed in users get if user.id + can :manage, User, id: user.id can :nominate, Election can :candidate, Election can :manage, Candidate, profile_id: user.profile.id diff --git a/app/views/notices/_form.html.erb b/app/views/notices/_form.html.erb index a42417b5d..c3a98203e 100644 --- a/app/views/notices/_form.html.erb +++ b/app/views/notices/_form.html.erb @@ -1,43 +1,43 @@ <%= form_for(@notice) do |f| %> - <%=render 'shared/form_errors', current: @notice%> + <%= render 'shared/form_errors', current: @notice %> - <%= f.label :title, class: 'reg-label'%> + <%= f.label :title, class: 'reg-label' %>
- <%= f.text_field :title,class: 'form-control' %> + <%= f.text_field :title, class: 'form-control' %>
- <%= f.label :description, class: 'reg-label'%> + <%= f.label :description, class: 'reg-label' %>
- <%= f.text_area :description,class: 'form-control',size:"120x10" %> + <%= f.text_area :description, class: 'form-control', size: "120x10" %>
- <%= f.label :public, class: 'reg-label'%> + <%= f.label :public, class: 'reg-label' %>
<%= f.check_box :public %>
- <%= f.label :d_publish, class: 'reg-label'%> + <%= f.label :d_publish, class: 'reg-label' %>
<%= f.date_field :d_publish, class: "form-control", id: 'datepicker1' %>
- <%= f.label :d_remove, class: 'reg-label'%> + <%= f.label :d_remove, class: 'reg-label' %>
<%= f.date_field :d_remove, class: "form-control", id: 'datepicker2' %>
- <%= f.label :sort, class: 'reg-label'%> + <%= f.label :sort, class: 'reg-label' %>
- <%= f.number_field :sort ,class: 'form-control'%> + <%= f.number_field :sort, class: 'form-control' %>
- <%= f.label :image, class: 'reg-label'%> + <%= f.label :image, class: 'reg-label' %>
- <% if @notice.image?%> - <%= image_tag(image_notice_path(@notice, style: 'small'))%>
+ <% if @notice.image? %> + <%= image_tag(image_notice_path(@notice, style: 'small')) %>
<% end %> - <%= f.file_field :image, class: 'form-control' %> + <%= f.file_field :image, class: 'form-control' %>
- <%= f.submit class:"btn btn-u" %> + <%= f.submit id: 'submit-notice', class: "btn btn-u" %>
<% end %> diff --git a/app/views/notices/_notice.html.erb b/app/views/notices/_notice.html.erb index 3948e8a90..025ec566a 100644 --- a/app/views/notices/_notice.html.erb +++ b/app/views/notices/_notice.html.erb @@ -1,13 +1,13 @@ -

<%=notice.title%>

+

<%= notice.title %>

- <% if notice.image?%> -
- <%= image_tag image_notice_path(notice,style: "large"), class: "img-responsive"%> -
-
- <%else%> -
- <%end%> - <%=simple_format(notice.description)%> -
-
\ No newline at end of file + <% if notice.image? %> +
+ <%= image_tag image_notice_path(notice, style: "large"), class: "img-responsive" %> +
+
+ <% else %> +
+ <% end %> + <%= simple_format(notice.description) %> +
+
diff --git a/app/views/notices/index.html.erb b/app/views/notices/index.html.erb index 6fecb96c7..3448a0382 100644 --- a/app/views/notices/index.html.erb +++ b/app/views/notices/index.html.erb @@ -1,7 +1,7 @@ <% provide(:title, 'Notiser') %>
-

Kandidaturer

+

Notiser

<%= grid(@notice_grid) do |g| g.row_attributes do |post| if (post.public == true) @@ -17,4 +17,5 @@ g.column name: "Sorteringsindex", attribute: 'sort' end -%>
-
\ No newline at end of file + <%=link_to('Skapa ny', new_notice_path, class: 'btn btn-u')%> +
diff --git a/config/routes.rb b/config/routes.rb index f6b1496d5..0c2d68210 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,7 +29,6 @@ get 'logga_in' => 'devise/sessions#new', as: :new_user_session post 'logga_in' => 'devise/sessions#create', as: :user_session delete 'logga_ut' => 'devise/sessions#destroy', as: :destroy_user_session - patch 'anvandare/redigera' => 'users#change_role', as: :change_role end get 'anvandare' => 'users#index', as: :users @@ -37,8 +36,6 @@ # Scope to change urls to swedish scope path_names: {new: 'ny', edit: 'redigera'} do - resources :notices - scope :hilbertcafe do namespace :admin do resources :cafe_works, path: :jobb, controller: :cafe_works, except: :index do @@ -136,17 +133,16 @@ end resources :albums, path: :galleri do - post :edit, on: :member - get :settings, path: :installningar, on: :collection + #post :edit, on: :member + #get :settings, path: :installningar, on: :collection get :upload_images, path: :ladda_upp, on: :member patch :upload_images, path: :ladda_upp, on: :member - delete :destroy_images, path: :ta_bort_bilder, on: :member - post :settings, path: :installningar, on: :collection - post '', on: :member, action: :show + #delete :destroy_images, path: :ta_bort_bilder, on: :member + #post :settings, path: :installningar, on: :collection + #post '', on: :member, action: :show resources :images, path: :bilder, except: [:new] end end - post '' => 'albums#index', as: :index_albums resources :short_links, except: [:show, :update, :edit] do collection do diff --git a/lib/tasks/tests_data.rake b/lib/tasks/tests_data.rake index 69b7ae042..27a7e7418 100644 --- a/lib/tasks/tests_data.rake +++ b/lib/tasks/tests_data.rake @@ -84,5 +84,9 @@ namespace :load_database do link: '/bil', index: 20, visible: true, turbolinks: false) Menu.find_or_create_by!(location: 'För medlemmar', name: 'Hilbertcafé', link: '/hilbertcafe', index: 30, visible: true, turbolinks: false) + + # Notice + Notice.find_or_create_by!(FactoryGirl.attributes_for(:notice)) + Notice.find_or_create_by!(FactoryGirl.attributes_for(:notice)) end end diff --git a/spec/factories/notice.rb b/spec/factories/notice.rb new file mode 100644 index 000000000..c597f19aa --- /dev/null +++ b/spec/factories/notice.rb @@ -0,0 +1,11 @@ +# encoding: UTF-8 +FactoryGirl.define do + factory :notice do + title + description + public true + d_publish { Time.zone.now } + d_remove { Time.zone.now + 10.days } + sort { rand(10..100) } + end +end diff --git a/spec/features/admin_notice_spec.rb b/spec/features/admin_notice_spec.rb new file mode 100644 index 000000000..60ed243ba --- /dev/null +++ b/spec/features/admin_notice_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' +feature 'admin tries to login' do + let(:user) { create(:admin) } + let(:notice) { build(:notice) } + scenario 'they get alert with text "Loggade in"' do + visit '/logga_in' + fill_in 'user_username', with: user.username + fill_in 'user_password', with: '12345678' + click_button 'Logga in' + page.should have_css('div.alert.alert-info') # Verify we get an alert + find('div.alert.alert-info').text.should include('Loggade in.') # Verify that the alert states we are signed in + # TODO Include warden to stub login + #login_as(user, scope: :user) + + # Test notice + visit notices_path + find('h2#notice-headline').text.should include('Notiser') + find(:linkhref, new_notice_path).click + fill_in 'notice_title', with: notice.title + fill_in 'notice_description', with: notice.description + find(:css, "#notice_public").set(notice.public) + fill_in 'notice[d_publish]', with: notice.d_publish + fill_in 'notice[d_remove]', with: notice.d_remove + fill_in 'notice_sort', with: notice.sort + find('#submit-notice').click + + page.should have_css('div.alert.alert-info') + find('div.alert.alert-info').text.should include(%(#{I18n.t(:notice)} #{I18n.t(:success_create)})) + end +end From 18bb9940440f6635f7fcd2df6d5416e749989480 Mon Sep 17 00:00:00 2001 From: davidwessman Date: Tue, 31 Mar 2015 12:38:29 +0200 Subject: [PATCH 06/19] Fixing Hound errors and page-errors --- app/controllers/albums_controller.rb | 11 +++++----- app/controllers/notices_controller.rb | 14 ++++++++---- app/controllers/page_elements_controller.rb | 2 +- app/views/albums/_links.html.erb | 4 ++-- app/views/councils/show.html.erb | 24 +++++++++++++-------- app/views/pages/_page.html.erb | 18 +++++++--------- 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index af57f84a8..de3c73f02 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -33,7 +33,6 @@ def create else render action: "new" end - end def destroy @@ -53,11 +52,11 @@ def upload_images #===== The magic is here ;) @count = 1 @total = params[:fotos].count - params[:fotos].each { |foto| + 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 @@ -82,8 +81,8 @@ def set_edit 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 diff --git a/app/controllers/notices_controller.rb b/app/controllers/notices_controller.rb index 895a73338..b748aedec 100644 --- a/app/controllers/notices_controller.rb +++ b/app/controllers/notices_controller.rb @@ -37,10 +37,14 @@ def destroy def image if @notice.image? - if (params[:style] == "original" || params[:style] == "large" || params[:style] == "small") - send_file(@notice.image.path(params[:style]), filename: @notice.image_file_name, type: "image/jpg", disposition: 'inline', x_sendfile: true) + if params[:style] == 'original' || params[:style] == 'large' || params[:style] == 'small' + send_file(@notice.image.path(params[:style]), + filename: @notice.image_file_name, type: 'image/jpg', + disposition: 'inline', x_sendfile: true) else - send_file(@notice.image.path(:large), filename: @notice.image_file_name, type: "image/jpg", disposition: 'inline', x_sendfile: true) + send_file(@notice.image.path(:large), + filename: @notice.image_file_name, type: 'image/jpg', + disposition: 'inline', x_sendfile: true) end end end @@ -48,6 +52,8 @@ def image private def notice_params - params.require(:notice).permit(:title, :description, :public, :d_publish, :d_remove, :sort, :image) + params.require(:notice).permit(:title, :description, + :public, :d_publish, :d_remove, + :sort, :image) end end diff --git a/app/controllers/page_elements_controller.rb b/app/controllers/page_elements_controller.rb index 751022b32..31b9f8a58 100644 --- a/app/controllers/page_elements_controller.rb +++ b/app/controllers/page_elements_controller.rb @@ -18,7 +18,7 @@ def edit def create if @page_element.save - redirect_to edit_page_page_element_path[@page, @page_element], notice: 'Elementet skapades' + redirect_to edit_page_page_element_path(@page, @page_element), notice: 'Elementet skapades' else render action: :new end diff --git a/app/views/albums/_links.html.erb b/app/views/albums/_links.html.erb index b82851a1d..2f1132e5e 100644 --- a/app/views/albums/_links.html.erb +++ b/app/views/albums/_links.html.erb @@ -1,4 +1,4 @@ -<% if current_user.has_role?(:galleri, :edit) %> +<% if can?(:manage,Album) %> <%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Lägg till bilder"), upload_images_album_path(@album), class: "btn-u btn-u-small" %> <%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Redigera"), edit_album_path(@album), class: "btn-u btn-u-small" %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/councils/show.html.erb b/app/views/councils/show.html.erb index 5bb46c280..33abd0d81 100644 --- a/app/views/councils/show.html.erb +++ b/app/views/councils/show.html.erb @@ -1,14 +1,20 @@ <% title('Utskott') %>
- <%if can? :edit, @council %> - <%= link_to (content_tag(:i, nil, class: "fa fa-edit") + " Redigera"), edit_council_path(@council), class: "btn-u btn-u-small"%> - <%end%> + <% if can? :edit, @council %> + <%= link_to(fa_icon('edit') + ' Redigera', edit_council_path(@council), class: "btn-u btn-u-small") %> + <% end %>
- <% if @page.present? %> - <%=render @page%> - <%end%> - <% if @council.posts.present? %> - <%= render 'posts/table', collection: @council.posts %> - <%end%> +
+ <% if @page.present? %> +
+ <%= render @page %> +
+ <% end %> + <% if @council.posts.present? %> +
+ <%= render 'posts/table', collection: @council.posts %> +
+ <% end %> +
diff --git a/app/views/pages/_page.html.erb b/app/views/pages/_page.html.erb index 234d4c571..884521fe0 100644 --- a/app/views/pages/_page.html.erb +++ b/app/views/pages/_page.html.erb @@ -1,11 +1,9 @@

<%= page.title %>

-
-
- - <%= render page.main %> -
- -
- <%= render page.side %> -
-
+
+ + <%= render page.main %> +
+ +
+ <%= render page.side %> +
From 4cd6adb01d74f3a09e9d657e4783c40fa4cff50f Mon Sep 17 00:00:00 2001 From: davidwessman Date: Tue, 31 Mar 2015 14:43:14 +0200 Subject: [PATCH 07/19] Fixes RentAbility --- app/models/ability.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index b63767adc..b79c50c42 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -14,7 +14,7 @@ def initialize(user) # TODO Should be removed when everyone is required to log in. # /d.wessman 2015-03-28 can [:read, :update_worker, :remove_worker, :authorize], CafeWork - can [:read, :main], Rent + can [:read, :main, :new, :edit,:create,:update, :destroy,:authorize], Rent # Abilities all signed in users get if user.id From 194a984977f18b3985f532e804ccdc477f276ee7 Mon Sep 17 00:00:00 2001 From: davidwessman Date: Wed, 1 Apr 2015 18:13:35 +0200 Subject: [PATCH 08/19] Fixing locales and adding tests --- app/controllers/application_controller.rb | 7 +- app/helpers/application_helper.rb | 19 ++- app/helpers/constants_helper.rb | 2 - app/models/list.rb | 3 - app/models/permission.rb | 2 +- app/models/post.rb | 2 +- app/views/devise/registrations/new.html.erb | 78 ++++----- app/views/devise/sessions/new.html.erb | 72 ++++---- app/views/devise/shared/_links.erb | 12 +- app/views/election/nominations/_form.html.erb | 2 +- app/views/election/nominations/create.js.erb | 6 +- app/views/elections/_index.html.erb | 2 +- app/views/layouts/_admin_dropdown.html.erb | 63 +++++++ app/views/layouts/_topbar.html.erb | 105 ++++-------- app/views/notices/_notice.html.erb | 8 +- config/locales/devise.sv.yml | 3 +- config/locales/en.yml | 29 ++++ config/locales/sv.the_role.yml | 17 -- config/locales/sv.yml | 154 +++++++++++------- lib/tasks/tests_data.rake | 11 +- spec/factories/role.rb | 4 - spec/features/admin_rent_spec.rb | 30 ++++ spec/features/login_visit_election.rb | 33 ++++ spec/features/visit_a_council.rb | 2 +- 24 files changed, 408 insertions(+), 258 deletions(-) delete mode 100644 app/helpers/constants_helper.rb delete mode 100644 app/models/list.rb create mode 100644 app/views/layouts/_admin_dropdown.html.erb delete mode 100644 config/locales/sv.the_role.yml create mode 100644 spec/features/admin_rent_spec.rb create mode 100644 spec/features/login_visit_election.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b06929fd4..e7b213c32 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 + " Should you be? Contact webmaster." + end end rescue_from ActiveRecord::RecordInvalid do |ex| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fdc444e24..1efe7c296 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3,15 +3,28 @@ def fa_icon(icon_name) content_tag :i, nil, class: ("fa fa-" + icon_name) end + def model_name(model) + if model.instance_of?(Class) + model.model_name.human + end + end + + def models_name(model) + if model.instance_of?(Class) + return model.model_name.human(count: 2) + end + end + def title(page_title) content_for(:title) { page_title } end + def full_title(page_title) - base_title = "F-sektionen" + base_title = 'F-sektionen' if page_title.empty? base_title else - "#{base_title} | #{page_title}" + %(#{base_title} | #{page_title}) end end @@ -24,6 +37,6 @@ def form_group &block e['class'] = 'form-control ' end end - content_tag :div, raw(html.to_html), class: 'form-group' + content_tag :div, raw(html.to_html), class: 'form-group' end end diff --git a/app/helpers/constants_helper.rb b/app/helpers/constants_helper.rb deleted file mode 100644 index 1fb532fb0..000000000 --- a/app/helpers/constants_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ConstantsHelper -end diff --git a/app/models/list.rb b/app/models/list.rb deleted file mode 100644 index b12f786a6..000000000 --- a/app/models/list.rb +++ /dev/null @@ -1,3 +0,0 @@ -# encoding: UTF-8 -class List < ActiveRecord::Base -end diff --git a/app/models/permission.rb b/app/models/permission.rb index bb7c7236b..5952c7069 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -1,5 +1,5 @@ class Permission < ActiveRecord::Base - has_many :posts, through: 'permission_post' + has_many :posts, through: :permission_posts has_many :permission_posts validates :subject_class, :action, presence: true end diff --git a/app/models/post.rb b/app/models/post.rb index 7a2ff6a06..65ffc3fb3 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -6,7 +6,7 @@ class Post < ActiveRecord::Base has_many :nominations has_many :candidates has_many :permission_posts - has_many :permissions, through: 'permission_posts' + has_many :permissions, through: :permission_posts # Scopes scope :studierad, -> { where(elected_by: "Studierådet").order(council_id: :asc) } diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 37509b553..f79272552 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,39 +1,43 @@
-
- <%= devise_error_messages! %> -
- <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {class: "reg-page", autofill: 'off'}, options: {autocomplete: 'off'}) do |f| %> - - <%= f.label 'Registrera ny användare', class: 'reg-header'%>
- -
- <%= fa_icon('user')%> - <%= f.text_field :username, class: 'form-control',:placeholder => 'Användarnamn', :autofocus => true%> -
-
- <%= fa_icon('envelope')%> - <%= f.email_field :email, class: 'form-control',:placeholder => 'E-postadress' %> -
-
- <%= fa_icon('lock')%> - <%= f.password_field :password, class: 'form-control',:placeholder => 'Nytt lösenord'%> -
-
- <%= fa_icon('lock')%> - <%= f.password_field :password_confirmation, class: 'form-control',:placeholder => 'Bekräfta lösenord' %> -
- <%= f.label 'Personnummer', class: 'reg-label'%>
- För att kolla medlemskap - sparas ej. -
- <%= fa_icon('bolt')%> - <%= text_field_tag :civic, nil, class: 'form-control',:placeholder => 'Personnummer (10 siffor i följd)'%> -
-
- <%= f.submit "Registrera",class: 'btn-u pull-right' %> -
- <%= render "devise/shared/links" %> - <% end %> -
-
-
+
+ <%= devise_error_messages! %> +
+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name), + html: {class: "reg-page", autofill: 'off'}, + options: {autocomplete: 'off'}) do |f| %> + + <%= f.label t('devise.sign_up'), class: 'reg-header' %>
+ +
+ <%= fa_icon('user') %> + <%= f.text_field :username, class: 'form-control', + placeholder: :username, autofocus: true %> +
+
+ <%= fa_icon('envelope') %> + <%= f.email_field :email, class: 'form-control', placeholder: :email %> +
+
+ <%= fa_icon('lock') %> + <%= f.password_field :password, class: 'form-control', placeholder: :password %> +
+
+ <%= fa_icon('lock') %> + <%= f.password_field :password_confirmation, class: 'form-control', + placeholder: :password_confirmation %> +
+ <%= t('registation.civic_check') %> +
+ <%= fa_icon('bolt') %> + <%= text_field_tag :civic, nil, class: 'form-control', + placeholder: t('attributes.civic') %> +
+
+ <%= f.submit nil, class: 'btn-u pull-right' %> +
+ <%= render "devise/shared/links" %> + <% end %> +
+
+ diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index 186d93786..e5ef7ca7d 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -1,39 +1,39 @@
-
-
- <%= form_for(resource,:html => {class: "reg-page"}, :as => resource_name, :url => session_path(resource_name)) do |f| %> - - <%= f.label 'Logga in', class: 'reg-header'%>
- -
- <%= fa_icon('user')%> - <%= f.text_field :username, :autofocus => true, class: 'form-control',:placeholder => 'Användarnamn'%> -
-
- <%= fa_icon('lock')%> - <%= f.password_field :password, class: 'form-control',:placeholder => 'Lösenord' %> -
-
-
- <% if devise_mapping.rememberable? -%> -
<%= f.check_box :remember_me %> <%= f.label 'Kom ihåg?' %>
- <% end -%> -
-
- <%= f.submit "Logga in",class: 'btn-u pull-right' %> -
-
- -
- <%= render "devise/shared/links" %> -
- <% end %> -
-
+
+
+ <%= form_for(resource, as: resource_name, + url: session_path(resource_name)) do |f| %> + <%= f.label t('devise.sign_in'), class: 'reg-header' %>
- - - - -
+
+ <%= fa_icon('user') %> + <%= f.text_field :username, autofocus: true, class: 'form-control', + placeholder: :username %> +
+
+ <%= fa_icon('lock') %> + <%= f.password_field :password, class: 'form-control', + placeholder: :password %> +
+
+
+ <% if devise_mapping.rememberable? -%> +
<%= f.check_box :remember_me %> + <%= f.label t('devise.remember_me') %>
+ <% end -%> +
+
+ <%= f.submit t('devise.sign_in'), class: 'btn-u pull-right' %> +
+
+ +
+ <%= render "devise/shared/links" %> +
+ <% end %> +
+
+ + + diff --git a/app/views/devise/shared/_links.erb b/app/views/devise/shared/_links.erb index cdfa2b172..959950118 100644 --- a/app/views/devise/shared/_links.erb +++ b/app/views/devise/shared/_links.erb @@ -1,25 +1,25 @@ <%- if controller_name != 'sessions' %> - <%= link_to "Logga in", new_session_path(resource_name) %>
+ <%= link_to t('devise.sign_in'), new_session_path(resource_name) %>
<% end -%> <%- if devise_mapping.registerable? && controller_name != 'registrations' %> - <%= link_to "Registrera", new_registration_path(resource_name) %>
+ <%= link_to t('devise.sign_up'), new_registration_path(resource_name) %>
<% end -%> <%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> - <%= link_to "Glömt lösenord?", new_password_path(resource_name) %>
+ <%= link_to t('devise.password_forgotten'), new_password_path(resource_name) %>
<% end -%> <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> - <%= link_to "Fick inte någon bekräftelse?", new_confirmation_path(resource_name) %>
+ <%= link_to t('devise.not_receive_confirm'), new_confirmation_path(resource_name) %>
<% end -%> <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> - <%= link_to "Fick ingen information för att låsa upp?", new_unlock_path(resource_name) %>
+ <%= link_to t('devise.not_receive_unlock'), new_unlock_path(resource_name) %>
<% end -%> <%- if devise_mapping.omniauthable? %> <%- resource_class.omniauth_providers.each do |provider| %> - <%= link_to "Logga in med #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
+ <%= link_to %(#{t('devise.sign_in_with')} #{provider.to_s.titleize}), omniauth_authorize_path(resource_name, provider) %>
<% end -%> <% end -%> diff --git a/app/views/election/nominations/_form.html.erb b/app/views/election/nominations/_form.html.erb index f0074ba80..6e660e128 100644 --- a/app/views/election/nominations/_form.html.erb +++ b/app/views/election/nominations/_form.html.erb @@ -22,6 +22,6 @@
- <%= f.submit "Spara", class: 'btn-u' %> + <%= f.submit nil, id: 'nomination-submit', class: 'btn-u' %>
<% end %> diff --git a/app/views/election/nominations/create.js.erb b/app/views/election/nominations/create.js.erb index 51be3fbba..4f24d6b79 100644 --- a/app/views/election/nominations/create.js.erb +++ b/app/views/election/nominations/create.js.erb @@ -1,6 +1,6 @@ <% if @saved == true %> $('#nomination-form').fadeOut('slow'); -$('#status').hide().html("

Tack för din nominering!

").fadeIn('slow'); +$('#status').hide().html("

<%=I18n.t('nomination.thank_you')

").fadeIn('slow'); <%else%> -$('#status').hide().html("

Namn och e-post måste fyllas i och en post måste väljas.

").fadeIn('slow'); -<%end%> \ No newline at end of file +$('#status').hide().html("

<%=@nomination.errors%>

").fadeIn('slow'); +<%end%> diff --git a/app/views/elections/_index.html.erb b/app/views/elections/_index.html.erb index 79ae3e798..4d3f5d643 100644 --- a/app/views/elections/_index.html.erb +++ b/app/views/elections/_index.html.erb @@ -1,5 +1,5 @@
-

<%= @election.title %>

+

<%= @election.title %>

<%= simple_format(@election.description) %>


diff --git a/app/views/layouts/_admin_dropdown.html.erb b/app/views/layouts/_admin_dropdown.html.erb new file mode 100644 index 000000000..436c57e74 --- /dev/null +++ b/app/views/layouts/_admin_dropdown.html.erb @@ -0,0 +1,63 @@ + diff --git a/app/views/layouts/_topbar.html.erb b/app/views/layouts/_topbar.html.erb index 60e8f017c..7372ba671 100644 --- a/app/views/layouts/_topbar.html.erb +++ b/app/views/layouts/_topbar.html.erb @@ -1,80 +1,33 @@
    - <%if user_signed_in? && can?(:manage, :all) %> -
  • <%=link_to image_tag('http://samson.fsektionen.se/projects/web/stages/production.svg?token=8d70d6eaf8ef80c828d2f1472e89dc6d'), - 'http://samson.fsektionen.se/projects/web/stages/production' %>
  • -
  • <%=link_to image_tag('http://samson.fsektionen.se/projects/web/stages/dev.svg?token=8d70d6eaf8ef80c828d2f1472e89dc6d'), - 'http://samson.fsektionen.se/projects/web/stages/dev' %>
  • -
  • - <% end%> - <% if user_signed_in? %> -
  • <%= link_to fa_icon("calendar"),:kalender %>
  • - <% if current_user.role_id != nil && Role.find_by_id(current_user.role_id) != Role.find_by_id(2)%> -
  • - + <% if can?(:manage, :all) %> +
  • + <% end %> + <% if user_signed_in? %> + <% if current_user.profile.posts.count > 0 %> + <%= render 'layouts/admin_dropdown' %> +
  • <% end %> -
  • -
  • <%= link_to fa_icon("calendar"), :kalender %>
  • +
  • + + - <% else %> -
  • - <%= link_to fa_icon("sign-in") + ' Logga in', new_user_session_path %> -
  • -
  • -
  • - <%= link_to fa_icon("plus") + ' Ny användare', new_user_registration_path %> -
  • - <% end %> -
+
  • <%= link_to Profile.model_name.human, current_user.profile %>
  • +
  • <%= link_to t('user.settings'), :edit_user_registration %>
  • +
  • <%= link_to t('devise.sign_out'), :destroy_user_session, method: :delete %>
  • + + + <% else %> +
  • + <%= link_to(fa_icon("sign-in") + ' '+ t('devise.sign_in'), new_user_session_path) %> +
  • +
  • +
  • + <%= link_to(fa_icon("plus") + ' ' + t('devise.sign_up'), new_user_registration_path) %> +
  • + <% end %> + diff --git a/app/views/notices/_notice.html.erb b/app/views/notices/_notice.html.erb index 025ec566a..dc47167f8 100644 --- a/app/views/notices/_notice.html.erb +++ b/app/views/notices/_notice.html.erb @@ -5,9 +5,11 @@ <%= image_tag image_notice_path(notice, style: "large"), class: "img-responsive" %>
    + <%= simple_format(notice.description) %> +
    <% else %>
    + <%= simple_format(notice.description) %> +
    <% end %> - <%= simple_format(notice.description) %> - - + diff --git a/config/locales/devise.sv.yml b/config/locales/devise.sv.yml index e2d2afe81..2909c51e6 100644 --- a/config/locales/devise.sv.yml +++ b/config/locales/devise.sv.yml @@ -54,4 +54,5 @@ sv: reset_password_instructions: subject: 'Instruktioner om återställning av lösenord' unlock_instructions: - subject: 'Instruktioner om upplåsning av konto' \ No newline at end of file + subject: 'Instruktioner om upplåsning av konto' + diff --git a/config/locales/en.yml b/config/locales/en.yml index d0262455c..a90a983d7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,3 +31,32 @@ en: profile_add_information: You have to fill out your name and surname. Please fill out the other information as well. error: error prevent_save: prevents the save + try_login: try to login. + + administrate: Administration + + devise: + remember_me: Remember me? + sign_in: Sign in + sign_out: Sign out + sign_up: Sign up + password_forgotten: Forgotten password? + sign_in_with: Sign in with + not_receive_unlock: Did not receive email about unlocking? + not_receive_confirm: Did not receive confirmation email? + + user: + settings: Account settings + registation: + civic_check: To control memebership in the Guild, will not be saved. + + attributes: + civic: Civic - 10 letters + + actions: + save: Spara + update: Uppdatera + send: Skicka + remove: Ta bort + create: Skapa + new: Ny diff --git a/config/locales/sv.the_role.yml b/config/locales/sv.the_role.yml deleted file mode 100644 index 2a0ee0fb8..000000000 --- a/config/locales/sv.the_role.yml +++ /dev/null @@ -1,17 +0,0 @@ -sv: - the_role: - role_created: Roll skapades - role_updated: Roll uppdaterades - role_deleted: Roll togs bort - section_created: Sektion skapades - section_not_created: Sektion skapades inte - section_rule_created: "Sektionsregel skapad" - section_rule_not_created: "Sektionsregel ej skapad" - section_rule_on: "Sektionsregel aktiverad" - section_rule_off: "Sektionsregel inaktiverad" - state_not_changed: "Sektionsregel ej ändraded" - section_deleted: Sektion borttagen - section_not_deleted: Sektion ej borttagen - section_rule_deleted: "Sektionsregel borttagen" - section_rule_not_deleted: "Sektionsregel ej borttagen" - access_denied: "Åtkomst nekad" \ No newline at end of file diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 28546afbd..820b0c8b5 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -1,11 +1,13 @@ sv: success_create: har skapats success_update: har uppdaterats - notice: Notisen profile_add_information: Du behöver fylla i namn och efternamn. Fyll gärna i den andra informationen också. your_profile: Din profil error: fel prevent_save: gör att det inte går att spara + try_login: prova att logga in. + + administrate: Administrera attributes: description: Beskrivning @@ -29,32 +31,82 @@ sv: council: Utskott comment: Kommentar access_code: Kod - - models: - notice: Notis - candidate: - one: Kandidatur - other: Kandidaturer - profile: - one: Profil - other: Profiler + password: Lösenord + username: Användarnamn + password_confirmation: Bekräfta lösenord + civic: Personnummer (10 siffror i följd) activerecord: models: + album: Album + cafe_work: Cafejobb candidate: one: Kandidatur other: Kandidaturer + constant: + one: Konstant + other: Konstanter + attributes: + value: Värde + contact: Kontakt + council: Utskott + document: Dokument + election: Val + event: Event + faq: Faq + image: + one: Bild + other: Bilder + menu: + one: Meny + other: Menyer + news: + one: Nyhet + other: Nyheter + nomination: + one: Nominering + other: Nomineringar + notice: + one: Notise + other: Notiser + page: + one: Sida + other: Sidor + page_element: Sidelement + permission: + one: Rättighet + other: Rättigheter + post: + one: Post + other: Poster profile: one: Profil other: Profiler + rent: + one: Bilbokning + other: Bilbokningar + role: + one: Roll + other: Roller short_link: one: Snabblänk other: Snabblänkar + user: Användare + work_post: + one: Jobbpost + other: Jobbposter attributes: + cafe_work: + work_day: Arbetsdag + d_year: År + pass: Pass + lp: Läsperiod + lv: Läsvecka short_link: link: Länknamn target: Måladress + activemodel: attributes: proposal: @@ -62,54 +114,6 @@ sv: sign_name: Ditt namn sign_title: Din titel (valfritt) - the_role: - role_created: Roll skapades - role_updated: Roll uppdaterades - role_deleted: Roll togs bort - section_created: Sektion skapades - section_not_created: Sektion skapades inte - section_rule_created: "Sektionsregel skapad" - section_rule_not_created: "Sektionsregel ej skapad" - section_rule_on: "Sektionsregel aktiverad" - section_rule_off: "Sektionsregel inaktiverad" - state_not_changed: "Sektionsregel ej ändraded" - section_deleted: Sektion borttagen - section_not_deleted: Sektion ej borttagen - section_rule_deleted: "Sektionsregel borttagen" - section_rule_not_deleted: "Sektionsregel ej borttagen" - access_denied: "Åtkomst nekad" - - admin: - roles: - new: - create: Skapa ny roll - name: Namn (små bokstäver) - title: Titel - description: Beskrivning - based_on_role: "Ny roll baseras på:" - role: - role_name: 'Namn:' - title: 'Titel:' - role_description: 'Beskrivning:' - delete_section: Ta bort sektion - section_delete_confirm: 'Vill du ta bort sektionen?' - rule_delete_confirm: 'Vill du ta bort regeln?' - enable: Aktivera - disable: Avaktivera - delete_rule: Ta bort regel - new_section_placeholder: Nytt sektionsnamn - create_section: Skapa ny sektion - new_rule_placeholder: Nytt namn på regel - create_rule: Skapa ny regel - role_export: "Exportera roll" - sidebar: - roles_export: "Exportera roller" - roles_import: "Importera roller" - roles_list: Lista med roller - new_role: Skapa ny roll - delete_role_confirm: 'Är du säker? Det kan vara farligt!' - roles_import_confirm: 'Det kan ändra behörigheter i ditt system, är du säker?' - errors: format: "%{message}" attributes: @@ -126,3 +130,37 @@ sv: formats: day: "%A %d/%m" invalid-url: Inte en giltig webadress + + unauthorized: + default: Någonting blev fel (rättigheter) + manage: + all: Inte auktoriserad för att %{action} %{subject}. + user: "Inte auktoriserad för att hantera användarkonton." + update: + project: "Inte tillåten att uppdatera projektet." + new: + nomination: Du måste logga in för att kunna nominera. + + devise: + remember_me: Kom ihåg mig? + sign_in: Logga in + sign_out: Logga ut + sign_up: Ny användare + password_forgotten: Glömt lösenord? + sign_in_with: Logga in med + not_receive_unlock: Fick inget upplåsningsmail? + not_receive_confirm: Fick inget bekräftelsemail? + + user: + settings: Kontoinställningar + + registation: + civic_check: För att kontrollera medlemskap i sektionen, sparas inte. + + helpers: + submit: + create: "Skapa %{model}" + submit: "Spara %{model}" + update: "Uppdatera %{model}" + + diff --git a/lib/tasks/tests_data.rake b/lib/tasks/tests_data.rake index 27a7e7418..5754ccd82 100644 --- a/lib/tasks/tests_data.rake +++ b/lib/tasks/tests_data.rake @@ -1,6 +1,6 @@ -namespace :load_database do +namespace :db do desc 'Loads some stuff into the database for local testing' - task(populate: :environment) do + task(populate_test: :environment) do # Councils pryl = Council.find_or_create_by!(title: 'Prylmästeriet', url: 'pryl', description: 'Detta är Prylmästeriet', public: true) @@ -88,5 +88,12 @@ namespace :load_database do # Notice Notice.find_or_create_by!(FactoryGirl.attributes_for(:notice)) Notice.find_or_create_by!(FactoryGirl.attributes_for(:notice)) + + # Election + election = Election.find_or_create_by!(FactoryGirl.attributes_for(:election)) + Post.all do |p| + election.posts << p + end + end end diff --git a/spec/factories/role.rb b/spec/factories/role.rb index b8e58c265..a73bfbc93 100644 --- a/spec/factories/role.rb +++ b/spec/factories/role.rb @@ -1,17 +1,13 @@ FactoryGirl.define do factory :role do - #initialize_with { Role.where(title: 'role').first_or_create } name 'A role' title 'role' description 'A role description' - the_role '' end factory :admin_role, class: Role do - #initialize_with { Role.where(title: 'admin').first_or_create } name 'The admin role' title 'admin' description 'An admin' - the_role '{"system":{"administrator":true}}' end end diff --git a/spec/features/admin_rent_spec.rb b/spec/features/admin_rent_spec.rb new file mode 100644 index 000000000..f654feb7f --- /dev/null +++ b/spec/features/admin_rent_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' +feature 'admin tries to login' do + let(:user) { create(:admin) } + let(:rent) { build(:rent) } + scenario 'they get alert with text "Loggade in"' do + visit '/logga_in' + fill_in 'user_username', with: user.username + fill_in 'user_password', with: '12345678' + click_button 'Logga in' + page.should have_css('div.alert.alert-info') # Verify we get an alert + find('div.alert.alert-info').text.should include('Loggade in.') # Verify that the alert states we are signed in + # TODO Include warden to stub login + #login_as(user, scope: :user) + + # Test notice + visit admin_rents_path + find('h2#notice-headline').text.should include('Notiser') + find(:linkhref, new_notice_path).click + fill_in 'notice_title', with: notice.title + fill_in 'notice_description', with: notice.description + find(:css, "#notice_public").set(notice.public) + fill_in 'notice[d_publish]', with: notice.d_publish + fill_in 'notice[d_remove]', with: notice.d_remove + fill_in 'notice_sort', with: notice.sort + find('#submit-notice').click + + page.should have_css('div.alert.alert-info') + find('div.alert.alert-info').text.should include(%(#{I18n.t(:notice)} #{I18n.t(:success_create)})) + end +end diff --git a/spec/features/login_visit_election.rb b/spec/features/login_visit_election.rb new file mode 100644 index 000000000..e318a3212 --- /dev/null +++ b/spec/features/login_visit_election.rb @@ -0,0 +1,33 @@ +require 'rails_helper' +feature 'not logged in' do + let(:user) { create(:user) } + let(:election) { create(:election) } + let(:post) { create(:post) } + before do + election.posts << post + end + scenario 'they try to visit election' do + visit elections_path + page.should have_css('h1#election-title') + find('h1#election-title').text.should include(election.title) + + # Try nomination page + visit new_election_nominations_path + page.should have_css('div.alert-danger') + find('div.alert-danger').text.should include(I18n.t('unauthorized.new.nomination')) + fill_in 'user_username', with: user.username + fill_in 'user_password', with: '12345678' + click_button 'Logga in' + page.should have_css('div.alert.alert-info') # Verify we get an alert + find('div.alert.alert-info').text.should include('Loggade in.') # Verify that the alert states we are signed in + + visit new_election_nominations_path + fill_in 'nomination_name', with: 'David Wessman' + fill_in 'nomination_email', with: 'd.wessman@fsektionen.se' + select(post, from: 'nomination_post_id') + fill_in 'nomination_motivation', with: 'Foo' + find('#nomination-submit').click + page.should have_css('div#status') + find('div#status').text.should include() # Verify that the alert states we are signed in + end +end diff --git a/spec/features/visit_a_council.rb b/spec/features/visit_a_council.rb index e373e6b43..870381fe3 100644 --- a/spec/features/visit_a_council.rb +++ b/spec/features/visit_a_council.rb @@ -1,5 +1,5 @@ require 'rails_helper' -feature 'admin tries to login' do +feature 'not logged in' do let(:user) { create(:user) } let(:council) { create(:council, :with_page, public: true) } scenario 'they get alert with text "Loggade in"' do From 35b4b82b2745b3fd19ec9f0ff2c1affa9c1f0484 Mon Sep 17 00:00:00 2001 From: davidwessman Date: Thu, 2 Apr 2015 01:12:28 +0200 Subject: [PATCH 09/19] Fixing admin menu, creating more feature tests, reworking councils, pages, posts --- app/assets/javascripts/cafe_works.js.coffee | 3 +- app/assets/javascripts/rents.js.coffee | 7 +- app/controllers/admin/rents_controller.rb | 11 +-- .../candidates_controller.rb | 15 +--- .../nominations_controller.rb | 2 +- app/models/ability.rb | 15 ++-- app/models/cafe_work.rb | 2 +- app/models/candidate.rb | 16 +--- app/models/election.rb | 80 ++++++++++--------- app/models/post.rb | 1 + app/views/admin/cafe_works/new.html.erb | 2 +- app/views/admin/elections/index.html.erb | 45 +++++++++-- app/views/admin/rents/_form.html.erb | 24 +++--- .../election_mailer/candidate_email.html.erb | 6 +- app/views/elections/_election.html.erb | 36 +++++++++ app/views/elections/_index.html.erb | 38 --------- app/views/elections/_posttab.html.erb | 6 +- .../candidates/_candidate_table.html.erb | 0 .../candidates/_form.html.erb | 0 .../candidates/candidate.html.erb | 0 .../candidates/index.html.erb | 0 .../candidates/new.html.erb | 0 .../candidates/show.html.erb | 0 app/views/elections/index.html.erb | 6 +- .../nominations/_form.html.erb | 14 ++-- .../nominations/create.js.erb | 2 +- .../nominations/new.html.erb | 6 +- app/views/layouts/_admin_dropdown.html.erb | 27 ++++--- config/locales/en.yml | 29 +++++-- config/locales/sv.yml | 22 +++++ config/routes.rb | 12 +-- lib/tasks/tests_data.rake | 7 +- .../controllers/cafe_works_controller_spec.rb | 5 +- spec/controllers/constants_controller_spec.rb | 3 +- .../candidates_controller_spec.rb | 16 ++-- spec/factories/elections.rb | 4 + spec/factories/posts.rb | 1 + spec/factories/role.rb | 13 --- spec/features/admin_rent_spec.rb | 34 ++++---- spec/features/login_visit_election.rb | 19 +++-- spec/models/cafe_work_spec.rb | 2 +- spec/models/candidate_spec.rb | 43 +++++----- 42 files changed, 323 insertions(+), 251 deletions(-) rename app/controllers/{election => elections}/candidates_controller.rb (74%) rename app/controllers/{election => elections}/nominations_controller.rb (90%) create mode 100644 app/views/elections/_election.html.erb delete mode 100644 app/views/elections/_index.html.erb rename app/views/{election => elections}/candidates/_candidate_table.html.erb (100%) rename app/views/{election => elections}/candidates/_form.html.erb (100%) rename app/views/{election => elections}/candidates/candidate.html.erb (100%) rename app/views/{election => elections}/candidates/index.html.erb (100%) rename app/views/{election => elections}/candidates/new.html.erb (100%) rename app/views/{election => elections}/candidates/show.html.erb (100%) rename app/views/{election => elections}/nominations/_form.html.erb (68%) rename app/views/{election => elections}/nominations/create.js.erb (63%) rename app/views/{election => elections}/nominations/new.html.erb (82%) rename spec/controllers/{election => elections}/candidates_controller_spec.rb (88%) delete mode 100644 spec/factories/role.rb diff --git a/app/assets/javascripts/cafe_works.js.coffee b/app/assets/javascripts/cafe_works.js.coffee index 1486edb13..6a6d1b996 100644 --- a/app/assets/javascripts/cafe_works.js.coffee +++ b/app/assets/javascripts/cafe_works.js.coffee @@ -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 -> diff --git a/app/assets/javascripts/rents.js.coffee b/app/assets/javascripts/rents.js.coffee index 7d596747a..cdb2372ae 100644 --- a/app/assets/javascripts/rents.js.coffee +++ b/app/assets/javascripts/rents.js.coffee @@ -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', @@ -35,4 +40,4 @@ $('document').ready -> else $('.after_disclaimer').hide() if $('#rent_disclaimer').is(':checked') - $('.after_disclaimer').show() \ No newline at end of file + $('.after_disclaimer').show() diff --git a/app/controllers/admin/rents_controller.rb b/app/controllers/admin/rents_controller.rb index f38588665..80eefdb51 100644 --- a/app/controllers/admin/rents_controller.rb +++ b/app/controllers/admin/rents_controller.rb @@ -17,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 @@ -36,14 +35,6 @@ def destroy private - 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 diff --git a/app/controllers/election/candidates_controller.rb b/app/controllers/elections/candidates_controller.rb similarity index 74% rename from app/controllers/election/candidates_controller.rb rename to app/controllers/elections/candidates_controller.rb index 296955afc..f14310a19 100644 --- a/app/controllers/election/candidates_controller.rb +++ b/app/controllers/elections/candidates_controller.rb @@ -1,5 +1,5 @@ # encoding: UTF-8 -class Election::CandidatesController < ApplicationController +class Elections::CandidatesController < ApplicationController before_action :set_election load_permissions_and_authorize_resource respond_to :html @@ -25,7 +25,7 @@ def create @candidate.profile = current_user.profile if @candidate.save flash[:notice] = 'Kandidaturen skapades.' - redirect_to [:election, @candidate] + redirect_to @candidate else render action: :new end @@ -34,7 +34,7 @@ def create def update if @candidate.update(candidate_params) flash[:notice] = 'Kandidaturen uppdaterades' - redirect_to [:election, @candidate] + redirect_to @candidate else render action: :show end @@ -43,17 +43,10 @@ def update def destroy @candidate.destroy flash[:notice] = 'Kandidaturen raderades' - redirect_to election_candidates_path + redirect_to candidates_path end private - def set_candidate - @candidate = Candidate.find_by_id(params[:id]) - if !@candidate.owner?(current_user) - flash[:error] = 'Du har inte rättigheter för att se kandidaturen.' - redirect_to(elections_path) - end - end def set_election @election = Election.current diff --git a/app/controllers/election/nominations_controller.rb b/app/controllers/elections/nominations_controller.rb similarity index 90% rename from app/controllers/election/nominations_controller.rb rename to app/controllers/elections/nominations_controller.rb index 2b47dbc23..397640f8c 100644 --- a/app/controllers/election/nominations_controller.rb +++ b/app/controllers/elections/nominations_controller.rb @@ -1,5 +1,5 @@ # encoding: UTF-8 -class Election::NominationsController < ApplicationController +class Elections::NominationsController < ApplicationController before_action :set_election load_permissions_and_authorize_resource diff --git a/app/models/ability.rb b/app/models/ability.rb index b79c50c42..e55d7e1b7 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -9,27 +9,26 @@ def initialize(user) # Abilities that everyone get. can :read, [News, Council, Post, Page, Election] can :read, Document, public: true - can :image, Notice + can [:display,:image], Notice + can [:collapse, :display], Post # TODO Should be removed when everyone is required to log in. # /d.wessman 2015-03-28 can [:read, :update_worker, :remove_worker, :authorize], CafeWork - can [:read, :main, :new, :edit,:create,:update, :destroy,:authorize], Rent + can [:read, :main, :new, :edit, :create, :update, :destroy, :authorize], Rent # Abilities all signed in users get if user.id can :manage, User, id: user.id - can :nominate, Election - can :candidate, Election + can [:nominate, :candidate], Election can :manage, Candidate, profile_id: user.profile.id + can :manage, Nomination can :manage, Profile, user_id: user.id - can :read, Post + can [:read, :display, :hide], Post can :read, Document can :read, :old_gallery - can :read, Event - # TODO We really need to move calendar to its own controller - can :calendar, Event + can [:read, :calendar], Event end # Note: Root access is given dynamically by having a post with permissions :manage, :all diff --git a/app/models/cafe_work.rb b/app/models/cafe_work.rb index a4a631e56..b2ebe4a23 100644 --- a/app/models/cafe_work.rb +++ b/app/models/cafe_work.rb @@ -8,7 +8,7 @@ class CafeWork < ActiveRecord::Base # Validations validates :work_day, :pass, :lp, :lv, presence: true validates :pass, :lp, inclusion: { in: 1..4 } - validates :lv, inclusion: { in: 1..7 } + validates :lv, inclusion: { in: 1..20 } validates :name, :lastname, :phone, :email, presence: true, if: :has_worker? validates :pass, uniqueness: { scope: [:work_day, :lv, :lp, :d_year] } diff --git a/app/models/candidate.rb b/app/models/candidate.rb index 1e2e9d516..847445140 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -7,7 +7,7 @@ class Candidate < ActiveRecord::Base # Validations validates :profile_id, uniqueness: { - scope: [:post_id, :election_id], message: 'har redan en likadan kandidatur' + scope: [:post_id, :election_id], message: I18n.t('candidates.similar_candidate') }, on: :create validates :name, :lastname, :stil_id, :email, :phone, :post, :profile, :election, presence: true @@ -31,26 +31,18 @@ def prepare(user) end def editable? - election.view_status == 2 || post.elected_by == 'Studierådet' + election.view_status == :during || post.elected_by == 'Studierådet' end def p_url - Rails.application.routes.url_helpers.election_candidate_url(id, host: PUBLIC_URL) + Rails.application.routes.url_helpers.candidate_url(id, host: PUBLIC_URL) end def p_path - Rails.application.routes.url_helpers.election_candidate_path(id) + Rails.application.routes.url_helpers.candidate_path(id) end def owner?(user) user.present? && user.profile == profile end - - def editable? - election.view_status == 2 || post.elected_by == 'Studierådet' - end - - def p_url - Rails.application.routes.url_helpers.election_candidate_url(id, host: PUBLIC_URL) - end end diff --git a/app/models/election.rb b/app/models/election.rb index 0fa742c7c..681e7a815 100644 --- a/app/models/election.rb +++ b/app/models/election.rb @@ -3,93 +3,97 @@ class Election < ActiveRecord::Base has_many :nominations, dependent: :destroy has_many :candidates, dependent: :destroy has_and_belongs_to_many :posts - + validates :url, presence: true, uniqueness: true def self.current self.order(start: :asc).where(visible: true).first || nil end - # Returns a number to load different views - # 1: before the election opens - # 2: during the election - # 3: after the election + def termin_grid + if (p = posts.termins).count > 0 + initialize_grid(p, name: 'election') + end + end + + def rest_grid + if (p = posts.not_termins).count > 0 + initialize_grid(p, name: 'election') + end + end + # Returns current status # /d.wessman def view_status - if self.start > Time.zone.now - return 1 - elsif (self.start <= Time.zone.now) && (self.end > Time.zone.now) - return 2 + if start > Time.zone.now + return :before + elsif start <= Time.zone.now && self.end > Time.zone.now + return :during else - return 3 + return :after end end # Returns a status text depending on the view_status # /d.wessman def status_text - i = view_status - if i == 1 - return self.text_before - elsif i == 2 - return self.text_during - else - return self.text_after + case view_status + when :before + text_before + when :during + text_during + when :after + text_after end end # Returns a status text for the nominations page # /d.wessman def nomination_status - if view_status != 3 - return "" + if view_status == :after + I18n.t('nominations.status_after') end - return "Det går endast att nominera till poster som inte väljs på Terminsmötet" end + # Returns the current posts # /d.wessman def current_posts - if view_status != 3 - posts - else + if view_status == :after posts.not_termins + else + posts end end # Returns the start_date if before, the end_date if during and none if after. # /d.wessman def countdown - i = view_status - if i == 1 - return self.start - elsif i == 2 - return self.end + case view_status + when :before + start + when :during + self.end end - nil end def candidate_count(post) if post.present? - self.candidates.where(post_id: post.id).count + candidates.where(post_id: post.id).count else 0 end end def can_candidate?(post) - if post.elected_by == "Terminsmötet" && view_status == 2 + if post.elected_by == 'Terminsmötet' && view_status == :during return true - elsif post.elected_by != "Terminsmötet" && view_status != 1 + elsif post.elected_by != 'Terminsmötet' && view_status != :before return true end - return false + + false end def to_param - if (self.url) - self.url - else - self.id - end + (url.present?) ? url : id end end diff --git a/app/models/post.rb b/app/models/post.rb index 65ffc3fb3..c0cc1e715 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -35,6 +35,7 @@ def printLimit def limited? end + def add_profile(profile) if limited? diff --git a/app/views/admin/cafe_works/new.html.erb b/app/views/admin/cafe_works/new.html.erb index 5067eec97..70452c60c 100644 --- a/app/views/admin/cafe_works/new.html.erb +++ b/app/views/admin/cafe_works/new.html.erb @@ -3,7 +3,7 @@
    <%= label_tag 'Cafejobb',nil, class: 'reg-header'%> <%= render 'form'%> - <%= link_to 'Tillbaka till cafebokning', :admin_cafe_works %> + <%= link_to 'Tillbaka till cafebokning', :admin_hilbert %>
    diff --git a/app/views/admin/elections/index.html.erb b/app/views/admin/elections/index.html.erb index 5db33e79d..a7f8662f3 100644 --- a/app/views/admin/elections/index.html.erb +++ b/app/views/admin/elections/index.html.erb @@ -1,8 +1,39 @@ -
    -
      - <% @elections.each do |elec|%> -
    • <%=link_to(elec.title,admin_election_path(elec))%>
    • - <%end%> - - <%=link_to('Nytt val',new_admin_election_path)%> +
      +
      +
      +
      +

      + Sektionsval

      + <%=link_to('Nytt val',new_admin_election_path, class: 'btn btn-u')%> +
      + + + + + + + + + + + + + + + <% @elections.each do |election| %> + + + + + + + + + + + <% end %> + +
      TitelUrlSynligÖppnarStängerAktuellt val?UppdateradRedigera
      <%= election.title %><%= election.url %><%= election.visible %><%= election.start%><%= election.end%><%= (election == Election.current) ? 'Sant': 'Falskt'%><%= election.updated_at %><%= link_to('Redigera', admin_election_path(election), class: "btn btn-u") %>
      +
      +
      diff --git a/app/views/admin/rents/_form.html.erb b/app/views/admin/rents/_form.html.erb index 5cb4e4f26..e009b3447 100644 --- a/app/views/admin/rents/_form.html.erb +++ b/app/views/admin/rents/_form.html.erb @@ -7,9 +7,9 @@
      <%= f.label 'Disclaimer', class: 'reg-label' %> - <%= f.check_box :disclaimer, id: "accepted_disclaimer" %> + <%= f.check_box :disclaimer, id: "accepted_disclaimer", checked: true %> <%= f.label 'Service', class: 'reg-label' %> - <%= f.check_box :services %> + <%= f.check_box :service %>
      <%= f.label 'Namn & Efternamn', class: 'reg-label' %> @@ -21,8 +21,8 @@ <%= f.label 'E-post & telefon', class: 'reg-label' %>
      -
      <%= f.text_field :email, class: 'form-control', placeholder: "Epost" %>
      -
      <%= f.text_field :phone, class: 'form-control', placeholder: "Telefon" %>
      +
      <%= f.email_field :email, class: 'form-control', placeholder: "Epost" %>
      +
      <%= f.phone_field :phone, class: 'form-control', placeholder: "Telefon" %>
      <%= f.label 'Syfte', class: 'reg-label' %> @@ -31,18 +31,17 @@
      <%= f.label 'Från', class: 'reg-label' %>
      - <%= f.datetime_select :d_from, minute_step: 10, class: 'form-control' %> + <%= f.text_field :d_from, class: 'form-control datetimepicker1' %>
      <%= f.label 'Till', class: 'reg-label' %>
      - <%= f.datetime_select :d_til, minute_step: 10, class: 'form-control' %> + <%= f.text_field :d_til, class: 'datetimepicker2'%>
      <%= f.label 'Utskott', class: 'reg-label' %>
      - <%= f.select :council_id, - options_from_collection_for_select(@councils, :id, :title, @rent.council_id), - include_blank: true, - class: "form-control listBox" %> + <%= f.collection_select(:council, Council.all, :id,:title, + include_blank: true, class: 'form-control listBox')%> +
      <%= f.label :status, class: 'reg-label' %> @@ -62,8 +61,9 @@ <%= f.text_area :comment, class: 'form-control' %>
      - <%= f.submit "Spara", class: "btn btn-u", data: {confirm: 'Som administratör bokar man över vad som helst (utan att påverka bokningen), ingenting valideras.'} %> + <%= f.submit "Spara", id: 'rent-submit', class: "btn btn-u", + data: {confirm: 'Som administratör bokar man över vad som helst (utan att påverka bokningen), ingenting valideras.'} %>
      -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/election_mailer/candidate_email.html.erb b/app/views/election_mailer/candidate_email.html.erb index d07ebf36b..704bafd63 100644 --- a/app/views/election_mailer/candidate_email.html.erb +++ b/app/views/election_mailer/candidate_email.html.erb @@ -10,9 +10,9 @@ <%if (@candidate.election.candidate_mail)%> <%= simple_format(@candidate.election.candidate_mail)%> <%end%> - <%if (@candidate.post.styrelse)%> + <%if @candidate.post.styrelse && @candidate.election.mail_styrelse_link.present?%> <%=link_to(@candidate.election.mail_styrelse_link,@candidate.election.mail_styrelse_link)%>

      - <%else%> + <%elsif @candidate.election.mail_link.present?%> <%=link_to(@candidate.election.mail_link,@candidate.election.mail_link)%>

      <%end%> <%else%> @@ -24,4 +24,4 @@

      Mvh,
      Valberedningen

      - \ No newline at end of file + diff --git a/app/views/elections/_election.html.erb b/app/views/elections/_election.html.erb new file mode 100644 index 000000000..903ce704b --- /dev/null +++ b/app/views/elections/_election.html.erb @@ -0,0 +1,36 @@ +
      +

      <%= election.title %>

      + +

      <%= simple_format(election.description) %>


      + +

      <%= simple_format(election.status_text) %>

      + <%= render "countdown" %> + +
      + <%= link_to(model_name(Nomination), new_nominations_path, class: "btn btn-election") %> +
      +
      + <%= link_to(model_name(Candidate), candidates_path, class: "btn btn-election") %> +
      + +
      +

      <%= election.view_status == :before ? t('elections.posts_before') : t('elections.posts_during') %>

      + <%= render "posttab", grid: @grid_election, election: election %> +
        +
      • <%= t('elections.x_posts') %>
      • +
      • <%= t('elections.star_posts') %>
      • +
      • <%= t('elections.orange_posts') %>
      • + <% if election.view_status == :after %> +
      • <%= t('elections.green_posts') %>
      • + <% end %> +
      + <% if election.view_status == :after %> +

      <%= t('elections.posts_after') %>

      + <%= render "posttab", grid: @grid_termins, election: election %> + <% end %> +
      + +

      <%= t('elections.get_in_touch') %> + <%= render partial: "contacts/kontakt", locals: {name: 'Spindelmän'} %>

      +
      +
      diff --git a/app/views/elections/_index.html.erb b/app/views/elections/_index.html.erb deleted file mode 100644 index 4d3f5d643..000000000 --- a/app/views/elections/_index.html.erb +++ /dev/null @@ -1,38 +0,0 @@ -
      -

      <%= @election.title %>

      - -

      <%= simple_format(@election.description) %>


      - -

      <%= simple_format(@election.status_text) %>

      - <%= render "countdown" %> - -
      - <%= link_to("Nominering", election_nominations_path, class: "btn btn-election") %> -
      -
      - <%= link_to("Kandidatur", election_candidates_path, class: "btn btn-election") %> -
      - -
      - <% if @election.view_status == 1%> -

      Poster som kommer kunna sökas

      - <%= render "posttab", grid: @grid_election %> -

      Orangefärgade fält innebär att posten sitter i styrelsen.

      - <% elsif @election.view_status == 2%> -

      Poster som kan sökas

      - <%= render "posttab", grid: @grid_election %> -

      Orangefärgade fält innebär att posten sitter i styrelsen.

      - <% elsif @election.view_status == 3%> -

      Poster som går att söka

      - <%= render "posttab", grid: @grid_election %> -

      Grönfärgade fält innebär att posten väljs av studierådet.

      -

      Poster som inte går att söka längre

      - <%= render "posttab", grid: @grid_termins %> -

      Orangefärgade fält innebär att posten sitter i styrelsen.

      - <%end%> -
      - -

      Ser något konstigt ut eller blir det fel? Hör av dig - till <%= render partial: "contacts/kontakt", locals: {name: 'Spindelmän'} %>

      -
      -
      diff --git a/app/views/elections/_posttab.html.erb b/app/views/elections/_posttab.html.erb index b1d937278..2d1d5cfcd 100644 --- a/app/views/elections/_posttab.html.erb +++ b/app/views/elections/_posttab.html.erb @@ -13,12 +13,12 @@ post.printLimit end g.column name: "Utskott", attribute: "council_id",filter: false do |post| - post.council.title + post.council end g.column name: "Väljs av", attribute: "elected_by",filter: false - if (@election.view_status != 1) + if (election.view_status != 1) g.column name: "Kandidater", filter: false do |post| - @election.candidate_count(post) + election.candidate_count(post) end end end -%> diff --git a/app/views/election/candidates/_candidate_table.html.erb b/app/views/elections/candidates/_candidate_table.html.erb similarity index 100% rename from app/views/election/candidates/_candidate_table.html.erb rename to app/views/elections/candidates/_candidate_table.html.erb diff --git a/app/views/election/candidates/_form.html.erb b/app/views/elections/candidates/_form.html.erb similarity index 100% rename from app/views/election/candidates/_form.html.erb rename to app/views/elections/candidates/_form.html.erb diff --git a/app/views/election/candidates/candidate.html.erb b/app/views/elections/candidates/candidate.html.erb similarity index 100% rename from app/views/election/candidates/candidate.html.erb rename to app/views/elections/candidates/candidate.html.erb diff --git a/app/views/election/candidates/index.html.erb b/app/views/elections/candidates/index.html.erb similarity index 100% rename from app/views/election/candidates/index.html.erb rename to app/views/elections/candidates/index.html.erb diff --git a/app/views/election/candidates/new.html.erb b/app/views/elections/candidates/new.html.erb similarity index 100% rename from app/views/election/candidates/new.html.erb rename to app/views/elections/candidates/new.html.erb diff --git a/app/views/election/candidates/show.html.erb b/app/views/elections/candidates/show.html.erb similarity index 100% rename from app/views/election/candidates/show.html.erb rename to app/views/elections/candidates/show.html.erb diff --git a/app/views/elections/index.html.erb b/app/views/elections/index.html.erb index 051f25bd6..eb112bee2 100644 --- a/app/views/elections/index.html.erb +++ b/app/views/elections/index.html.erb @@ -1,8 +1,8 @@ <% provide(:title, 'Val') %>
      - <% if @election %> - <%= render 'index' %> - <% if can? :edit, @election %> + <% if @election.present? %> + <%= render @election, election: @election %> + <% if can? :manage, @election %>
      <%= link_to("Redigera valet!", admin_election_path(@election), class: "btn btn-election ") %>
      <% end %> <% else %> diff --git a/app/views/election/nominations/_form.html.erb b/app/views/elections/nominations/_form.html.erb similarity index 68% rename from app/views/election/nominations/_form.html.erb rename to app/views/elections/nominations/_form.html.erb index 6e660e128..6b2be0347 100644 --- a/app/views/election/nominations/_form.html.erb +++ b/app/views/elections/nominations/_form.html.erb @@ -1,21 +1,21 @@ -<%= form_for([:election,nomination], remote: true) do |f| %> - <%= render 'shared/form_errors', current: @nomination %> - <%= f.label 'Namn', class: 'reg-label' %> +<%= form_for(nomination, remote: true) do |f| %> + <%= render 'shared/form_errors', current: nomination %> + <%= f.label :name, class: 'reg-label' %>
      <%= f.text_field :name, class: 'form-control' %>
      - <%= f.label 'E-post', class: 'reg-label' %> + <%= f.label :email, class: 'reg-label' %>
      <%= f.email_field :email, class: 'form-control' %>
      - <%= f.label 'Post', class: 'reg-label' %>
      - <%= f.select :post_id, + <%= f.label model_name(Post), class: 'reg-label' %>
      + <%= f.select :post, options_from_collection_for_select(election.current_posts, :id, :title, params[:post].to_i), include_blank: true, class: "form-control listBox" %>
      - <%= f.label 'Motivering', class: 'reg-label' %>
      + <%= f.label :motivation, class: 'reg-label' %>
      Frivillig - den nominerade kan se den i ett mejl.
      <%= f.text_area :motivation, class: 'form-control' %> diff --git a/app/views/election/nominations/create.js.erb b/app/views/elections/nominations/create.js.erb similarity index 63% rename from app/views/election/nominations/create.js.erb rename to app/views/elections/nominations/create.js.erb index 4f24d6b79..78082767e 100644 --- a/app/views/election/nominations/create.js.erb +++ b/app/views/elections/nominations/create.js.erb @@ -1,6 +1,6 @@ <% if @saved == true %> $('#nomination-form').fadeOut('slow'); -$('#status').hide().html("

      <%=I18n.t('nomination.thank_you')

      ").fadeIn('slow'); +$('#status').hide().html("

      <%=I18n.t('nomination.thank_you')%>

      ").fadeIn('slow'); <%else%> $('#status').hide().html("

      <%=@nomination.errors%>

      ").fadeIn('slow'); <%end%> diff --git a/app/views/election/nominations/new.html.erb b/app/views/elections/nominations/new.html.erb similarity index 82% rename from app/views/election/nominations/new.html.erb rename to app/views/elections/nominations/new.html.erb index abdb654dd..500f3c625 100644 --- a/app/views/election/nominations/new.html.erb +++ b/app/views/elections/nominations/new.html.erb @@ -1,5 +1,5 @@ <% provide(:title, 'Val') %> -<% if @election.view_status != 1 %> +<% if @election.view_status != :after %>
      @@ -16,13 +16,13 @@ <%= render 'form', election: @election, nomination: @nomination%>
      - <%= link_to 'Tillbaka', elections_path, class: "btn-u btn-u-small" %> + <%= link_to t('actions.back'), elections_path, class: "btn-u btn-u-small" %>
      <% else %>
      -

      <%= label_tag 'Nomineringar:', nil, class: 'reg-header' %>

      +

      <%= label_tag models_name(Nomination), nil, class: 'reg-header' %>

      <%= render 'elections/countdown' %> <%= link_to image_tag("layout/f.svg", class: "val-logo"), elections_path %>
      diff --git a/app/views/layouts/_admin_dropdown.html.erb b/app/views/layouts/_admin_dropdown.html.erb index 436c57e74..b32665b52 100644 --- a/app/views/layouts/_admin_dropdown.html.erb +++ b/app/views/layouts/_admin_dropdown.html.erb @@ -18,16 +18,22 @@ <% end %> <% if can? :manage, Page %> + <%end%> + <% if can? :manage, Rent %> + + <%end%> + <% if can? :manage, Election %> + <%end%> <% if can? :modify, Event %>