jinda 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/jinda/install_generator.rb +24 -10
  3. data/lib/generators/jinda/templates/app/assets/javascripts/application.js-jqm +2 -0
  4. data/lib/generators/jinda/templates/app/assets/stylesheets/{application.css → application.css.scss} +0 -0
  5. data/lib/generators/jinda/templates/app/controllers/api/v1/notes_controller.rb +81 -0
  6. data/lib/generators/jinda/templates/app/controllers/jinda_org/jinda_controller.rb +22 -0
  7. data/lib/generators/jinda/templates/app/controllers/jinda_org/notes_controller.rb +86 -0
  8. data/lib/generators/jinda/templates/app/jinda/index.mm +138 -21
  9. data/lib/generators/jinda/templates/app/mailers/note_mailer.rb +10 -0
  10. data/lib/generators/jinda/templates/app/models/note.rb +22 -0
  11. data/lib/generators/jinda/templates/app/views/api/v1/note.haml +0 -0
  12. data/lib/generators/jinda/templates/app/views/jinda/index.html.haml +1 -1
  13. data/lib/generators/jinda/templates/app/views/jinda/run_form.haml +4 -0
  14. data/lib/generators/jinda/templates/app/views/note_mailer/gmail.html.haml +7 -0
  15. data/lib/generators/jinda/templates/app/views/note_mailer/gmail.text.haml +8 -0
  16. data/lib/generators/jinda/templates/app/views/notes/delete/select_note.html.erb +14 -0
  17. data/lib/generators/jinda/templates/app/views/notes/edit/edit_note.html.erb +10 -0
  18. data/lib/generators/jinda/templates/app/views/notes/edit/select_note.html.erb +14 -0
  19. data/lib/generators/jinda/templates/app/views/notes/index.haml +71 -0
  20. data/lib/generators/jinda/templates/app/views/notes/mail/display_mail.html.erb +20 -0
  21. data/lib/generators/jinda/templates/app/views/notes/mail/select_note.html.erb +19 -0
  22. data/lib/generators/jinda/templates/app/views/notes/mail/show.html.haml +13 -0
  23. data/lib/generators/jinda/templates/app/views/notes/my.haml +21 -0
  24. data/lib/generators/jinda/templates/app/views/notes/new/new_note.html.erb +13 -0
  25. data/lib/generators/jinda/templates/app/views/notes/show.haml +10 -0
  26. data/lib/generators/jinda/templates/app/views/notes/xedit/edit_note.html.erb +10 -0
  27. data/lib/generators/jinda/templates/spec/controllers/api/v1_get_index_spec.rb +23 -0
  28. data/lib/generators/jinda/templates/spec/controllers/api/v1_get_my_spec.rb +14 -0
  29. data/lib/generators/jinda/templates/spec/controllers/api/v1_post_spec.rb +19 -0
  30. data/lib/generators/jinda/templates/spec/mailers/note_spec.rb +24 -0
  31. data/lib/generators/jinda/templates/spec/mailers/previews/note_preview.rb +9 -0
  32. data/lib/generators/jinda/templates/spec/models/note_spec.rb +41 -0
  33. data/lib/generators/jinda/templates/spec/rails_helper.rb +29 -40
  34. data/lib/generators/jinda/templates/spec/support/authentication_helper.rb +20 -0
  35. data/lib/generators/jinda/templates/spec/support/factory_bot.rb +9 -3
  36. data/lib/generators/jinda/templates/spec/support/request_spec_helper.rb +8 -0
  37. data/lib/jinda/ template/view.html.erb +0 -2
  38. data/lib/jinda/version.rb +1 -1
  39. metadata +29 -4
  40. data/lib/generators/jinda/templates/install.sh +0 -7
