Top Level Namespace

Defined Under Namespace

Modules: ActionView, AdminsHelper, ApplicationCable, ApplicationHelper, ArticlesHelper, AuthenticationHelper, BasicHelper, CommentsHelper, CtrsHelper, DevsHelper, Jinda, JindaGeneralConcern, JindaRunConcern, OmniauthMacros, PicturesHelper, RequestSpecHelper, SitemapHelper, UsersHelper Classes: Address, AdminsController, ApplicationController, ApplicationMailer, ApplicationSystemTestCase, Article, ArticlesController, Comment, CommentsController, DocsController, IdentitiesController, Identity, JindaController, JindaMailer, Note, NoteMailer, NotePreview, NotesController, Param, PasswordResetsController, Person, RegistrationRoutesTest, SessionsController, SitemapController, String, User, UserMailer, UsersController

Constant Summary collapse

@@runtime_gems =
[
  ["bson", "4.4.2"],
  ["maruku", "~> 0.7.3"],
  ["bcrypt"],
  ["rouge"],
  ["normalize-rails"],
  ["font-awesome-rails"],
  ["font-awesome-sass", "~> 5.12.0"],
  ["meta-tags"],
  ["jquery-turbolinks", "2.1.0"],
  ["mongo", "2.11.3"],
  ["turbolinks_render"],
  ["haml-rails", "~> 2.0.1"],
  ["haml", "~> 5.1", ">= 5.1.2"],
  ["mail"],
  ["prawn"],
  ["redcarpet"],
  ["oauth2", "1.4.4"],
  ["omniauth", "1.9.1"],
  ["omniauth-oauth2", "1.6.0"],
  ["omniauth-identity", "~> 1.1.1"],
  ["omniauth-facebook", "6.0.0"],
  ["omniauth-google-oauth2", "0.8.0"],
  ["dotenv-rails"],
  ["cloudinary", "1.13.2"],
  ["kaminari", "1.2.0"],
  ["jquery-rails", "4.3.5"]
]

Instance Method Summary collapse

Instance Method Details

#add_jinda(doc, attr_hash) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/jinda/gen_models.rb', line 45

def add_jinda(doc, attr_hash)
  if doc =~ /#{@btext}/
    s1,s2,s3= doc.partition(/  #{@btext}.*#{@etext}\n/m)
      s2= ""
  else
    s1,s2,s3= doc.partition("include Mongoid::Document\n")
  end
  doc= s1+s2+ <<-EOT
  #{@btext}
  include Mongoid::Timestamps
  EOT

  attr_hash.each do |a|
    # doc+= "\n*****"+a.to_s+"\n"
    if a[:edit]
      doc += "  #{a[:text]}\n"
    else
      # Fixed: Capitalize only first char
      # doc += "  field :#{a[:code]}, :type => #{a[:type].capitalize}\n"
      a[:type][0] = a[:type][0].capitalize 
      doc += "  field :#{a[:code]}, :type => #{a[:type]}\n"
    end
  end
  doc += "  #{@etext}\n"
  doc + s3
end

#add_utf8(doc) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/jinda/gen_models.rb', line 72

def add_utf8(doc)
  unless doc =~ /encoding\s*:\s*utf-8/
    doc.insert 0, "# encoding: utf-8\n"
  else
    doc
  end
end

#affirm(s) ⇒ Object



128
129
130
# File 'lib/jinda/gen_helpers.rb', line 128

def affirm(s)
  return s =~ /[y|yes|t|true]/i ? true : false
end

#ajax?(s) ⇒ Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/jinda/themes.rb', line 133

def ajax?(s)
  return s.match('file_field') ? false : true
end

#ajax_noticeObject



30
31
32
33
34
35
36
37
38
# File 'lib/jinda/gen_xmain.rb', line 30

def ajax_notice
  if notice=Jinda::Notice.recent(current_ma_user, request.env["REMOTE_ADDR"])
    notice.update_attribute :unread, false
    js = "notice('#{notice.message}');"
  else
    js = ""
  end
  render plain: "<script>#{js}</script>"
end

#align_text(s, pixel = 3) ⇒ Object



104
105
106
# File 'lib/jinda/themes.rb', line 104

def align_text(s, pixel=3)
  "<span style='position:relative; top:-#{pixel}px;'>#{s}</span>".html_safe
end

#authorize?Boolean

use in pending tasks

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jinda/themes.rb', line 43

def authorize? # use in pending tasks
  @runseq= @xmain.runseqs.find @xmain.current_runseq
  return false unless @runseq
  @user = current_ma_user
  set_global
  return false unless eval(@runseq.rule) if @runseq.rule
  return true if true_action?(@runseq.action)
  # return false if check_wait
  return true if @runseq.role.blank?
  unless @runseq.role.empty?
    return false unless @user.role
    return @user.role.upcase.split(',').include?(@runseq.role.upcase)
  end
  return true
end

#authorize_init?Boolean

use when initialize new transaction

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jinda/themes.rb', line 58

def authorize_init? # use when initialize new transaction
  # check module role
  mrole = @service.module.role
  return false if mrole && !current_ma_user
  return false if mrole && !current_ma_user.has_role(mrole)

  # check step 1 role
  xml= @service.xml
  step1 = REXML::Document.new(xml).root.elements['node']
  role= get_option_xml("role", step1) || ""
  #    rule= get_option_xml("rule", step1) || true
  rule= get_option_xml("rule", step1) || true
  return true if role==""
  unless current_ma_user
    return role.blank?
  else
    return false unless current_ma_user.role
    return current_ma_user.has_role(role)
  end

end

#b(s) ⇒ Object



1
2
3
# File 'lib/jinda/refresh.rb', line 1

def b(s)
  "<b>#{s}</b>".html_safe
end

#clear_xmainsObject



26
27
28
29
# File 'lib/jinda/gen_xmain.rb', line 26

def clear_xmains
  Jinda::Xmain.where(:status =>{'$in'=>['R','I']}).update_all(:status=>'X')
  redirect_to action:"pending"
end

#code_div(s) ⇒ Object



130
131
132
# File 'lib/jinda/themes.rb', line 130

def code_div(s)
  "<pre style='background-color: #efffef;'><code class='ruby' lang='ruby'>    #{s}</code></pre>".html_safe
end

#code_text(s) ⇒ Object

old def code(s)



7
8
9
# File 'lib/jinda/refresh.rb', line 7

def code_text(s) # old def code(s)
  "<pre style='background-color: #efffef;'><code class='ruby' lang='ruby'>#{s}</code></pre>".html_safe
end

#controller_exists?(modul) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/jinda/gen_helpers.rb', line 23

def controller_exists?(modul)
  File.exists? "#{Rails.root}/app/controllers/#{modul}_controller.rb"
end

#create_runseq(xmain) ⇒ Object

]

