Page Model/Controller entfernt, Migration

This commit is contained in:
Andreas Stephanides
2013-07-22 14:37:49 +02:00
parent 607d408bc6
commit 81cbf2b940
19 changed files with 29 additions and 309 deletions

View File

@@ -1,57 +0,0 @@
class PagesController < ApplicationController
layout :get_layout
before_filter :find_page, :except => [:new, :show, :create]
before_filter :find_body, :only => [:edit]
def new
@page = Page.new
end
def edit
end
def show
@page = Page.find(params[:id] || Page.welcome)
end
def create
@page = Page.new(params[:page])
if @page.save
flash[:notice] = "Successfully created page."
redirect_to @page
else
render :action => 'new'
end
end
def update
if @page.update_attributes(params[:page])
flash[:notice] = "Successfully updated page."
redirect_to @page
else
render :action => 'edit'
end
end
def destroy
@page.destroy
flash[:notice] = "Successfully destroyed page."
end
def preview
render :text => @page.preview(params[:data])
end
private
def find_page
@page = Page.find(params[:id])
end
def find_body
@page.body = params[:page][:body] rescue @page.raw_content
end
end

View File

@@ -1,65 +0,0 @@
class PagesController < ApplicationController
before_filter :find_page, :except => [:new, :show, :create]
before_filter :find_body, :only => [:edit]
def new
@page = Page.new
@page.name=params[:name]
end
def edit
end
def show
if params[:id].to_i >0
@page = Page.find(params[:id] || Page.welcome)
else
id=Page.find_id(params[:id])
if id.nil?
redirect_to url_for(:path_only=>true,:controller=>"pages",:action=>"new", :name=>params[:id])
else
@page =Page.find(Page.find_id(params[:id]))
end
end
end
def create
@page = Page.new(params[:page])
if @page.save
flash[:notice] = "Successfully created page."
redirect_to @page
else
render :action => 'new'
end
end
def update
if @page.update_attributes(params[:page])
flash[:notice] = "Successfully updated page."
redirect_to @page
else
render :action => 'edit'
end
end
def destroy
@page.destroy
flash[:notice] = "Successfully destroyed page."
end
def preview
render :text => @page.preview(params[:data])
end
private
def find_page
@page = Page.find(params[:id])
end
def find_body
@page.body = params[:page][:body] rescue @page.raw_content
end
end

View File

@@ -1,2 +1,2 @@
module LvasHelper module LvasHelper # :nodoc:
end end

View File

@@ -1,2 +1,2 @@
module NeuigkeitenHelper module NeuigkeitenHelper # :nodoc:
end end

View File

@@ -1,3 +1,8 @@
##
# Author:: Andreas Stephanides
# License:: GPL
# Dieses Model repräsentiert eine LVA. Die notwendigen Informationen können mit TISS (dem Online System der TU Wien) synchronisiert werden
class Lva < ActiveRecord::Base class Lva < ActiveRecord::Base
has_paper_trail # Versionsver has_paper_trail # Versionsver
attr_accessible :desc, :ects, :lvanr, :name, :stunden, :modul_ids attr_accessible :desc, :ects, :lvanr, :name, :stunden, :modul_ids
@@ -6,10 +11,12 @@ class Lva < ActiveRecord::Base
translates :desc, :fallbacks_for_empty_translations => true translates :desc, :fallbacks_for_empty_translations => true
has_many :beispiele , :class_name => "Beispiel" has_many :beispiele , :class_name => "Beispiel"
after_initialize :load_tissdata after_initialize :load_tissdata
##
# Lade den Hash aus TISS und speichere diesen in @hash
#
def hash def hash
url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W" url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W"
@hash=Hash.from_xml(open(url).read) @hash=Hash.from_xml(open(url).read)
end end
def objective def objective
@@ -21,9 +28,10 @@ class Lva < ActiveRecord::Base
def person def person
@person @person
end end
private
def load_tissdata private
def load_tissdata
url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W" url= "https://tiss.tuwien.ac.at/api/course/"+ self.lvanr.to_s+"-2012W"
begin begin
@hash=Hash.from_xml(open(url).read)["tuvienna"] @hash=Hash.from_xml(open(url).read)["tuvienna"]
@@ -37,7 +45,7 @@ end
end end
rescue OpenURI::HTTPError => e rescue OpenURI::HTTPError => e
end end
end end

View File

