mindapp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,40 +1,160 @@
1
1
  # Mindapp
2
2
 
3
- gem to generate ror app from mind map
3
+ I like to develop application using Ruby on Rails. I find that most of my projects has some common tasks such as basic design, user administration, logging, workflow, etc. So I decide to use mind map to act as a language to explain what I want and have the tool generates the application that conform to standard framework so I can then customize everything later on. Mind map is used in design phase where it generates models and controller, in execution phase where it controls the work flow, and also use to generate documentation. System Analyst could use mind map to communicate with technical team to align their requirements and help in development.
4
4
 
5
- ## Warning
5
+ ## Prerequisites
6
6
 
7
- * under heavy development, not ready yet
7
+ * Ruby 1.9
8
+ * Rails 3.2
9
+ * MongoDB
10
+ * Freemind 0.9
8
11
 
9
12
  ## Convention
10
13
 
11
14
  * database is MongoDB
12
- * images stored in or Cloudinary (default) unset IMAGE_LOCATION in initializer/mindapp.rb to use file system
13
- * mail use Gmail SMTP
15
+ * images stored in or Cloudinary by default, set IMAGE_LOCATION in `initializer/mindapp.rb` to use file system
16
+ * mail use Gmail SMTP, set up credential in `config/application.rb`
14
17
  * authentication use omniauth-identity
18
+ * use Rspec for test
15
19
 
16
20
  ## Installation
17
21
 
22
+ Create Rails app without ActiveRecord
23
+
24
+ $ rails new app --skip-test-unit --skip-bundle --skip-active-record
25
+
18
26
  Add this line to your application's Gemfile:
19
27
 
20
28
  gem 'mindapp'
21
29
 
22
- And then execute:
30
+ you may also need to enable gem `therubyracer` as well, then execute:
23
31
 
24
32
  $ bundle
25
33
 
26
- Then generate and seed, which will create initial user admin:secret
34
+ Then generate and seed (you will be asked to overwrite `db/seeds.rb`) , which will create initial user admin:secret
27
35
 
28
36
  $ rails generate mindapp:install
37
+ $ bundle
29
38
  $ rake db:seed
30
39
 
31
- Your app is now ready at http://localhost:3000/. When make changes to app/mindapp/index.mm, run
40
+ Your app is now ready at http://localhost:3000/.
41
+
42
+ $ rails server
43
+
44
+ When make changes to app/mindapp/index.mm, run
32
45
 
33
46
  $ rake mindapp:update
34
47
 
