jinda 0.7.1 → 0.7.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ @custom_gems = Array.new
2
+ @custom_gems =
3
+ [
4
+ ["mongoid-paperclip", require: "mongoid_paperclip"],
5
+ ["kaminari-mongoid", "1.0.1"],
6
+ ["nokogiri", "~> 1.11.0"]
7
+ # ["mongoid", git: "git@github.com:kul1/mongoid-jinda.git"]
8
+ ]
@@ -0,0 +1,20 @@
1
+ @dev_gems = Array.new
2
+ @dev_gems =
3
+ [
4
+ ["shoulda"],
5
+ ["rspec"],
6
+ ["rspec-rails"],
7
+ ["better_errors"],
8
+ ["binding_of_caller"],
9
+ ["pry-byebug"],
10
+ ["factory_bot_rails"],
11
+ ["database_cleaner"],
12
+ ["guard"],
13
+ ["guard-rspec"],
14
+ ["guard-minitest"],
15
+ ["capybara"],
16
+ ["selenium-webdriver"],
17
+ ["rb-fsevent"],
18
+ ["valid_attribute"],
19
+ ["faker"]
20
+ ]
@@ -0,0 +1,30 @@
1
+ # @runtime_gems = Array.new
2
+ @@runtime_gems =
3
+ [
4
+ ["bson", "4.4.2"],
5
+ ["maruku", "~> 0.7.3"],
6
+ ["bcrypt"],
7
+ ["rouge"],
8
+ ["normalize-rails"],
9
+ ["font-awesome-rails"],
10
+ ["font-awesome-sass", "~> 5.12.0"],
11
+ ["meta-tags"],
12
+ ["jquery-turbolinks", "2.1.0"],
13
+ ["mongo", "2.11.3"],
14
+ ["turbolinks_render"],
15
+ ["haml-rails", "~> 2.0.1"],
16
+ ["haml", "~> 5.1", ">= 5.1.2"],
17
+ ["mail"],
18
+ ["prawn"],
19
+ ["redcarpet"],
20
+ ["oauth2", "1.4.4"],
21
+ ["omniauth", "1.9.1"],
22
+ ["omniauth-oauth2", "1.6.0"],
23
+ ["omniauth-identity", "~> 1.1.1"],
24
+ ["omniauth-facebook", "6.0.0"],
25
+ ["omniauth-google-oauth2", "0.8.0"],
26
+ ["dotenv-rails"],
27
+ ["cloudinary", "1.13.2"],
28
+ ["kaminari", "1.2.0"],
29
+ ["jquery-rails", "4.3.5"]
30
+ ]
@@ -0,0 +1,3 @@
1
+ ## Todo
2
+ - Seperate gems file from gems_install.rb
3
+
@@ -0,0 +1,132 @@
1
+ def setup_gems
2
+ # # define required gems: jinda_gem, jinda_dev_gem
3
+ jinda_gem =
4
+ [
5
+ ["bson", "4.4.2"],
6
+ ["maruku", "~> 0.7.3"],
7
+ ["bcrypt"],
8
+ ["rouge"],
9
+ ["normalize-rails"],
10
+ ["font-awesome-rails"],
11
+ ["font-awesome-sass", "~> 5.12.0"],
12
+ ["meta-tags"],
13
+ ["jquery-turbolinks", "2.1.0"],
14
+ ["mongo", "2.11.3"],
15
+ ["turbolinks_render"],
16
+ ["haml-rails", "~> 2.0.1"],
17
+ ["haml", "~> 5.1", ">= 5.1.2"],
18
+ ["mail"],
19
+ ["prawn"],
20
+ ["redcarpet"],
21
+ ["oauth2", "1.4.4"],
22
+ ["omniauth", "1.9.1"],
23
+ ["omniauth-oauth2", "1.6.0"],
24
+ ["omniauth-identity", "~> 1.1.1"],
25
+ ["omniauth-facebook", "6.0.0"],
26
+ ["omniauth-google-oauth2", "0.8.0"],
27
+ ["dotenv-rails"],
28
+ ["cloudinary", "1.13.2"],
29
+ ["kaminari", "1.2.0"],
30
+ ["jquery-rails", "4.3.5"]
31
+ ]
32
+ #
33
+ jinda_custom_gem =
34
+ [
35
+ ["mongoid-paperclip", require: "mongoid_paperclip"],
36
+ ["kaminari-mongoid", "1.0.1"],
37
+ ["nokogiri", "~> 1.11.0"],
38
+ ["mongoid", git: "git@github.com:kul1/mongoid-jinda.git"]
39
+ # ["mongoid", "~> 7.1.0"]
40
+ ]
41
+ #
42
+ jinda_dev_gem =
43
+ [
44
+ ["shoulda"],
45
+ ["rspec"],
46
+ ["rspec-rails"],
47
+ ["better_errors"],
48
+ ["binding_of_caller"],
49
+ ["pry-byebug"],
50
+ ["factory_bot_rails"],
51
+ ["database_cleaner"],
52
+ ["guard"],
53
+ ["guard-rspec"],
54
+ ["guard-minitest"],
55
+ ["capybara"],
56
+ ["selenium-webdriver"],
57
+ ["rb-fsevent"],
58
+ ["valid_attribute"],
59
+ ["faker"]
60
+ ]
61
+
62
+ # Check each jinda_gem and create new array if found one otherwise just create.
63
+ # Open Gemfile add gem if not exist
64
+ jinda_gem.each do |g|
65
+ unless (%x(gem list -e --no-versions #{g[0]})) == "#{g[0]}\n"
66
+ if g.count == 2
67
+ gem g[0], g[1]
68
+ else
69
+ gem g[0]
70
+ end
71
+ else
72
+ if g.count == 2
73
+ xgem_0 = %x(gem list -e #{g[0]})
74
+ unless xgem_0.include?(("#{g[1]}").gsub(/[~> ]/, ''))
75
+ # puts " Found existing #{xgem_0} in Gemfile or System, Please edit Gemfile", :red
76
+ puts " Found existing #{xgem_0} in Gemfile or System, Please edit Gemfile"
77
+ gem g[0], g[1]
78
+ else
79
+ # puts " Checking #{g[0]} found Ver. #{g[1]} already exist in Gemfile", :green
80
+ puts " Checking #{g[0]} found Ver. #{g[1]} already exist in Gemfile"
81
+ end
82
+ end
83
+ # puts " SKIP adding #{g[0]} in Gemfile", :yellow
84
+ puts " SKIP adding #{g[0]} in Gemfile"
85
+ end
86
+ end
87
+
88
+ # create list of gem in sub-group dev and test
89
+ jinda_dev_new = Array.new
90
+ jinda_dev_gem.each do |g|
91
+ unless (%x(gem list -e --no-versions #{g[0]})) == "#{g[0]}\n"
92
+ jinda_dev_new << g
93
+ else
94
+ # puts " #{g[0]} already exist in Gemfile", :yellow
95
+ puts " #{g[0]} already exist in Gemfile"
96
+ end
97
+ end
98
+ unless jinda_dev_new.count == 0
99
+ gem_group :development, :test do
100
+ jinda_dev_new.each do |n|
101
+ if n.count == 1
102
+ gem n[0]
103
+ else
104
+ gem n[0], n[1]
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ # create list of custom gem
111
+ jinda_custom_new = Array.new
112
+ jinda_custom_gem.each do |g|
113
+ # unless (%x(gem list -e --no-versions #{g[0]})) == "#{g[0]}\n"
114
+ unless File.read("Gemfile").include?("#{g[0]}, #{g[1]}")
115
+ jinda_custom_new << g
116
+ else
117
+ puts " #{g[0]} already exist in Gemfile", :yellow
118
+ puts " #{g[0]} already exist in Gemfile", :yellow
119
+ end
120
+ end
121
+ unless jinda_custom_new.count == 0
122
+ jinda_custom_new.each do |c|
123
+ # puts " Checking if #{c[0]} already exist in Gemfile", :yellow
124
+ puts " Checking if #{c[0]} already exist in Gemfile"
125
+ if c.count == 1
126
+ gem c[0]
127
+ else
128
+ gem c[0], c[1]
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,6 @@
1
+ binding.pry
2
+ puts 'This is test'
3
+ puts 'This is test'
4
+ puts 'This is test'
5
+ puts 'This is test'
6
+ puts 'This is test'
@@ -16,7 +16,7 @@ Rails Application Generator using Freemind
16
16
  These versions works for sure but others may do.
17
17
 
18
18
  * Ruby 2.7.0
19
- * Rails 6.0.2
19
+ * Rails 6.0.3
20
20
  * MongoDB 6
21
21
  * Freemind 1.0.1
22
22
 
@@ -36,7 +36,7 @@ app without ActiveRecord
36
36
 
37
37
  ## Add jinda to your Gemfile:
38
38
 
39
- gem 'jinda', '~> 0.5.3'
39
+ gem 'jinda'
40
40
 
41
41
  For Development (most updated)
42
42
 
@@ -0,0 +1,31 @@
1
+ class CommentsController < ApplicationController
2
+ before_action :comment_params, only: [:create]
3
+ before_action :load_commmentable
4
+
5
+ def index
6
+ @comments = @commentable.comments
7
+ end
8
+
9
+ def create
10
+ @comment = @commentable.comments.new comment_params
11
+ @comment.save!
12
+ redirect_to [@commentable], notice: "Comment created"
13
+ end
14
+
15
+ private
16
+
17
+ # def article_params
18
+ # params.require(:comment).permit(:article_id)
19
+ # end
20
+
21
+ def comment_params
22
+ resource = request.path.split('/')[1]
23
+ commentable_id = "#{resource.singularize.to_sym}_id" #:article_id
24
+ params.require(:comment).permit(:body, :user_id,:name, :image, commentable_id.to_sym)
25
+ end
26
+
27
+ def load_commmentable
28
+ resource, id = request.path.split('/')[1,2]
29
+ @commentable = resource.singularize.classify.constantize.find(id)
30
+ end
31
+ end
@@ -15,7 +15,9 @@ class ArticlesController < ApplicationController
15
15
  @article = Article.find(article_params)
16
16
  @commentable = @article
17
17
  @comments = @commentable.comments.desc(:created_at).page(params[:page]).per(10)
18
-
18
+ @user = User.find(@article.user_id)
19
+ @show = Hash.new
20
+ @show = {:article => @article, :comments => @comments, :user => @user}
19
21
  prepare_meta_tags(title: @article.title,
20
22
  description: @article.text,
21
23
  keywords: @article.keywords)
@@ -9,6 +9,7 @@ class UsersController < ApplicationController
9
9
  def update_user
10
10
  # can't use session, current_ma_user inside jinda methods
11
11
  $user.update_attribute :email, $xvars["enter_user"]["user"]["email"]
12
+ $user.update_attribute :image, $xvars["enter_user"]["user"]["image"]
12
13
  end
13
14
  def change_password
14
15
  # check if old password correct
@@ -4,9 +4,10 @@ class Comment
4
4
  # jinda begin
5
5
  include Mongoid::Timestamps
6
6
  field :body, :type => String
7
+ field :name, :type => String
8
+ field :image, :type => String
7
9
  belongs_to :article, :class_name => "Article"
8
10
  belongs_to :user, :class_name => "User"
9
- belongs_to :job, :class_name => "Job"
10
11
  belongs_to :commentable, polymorphic: true
11
12
  index({ commentable_id: 1, commentable_type: 1})
12
13
  # jinda end
@@ -1,10 +1,5 @@
1
1
  .box.box-info
2
2
  .box-header.with-border
3
-
4
- %h3.box-title
5
- = @page_title
6
- .label-warning
7
- = flash[:notice]
8
3
  .box-tools.pull-right
9
4
  %button.btn.btn-box-tool{"data-widget" => "collapse", :type => "button"}
10
5
  %i.fa.fa-minus
@@ -16,6 +11,9 @@
16
11
  %table.table.no-margin
17
12
  %thead
18
13
  %tr
14
+ - unless current_ma_user.nil?
15
+ - if current_ma_user.role.include?"A"
16
+ %th Author
19
17
  %th Title
20
18
  %th Description
21
19
  %th Created
@@ -23,7 +21,12 @@
23
21
  %th Delete
24
22
  %th Edit
25
23
  - report.each do |article|
24
+ - user = User.find(article.user_id)
26
25
  %tr
26
+ -# if current_ma_user.role.include?"A"
27
+ - unless current_ma_user.nil?
28
+ - if current_ma_user.role.include?"A"
29
+ %td= user.code
27
30
  %td= link_to article.title, :controller=>"articles", :action=>"show", :article_id => article.id
28
31
  %td= article.text.html_safe
29
32
  %td= article.created_at.strftime('%m/%d/%Y')
@@ -1,42 +1,58 @@
1
- - title @article.title
2
- - description @article.text
3
- - keywords @article.keywords
1
+ - title @show[:article][:title]
2
+ - description @show[:article][:text]
3
+ - keywords @show[:article][:keywords]
4
4
  .container
5
5
  %div.row::before
6
6
  %div.col-md-12
7
- %h2.display-3.mt-5.pt-5
8
- = @article.title
9
- = link_to image_tag('pencil.png', style:'border:none; float:right;', id: 'article_pen'), {controller: "articles", action: "edit", article_id: @article.id}, data: { confirm: "Please Confirm" }
10
- %hr
11
- = @article.text
12
- %h4.display-5
13
- = @article.body.html_safe
14
- - @comments.each do |comment|
15
- %div#article-comment.ui-corner-all
16
- .col-md-10.col-sm-12
17
- %div.small-box.bg-gray
18
- %div.inner
19
- %div.font-weight-light
20
- Author:
21
- %b= comment.user.code if comment.user
22
- %div#comment-body
23
- %i= comment.body
24
- %hr
7
+ .row-description
8
+ %h2.display-3.mt-5.pt-5
9
+ = @show[:article][:title]
10
+ = link_to image_tag('pencil.png', style:'border:none; float:right;', id: 'article_pen'), {controller: "articles", action: "edit", article_id: @article.id}, data: { confirm: "Please Confirm" }
11
+ %div.font-weight-light
12
+ by
13
+ %img.img-circle{:alt => "User Image", src: @show[:user][:image] }/
14
+ %div.font-weight-light
15
+ = @show[:user][:code]
16
+ %div.font-weight-light
17
+ = @show[:article][:created_at]
18
+ %hr
19
+ = @show[:article][:text]
20
+ %h4.row-body
21
+ = @show[:article][:body].html_safe
22
+ %hr
23
+ - @show[:comments].each do |comment|
24
+ %div#article-comment.ui-corner-all
25
+ .col-md-12
26
+ %div.small-box.bg-white.text-info
27
+ %div.inner
28
+ %div.font-weight-light
29
+ - user_image = get_user_image(comment.user_id)
30
+ %img.comment-user-image{:alt => "User Image", src: user_image}/
25
31
 
26
- .container
27
- .card
32
+ %div.font-weight-light
33
+ Author:
34
+ %b= comment.name if comment.name
35
+ %div.right-date
36
+ 12/12/2021
37
+ %div#comment-body
38
+ %i= comment.body
28
39
 
29
40
  - if login?
30
- %h4.display-5
31
- Add a comment:
32
- = form_with(model: [@article, Comment.new], local: true) do |f|
33
- .form-group
34
- = f.hidden_field :article_id, :value => @article.id
35
- .form-group
36
- = f.label :body, "Comment"
37
- .form-group
38
- = f.text_area :body, rows: 5, class: "form-control"
39
- .form-group
40
- = f.hidden_field :user_id, :value => current_ma_user
41
- .form-group
42
- = f.submit "Submit", class: "btn btn-default btn-success"
41
+ %hr
42
+ %h4.col-md-12
43
+ Add a comment:
44
+ = form_with(model: [@show[:article], Comment.new], local: true) do |f|
45
+ .form-group
46
+ = f.hidden_field :article_id, :value => @show[:article][:id]
47
+ .form-group
48
+ = f.label :body, "Comment"
49
+ .form-group
50
+ = f.text_area :body, rows: 5, class: "form-control"
51
+ .form-group
52
+ = f.hidden_field :user_id, :value => current_ma_user.id
53
+ .form-group
54
+ = f.hidden_field :name, :value => current_ma_user.code
55
+ .form-group
56
+ = f.hidden_field :image, :value => current_ma_user.image
57
+ .form-group
58
+ = f.submit "Submit", class: "btn btn-default btn-success"
@@ -5,4 +5,6 @@
5
5
  <%= fields_for user do |f| %>
6
6
  <%= f.label :email, "Email" %>
7
7
  <%= f.text_field :email %>
8
+ <%= f.label :image, "image link" %>
9
+ <%= f.text_field :image%>
8
10
  <% end %>
data/lib/jinda/themes.rb CHANGED
@@ -1,163 +1,175 @@
1
1
 
2
- # ############################### Themes ###################################
3
- #
4
- # Check login user information from User model: name(code), image for Themes
5
- #
6
- # ##########################################################################
7
- def get_login_user_info
8
- if current_ma_user.present?
9
- $user_image = current_ma_user.image
10
- $user_name = current_ma_user.code
11
- $user_email = current_ma_user.email
12
- $user_id = current_ma_user.try(:id)
13
- else
14
- $user_image = asset_url("user.png", :width => "48")
15
- $user_name = 'Guest User'
16
- $user_email = 'guest@sample.com'
17
- $user_id = ''
18
- end
19
- return $user_image, $user_name, $user_email,$user_id
20
- end
2
+ # ############################### Themes ###################################
3
+ #
4
+ # Check login user information from User model: name(code), image for Themes
5
+ #
6
+ # ##########################################################################
7
+ def get_login_user_info
8
+ if current_ma_user.present?
9
+ $user_image = ((current_ma_user.image != "") ? current_ma_user.image : asset_url("user.png", :width => "48"))
10
+ $user_name = current_ma_user.code
11
+ $user_email = current_ma_user.email
12
+ $user_id = current_ma_user.try(:id)
13
+ else
14
+ $user_image = asset_url("user.png", :width => "48")
15
+ $user_name = 'Guest User'
16
+ $user_email = 'guest@sample.com'
17
+ $user_id = ''
18
+ end
19
+ return $user_image, $user_name, $user_email,$user_id
20
+ end
21
+ # search image from User in Article/View/Show
22
+ def get_user_image(user_id)
23
+ user_image = User.find(user_id).image
24
+ user_image = ((user_image != "") ? user_image : asset_url("user.png", :width => "48"))
25
+ return user_image
26
+ end
21
27
 
22
- def name2code(s)
23
- # rather not ignore # symbol cause it could be comment
24
- code, name = s.split(':')
25
- code.downcase.strip.gsub(' ','_').gsub(/[^#_\/a-zA-Z0-9]/,'')
26
- end
27
- def name2camel(s)
28
- s.gsub(' ','_').camelcase
29
- end
30
- def true_action?(s)
31
- %w(call ws redirect invoke email).include? s
32
- end
33
- def set_global
34
- $xmain= @xmain ; $runseq = @runseq ; $user = current_ma_user ; $xvars= @xmain.xvars; $ip = request.env["REMOTE_ADDR"]
35
- end
36
- def authorize? # use in pending tasks
37
- @runseq= @xmain.runseqs.find @xmain.current_runseq
38
- return false unless @runseq
39
- @user = current_ma_user
40
- set_global
41
- return false unless eval(@runseq.rule) if @runseq.rule
42
- return true if true_action?(@runseq.action)
43
- # return false if check_wait
44
- return true if @runseq.role.blank?
45
- unless @runseq.role.empty?
46
- return false unless @user.role
47
- return @user.role.upcase.split(',').include?(@runseq.role.upcase)
48
- end
49
- return true
50
- end
51
- def authorize_init? # use when initialize new transaction
52
- # check module role
53
- mrole = @service.module.role
54
- return false if mrole && !current_ma_user
55
- return false if mrole && !current_ma_user.has_role(mrole)
56
28
 
57
- # check step 1 role
58
- xml= @service.xml
59
- step1 = REXML::Document.new(xml).root.elements['node']
60
- role= get_option_xml("role", step1) || ""
61
- # rule= get_option_xml("rule", step1) || true
62
- rule= get_option_xml("rule", step1) || true
63
- return true if role==""
64
- unless current_ma_user
65
- return role.blank?
66
- else
67
- return false unless current_ma_user.role
68
- return current_ma_user.has_role(role)
69
- end
29
+ def name2code(s)
30
+ # rather not ignore # symbol cause it could be comment
31
+ code, name = s.split(':')
32
+ code.downcase.strip.gsub(' ','_').gsub(/[^#_\/a-zA-Z0-9]/,'')
33
+ end
34
+ def name2camel(s)
35
+ s.gsub(' ','_').camelcase
36
+ end
37
+ def true_action?(s)
38
+ %w(call ws redirect invoke email).include? s
39
+ end
40
+ def set_global
41
+ $xmain= @xmain ; $runseq = @runseq ; $user = current_ma_user ; $xvars= @xmain.xvars; $ip = request.env["REMOTE_ADDR"]
42
+ end
43
+ def authorize? # use in pending tasks
44
+ @runseq= @xmain.runseqs.find @xmain.current_runseq
45
+ return false unless @runseq
46
+ @user = current_ma_user
47
+ set_global
48
+ return false unless eval(@runseq.rule) if @runseq.rule
49
+ return true if true_action?(@runseq.action)
50
+ # return false if check_wait
51
+ return true if @runseq.role.blank?
52
+ unless @runseq.role.empty?
53
+ return false unless @user.role
54
+ return @user.role.upcase.split(',').include?(@runseq.role.upcase)
55
+ end
56
+ return true
57
+ end
58
+ def authorize_init? # use when initialize new transaction
59
+ # check module role
60
+ mrole = @service.module.role
61
+ return false if mrole && !current_ma_user
62
+ return false if mrole && !current_ma_user.has_role(mrole)
70
63
 
71
- end
72
- def ma_log(message)
73
- # Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
74
- # :unread=> true, :ip=> ($ip || request.env["REMOTE_ADDR"])
75
- if session[:user_id]
76
- Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
77
- :user_id => $user.id, :unread=> true, :ip=>request.env["REMOTE_ADDR"]
78
- else
79
- Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
80
- :unread=> true, :ip=>request.env["REMOTE_ADDR"]
81
- end
82
- end
64
+ # check step 1 role
65
+ xml= @service.xml
66
+ step1 = REXML::Document.new(xml).root.elements['node']
67
+ role= get_option_xml("role", step1) || ""
68
+ # rule= get_option_xml("rule", step1) || true
69
+ rule= get_option_xml("rule", step1) || true
70
+ return true if role==""
71
+ unless current_ma_user
72
+ return role.blank?
73
+ else
74
+ return false unless current_ma_user.role
75
+ return current_ma_user.has_role(role)
76
+ end
83
77
 
84
- alias :ma_notice :ma_log
78
+ end
79
+ def ma_log(message)
80
+ # Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
81
+ # :unread=> true, :ip=> ($ip || request.env["REMOTE_ADDR"])
82
+ if session[:user_id]
83
+ Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
84
+ :user_id => $user.id, :unread=> true, :ip=>request.env["REMOTE_ADDR"]
85
+ else
86
+ Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
87
+ :unread=> true, :ip=>request.env["REMOTE_ADDR"]
88
+ end
89
+ end
85
90
 
86
- # methods from application_helper
87
- def markdown(text)
88
- erbified = ERB.new(text.html_safe).result(binding)
89
- red = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
90
- red.render(erbified).html_safe
91
- end
92
- def align_text(s, pixel=3)
93
- "<span style='position:relative; top:-#{pixel}px;'>#{s}</span>".html_safe
94
- end
95
- def status_icon(status)
96
- case status
97
- when 'R'
98
- image_tag 'user.png'
99
- when 'F'
100
- image_tag 'tick.png'
101
- when 'I'
102
- image_tag 'control_play.png'
103
- when 'E'
104
- image_tag 'logout.png'
105
- when 'X'
106
- image_tag 'cross.png'
107
- else
108
- image_tag 'cancel.png'
109
- end
110
- end
111
- def role_name(code)
112
- role= Jinda::Role.where(code:code).first
113
- return role ? role.name : ""
114
- end
115
- def uncomment(s)
116
- s.sub(/^#\s/,'')
117
- end
118
- def code_div(s)
119
- "<pre style='background-color: #efffef;'><code class='ruby' lang='ruby'> #{s}</code></pre>".html_safe
120
- end
121
- def ajax?(s)
122
- return s.match('file_field') ? false : true
123
- end
124
- def step(s, total) # square text
125
- s = (s==0)? 1: s.to_i
126
- total = total.to_i
127
- out ="<div class='step'>"
128
- (s-1).times {|ss| out += "<span class='steps_done'>#{(ss+1)}</span>" }
129
- out += %Q@<span class='step_now' >@
130
- out += s.to_s
131
- out += "</span>"
132
- out += %Q@@
133
- for i in s+1..total
134
- out += "<span class='steps_more'>#{i}</span>"
135
- end
136
- out += "</div>"
137
- out.html_safe
138
- end
91
+ alias :ma_notice :ma_log
139
92
 
140
- def current_ma_user
141
- # if session[:user_id]
142
- # return @user ||= User.find(session[:user_id]['$oid'])
143
- # else
144
- # return nil
145
- # end
146
- #@user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
147
- @user ||= User.where(:auth_token => cookies[:auth_token]).first if cookies[:auth_token]
148
- return @user
149
- end
93
+ # methods from application_helper
94
+ def markdown(text)
95
+ begin
96
+ erbified = ERB.new(text.html_safe).result(binding)
97
+ rescue => error
98
+ flash[:notice] = "This ruby version not support #{error}"
99
+ return
100
+ end
101
+ red = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
102
+ red.render(erbified).html_safe
103
+ end
104
+ def align_text(s, pixel=3)
105
+ "<span style='position:relative; top:-#{pixel}px;'>#{s}</span>".html_safe
106
+ end
107
+ def status_icon(status)
108
+ case status
109
+ when 'R'
110
+ image_tag 'user.png'
111
+ when 'F'
112
+ image_tag 'tick.png'
113
+ when 'I'
114
+ image_tag 'control_play.png'
115
+ when 'E'
116
+ image_tag 'logout.png'
117
+ when 'X'
118
+ image_tag 'cross.png'
119
+ else
120
+ image_tag 'cancel.png'
121
+ end
122
+ end
123
+ def role_name(code)
124
+ role= Jinda::Role.where(code:code).first
125
+ return role ? role.name : ""
126
+ end
127
+ def uncomment(s)
128
+ s.sub(/^#\s/,'')
129
+ end
130
+ def code_div(s)
131
+ "<pre style='background-color: #efffef;'><code class='ruby' lang='ruby'> #{s}</code></pre>".html_safe
132
+ end
133
+ def ajax?(s)
134
+ return s.match('file_field') ? false : true
135
+ end
136
+ def step(s, total) # square text
137
+ s = (s==0)? 1: s.to_i
138
+ total = total.to_i
139
+ out ="<div class='step'>"
140
+ (s-1).times {|ss| out += "<span class='steps_done'>#{(ss+1)}</span>" }
141
+ out += %Q@<span class='step_now' >@
142
+ out += s.to_s
143
+ out += "</span>"
144
+ out += %Q@@
145
+ for i in s+1..total
146
+ out += "<span class='steps_more'>#{i}</span>"
147
+ end
148
+ out += "</div>"
149
+ out.html_safe
150
+ end
150
151
 
151
- def ui_action?(s)
152
- %w(form output mail pdf).include? s
153
- end
154
- # def handle_ma_notice
155
- # if Jinda::Notice.recent.count>0
156
- # notice= Jinda::Notice.recent.last
157
- # notice.update_attribute :unread, false
158
- # "<script>notice('#{notice.message}');</script>"
159
- # else
160
- # ""
161
- # end
162
- # end
152
+ def current_ma_user
153
+ # if session[:user_id]
154
+ # return @user ||= User.find(session[:user_id]['$oid'])
155
+ # else
156
+ # return nil
157
+ # end
158
+ #@user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
159
+ @user ||= User.where(:auth_token => cookies[:auth_token]).first if cookies[:auth_token]
160
+ return @user
161
+ end
162
+
163
+ def ui_action?(s)
164
+ %w(form output mail pdf).include? s
165
+ end
166
+ # def handle_ma_notice
167
+ # if Jinda::Notice.recent.count>0
168
+ # notice= Jinda::Notice.recent.last
169
+ # notice.update_attribute :unread, false
170
+ # "<script>notice('#{notice.message}');</script>"
171
+ # else
172
+ # ""
173
+ # end
174
+ # end
163
175