@@ -1,75 +0,0 @@
class Page < ActiveRecord::Base
acts_as_nested_set
# Temporarily hard coded
FORMAT = :textile
WIKI = Rails.root.join("db", "wiki.git")
before_create :create_page
before_update :update_page
before_destroy :delete_page
attr_accessible :body, :name, :change_comment
attr_accessor :body, :change_comment
def content
page.formatted_data
end
def raw_content
page.raw_data
end
def self.welcome
Page.first(:conditions => {:name => 'Welcome'})
end
def author
page.version.author.name.gsub(/<>/, '')
end
def date
page.version.authored_date
end
def preview(data)
wiki.preview_page('Preview', data, FORMAT).formatted_data
end
def self.find_id(nme)
p=Page.first(:conditions=> {:name=>nme})
if p.nil?
pg=wiki.page(nme)
if !pg.nil?
p=Page.new(:name=>nme,:body=>pg.raw_data)
end
end
p
end
private
def self.wiki
@@golum ||= Gollum::Wiki.new(WIKI, :base_path =>"/pages",)
end
def wiki
@@golum ||= Gollum::Wiki.new(WIKI, :base_path =>"/pages")
end
def page
wiki.page(self.name)
end
def create_page
wiki.write_page(name, FORMAT, body || '', {:message => self.change_comment, :name => 'tester', :author => 'tester'})
end
def update_page
wiki.update_page(page, name, FORMAT, body || self.raw_content, {:message => self.change_comment, :name => 'tester', :author => 'tester'})
end
def delete_page
wiki.delete_page(page, COMMIT)
end
end

View File

@@ -27,4 +27,4 @@
<p><%= link_to "Neuigkeiten", rubriken_path %></p> <p><%= link_to "Neuigkeiten", rubriken_path %></p>
<p><b>Wiki</b></p> <p><b>Wiki</b></p>
<p><%= link_to "Wiki", page_path(Page.find(1)) %></p> <p></p>

View File

@@ -1,23 +0,0 @@
= form_for(@page) do |f|
%p
= f.label :name
= f.text_field :name
%p
- unless @page.new_record?
= link_to 'Edit mode', '#', :id => 'write'
= link_to 'Preview mode', preview_page_path(@page), :id => 'preview'
#write_area
= f.textile_editor :body
#preview_area.hide
%p
= f.label 'Describe this change (optional)'
= f.text_field :change_comment
.actions
= f.submit
= cancel_link
= raw(textile_editor_initialize(:framework => :jquery))

View File

@@ -1,12 +0,0 @@
<%= tinymce_assets %>
<%= semantic_form_for @page do |f| %>
<%= f.inputs do %>
<%= f.input :name %>
<%= f.input :body, :as=>:text,:input_html=>{:style=>"width:100%;font-familiy:Times New Roman;"} %>
<%= f.input :change_comment %>
<% end %>
<%= tinymce %>
<%= f.actions do %>
<%= f.action :submit, :as =>:input %>
<% end %>
<% end %>

View File

@@ -1,3 +0,0 @@
%h3 Table of contents
%ul#pages_list= render Page.root

View File

@@ -1,7 +0,0 @@
%li{:id => dom_id(page), :class => "level_#{page.level}"}
= link_to page.name, page_path(page)
= link_to '(Add)', new_page_path, :rel => dom_id(page)
- unless page.children.empty?
%ul= render page.children

View File

@@ -1,5 +0,0 @@
<% unless @page.errors.any? -%>
$("#flash_notice").html("<%= escape_javascript(flash[:notice])%>");
$("#flash_notice").show(300);
$("#<%= dom_id(@page)%>").fadeOut('fast');
<% end -%>

View File

@@ -1,2 +0,0 @@
%h1="Editing page \"#{@page.name}\""
= render 'form'

View File

@@ -1,2 +0,0 @@
<h1>Edit Form</h1>
<%= render 'form' %>

View File

@@ -1,2 +0,0 @@
%h1 New page
= render 'form'

View File

@@ -1,15 +0,0 @@
%small
= breadcrumbs(@page)
%h4
= "#{@page.name}"
= link_to '(Edit)', edit_page_path(@page)
= link_to '(Destroy)', @page, :remote => true, :confirm => 'Are you sure?', :method => :delete
%small= "Last edited by #{@page.author} #{time_ago_in_words(@page.date)} ago."
%hr
= raw(@page.content)
%hr

View File

@@ -1,8 +0,0 @@
<%= breadcrumbs(@page) %>
<h1><%= @page.name %></h1>
<%= raw(@page.content)%>
<hr />
<%= link_to '(Edit)', edit_page_path(@page)%>
<%= link_to '(Destroy)', @page, :remote => true, :confirm => 'Are you sure?', :method => :delete
%>

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130301000000) do ActiveRecord::Schema.define(:version => 20130214233723) do
create_table "beispiel_translations", :force => true do |t| create_table "beispiel_translations", :force => true do |t|
t.string "locale" t.string "locale"
@@ -120,18 +120,6 @@ ActiveRecord::Schema.define(:version => 20130301000000) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
create_table "pages", :force => true do |t|
t.string "name"
t.string "url"
t.integer "parent_id"
t.integer "lft"
t.integer "rgt"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "pages", ["parent_id"], :name => "index_pages_on_parent_id"
create_table "roles", :force => true do |t| create_table "roles", :force => true do |t|
t.string "name" t.string "name"
t.integer "resource_id" t.integer "resource_id"