Skip to content

Commit

Permalink
allow to add/remove app in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
xixilive committed May 30, 2014
1 parent 21f1c64 commit d522004
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 157 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db/*
5 changes: 5 additions & 0 deletions controllers/apps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def self.included base
erb :app, locals: { app: @app }
end

delete '/apps/:id' do
@app.delete
redirect to('/')
end

post '/apps/:id/test' do
begin
echostr = Wechat::Utils.rand_secret
Expand Down
63 changes: 0 additions & 63 deletions db/wxh8y4bm2pwx7ujfbe.yml

This file was deleted.

91 changes: 0 additions & 91 deletions db/wxyscwsrxrjgtoqm54.yml

This file was deleted.

12 changes: 11 additions & 1 deletion models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ module Persistable
attr_reader :filename

def write
File.open(File.join(Models.store_dir, "#{filename}.yml"), 'w'){|f| f.puts self.to_yaml }
File.open(file_path, 'w'){|f| f.puts self.to_yaml }
end
alias :save :write

def delete
FileUtils.rm_rf(file_path)
end
alias :remove :delete

private
def file_path
File.join(Models.store_dir, "#{filename}.yml")
end

end
end

Expand Down
4 changes: 4 additions & 0 deletions views/app.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<% if app.url.to_s == '' %>
<p class="alert alert-danger">Needs to set url for this app!</p>
<% end %>

<div class="row">
<div class="col-sm-5">
<div class="panel panel-default">
Expand Down
22 changes: 20 additions & 2 deletions views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
<% apps.each do |app| %>
<div class="panel panel-default">
<div class="panel-heading text-center"><%= app.label %></div>
<div class="panel-body text-center">
<form class="panel-body text-center" method="post" action="/apps/<%= app.id %>">
<input type="hidden" name="_method" value="DELETE" />
<div class="btn-group">
<a class="btn btn-default" href="/apps/<%= app.id %>">Details</a>
<a class="btn btn-default" href="/apps/<%= app.id %>/test" rel="test_app">Test App</a>
<a class="btn btn-success" href="/apps/<%= app.id %>/message">Send Messages</a>
<button type="submit" class="btn btn-danger">Delete</a>
</div>
</div>
<% if app.url.to_s == '' %>
<p class="text-danger">Needs to <a href="/apps/<%= app.id %>">set url</a> for this app!</p>
<% end %>
</form>
</div>
<% end %>

<div class="panel panel-default">
<form class="panel-body text-center" method="post" action="/">
<span class="text-muted">Needs another App?</span> <button type="submit" class="btn btn-default">New App</button>
</form>
<% if apps.size > 1 %>
<form class="panel-body text-center" method="post" action="/">
<input type="hidden" name="_method" value="DELETE" />
<span class="text-muted">Want to clear all Apps?</span> <button type="submit" class="btn btn-danger">Clear all Apps</button>
</form>
<% end %>
</div>

</div>

<div class="col-sm-6">
Expand Down
10 changes: 10 additions & 0 deletions wechat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ class WechatFaker < Sinatra::Base
erb :index, locals: { apps: Wechat::Models::App.all }
end

post '/' do
Wechat::Models.setup
redirect to('/')
end

delete '/' do
Wechat::Models.purge
redirect to('/')
end

include Wechat::Controllers
end

0 comments on commit d522004

Please sign in to comment.