Each xmain  will create many run_seq as many as steps and form_steps

]

@runseq ################################]
@runseq => #<Jinda::Runseq _id: 5df31912a54d758417a7afc9, 
 created_at: 2019-12-13 04:52:34 UTC, 
 updated_at: 2019-12-13 04:52:43 UTC, 
 user_id: nil, 
 xmain_id: BSON::ObjectId('5df31912a54d758417a7afc7'), 
 action: "do", 
 status: "R", 
 code: "create", 
 name: "Create Article", 
 role: "", 
 rule: "true", 
 rstep: 2, 
 form_step: 1, 
 start: 2019-12-13 04:52:43 UTC, 
 stop: nil, 
 end: true, 
 xml: "<node CREATED='1493419491125' ID='ID_1687683396' MODIFIED='1493483244848' TEXT='create: Create Article'><icon BUILTIN='bookmark'/></node>", 
 ip: nil>

]



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/jinda/gen_runseq.rb', line 28

def create_runseq(xmain)
  @xvars= xmain.xvars
  default_role= get_default_role
  xml= xmain.service.xml
  root = REXML::Document.new(xml).root
  i= 0; j= 0 # i= step, j= form_step
  root.elements.each('node') do |activity|
    text= activity.attributes['TEXT']
    next if ma_comment?(text)
    next if text =~/^rule:\s*/
    action= freemind2action(activity.elements['icon'].attributes['BUILTIN']) if activity.elements['icon']
    return false unless action
    i= i + 1
    output_ma_display= false
    if action== ('output'|| 'list' ||'folder')
      ma_display= get_option_xml("display", activity)
      if ma_display && !affirm(ma_display)
        output_ma_display= false
      else
        output_ma_display= true
      end
    end
    j= j + 1 if (action=='form' || output_ma_display)
    @xvars['referer'] = activity.attributes['TEXT'] if action=='redirect'
    if action!= 'if' && !text.blank?
      scode, name= text.split(':', 2)
      name ||= scode; name.strip!
      code= name2code(scode)
    else
      code= text
      name= text
    end
    role= get_option_xml("role", activity) || default_role
    rule= get_option_xml("rule", activity) || "true"
    runseq= Jinda::Runseq.create :xmain=>xmain.id,
      :name=> name, :action=> action,
      :code=> code, :role=>role.upcase, :rule=> rule,
      :rstep=> i, :form_step=> j, :status=>'I',
      :xml=>activity.to_s
    xmain.current_runseq= runseq.id if i==1
  end
  @xvars['total_steps']= i
  @xvars['total_form_steps']= j
end

#create_xmain(service) ⇒ Object

] Each Service at one moment will create one xmain ]



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jinda/gen_xmain.rb', line 6

