Class: Knitkit::ErpApp::Desktop::VersionsController

Inherits:
AppController
  • Object
show all
Defined in:
app/controllers/knitkit/erp_app/desktop/versions_controller.rb

Constant Summary

Constants inherited from AppController

AppController::KNIT_KIT_ROOT

Instance Method Summary collapse

Methods inherited from AppController

#available_roles, #websites

Instance Method Details

#content_versionsObject

content



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/knitkit/erp_app/desktop/versions_controller.rb', line 7

def content_versions
  content   = Content.find(params[:id])
  website   = Website.find(params[:site_id])
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
  sort      = sort_hash[:property] || 'version'
  dir       = sort_hash[:direction] || 'DESC'
  limit     = params[:limit] || 15
  start     = params[:start] || 0

  versions = content.versions.order("#{sort} #{dir}").offset(start).limit(limit)

  Content::Version.class_exec(website) do
    cattr_accessor :website
    self.website = website
    def active
      published_site_id = self.website.active_publication.id
      !PublishedElement.includes([:published_website]).where('published_websites.id = ? and published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', published_site_id, self.content_id, 'Content', self.version).first.nil?
    end

    def published_element
      PublishedElement.where('published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', self.content_id, 'Content', self.version).first
    end

    def published
      !published_element.nil?
    end

    def publisher
      published_element.published_by_username if published
    end

  end

  render :json => {:totalCount => content.versions.count,
    :data => versions.collect{|version|version.to_hash(
        :only => [:id, :content_id, :version, :title, :body_html, :excerpt_html, :updated_at],
        :methods => [:active, :published, :publisher])}
  }
end

#get_website_section_versionObject



132
133
134
# File 'app/controllers/knitkit/erp_app/desktop/versions_controller.rb', line 132

def get_website_section_version
  render :text => WebsiteSection::Version.find(params[:id]).layout
end

#non_published_content_versionsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/knitkit/erp_app/desktop/versions_controller.rb', line 47

def non_published_content_versions
  content   = Content.find(params[:id])
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
  sort      = sort_hash[:property] || 'version'
  dir       = sort_hash[:direction] || 'DESC'
  limit     = params[:limit] || 15
  start     = params[:start] || 0

  versions = content.versions.order("#{sort} #{dir}").offset(start).limit(limit)

  render :json => {:totalCount => content.versions.count,
    :data => versions.collect{|version|version.to_hash(
        :only => [:id, :version, :title, :body_html, :excerpt_html, :updated_at])}
  }
end

#publish_contentObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/knitkit/erp_app/desktop/versions_controller.rb', line 63

def publish_content
  begin
    current_user.with_capability('publish', 'Content') do
      content = Content.find(Content::Version.find(params[:id]).content_id)
      content.publish(Website.find(params[:site_id]), params[:comment], params[:version], current_user)

      render :json => {:success => true}
    end
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
    render :json => {:success => false, :message => ex.message}
  end
end

#publish_website_sectionObject



136
137
138
139
140
141
# File 'app/controllers/knitkit/erp_app/desktop/versions_controller.rb', line 136

def publish_website_section
  website_section = WebsiteSection.find(WebsiteSection::Version.find(params[:id]).website_section_id)
  website_section.publish(Website.find(params[:site_id]), params[:comment], params[:version], current_user)

  render :json => {:success => true}
end

#revert_contentObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/knitkit/erp_app/desktop/versions_controller.rb', line 76

def revert_content
  begin
    current_user.with_capability('revert_version', 'Content') do
      content = Content.find(Content::Version.find(params[:id]).content_id)
      version = params[:version]
      content.revert_to(version)
      content.save!

      render :json => {:success => true}
    end
  rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
    render :json => {:success => false, :message => ex.message}
  end
end

#revert_website_sectionObject



143
144
145
146
147
148
149
150
# File 'app/controllers/knitkit/erp_app/desktop/versions_controller.rb', line 143

def revert_website_section
  website_section = WebsiteSection.find(WebsiteSection::Version.find(params[:id]).website_section_id)
  version = params[:version]
  website_section.revert_to(version)
  website_section.save!

  render :text => {:success => true, :body_html => website_section.layout}.to_json
end

#website_section_layout_versionsObject

website section layouts



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/controllers/knitkit/erp_app/desktop/versions_controller.rb', line 93

def website_section_layout_versions
  website_section = WebsiteSection.find(params[:id])
  website = Website.find(params[:site_id])
  sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
  sort = sort_hash[:property] || 'version'
  dir  = sort_hash[:direction] || 'DESC'
  limit = params[:limit] || 15
  start = params[:start] || 0

  versions = website_section.versions.order("#{sort} #{dir}").offset(start).limit(limit)

  WebsiteSection::Version.class_exec(website) do
    cattr_accessor :website
    self.website = website
    def active
      published_site_id = self.website.active_publication.id
      !PublishedElement.includes([:published_website]).where('published_websites.id = ? and published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', published_site_id, self.website_section_id, 'WebsiteSection', self.version).first.nil?
    end

    def published_element
      PublishedElement.where('published_element_record_id = ? and published_element_record_type = ? and published_elements.version = ?', self.website_section_id, 'WebsiteSection', self.version).first
    end

    def published
      !published_element.nil?
    end

    def publisher
      published_element.published_by_username if published
    end
  end

  render :json => {:totalCount => website_section.versions.count,
    :data => versions.collect{|version|version.to_hash(
        :only => [:id, :version, :title, :updated_at],
        :methods => [:active, :published, :publisher])}
  }
end