35
- ## Usage
48
+ ## Sample Application
49
+
50
+ Supposed we want to create ecommerce web site
51
+
52
+ $ rails new shop --skip-test-unit --skip-bundle --skip-active-record
53
+
54
+ edit Gemfile:
55
+
56
+ gem 'mindapp', :git => "git://github.com/songrit/mindapp.git"
57
+
58
+ depend on your operating system, you may need to uncomment
59
+
60
+ gem 'therubyracer', :platforms => :ruby
61
+
62
+ install gems
63
+
64
+ $ bundle
65
+
66
+ generate mindapp application
67
+
68
+ $ rails generate mindapp:install
69
+
70
+ it will ask to overwrite the seeds.rb file, enter y, then run bundle again to install additional gems added by mindapp
71
+
72
+ The next step is create admin user
73
+
74
+ $ rake db:seed
75
+
76
+ now the application is ready, start it as any Rails application
77
+
78
+ $ rails server
79
+
80
+ go to http://localhost:3000, click *Sign In* on the left menu, and enter user name `admin` and password `secret`
81
+
82
+ ![home.mm](http://songrit.googlecode.com/files/home.png)
83
+
84
+ Now open file `app/mindapp/index.mm` using Freemind
85
+
86
+ ![index.mm](http://songrit.googlecode.com/files/mm.png)
87
+
88
+ The 3 main branches are
89
+
90
+ * models - this defines all the models to use in the application
91
+ * services - this defines services which will be come the menu on the left of the screen. There will be 2 levels; the first sub branch is the main menu (modules) and the second sub branch is the sub menu (services)
92
+ * roles - this defines role for all users
93
+
94
+ ### models
95
+
96
+ Fiirst, we need to create some product so we click on models we'll see 2 models person and address. These are sample only. You can delete them or modify them however you want. We'll take a look at them first
97
+
98
+ ![models](http://songrit.googlecode.com/files/models.png)
99
+
100
+ The first sub branch (e.g. person) is the model name. According to Rails convention, this should be a singular word. The next sub branch are columns in the database. Let's take a look at each:
101
+
102
+ * `fname` - this create a column (field) called fname which is a String by default
103
+ * `sex: integer` - this create a column called sex, it is integer so must be explicity defined. The next sub branch (1: male) is disregarded by Mindapp so we can put whatever we want. Here I just put some reminder.
104
+ * `belongs_to :address` - here we have ![edit](http://songrit.googlecode.com/files/edit.png) icon. this means whatever text on this line will be added as is to the model Mindapp generates. You use this to specify anything you want such as association, index, remarks in code, etc. according to mongoid gem. To draw the icon, rest mouse on the branch and hit <Alt-I>
105
+ * `dob: date` - use any type that mongoid has
106
+ * `photo` - for file field, just use String here. Mindapp will receive the binary file and store in file system or cloudinary then generate a url link to it.
107
+
108
+ In this example we just want a product model, so delete the person and address model and add a product branch like so
109
+
110
+ ![product](http://songrit.googlecode.com/files/product.png)
111
+
112
+ Save the mind map then run:
113
+
114
+ rake mindapp:update
115
+
116
+ This will create file `app/models/product.rb`. In this file, note the comment lines `# mindapp begin` and ` # mindapp end`. Everything inside these comments will get overwritten according to the mind map so if you need to put anything inside here, use the mind map instead. You can add any thing outside these comment lines which will be preserved when doing mindapp:update.
117
+
118
+ ### services
119
+
120
+ Next we'll add some product into the database, we'll first take a look at the services branch, which already has 3 sub branches; users, admins, and devs. Unlike models person and address, these branches are used by the system so I suggest that you don't delete them. Let's open the users branch
121
+
122
+ ![users](http://songrit.googlecode.com/files/users.png)
123
+
124
+ The text `users:User` on the sub branch has these implications:
125
+
126
+ * `users` correspond to `app/controllers/users_controller.rb` which already exist when you do rails generate mindapp:install. New branch will create new controller if not exist. In Mindapp term, this will be called module.
127
+ * `User` will create entry in main menu on the left of the screen
128
+
129
+ The next sub branch has the following:
130
+
131
+ * `role: m` - means that this whole module (menu) is available only to user who has role m (if you open the role branch now will see that role m is member). All registered user has role m by default. User who is not log on would not be able to access this module.
132
+ * `link:info: /users` - means that this is a link, the format is link: *submenu label* : *url* where submenu label is the text to show in the submenu and url is the link to go to, in this case, it woud go to http://localhost:3000/users which will perform action index of users_controller.
133
+ * `user:edit` the branch that do not start with role:, rule:, nor link: will be a Mindapp service. You will then specify the sequence of the execution as in this example there are 3 sub branches - enter_user, update_user, and rule:login? Let's take a look at them:
134
+
135
+ * `enter_user:edit` - the first step is to display a form to input user information, this is accompanied by icon ![attach](http://songrit.googlecode.com/files/attach.png) which means user interface screen. and will correspond to a view file `app/views/users/user/enter_user.html.erb` where `/users` comes from the module name (the sub branch of services), `/user` comes from the service name (the sub branch of users), and `enter_user.html.erb` comes from the first part of this branch. The `edit` after the colon is just a description of this step. This branch also has sub branch `rule:login? && own_xmain?` which specify rule for this step that the user must be login and can continue this task if he is the one who started it. *task* in here means each instance of service.
136
+ * `update_user` - this icon ![bookmark](http://songrit.googlecode.com/files/bookmark.png) means to execute method update_user within `users_controller.rb`
137
+
138
+ Armed with this knowledge, we are ready to add new product into our application like so:
139
+
140
+ ![products](http://songrit.googlecode.com/files/products.png)
141
+
142
+ To generate controller and views we save this mind map and run
143
+
144
+ rake mindapp:update
145
+
146
+ open file `app/views/products/add/enter.html.erb` you'll see some sample view already in there but commented. edit the file so it look like this
147
+
148
+ ![enter](http://songrit.googlecode.com/files/enter.png)
149
+
150
+ Note that we do not specify form_tag and submit_tag, these will be supplied by Mindapp.
151
+
152
+ then open file `app/controllers/products_controller.rb` and edit to be as follow
153
+
154
+ ![products_controller](http://songrit.googlecode.com/files/products_controller.png)
155
+
36
156
 
37
- TODO: Write usage instructions here
157
+ ... to be continued ...
38
158
 
39
159
  ## Contributing
40
160
 
@@ -79,8 +79,8 @@ DEFAULT_TITLE = 'Mindapp'
79
79
  DEFAULT_HEADER = 'Mindapp'
80
80
  GMAP = true
81
81
  NEXT = "Next >"
82
- # unset IMAGE_LOCATION to use cloudinary
83
- # IMAGE_LOCATION = "upload"
82
+ # comment IMAGE_LOCATION to use cloudinary
83
+ IMAGE_LOCATION = "upload"
84
84
  # for debugging
85
85
  # DONT_SEND_MAIL = true
86
86
  }
@@ -127,8 +127,9 @@ end
127
127
  def gen_user
128
128
  copy_file "seeds.rb","db/seeds.rb"
129
129
  end
130
- def gen_sample_cloudinary
130
+ def gen_image_store
131
131
  copy_file "cloudinary.yml","config/cloudinary.yml"
132
+ empty_directory "upload" # create upload directory just in case
132
133
  end
133
134
  end
134
135
  end
@@ -9,6 +9,7 @@ class MindappController < ApplicationController
9
9
  @xmains = Mindapp::Xmain.in(status:['E']).desc(:created_at).page(params[:page]).per(10)
10
10
  end
11
11
  def pending
12
+ @title= "Pending Tasks"
12
13
  @xmains = Mindapp::Xmain.in(status:['R','I']).asc(:created_at)
13
14
  end
14
15
  def cancel
@@ -255,8 +256,8 @@ class MindappController < ApplicationController
255
256
  :display=>true,
256
257
  :secured => @xmain.service.secured )
257
258
  if defined?(IMAGE_LOCATION)
258
- file_name = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
259
- File.open(file_name,"wb") { |f| f.puts(params.read) }
259
+ filename = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
260
+ File.open(filename,"wb") { |f| f.puts(params.read) }
260
261
  eval "@xvars[@runseq.code][key] = '#{url_for(:action=>'document', :id=>doc.id, :only_path => true )}' "
261
262
  doc.update_attributes :url => filename, :basename => File.basename(filename), :cloudinary => false
262
263
  else
@@ -276,8 +277,8 @@ class MindappController < ApplicationController
276
277
  :data_text=> '',
277
278
  :display=>true, :secured => @xmain.service.secured )
278
279
  if defined?(IMAGE_LOCATION)
279
- file_name = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
280
- File.open(file_name,"wb") { |f| f.puts(params.read) }
280
+ filename = "#{IMAGE_LOCATION}/f#{Param.gen(:asset_id)}"
281
+ File.open(filename,"wb") { |f| f.puts(params.read) }
281
282
  eval "@xvars[@runseq.code][key][key1] = '#{url_for(:action=>'document', :id=>doc.id, :only_path => true)}' "
282
283
  doc.update_attributes :url => filename, :basename => File.basename(filename), :cloudinary => false
283
284
  else
@@ -289,6 +290,7 @@ class MindappController < ApplicationController
289
290
  def doc_print
290
291
  render :file=>'public/doc.html', :layout=>'layouts/print'
291
292
  end
293
+ # generate documentation for application
292
294
  def doc
293
295
  require 'rdoc'
294
296
  @app= get_app
@@ -316,6 +318,22 @@ class MindappController < ApplicationController
316
318
  }
317
319
  end
318
320
  end
321
+ # handle uploaded image
322
+ def document
323
+ doc = Mindapp::Doc.find params[:id]
324
+ if doc.cloudinary
325
+ require 'net/http'
326
+ require "uri"
327
+ uri = URI.parse(doc.url)
328
+ data = Net::HTTP.get_response(uri)
329
+ # require 'open-uri'
330
+ # data= open(doc.url)
331
+ send_data(data.body, :filename=>doc.filename, :type=>doc.content_type, :disposition=>"inline")
332
+ else
333
+ data= read_binary(doc.url)
334
+ send_data(data, :filename=>doc.filename, :type=>doc.content_type, :disposition=>"inline")
335
+ end
336
+ end
319
337
  def status
320
338
  @xmain= Mindapp::Xmain.where(:xid=>params[:xid]).first
321
339
  @title= "Task number #{params[:xid]} #{@xmain.name}"
@@ -466,4 +484,7 @@ class MindappController < ApplicationController
466
484
  @xmains = GmaXmain.find(@docs.map(&:ma_xmain_id)).sort { |a,b| b.id<=>a.id }
467
485
  # @xmains = GmaXmain.find @docs.map(&:created_at).sort { |a,b| b<=>a }
468
486
  end
487
+ def read_binary(path)
488
+ File.open path, "rb" do |f| f.read end
489
+ end
469
490
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  class SessionsController < ApplicationController
3
3
  def new
4
- @title= 'เข้าใช้ระบบ'
4
+ @title= 'Sign In'
5
5
  end
6
6
 
7
7
  # to refresh the page, must know BEFOREHAND that the action needs refresh
@@ -1,8 +1,8 @@
1
1
  <map version="0.9.0">
2
2
  <!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->
3
3
  <node CREATED="1273819432637" ID="ID_1098419600" MODIFIED="1334737006485" TEXT="Mindapp">
4
- <node CREATED="1273819462973" ID="ID_282419531" MODIFIED="1334737064016" POSITION="right" TEXT="services">
5
- <node CREATED="1275756501221" FOLDED="true" ID="ID_1720745721" MODIFIED="1359019893815" TEXT="users:user">
4
+ <node CREATED="1273819462973" ID="ID_282419531" MODIFIED="1360214980377" POSITION="right" TEXT="services">
5
+ <node CREATED="1275756501221" ID="ID_1720745721" MODIFIED="1360217830024" TEXT="users:User">
6
6
  <node CREATED="1278491598711" ID="ID_1662699954" MODIFIED="1278491602025" TEXT="role:m"/>
7
7
  <node CREATED="1279700865182" ID="ID_1266797279" MODIFIED="1357798847781" TEXT="link:info: /users"/>
8
8
  <node CREATED="1319015338880" ID="ID_189841353" MODIFIED="1330477824203" TEXT="link:pending tasks: /mindapp/pending"/>
@@ -14,7 +14,6 @@
14
14
  <node CREATED="1275756530989" ID="ID_1221806432" MODIFIED="1282822205361" TEXT="update_user">
15
15
  <icon BUILTIN="bookmark"/>
16
16
  </node>
17
- <node CREATED="1276062721100" ID="ID_982357600" MODIFIED="1276062727685" TEXT="rule: login?"/>
18
17
  </node>
19
18
  <node CREATED="1275756504750" ID="ID_1382277695" MODIFIED="1355422424108" TEXT="pwd:change password">
20
19
  <node CREATED="1275756515843" ID="ID_1559014937" MODIFIED="1330477842311" TEXT="enter: edit">
@@ -24,10 +23,9 @@
24
23
  <node CREATED="1275756530989" ID="ID_1566171053" MODIFIED="1275756553762" TEXT="change_password">
25
24
  <icon BUILTIN="bookmark"/>
26
25
  </node>
27
- <node CREATED="1276062721100" ID="ID_1806588076" MODIFIED="1276062727685" TEXT="rule: login?"/>
28
26
  </node>
29
27
  </node>
30
- <node CREATED="1275752678377" FOLDED="true" ID="ID_1348489452" MODIFIED="1359019899148" TEXT="admins:admin">
28
+ <node CREATED="1275752678377" ID="ID_1348489452" MODIFIED="1360217844599" TEXT="admins:Admin">
31
29
  <node CREATED="1275752688167" ID="ID_229996461" MODIFIED="1275752690948" TEXT="role:a"/>
32
30
  <node CREATED="1282722836614" ID="ID_1213363124" MODIFIED="1330477902602" TEXT="edit_role:edit user role">
33
31
  <node CREATED="1282722862918" ID="ID_1190117882" MODIFIED="1330477922159" TEXT="select_user:select user">
@@ -45,17 +43,17 @@
45
43
  <node CREATED="1273913393454" ID="ID_1088166839" MODIFIED="1355422465435" TEXT="link: pending tasks: /mindapp/pending"/>
46
44
  <node CREATED="1275790679363" ID="ID_829325467" MODIFIED="1355422470135" TEXT="link: logs: /mindapp/logs"/>
47
45
  </node>
48
- <node CREATED="1273706796854" ID="ID_1003882979" MODIFIED="1359019900806" TEXT="devs: developer">
46
+ <node CREATED="1273706796854" ID="ID_1003882979" MODIFIED="1360214993008" TEXT="devs: Developer">
49
47
  <node CREATED="1275373154914" ID="ID_340725299" MODIFIED="1275373158632" TEXT="role:d"/>
50
48
  <node CREATED="1275788317299" ID="ID_716276608" MODIFIED="1359019912446" TEXT="link: error_logs: /mindapp/error_logs"/>
51
49
  </node>
52
50
  </node>
53
- <node CREATED="1273819465949" ID="ID_855471610" MODIFIED="1355422517520" POSITION="right" TEXT="roles">
51
+ <node CREATED="1273819465949" FOLDED="true" ID="ID_855471610" MODIFIED="1360164683130" POSITION="right" TEXT="roles">
54
52
  <node CREATED="1273819847470" ID="ID_1681080231" MODIFIED="1330477307826" TEXT="m: member"/>
55
53
  <node CREATED="1273819855875" ID="ID_1429503284" MODIFIED="1330477311102" TEXT="a: admin"/>
56
54
  <node CREATED="1273819859775" ID="ID_568365839" MODIFIED="1330477315009" TEXT="d: developer"/>
57
55
  </node>
58
- <node CREATED="1273819456867" ID="ID_1677010054" MODIFIED="1334737066801" POSITION="left" TEXT="models">
56
+ <node CREATED="1273819456867" FOLDED="true" ID="ID_1677010054" MODIFIED="1360164679975" POSITION="left" TEXT="models">
59
57
  <node CREATED="1292122118499" FOLDED="true" ID="ID_1957754752" MODIFIED="1355422535015" TEXT="person">
60
58
  <node CREATED="1292122135809" ID="ID_1617970069" MODIFIED="1332878659106" TEXT="fname"/>
61
59
  <node CREATED="1292122150362" ID="ID_1200135538" MODIFIED="1332878662388" TEXT="lname"/>
@@ -1,4 +1,3 @@
1
- - @title= "Pending Jobs"
2
1
  - @xmains= xmains
3
2
  %table{:id=>"pending-table", :width=>"100%"}
4
3
  %tr{:style=>"color:white; background-color:#97BF60;"}
@@ -4,7 +4,7 @@
4
4
  %h2 Requirements
5
5
  %ul
6
6
  %li Rails 3.2
7
- %li Rubygems 1.8.7
7
+ %li Rubygems 1.8
8
8
 
9
9
  %h2 Installation
10
10
  %ul
@@ -0,0 +1,9 @@
1
+ development:
2
+ cloud_name: "sample"
3
+ api_key: "874837483274837"
4
+ api_secret: "a676b67565c6767a6767d6767f676fe1"
5
+
6
+ production:
7
+ cloud_name: "sample"
8
+ api_key: "874837483274837"
9
+ api_secret: "a676b67565c6767a6767d6767f676fe1"
@@ -1,4 +1,4 @@
1
- if Identity.count==0
1
+ unless Identity.where(code:"admin").exists?
2
2
  identity= Identity.create :code => "admin", :email => "admin@test.com", :password => "secret",
3
3
  :password_confirmation => "secret"
4
4
  User.create :provider => "identity", :uid => identity.id.to_s, :code => identity.code,
@@ -1,3 +1,3 @@
1
1
  module Mindapp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-24 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: generate Ruby on Rails app from mind map
15
15
  email:
@@ -222,6 +222,7 @@ files:
222
222
  - lib/generators/mindapp/templates/app/views/users/index.haml
223
223
  - lib/generators/mindapp/templates/app/views/users/pwd/enter.html.erb
224
224
  - lib/generators/mindapp/templates/app/views/users/user/enter_user.html.erb
225
+ - lib/generators/mindapp/templates/cloudinary.yml
225
226
  - lib/generators/mindapp/templates/mindapp.yml
226
227
  - lib/generators/mindapp/templates/seeds.rb
227
228
  - lib/generators/mindapp/templates/spec/controllers/admins_controller_spec.rb