def create_xmain(service)
  c = name2camel(service.module.code)
  custom_controller= "#{c}Controller"
  params["return"] = request.env['HTTP_REFERER']
  Jinda::Xmain.create :service=>service,
    :start=>Time.now,
    :name=>service.name,
    :ip=> get_ip,
    :status=>'I', # init
    :user=>current_ma_user,
    :xvars=> {
      :service_id=>service.id,
      :p=>params.to_unsafe_h,
      :id=>params[:id],
      :user_id=>current_ma_user.try(:id),
      :custom_controller=>custom_controller,
      :host=>request.host,
      :referer=>request.env['HTTP_REFERER']
    }
end

#current_ma_userObject



152
153
154
155
156
157
158
159
160
161
# File 'lib/jinda/themes.rb', line 152

def current_ma_user
  # if session[:user_id]
  #   return @user ||= User.find(session[:user_id]['$oid'])
  # else
  #   return nil
  # end
  #@user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
  @user ||= User.where(:auth_token => cookies[:auth_token]).first if cookies[:auth_token]
  return @user
end

#dup_hash(a) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/jinda/gen_helpers.rb', line 26

def dup_hash(a)
  h = Hash.new(0)
  a.each do |aa|
    h[aa] += 1
  end
  return h
end

#freemind2action(s) ⇒ Object



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
# File 'lib/jinda/gen_helpers.rb', line 96

def freemind2action(s)
  case s.downcase
    #when 'bookmark' # Excellent
    #  'call'
  when 'bookmark' # Excellent
    'do'
  when 'attach' # Look here
    'form'
  when 'edit' # Refine
    'pdf'
  when 'wizard' # Magic
    'ws'
  when 'help' # Question
    'if'
  when 'forward' # Forward
    # 'redirect'
    'direct_to'
  when 'kaddressbook' #Phone
    'invoke' # invoke new service along the way
  when 'idea' # output
    'output'
  when 'list' # List
    'list'
  when 'folder' # Folder
    'folder'
  when 'mail'
    'mail'
  # when 'xmag' # Tobe discussed
  when 'To be discusssed'
    'search'  
  end
end

#gen_view_createfile(s, f, t) ⇒ Object



16
17
18
19
20
# File 'lib/jinda/gen_helpers.rb', line 16

def gen_view_createfile(s,f,t)
  FileUtils.cp s,f
  # FileUtils.cp "app/jinda/template/linkview.haml",f
  t << "create file #{f}"
end

#gen_view_file_exist?(dir) ⇒ Boolean

Methods to be overrided by gemhelp #

for Rspec Test

Returns:

  • (Boolean)


7
8
9
# File 'lib/jinda/gen_helpers.rb', line 7

def gen_view_file_exist?(dir)
  File.exists?(dir)
end

#gen_view_mkdir(dir, t) ⇒ Object



11
12
13
14
# File 'lib/jinda/gen_helpers.rb', line 11

def gen_view_mkdir(dir,t)
  Dir.mkdir(dir)
  t << "create directory #{dir}"
end

#gen_viewsObject

Jinda Rake Task #



5
6
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jinda/rake_views.rb', line 5

def gen_views
  t = ["*** generate ui ***"]

  # create array of files to be tested
  $afile = Array.new

  Jinda::Module.all.each do |m|
    m.services.each do |s|
      dir ="app/views/#{s.module.code}"
      unless gen_view_file_exist?(dir)
        gen_view_mkdir(dir,t) 
      end

      if s.code=='link'
        f= "app/views/#{s.module.code}/index.haml"
        $afile << f
        unless gen_view_file_exist?(f)
          sv = "app/jinda/template/linkview.haml"
          f= "app/views/#{s.module.code}/index.haml"
          gen_view_createfile(sv,f,t)
        end
        next   
      end

      dir ="app/views/#{s.module.code}/#{s.code}"
      unless gen_view_file_exist?(dir)
        gen_view_mkdir(dir,t) 
      end

      xml= REXML::Document.new(s.xml)
      xml.elements.each('*/node') do |activity|
        icon = activity.elements['icon']
        next unless icon
        action= freemind2action(icon.attributes['BUILTIN'])
        next unless ui_action?(action)
        code_name = activity.attributes["TEXT"].to_s
        next if code_name.comment?
        code= name2code(code_name)
        if action=="pdf"
          f= "app/views/#{s.module.code}/#{s.code}/#{code}.pdf.prawn"
        else
          f= "app/views/#{s.module.code}/#{s.code}/#{code}.html.erb"
        end
        $afile << f
        unless gen_view_file_exist?(f)
          sv = "app/jinda/template/view.html.erb"
          gen_view_createfile(sv,f,t)
        end
      end
    end
  end
  puts $afile.join("\n")
  puts t.join("\n")
  return $afile  
end

