Class: ComptaAdmin

Inherits:
View
  • Object
show all
Defined in:
lib/africompta/views/compta/admin.rb

Instance Method Summary collapse

Instance Method Details

#layoutObject



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
# File 'lib/africompta/views/compta/admin.rb', line 2

def layout
  @order = 300
  @rsync_log = '/tmp/update_africompta'

  gui_vbox do
    gui_hbox do
      show_button :merge
    end
    gui_hbox do
      show_button :update_program
    end
    gui_hbox do
      show_button :archive, :clean_up, :connect_server
    end
    gui_window :result do
      show_html :txt
      show_button :close
    end

    gui_window :get_server do
      show_str :url, width: 200
      show_str :user
      show_str :pass
      show_button :copy_from_server
    end
  end
end

#rpc_button_archive(session, data) ⇒ Object



36
37
38
# File 'lib/africompta/views/compta/admin.rb', line 36

def rpc_button_archive(session, data)
  Accounts.archive
end

#rpc_button_clean_up(session, data) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/africompta/views/compta/admin.rb', line 40

def rpc_button_clean_up(session, data)
  count_mov, bad_mov,
      count_acc, bad_acc = AccountRoot.clean
  reply(:window_show, :result) +
      reply(:update, :txt => "Movements total / bad: #{count_mov}/#{bad_mov}<br>" +
                       "Accounts total / bad: #{count_acc}/#{bad_acc}")
end

#rpc_button_close(session, data) ⇒ Object



65
66
67
# File 'lib/africompta/views/compta/admin.rb', line 65

def rpc_button_close(session, data)
  reply(:window_hide)
end

#rpc_button_connect_server(session, data) ⇒ Object



48
49
50
51
52
# File 'lib/africompta/views/compta/admin.rb', line 48

def rpc_button_connect_server(session, data)
  reply(:window_show, :get_server) +
      reply(:update, url: 'http://localhost:3303/acaccess',
            user: 'other', pass: 'other')
end

#rpc_button_copy_from_server(session, data) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/africompta/views/compta/admin.rb', line 54

def rpc_button_copy_from_server(session, data)
  remote = Remotes.get_db(data._url, data._user, data._pass)
  reply(:window_hide) +
      reply(:window_show, :result) +
      if remote.class == Remote
        reply(:update, txt: 'Copying was successful.')
      else
        reply(:update, txt: "Error while copying:\n#{remote}")
      end
end

#rpc_button_merge(session, data) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/africompta/views/compta/admin.rb', line 69

def rpc_button_merge(session, data)
  @merge = Thread.new do
    System.rescue_all do
      (@remote = Remotes.search_all_.first).do_merge
    end
  end
  session.s_data._compta_admin = :merge
  reply(:window_show, :result) +
      reply(:update, txt: 'Starting merge') +
      reply(:auto_update, -1)
end

#rpc_button_update_program(session, data) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/africompta/views/compta/admin.rb', line 116

def rpc_button_update_program(session, data)
  session.s_data._compta_admin = :update_program
  remote_path = 'profeda.org::africompta-mac'
  if System.run_str('pwd') =~ /AfriCompta\.app/
    log_msg :update_africompta, 'Updating real app'
    bwlimit = ''
    local_path = '../../../..'
  else
    log_msg :update_africompta, 'Simulating update in /tmp'
    bwlimit = '--bwlimit=10k'
    local_path = '/tmp'
  end
  ac_cmd = "rsync -az --delete --info=progress2 #{bwlimit} #{remote_path} #{local_path}"
  session.s_data._update_program = spawn(ac_cmd, :out => @rsync_log)

  reply(:window_show, :result) +
      reply(:update, txt: 'Starting update') +
      reply(:auto_update, -1)
end

#rpc_update_view(session) ⇒ Object



30
31
32
33
34
# File 'lib/africompta/views/compta/admin.rb', line 30

def rpc_update_view(session)
  super(session) +
      reply_visible(ConfigBase.has_function?(:accounting_standalone),
                    [:connect_server, :update_program])
end

#rpc_update_with_values(session, data) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/africompta/views/compta/admin.rb', line 81

def rpc_update_with_values(session, data)
  case session.s_data._compta_admin
    when :merge
      stat_str = %w(got_accounts put_accounts got_movements put_movements
              put_movements_changes).collect { |v| "#{v}: #{@remote.send(v)}" }.
          join('<br>')
      ret = @remote.step =~ /^done/ ? reply(:auto_update, 0) : []
      ret + reply(:update, txt: "Merge-step: #{@remote.step}<br>" + stat_str)
    when :update_program
      stat = IO.read(@rsync_log).split("\r")
      if Process.waitpid(session.s_data._update_program, Process::WNOHANG)
        session.s_data._update_program = nil
        reply(:update, txt: 'Update finished<br>eventual non-100% total is normal<br>' +
                         stat.last(2).join('<br>')) +
            reply(:auto_update, 0)
      else
        reply(:update, txt: 'Updating<br>' + stat.last.to_s)
      end
    else
      dputs(0) { "Updating with #{data.inspect} and #{session.inspect}" }
  end
end