diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb new file mode 100644 index 0000000..99fc2da --- /dev/null +++ b/app/controllers/clients_controller.rb @@ -0,0 +1,48 @@ +class ClientsController < ApplicationController + + def index + @clients = Client.where(user_id: current_user.id) + end + + def new + @client = Client.new + end + + def create + @client = Client.new(client_params) + @client.user_id = current_user.id + if @client.save + redirect_to clients_path + else + render :new + end + end + + def edit + @client = Client.find(params[:id]) + end + + def update + @client = Client.find(params[:id]) + @client.user_id = current_user.id + if @client.update(client_params) + redirect_to clients_path + else + render 'edit' + end + end + + def destroy + @client = Client.find(params[:id]) + @client.destroy unless @client.blank? + + redirect_to clients_path + end + + private + + def client_params + params.require(:client).permit(:name, :description) + end + +end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb new file mode 100644 index 0000000..6491792 --- /dev/null +++ b/app/controllers/notes_controller.rb @@ -0,0 +1,57 @@ +class NotesController < ApplicationController + + def index + @client = Client.where(id: params[:client_id]).first + @notes = Note.where(client_id: params[:client_id]).order(name: :asc) + end + + def show + @note = Note.where('client_id = ? AND id = ?', params[:client_id], params[:id]) + end + + def new + @note = Note.new + @client = Client.where(id: params[:client_id]).first + end + + def create + @note = Note.new(note_params) + @note.client_id = params[:client_id] + @client = Client.where(id: params[:client_id]).first + if @note.save + redirect_to notes_path(client_id: @client.id) + else + render :new + end + end + + def edit + @note = Note.find(params[:id]) + @client = Client.where(id: params[:client_id]).first + end + + def update + @note = Note.find(params[:id]) + @client = Client.where(id: params[:client_id]).first + if @note.update(note_params) + redirect_to notes_path(client_id: @client.id) + else + render 'edit' + end + end + + def destroy + @note = Note.find(params[:id]) + @client = Client.where(id: params[:client_id]).first + @note.destroy unless @note.blank? + + redirect_to notes_path(client_id: @client.id) + end + + private + + def note_params + params.require(:note).permit(:name, :content) + end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0609e40..6c3b513 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,6 +7,7 @@ module ApplicationHelper ret += create_menu_li("glyphicon glyphicon-list-alt","Faktury","/invoices","invoices") ret += create_menu_li("glyphicon glyphicon-book","Klienci","/customers","customers") ret += create_menu_li("glyphicon glyphicon-shopping-cart","Produkty","/products","products") + ret += create_menu_li("glyphicon glyphicon-book","Obsługa","/clients","clients") ret += create_menu_li("glyphicon glyphicon-cog","Ustawienia","/settings/index","settings") return raw(ret) end diff --git a/app/models/client.rb b/app/models/client.rb new file mode 100644 index 0000000..f906397 --- /dev/null +++ b/app/models/client.rb @@ -0,0 +1,3 @@ +class Client < ApplicationRecord + belongs_to :user +end diff --git a/app/models/client_file.rb b/app/models/client_file.rb new file mode 100644 index 0000000..9e424e4 --- /dev/null +++ b/app/models/client_file.rb @@ -0,0 +1,3 @@ +class ClientFile < ApplicationRecord + belongs_to :client +end diff --git a/app/models/note.rb b/app/models/note.rb new file mode 100644 index 0000000..77dd21d --- /dev/null +++ b/app/models/note.rb @@ -0,0 +1,3 @@ +class Note < ApplicationRecord + belongs_to :client +end diff --git a/app/models/platform.rb b/app/models/platform.rb new file mode 100644 index 0000000..663b820 --- /dev/null +++ b/app/models/platform.rb @@ -0,0 +1,3 @@ +class Platform < ApplicationRecord + belongs_to :client +end diff --git a/app/views/clients/_form.html.erb b/app/views/clients/_form.html.erb new file mode 100644 index 0000000..8214fc0 --- /dev/null +++ b/app/views/clients/_form.html.erb @@ -0,0 +1,23 @@ + +<%= form_for @client, html: {class: "form-horizontal"} do |f| %> +<% if @client.errors.any? %> + <%= raw errors_to_html(@client.errors) %> +<% end %> +
| Nazwa | +Opis | +Akcje | +
|---|---|---|
| <%= link_to client.name, { controller: :notes, action: :index, client_id: client.id } %> | +<%= client.description %> | ++ <%= link_to raw(' Edycja'), edit_client_path(client), class: "btn btn-primary btn-xs" %> + <%= link_to raw(' Usuń'), client_path(client), class: "btn btn-danger btn-xs", method: :delete, data: { confirm: 'Czy na pewno usunąć?' } %> + | +
| Nazwa | +Zawartość | +Akcje | +
|---|---|---|
| <%= note.name %> | +
+
+ <% short_content = truncate(note.content, length: 30, separator: ' ', omission: '...') %>
+
+
+
+ <% if note.content.length > 30 %>
+
+
+
+ <%= raw simple_format(short_content) %>
+
+
+ <% else %>
+ <%= raw simple_format(short_content) %>
+ <% end %>
+ |
+ + <%= link_to raw(' Edycja'), edit_note_path(note, client_id: @client.id), class: "btn btn-primary btn-xs" %> + <%= link_to raw(' Usuń'), note_path(note, client_id: @client.id), class: "btn btn-danger btn-xs", method: :delete, data: { confirm: 'Czy na pewno usunąć?' } %> + | +