#get_appObject

##########################################################################

Load index.mm from Rails

##########################################################################



6
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
# File 'lib/jinda/get_app.rb', line 6

def get_app
  # MM was defined in Rails: config/initializer/jinda.rb
  f= MM || "#{Rails.root}/app/jinda/index.mm" 
  dir= File.dirname(f)
  t= REXML::Document.new(File.read(MM).gsub("\n","")).root
  recheck= true ; first_pass= true
  while recheck
    recheck= false
    t.elements.each("//node") do |n|
      if n.attributes['LINK'] # has attached file
        if first_pass
          f= "#{dir}/#{n.attributes['LINK']}"
        else
          f= n.attributes['LINK']
        end
        next unless File.exists?(f)
        tt= REXML::Document.new(File.read(f).gsub("\n","")).root.elements["node"]
        make_folders_absolute(f,tt)
        tt.elements.each("node") do |tt_node|
          n.parent.insert_before n, tt_node
        end
        recheck= true
        n.parent.delete_element n
      end
    end
    first_pass = false
  end
  return t
end

#get_default_roleObject



56
57
58
59
# File 'lib/jinda/refresh.rb', line 56

def get_default_role
  default_role= Jinda::Role.where(:code =>'default').first
  return default_role ? default_role.name.to_s : ''
end

#get_ipObject



53
54
55
# File 'lib/jinda/refresh.rb', line 53

def get_ip
  request.env['HTTP_X_FORWARDED_FOR'] || request.env['REMOTE_ADDR']
end

#get_login_user_infoObject

############################### Themes ###################################

Check login user information from User model: name(code), image for Themes

##########################################################################



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jinda/themes.rb', line 7

def 
  if current_ma_user.present?
    $user_image = ((current_ma_user.image != "") ? current_ma_user.image :  asset_url("user.png", :width => "48"))
    $user_name = current_ma_user.code
    $user_email = current_ma_user.email
    $user_id = current_ma_user.try(:id)
  else
    $user_image = asset_url("user.png", :width => "48")
    $user_name = 'Guest User'
    $user_email = '[email protected]'
    $user_id = ''
  end
  return $user_image, $user_name, $user_email,$user_id
end

#get_option(opt, runseq = @runseq) ⇒ Object

Todo refactor code



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jinda/refresh.rb', line 36

def get_option(opt, runseq=@runseq)
  xml= REXML::Document.new(runseq.xml).root
  url=''
  # get option from second element of node using '//node'
  xml.each_element('//node') do |n|
    if n.attributes['TEXT']
      text = n.attributes['TEXT']
      url= text if text =~ /^#{opt}:\s*/
    end
  end
  return nil if url.blank?
  c, h= url.split(':', 2)
  opt= h ? h.strip : false
end

#get_option_xml(opt, xml) ⇒ Object

return nil or value of opt: if provided



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/jinda/gen_helpers.rb', line 48

def get_option_xml(opt, xml)
  if xml
    url=''
    xml.each_element('node') do |n|
      text= n.attributes['TEXT']
      # check if opt match from beginning of text
      url= text if text =~/^#{opt}/
    end
    return nil if url.blank?
    c, h= url.split(':', 2)
    opt= h ? h.strip : true
  else
    return nil
  end
end

#get_user_image(user_id) ⇒ Object

search image from User in Article/View/Show



22
23
24
25
26
# File 'lib/jinda/themes.rb', line 22

def get_user_image(user_id)
  user_image = User.find(user_id).image
  user_image = ((user_image != "") ? user_image :  asset_url("user.png", :width => "48"))
  return user_image
end

#init_vars(xmain) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jinda/init_vars.rb', line 10

def init_vars(xmain)
  @xmain= Jinda::Xmain.find xmain
  @xvars= @xmain.xvars
  @runseq= @xmain.runseqs.find @xmain.current_runseq
  #    authorize?
  @xvars['current_step']= @runseq.rstep
  @xvars['referrer']= request.referrer
  session[:xmain_id]= @xmain.id
  session[:runseq_id]= @runseq.id
  unless params[:action]=='run_call'
    @runseq.start ||= Time.now
    @runseq.status= 'R' # running
    @runseq.save
  end
  $xmain= @xmain; $xvars= @xvars
  $runseq_id= @runseq.id
  $user_id= current_ma_user.try(:id)
end

#init_vars_by_runseq(runseq_id) ⇒ Object



1
2
3
4
5
6
7
8
9
# File 'lib/jinda/init_vars.rb', line 1

def init_vars_by_runseq(runseq_id)
  @runseq= Jinda::Runseq.find runseq_id
  @xmain= @runseq.xmain
  @xvars= @xmain.xvars
  #@xvars[:current_step]= @runseq.rstep
  @runseq.start ||= Time.now
  @runseq.status= 'R' # running
  @runseq.save