@@ -0,0 +1,10 @@
1
+ class NoteMailer < ActionMailer::Base
2
+ default from: "from@example.com"
3
+
4
+ def gmail(body , to="", subject="", from="")
5
+ @body = body
6
+ @title = subject
7
+ @from = from
8
+ mail(:to => to, :subject => subject, :from => from)
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ class Note
3
+ include Mongoid::Document
4
+ # jinda begin
5
+ include Mongoid::Timestamps
6
+ include Mongoid::Attributes::Dynamic
7
+ field :title, :type => String
8
+ field :body, :type => String
9
+ belongs_to :user
10
+ before_validation :ensure_title_has_a_value
11
+ validates :title, length: { maximum: (MAX_TITLE_LENGTH = 30), message: "Must be less than 30 characters" }, presence: true
12
+ validates :body, length: { maximum: (MAX_BODY_LENGTH = 1000), message: "Must be less than 1000 characters"}
13
+ private
14
+ def ensure_title_has_a_value
15
+ if title.blank?
16
+ self.title = body[0..(MAX_TITLE_LENGTH-1)] unless body.blank?
17
+ end
18
+ end
19
+
20
+
21
+ # jinda end
22
+ end
@@ -21,7 +21,7 @@
21
21
 
22
22
  %h2 Installation
23
23
  %ul
24
- %li add gem 'jinda', '0.4.4'
24
+ %li add gem 'jinda', '0.4.5'
25
25
  %li bundle
26
26
  %li rails generate jinda:install
27
27
  %li (run all with "sh install.sh" )
@@ -35,4 +35,8 @@
35
35
  $( document ).one( "pagechange", function(){
36
36
  $('input[type="file"]').textinput({theme: 'c'});
37
37
  });
38
+
39
+ function validate() {
40
+ // alert("Validate");
41
+ }
38
42
 