end


4
5
6
# File 'lib/jinda/refresh.rb', line 4

def link_to_blank(body, url_options = {}, html_options = {})
  link_to(body, url_options, html_options.merge(target: "_blank"))
end

#listed(node) ⇒ Object

Option to unlisted in the menu_mm if icon ‘button_cancel’



73
74
75
76
77
78
79
80
# File 'lib/jinda/gen_helpers.rb', line 73

def listed(node)
  icons=[]
  node.each_element("icon") do |nn|
    icons << nn.attributes["BUILTIN"]
  end

  return !icons.include?("button_cancel")
end

#login?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/jinda/gen_helpers.rb', line 33

def login?
  ## To use remember me cookies then remove
  #session[:user_id] != nil
  current_ma_user != nil
  #cookies[:auth_token] != nil
end

#m_icon(node) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/jinda/gen_helpers.rb', line 63

def m_icon(node)
  mcons=[]
  node.each_element("icon") do |mn|
    mcons << mn.attributes["BUILTIN"]
  end
  ticon = mcons[0].to_s
  return ticon
end

#ma_comment?(s) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/jinda/refresh.rb', line 50

def ma_comment?(s)
  s[0]==35
end

#ma_log(message) ⇒ Object Also known as: ma_notice



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/jinda/themes.rb', line 79

def ma_log(message)
  #  Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
  #    :unread=> true, :ip=> ($ip || request.env["REMOTE_ADDR"])
  if session[:user_id]
    Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
      :user_id => $user.id, :unread=> true, :ip=>request.env["REMOTE_ADDR"]
  else
    Jinda::Notice.create :message => ERB::Util.html_escape(message.gsub("`","'")),
      :unread=> true, :ip=>request.env["REMOTE_ADDR"]
  end
end

#ma_menu?Boolean

Returns:

  • (Boolean)


88
89
90
91
92
93
94
# File 'lib/jinda/gen_helpers.rb', line 88

def ma_menu?
  icons=[]
  node.each_element("icon") do |mn|
    icons << mn.attributes["BUILTIN"]
  end
  return icons.include?("menu")
end

#ma_secured?(node) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
# File 'lib/jinda/gen_helpers.rb', line 81

def ma_secured?(node)
  icons=[]
  node.each_element("icon") do |nn|
    icons << nn.attributes["BUILTIN"]
  end
  return icons.include?("password")
end

#make_fields(n) ⇒ Object



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
131
132
133
# File 'lib/jinda/gen_models.rb', line 99

def make_fields(n)
  # s= field string used by generate model cli (old style jinda)
  s= ""
  # h= hash :code, :type, :edit, :text
  h= []
  n.each_element('node') do |nn|
    text = nn.attributes['TEXT']
    icon = nn.elements['icon']
    edit= (icon && icon.attribute('BUILTIN').value=="edit")
    next if text.comment? && !edit

    # sometimes freemind puts all fields inside a blank node
    unless text.empty?
      k,v= text.split(/:\s*/,2)
      v ||= 'string'
      v= 'float' if v=~/double/i
      s << " #{name2code(k.strip)}:#{v.strip} "
      h << {:code=>name2code(k.strip), :type=>v.strip, :edit=>edit, :text=>text}
    else
      nn.each_element('node') do |nnn|
        icon = nnn.elements['icon']
        edit1= (icon && icon.attribute('BUILTIN').value=="edit")
        text1 = nnn.attributes['TEXT']
        next if text1 =~ /\#.*/
        k,v= text1.split(/:\s*/,2)
        v ||= 'string'
        v= 'float' if v=~/double/i
        s << " #{name2code(k.strip)}:#{v.strip} "
        h << {:code=>name2code(k.strip), :type=>v.strip, :edit=>edit1, :text=>text1}
      end
    end
  end
  # f
  h
end

#make_folders_absolute(f, tt) ⇒ Object

inspect all nodes that has attached file (2 cases) and replace relative path with absolute path



81
82
83
84
85
86
87
# File 'lib/jinda/gen_models.rb', line 81

def make_folders_absolute(f,tt)
  tt.elements.each("//node") do |nn|
    if nn.attributes['LINK']
      nn.attributes['LINK']= File.expand_path(File.dirname(f))+"/#{nn.attributes['LINK']}"
    end
  end
end

#markdown(text) ⇒ Object

methods from application_helper



94
95
96
97
98
99
100
101
102
103
# File 'lib/jinda/themes.rb', line 94

def markdown(text)
  begin
    erbified = ERB.new(text.html_safe).result(binding)
  rescue => error
    flash[:notice] = "This ruby version not support #{error}"
    return
  end
  red = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
  red.render(erbified).html_safe
end

#model_exists?(model) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/jinda/gen_models.rb', line 95