@@ -0,0 +1,7 @@
1
+ %h1= @title
2
+
3
+ %p
4
+ =@body
5
+
6
+ %p
7
+ =@from
@@ -0,0 +1,8 @@
1
+ %h1= @title
2
+
3
+ %p
4
+ = @body
5
+ %p
6
+ = @from
7
+
8
+
@@ -0,0 +1,14 @@
1
+
2
+ <%
3
+ if current_ma_user.role.upcase.split(',').include?("A")
4
+ note= Note.all.desc(:created_at)
5
+ else
6
+ note= Note.where(user: current_ma_user).desc(:created_at)
7
+ end
8
+ %>
9
+ <div class="field" data-role="fieldcontain">
10
+ <%= label_tag :title, 'Select Note' %>
11
+ <br>
12
+ <br>
13
+ <%= select_tag :id, options_from_collection_for_select(note, :id, :title), "notee-menu"=>"false" %>
14
+ </div>
@@ -0,0 +1,10 @@
1
+ <%- @title= 'Edit Note' %>
2
+ <%
3
+ doc = Note.find_by :id => $xvars["select_note"]["id"]
4
+ %>
5
+ <%= fields_for doc do |f| %>
6
+ <%= f.label :title, "Title" %>
7
+ <%= f.text_field :title, required: true %><Br>
8
+ <%= f.label :body, "Body Content" %>
9
+ <%= f.cktext_area :body, :cols=>50, :rows=>6 ,required: true %>
10
+ <% end %>
@@ -0,0 +1,14 @@
1
+
2
+ <%
3
+ if current_ma_user.role.upcase.split(',').include?("A")
4
+ note= Note.all.desc(:created_at)
5
+ else
6
+ note= Note.where(user: current_ma_user).desc(:created_at)
7
+ end
8
+ %>
9
+ <div class="field" data-role="fieldcontain">
10
+ <%= label_tag :title, 'Select Note' %>
11
+ <br>
12
+ <br>
13
+ <%= select_tag :id, options_from_collection_for_select(note, :id, :title), "notee-menu"=>"false" %>
14
+ </div>
@@ -0,0 +1,71 @@
1
+ .container
2
+ %div(style="text-align:center")
3
+ %h1 Notes
4
+
5
+ %h2 Notes Overview
6
+ %div(style="text-align:center")
7
+ %h3 Notes is a personel message system or platform that design in rails which can be modified to use all rails features such as files attachment, reminder, mail, social network sharing. This version support key features below.
8
+
9
+ %h2 Key features
10
+ %ul
11
+ %li Support multi-user
12
+ %li Title input maximum 30 characters
13
+ %li Body input maximum 1000 characters
14
+ %li Blank Title will use body content when save
15
+ %li Able to mail each Note
16
+ %li Support dynamic user roles for each view/controller such as admin, member, developer (A,M,D) or any assign in role table/collection
17
+ %li Full test in Key features with rspec
18
+ %li Support MVC work flow like normal rails, however this program use controller/helper feature call all controller in order to easy generate using my gem Jinda
19
+
20
+ %h2 Current gems version found:
21
+ %ul
22
+ %li Ruby Version #{RUBY_VERSION }
23
+ %li Rails Version #{Rails.version }
24
+ %li gem jinda #{Gem.loaded_specs['jinda'].version}
25
+
26
+
27
+
28
+ %h2 Recently tested with:
29
+ %ul
30
+ %li rspec
31
+ %li in localhost please run $rspec
32
+
33
+ %h2 Requirement
34
+ %ul
35
+ %li Mongodb as database
36
+
37
+ %h2 Installation
38
+ %ul
39
+ %li in localhost $git clone https://github.com/kul1/notes.git
40
+ %li install mongodb from https://docs.mongodb.com/manual/installation/
41
+ %li bundle install
42
+ %li rake jinda:seed # to add user: "admin" password: "secret"
43
+
44
+ %h2 Modification in app/jinda/index.mm (Using Freemind)
45
+ %ul
46
+ %li All models, views and controllers can be changed and result in Main menu
47
+ %li (Rails MVC still running in parallel)
48
+ %div(style="text-align:center")
49
+ = image_tag "app_schema.png"
50
+ %li Note model change as in image:
51
+ %div(style="text-align:center")
52
+ = image_tag "note_model.png"
53
+ %li then update app design in app/jinda/index.mm, by run
54
+ %li $rake jinda:update
55
+
56
+ %h2 Usage
57
+ %ul
58
+ %li Sign in: your user name with email # default role as ""
59
+ %li (can set default to "" or m (member) or any group role in index.mm using freemind)
60
+ %li Sign in as user admin password "secret" to menu Admin and change user role to any like "m" or "m,a,d" for (member, admin, group)
61
+ %li
62
+ %div(style="text-align:center")
63
+ = image_tag "edit_role.png"
64
+ %h2 What missing (in limited time)
65
+ %ul
66
+ %li css on each Note pages which required work on platform themes
67
+ %li Better features eg: able to selecte several notes for action
68
+ %li Live email in Heroku (avoid security in noth github, heroku and Gmail blocked by serveral tested)
69
+
70
+
71
+
@@ -0,0 +1,20 @@
1
+ <%
2
+ doc = Note.find_by :id => $xvars["select_note"]["id"]
3
+ %>
4
+
5
+ <% email = $xvars["select_note"]["email"] %>
6
+ <div class=field(data-role=fieldcontain)>
7
+ <label class = ui-input-text for="email">Mail to:</label>
8
+ <b>
9
+ <%= email %>
10
+ </b>
11
+
12
+ </div>
13
+ <div class=fieldcontain>
14
+ <%= fields_for doc do |f| %>
15
+ <%= f.label :title, "Subject" %>
16
+ <%= f.text_field :title %>
17
+ <%= f.label :body, "Content" %>
18
+ <%= f.text_area :body, :cols=>50, :rows=>6 %>
19
+ <% end %>
20
+ </div>
@@ -0,0 +1,19 @@
1
+
2
+ <%
3
+ if current_ma_user.role.upcase.split(',').include?("A")
4
+ note= Note.all.desc(:created_at)
5
+ else
6
+ note= Note.where(user: current_ma_user).desc(:created_at)
7
+ end
8
+ %>
9
+ <div class="field" data-role="fieldcontain">
10
+ <%= label_tag :email %>
11
+ <br>
12
+ <br>
13
+ <%= text_field_tag :email, @identity.try(:email) %>
14
+ </div>
15
+ <div class="field" data-role="fieldcontain">
16
+ <%= label_tag :title, 'Select Note' , :class => "ui_input_text" %>
17
+ <br>
18
+ <br>
19
+ <%= select_tag :id, options_from_collection_for_select(note, :id, :title), "notee-menu"=>"false" %>
@@ -0,0 +1,13 @@
1
+ - title @note.title
2
+ - description @note.body
3
+
4
+ - @title= 'Show Note'
5
+ - doc = Note.find_by :id => $xvars["select_note"]["id"]
6
+ = fields_for doc do |f|
7
+ = f.label :title, "Title"
8
+ = f.text_field :title
9
+ %br/
10
+ = f.label :body, "Body Content"
11
+ = f.cktext_area :body, :cols=>50, :rows=>6
12
+
13
+ = link_to image_tag('pencil.png', style:'border:none; float:none;'), {controller: "jinda", action: "init", s: 'notes:xedit', note_id: @note.id}, data: { confirm: "Please Confirm" }
@@ -0,0 +1,21 @@
1
+ - @title= "My Notes"
2
+ %P
3
+ - @page_title = 'My Notes'
4
+ = paginate @notes
5
+ %table{:id=>"note-table", :data-mode => "reflow", :data-role => "table"}
6
+ %tr
7
+ %th Title
8
+ %th Body
9
+ %th Created
10
+ %th Updated
11
+ %th Delete
12
+ %th Edit
13
+ - @notes.each do |note|
14
+ %tr
15
+ %td= link_to note.title, :controller=>"notes", :action=>"show", :id=>note.id
16
+ %td= note.body
17
+ %td= note.created_at.strftime('%m/%d/%Y')
18
+ %td= note.updated_at.strftime('%m/%d/%Y')
19
+ %td(align='center')= link_to image_tag('delete.png', style:'border:none; float:none;'), "#", :onclick=>"if (confirm('Please Confirm')) {location.hash='/notes/destroy/#{note.id}';}"
20
+ %td(align='center')= link_to image_tag('pencil.png', style:'border:none; float:none;'), {controller: "jinda", action: "init", s: 'notes:xedit', note_id: note.id}, data: { confirm: "Please Confirm" }
21
+
@@ -0,0 +1,13 @@
1
+ <%- @title= 'New Note' %>
2
+ <%
3
+ doc = Note.new :issue_on=> Date.today, :process_at => Time.now
4
+ %>
5
+ <div name= "note_new">
6
+
7
+ <%= fields_for doc, validate: true do |f| %>
8
+ <%= f.label :title, "Title" %>
9
+ <%= f.text_field :title %><Br>
10
+ <%= f.label :body, "Body Content" %>
11
+ <%= f.cktext_area :body, :cols=>50, :rows=>6, required: true %>
12
+ <% end %>
13
+ </div>
@@ -0,0 +1,10 @@
1
+ - @title= 'Show Note'
2
+ - doc = Note.find_by :id => @note.id
3
+
4
+ %h3.ui-bar.ui-bar-a.ui-corner-all Title: #{@note.title}
5
+       
6
+ .ui-body.ui-body-a.ui-corner-all
7
+           
8
+ %p #{@note.body}
9
+
10
+ = link_to image_tag('pencil.png', style:'border:none; float:none;'), {controller: "jinda", action: "init", s: 'notes:xedit', note_id: @note.id}, data: { confirm: "Please Confirm" }
@@ -0,0 +1,10 @@
1
+ <%- @title= 'Edit Note' %>
2
+ <%
3
+ doc = Note.find_by :id=> $xvars["p"]["note_id"]
4
+ %>
5
+ <%= fields_for doc do |f| %>
6
+ <%= f.label :title, "Title" %>
7
+ <%= f.text_field :title %><Br>
8
+ <%= f.label :body, "Body Content" %>
9
+ <%= f.cktext_area :body, :cols=>50, :rows=>6 %>
10
+ <% end %>
@@ -0,0 +1,23 @@
1
+ require 'rails_helper'
2
+ # describe Api::V1::NotesController, '#index', type: :request do
3
+ RSpec.describe 'Notes API', type: :request do
4
+ # let(:notes) { create_list(:note,1)}
5
+ # let!(:notes) {Note.create(title: "dddd", body: "body")}
6
+ let!(:note) {FactoryBot.create_list(:note, 9)}
7
+ let(:note_id) { notes.first.id }
8
+
9
+ describe 'GET /api/v1/notes' do
10
+ before { get api_v1_notes_path }
11
+
12
+ it 'returns notes size as expected' do
13
+ expect(json).not_to be_empty
14
+ expect(json.size).to eq(9)
15
+ end
16
+
17
+ it 'returns status code 200' do
18
+ expect(response).to have_http_status(:success)
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,14 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe 'Notes API', type: :request do
4
+ let!(:note) {FactoryBot.create_list(:note, 9)}
5
+ before {get api_v1_notes_my_path}
6
+
7
+ it 'returns all notes' do
8
+ expect(json.size).to eq(9)
9
+ end
10
+ it 'returns status code 200' do
11
+ expect(response).to have_http_status(:success)
12
+ end
13
+ end
14
+
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+ describe Api::V1::NotesController , type: :controller do
3
+
4
+ before do
5
+ create_and_sign_in_user
6
+ post :create , params: { :body => 'test_body', :title => 'test_title', :user => User.first}
7
+ end
8
+
9
+ it 'returns the title' do
10
+ expect(JSON.parse(@response.body)['title']).to eq('test_title')
11
+ end
12
+ it 'returns the body' do
13
+ expect(JSON.parse(@response.body)['body']).to eq('test_body')
14
+ end
15
+
16
+ it 'returns a created status' do
17
+ expect(response).to have_http_status(:created)
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe NoteMailer do
4
+
5
+
6
+ describe 'gmail' do
7
+
8
+ let(:mail) {NoteMailer.gmail("Test Body", "receiver@email.com", "Test title", "from@example.com")}
9
+
10
+
11
+ it 'renders the subject' do
12
+ expect(mail.subject).to eql('Test title')
13
+ end
14
+
15
+ it 'renders the receiver email' do
16
+ expect(mail.to).to eql(['receiver@email.com'])
17
+ end
18
+
19
+ it 'renders the sender email' do
20
+ expect(mail.from).to eql(['from@example.com'])
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,9 @@
1
+ # Preview all emails at http://localhost:3000/rails/mailers/note
2
+ class NotePreview < ActionMailer::Preview
3
+
4
+ # Preview this email at http://localhost:3000/rails/mailers/note/gmail
5
+ def gmail
6
+ NoteMailer.gmail
7
+ end
8
+
9
+ end
@@ -0,0 +1,41 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Note, type: :model do
4
+ describe "Required only title (Maximum 30)" do
5
+
6
+ it "valid with both title and body" do
7
+ before_count = Note.count
8
+ Note.create(title: "dddd", body: "body")
9
+ expect(Note.count).not_to eq(before_count)
10
+ end
11
+
12
+ it "valid with only title" do
13
+ before_count = Note.count
14
+ Note.create(title: "Title")
15
+ expect(Note.count).not_to eq(before_count)
16
+ end
17
+
18
+ it "invalid with only body" do
19
+ before_count = Note.count
20
+ Note.new(body: "body")
21
+ expect(Note.count).to eq(before_count)
22
+ end
23
+
24
+ it "invalid body length more than 1000" do
25
+ before_count = Note.count
26
+ title_max = "x"*30
27
+ body_max = "y"*1001
28
+ Note.create(title: title_max, body: body_max)
29
+ expect(Note.count).to eq(before_count)
30
+ end
31
+ end
32
+
33
+ describe "title data blank" do
34
+ it "auto fill from body" do
35
+ note = Note.create(:title => "", :body => "Body content")
36
+ note.title.should == "Body content"
37
+ end
38
+ end
39
+
40
+ end
41
+