def model_exists?(model)
  File.exists? "#{Rails.root}/app/models/#{model}.rb"
end

#name2camel(s) ⇒ Object



34
35
36
# File 'lib/jinda/themes.rb', line 34

def name2camel(s)
  s.gsub(' ','_').camelcase
end

#name2code(s) ⇒ Object



29
30
31
32
33
# File 'lib/jinda/themes.rb', line 29

def name2code(s)
  # rather not ignore # symbol cause it could be comment
  code, name = s.split(':')
  code.downcase.strip.gsub(' ','_').gsub(/[^#_\/a-zA-Z0-9]/,'')
end

#negate(s) ⇒ Object



131
132
133
# File 'lib/jinda/gen_helpers.rb', line 131

def negate(s)
  return s =~ /[n|no|f|false]/i ? true : false
end

#own_xmain?Boolean

cookies != nil

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
# File 'lib/jinda/gen_helpers.rb', line 39

def own_xmain?
  if $xmain
    return current_ma_user.id==$xvars['user_id']
  else
    # if eval on first step would return true so user can start service
    return true
  end
end

#process_controllersObject



3
4
5
6
7
8
9
10
# File 'lib/jinda/gen_controller.rb', line 3

def process_controllers
  process_services
  modules= Jinda::Module.all
  modules.each do |m|
    next if controller_exists?(m.code)
    system("rails generate controller #{m.code}")
  end
end

#process_modelsObject



3
4
5
6
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
# File 'lib/jinda/gen_models.rb', line 3

def process_models

  # app= get_app
  # t= ["process models"]
  #  xml map sample from index.mm 
  #   node @CREATED=1273819432637 @ID=ID_1098419600 @MODIFIED=1334737006485 @TEXT=Jinda 
  #    node @CREATED=1273819462973 @ID=ID_282419531 @MODIFIED=1493705904561 @POSITION=right @TEXT=services 
  #     node @CREATED=1273819465949 @FOLDED=true @ID=ID_855471610 @MODIFIED=1493768913078 @POSITION=right @TEXT=roles 
  #      node @CREATED=1273819456867 @ID=ID_1677010054 @MODIFIED=1493418874718 @POSITION=left @TEXT=models 
  #       node @CREATED=1292122118499 @FOLDED=true @ID=ID_1957754752 @MODIFIED=1493705885123 @TEXT=person 
  #       node @CREATED=1292122236285 @FOLDED=true @ID=ID_959987887 @MODIFIED=1493768919147 @TEXT=address 
  #       node @CREATED=1493418879485 @ID=ID_1995497233 @MODIFIED=1493718770637 @TEXT=article 
  #       node @CREATED=1493418915637 @ID=ID_429078131 @MODIFIED=1493418930081 @TEXT=comment 

  models= @app.elements["//node[@TEXT='models']"] || REXML::Document.new
  models.each_element('node') do |model|
    # t << "= "+model.attributes["TEXT"]
    model_name= model.attributes["TEXT"]
    next if model_name.comment?
    model_code= name2code(model_name)
    model_file= "#{Rails.root}/app/models/#{model_code}.rb"

    if File.exists?(model_file)
      doc= File.read(model_file)
    else
      system("rails generate model #{model_code}")
      doc= File.read(model_file)
    end

    doc = add_utf8(doc)
    attr_hash= make_fields(model)
    doc = add_jinda(doc, attr_hash)
    # t << "modified:   #{model_file}"
    File.open(model_file, "w") do |f|
      f.puts doc
    end

  end

  # puts t.join("\n")
end

#process_servicesObject

##########################################################################

Create / Update Modules, Runseqs, Services from XML

##########################################################################



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/jinda/gen_services.rb', line 8

def process_services
  # todo: persist mm_md5
  xml= @app||get_app
  if defined? session
    md5= Digest::MD5.hexdigest(xml.to_s)
    if session[:mm_md5]
      return if session[:mm_md5]==md5
    else
      session[:mm_md5]= md5
    end
  end
  protected_services = []
  protected_modules = []
  mseq= 0
  @services= xml.elements["//node[@TEXT='services']"] || REXML::Document.new
  @services.each_element('node') do |m|
    # get icon for service menu
    ss= m.attributes["TEXT"]
    code, name= ss.split(':', 2)
    next if code.blank?
    next if code.comment?
    module_code= code.to_code
    menu_icon = m_icon(m)

    # ##########################################################################
    # First Node eg: Module Name 
    # ##########################################################################
    # create or update to GmaModule
    ma_module= Jinda::Module.find_or_create_by :code=>module_code
    ma_module.update_attributes :uid=>ma_module.id.to_s, :icon=>menu_icon
    protected_modules << ma_module.uid
    name = module_code if name.blank?
    ma_module.update_attributes :name=> name.strip, :seq=> mseq
    mseq += 1
    seq= 0

    # ##########################################################################
    # Second Nodes eg: Role, Link otherwise Services
    # ##########################################################################
    m.each_element('node') do |s|
      service_name= s.attributes["TEXT"].to_s
      scode, sname= service_name.split(':', 2)
      sname ||= scode; sname.strip!
      scode= scode.to_code
      if scode=="role"
        ma_module.update_attribute :role, sname
        next
      end
      if scode.downcase=="link"
        role= get_option_xml("role", s) || ""
        rule= get_option_xml("rule", s) || ""
        ma_service= Jinda::Service.find_or_create_by :module_code=> ma_module.code, :code=> scode, :name=> sname
        ma_service.update_attributes :xml=>s.to_s, :name=>sname,
          :list=>listed(s), :ma_secured=>ma_secured?(s),
          :module_id=>ma_module.id, :seq => seq,
          :confirm=> get_option_xml("confirm", xml),
          :role => role, :rule => rule, :uid=> ma_service.id.to_s
        seq += 1
        protected_services << ma_service.uid
      else

        # ##########################################################################
        # Second and Third Nodes eg: Role, Normal Services
        # ##########################################################################
        # normal service
        step1 = s.elements['node']
        role= get_option_xml("role", step1) || ""
        rule= get_option_xml("rule", step1) || ""
        ma_service= Jinda::Service.find_or_create_by :module_code=> ma_module.code, :code=> scode
        ma_service.update_attributes :xml=>s.to_s, :name=>sname,
          :list=>listed(s), :ma_secured=>ma_secured?(s),
          :module_id=>ma_module.id, :seq => seq,
          :confirm=> get_option_xml("confirm", xml),
          :role => role, :rule => rule, :uid=> ma_service.id.to_s
        seq += 1
        protected_services << ma_service.uid
      end
    end
  end
  Jinda::Module.not_in(:uid=>protected_modules).delete_all
  Jinda::Service.not_in(:uid=>protected_services).delete_all
end

#read_binary(path) ⇒ Object

def refresh_to

respond_to do |format|
  format.js { render :js => "refresh();" }
end

end



28
29
30
# File 'lib/jinda/refresh.rb', line 28

def read_binary(path)
  File.open path, "rb" do |f| f.read end
end

#redirect_to_rootObject



31
32
33
# File 'lib/jinda/refresh.rb', line 31

def redirect_to_root
  redirect_to root_path
end

#refresh_to(url = '/', option = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/jinda/refresh.rb', line 11

def refresh_to(url='/', option={})
  if option[:alert]
    ma_log option[:alert]
  end
  # skip # 
  # Rails 5.2 not allow to use js inline call
  render inline: "<script>window.location.replace('#{url}')</script>"
  # redirect_to url
  # render js: "window.location.replace(\'#{url}\')" 
end

#role_name(code) ⇒ Object



123
124
125
126
# File 'lib/jinda/themes.rb', line 123

def role_name(code)
  role= Jinda::Role.where(code:code).first
  return role ? role.name : ""
end

#set_globalObject



40
41
42
# File 'lib/jinda/themes.rb', line 40

def set_global
  $xmain= @xmain ; $runseq = @runseq ; $user = current_ma_user ; $xvars= @xmain.xvars; $ip = request.env["REMOTE_ADDR"]
end

#setup_gemsObject



1
2
3
4
5
6
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
131
132
# File 'lib/generators/jinda/installer/gems_install.rb', line 1

def setup_gems
	#         # define required gems: jinda_gem, jinda_dev_gem
	jinda_gem = 
		[
			["bson", "4.4.2"],
			["maruku", "~> 0.7.3"],
			["bcrypt"],
			["rouge"],
			["normalize-rails"],
			["font-awesome-rails"],
			["font-awesome-sass", "~> 5.12.0"],
			["meta-tags"],
			["jquery-turbolinks", "2.1.0"],
			["mongo", "2.11.3"],
			["turbolinks_render"],
			["haml-rails", "~> 2.0.1"],
			["haml", "~> 5.1", ">= 5.1.2"],
			["mail"],
			["prawn"],
			["redcarpet"],
			["oauth2", "1.4.4"],
			["omniauth", "1.9.1"],
			["omniauth-oauth2", "1.6.0"],
			["omniauth-identity", "~> 1.1.1"],
			["omniauth-facebook", "6.0.0"],
			["omniauth-google-oauth2", "0.8.0"],
			["dotenv-rails"],
			["cloudinary", "1.13.2"],
			["kaminari", "1.2.0"],
			["jquery-rails", "4.3.5"]
	]
	# 
	jinda_custom_gem = 
		[
			["mongoid-paperclip", require: "mongoid_paperclip"],
			["kaminari-mongoid", "1.0.1"],
			["nokogiri", "~> 1.11.0"],
			["mongoid", git: "[email protected]:kul1/mongoid-jinda.git"]
	# ["mongoid", "~> 7.1.0"]
	]
	# 
	jinda_dev_gem =
		[
			["shoulda"],
			["rspec"],
			["rspec-rails"],
			["better_errors"],
			["binding_of_caller"],
			["pry-byebug"],
			["factory_bot_rails"],
			["database_cleaner"],
			["guard"],
			["guard-rspec"],
			["guard-minitest"],
			["capybara"],
			["selenium-webdriver"],
			["rb-fsevent"],
			["valid_attribute"],
			["faker"]
	]

	# Check each jinda_gem and create new array if found one otherwise just create.
	# Open Gemfile add gem if not exist
	jinda_gem.each do |g|
		unless (%x(gem list -e --no-versions #{g[0]})) == "#{g[0]}\n"
			if g.count == 2
				gem g[0], g[1]
			else
				gem g[0]
			end
		else
			if g.count == 2
				xgem_0 = %x(gem list -e #{g[0]})
				unless xgem_0.include?(("#{g[1]}").gsub(/[~> ]/, ''))
					# puts "    Found existing #{xgem_0} in Gemfile or System, Please edit Gemfile", :red
					puts "    Found existing #{xgem_0} in Gemfile or System, Please edit Gemfile"
					gem g[0], g[1]
				else  
					# puts "     Checking #{g[0]} found Ver. #{g[1]} already exist in Gemfile", :green
					puts "     Checking #{g[0]} found Ver. #{g[1]} already exist in Gemfile"
				end 
			end
			# puts "     SKIP adding #{g[0]} in Gemfile", :yellow
			puts "     SKIP adding #{g[0]} in Gemfile"
		end
	end

	# create list of gem in sub-group dev and test
	jinda_dev_new  = Array.new
	jinda_dev_gem.each do |g|
		unless (%x(gem list -e --no-versions #{g[0]})) == "#{g[0]}\n"
			jinda_dev_new << g
		else
			# puts "     #{g[0]} already exist in Gemfile", :yellow
			puts "     #{g[0]} already exist in Gemfile"
		end
	end
	unless jinda_dev_new.count == 0
		gem_group :development, :test do
			jinda_dev_new.each do |n|
				if n.count == 1
					gem n[0]
				else
					gem n[0], n[1]
				end
			end
		end
	end

	# create list of custom gem
	jinda_custom_new = Array.new
	jinda_custom_gem.each do |g|
		# unless (%x(gem list -e --no-versions #{g[0]})) == "#{g[0]}\n"
		unless File.read("Gemfile").include?("#{g[0]}, #{g[1]}")
			jinda_custom_new << g
		else
			puts "     #{g[0]} already exist in Gemfile", :yellow
			puts "     #{g[0]} already exist in Gemfile", :yellow
		end
	end
	unless jinda_custom_new.count == 0
		jinda_custom_new.each do |c|
			# puts "     Checking if #{c[0]} already exist in Gemfile", :yellow
			puts "     Checking if #{c[0]} already exist in Gemfile"
			if c.count == 1
				gem c[0]
			else
				gem c[0], c[1]
			end
		end
	end
end

#sign_in?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
# File 'lib/jinda/refresh.rb', line 61

def sign_in?
  if current_ma_user.present?
    return true
  else
    return false
  end
end

#status_icon(status) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/jinda/themes.rb', line 107

def status_icon(status)
  case status
  when 'R'
    image_tag 'user.png'
  when 'F'
    image_tag 'tick.png'
  when 'I'
    image_tag 'control_play.png'
  when 'E'
    image_tag 'logout.png'
  when 'X'
    image_tag 'cross.png'
  else
    image_tag 'cancel.png'
  end
end

#step(s, total) ⇒ Object

square text



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/jinda/themes.rb', line 136

def step(s, total) # square text
  s = (s==0)? 1: s.to_i
  total = total.to_i
  out ="<div class='step'>"
  (s-1).times {|ss| out += "<span class='steps_done'>#{(ss+1)}</span>" }
  out += %Q@<span class='step_now' >@
  out += s.to_s
  out += "</span>"
  out += %Q@@
  for i in s+1..total
    out += "<span class='steps_more'>#{i}</span>"
  end
  out += "</div>"
  out.html_safe
end

#true_action?(s) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/jinda/themes.rb', line 37

def true_action?(s)
  %w(call ws redirect invoke email).include? s
end

#ui_action?(s) ⇒ Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/jinda/themes.rb', line 163

def ui_action?(s)
  %w(form output mail pdf).include? s
end

#uncomment(s) ⇒ Object



127
128
129
# File 'lib/jinda/themes.rb', line 127

def uncomment(s)
  s.sub(/^#\s/,'')
end