Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
faf5604
Add OnlineStoreTheme
Nov 18, 2015
bf97a29
Add OnlineStoreType
Nov 18, 2015
c7fe4c1
Delete OnlineStoreType
Nov 23, 2015
b47e4c8
Add OnlineStore
Nov 23, 2015
644a9c6
Add validations
Nov 23, 2015
278c0a6
Add online stores products join table
Nov 23, 2015
8d3d13b
Add online stores menu
Nov 23, 2015
adf4286
Add routes for online stores
Nov 23, 2015
91a5d40
Override to_s
Nov 23, 2015
d03d532
Add translations
Nov 23, 2015
e05c5e8
Add online stores form partial
Nov 23, 2015
00c4d46
Add translations
Nov 23, 2015
ae6b8ef
Add edit view
Nov 23, 2015
a7b44ad
Add index view
Nov 23, 2015
a17c442
Add new view
Nov 23, 2015
5085b5b
Add online_stores to permissions fixtures
Nov 23, 2015
ea989cd
Use OnlineStore.model_name as the model name for OnlineStore's children
Nov 23, 2015
b230cb7
Add OnlineStoresController and tests
Nov 23, 2015
72c4059
Add translations
Nov 23, 2015
b805a87
Add translations
Nov 23, 2015
8506698
Override to_s method
Nov 23, 2015
91105ab
Show theme in index
Nov 23, 2015
7f43ac3
Allow changing theme
Nov 23, 2015
2e853f6
Monkey patch class to respond_to demodulize
Nov 23, 2015
e725702
Allow selecting type in form
Nov 23, 2015
b5fb05b
Add translations
Nov 23, 2015
ec911aa
Show type in index
Nov 23, 2015
edaf0e9
Add type to allowed parameters
Nov 23, 2015
a6e19e9
Use eager loading in development
Nov 23, 2015
2af88dd
Revert "Use eager loading in development"
Nov 23, 2015
f72742f
Include PupenextSingleTableInheritance
Nov 23, 2015
cdd891c
Revert "Monkey patch class to respond_to demodulize"
Nov 23, 2015
fe45a07
Use child_class_names method
Nov 23, 2015
6f26d51
Load online_stores fixtures
Nov 23, 2015
60e54cb
Post type too
Nov 23, 2015
da60bed
Add company association to online store
Nov 23, 2015
f7e98c5
Combine migrations
Nov 23, 2015
a4b69f9
Add online store association to online store theme
Nov 23, 2015
1fd9372
Add translations
Nov 23, 2015
7910f1d
Don't include blank
Nov 23, 2015
c8ebf28
Add PrestaShop
Nov 23, 2015
1fd5c67
Update schema
Nov 23, 2015
d884153
Remove unnecessary try
Nov 23, 2015
4ecdd1e
Allow adding and updating products
Nov 23, 2015
6e29039
Override to_s method
Nov 23, 2015
7c28197
Add translations
Nov 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions app/controllers/administration/online_stores_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class Administration::OnlineStoresController < AdministrationController
def index
@online_stores = OnlineStore.all
end

def show
render :edit
end

def new
@online_store = OnlineStore.new
end

def edit; end

def create
@online_store = OnlineStore.new(online_store_params)

if @online_store.save
redirect_to online_stores_url, notice: t('.success')
else
render :new
end
end

def update
if @online_store.update(online_store_params)
redirect_to online_stores_url, notice: t('.success')
else
render :edit
end
end

def destroy
@online_store.destroy

redirect_to online_stores_url, notice: t('.success')
end

private

def find_resource
@online_store = OnlineStore.find(params[:id])
end

def online_store_params
params.require(:online_store).permit(:name,
:online_store_theme_id,
{ product_ids: [] },
:type)
end
end
1 change: 1 addition & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Company < ActiveRecord::Base
has_many :customer_transports, through: :customers, source: :transports
has_many :mail_servers
has_many :incoming_mails, through: :mail_servers
has_many :online_stores

accepts_nested_attributes_for :bank_accounts, :users

Expand Down
22 changes: 22 additions & 0 deletions app/models/online_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class OnlineStore < BaseModel
include PupenextSingleTableInheritance

belongs_to :company
belongs_to :theme, foreign_key: :online_store_theme_id, class_name: 'OnlineStoreTheme'

has_and_belongs_to_many :products, join_table: :online_stores_products

validates :name, presence: true, length: { in: 1..255 }

def to_s
name
end

def self.child_class_names
[
OnlineStore::Magento,
OnlineStore::PrestaShop,
OnlineStore::Pupeshop
].index_by(&:to_s)
end
end
5 changes: 5 additions & 0 deletions app/models/online_store/magento.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class OnlineStore::Magento < OnlineStore
def self.model_name
OnlineStore.model_name
end
end
5 changes: 5 additions & 0 deletions app/models/online_store/presta_shop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class OnlineStore::PrestaShop < OnlineStore
def self.model_name
OnlineStore.model_name
end
end
5 changes: 5 additions & 0 deletions app/models/online_store/pupeshop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class OnlineStore::Pupeshop < OnlineStore
def self.model_name
OnlineStore.model_name
end
end
9 changes: 9 additions & 0 deletions app/models/online_store_theme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class OnlineStoreTheme < ActiveRecord::Base
has_many :online_stores

validates :name, presence: true, length: { in: 1..255 }

def to_s
name
end
end
6 changes: 6 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Product < BaseModel
o.has_one :cover_thumbnail, -> { where(kayttotarkoitus: :th).order(:jarjestys, :tunnus) }
end

has_and_belongs_to_many :online_stores, join_table: :online_stores_products

delegate :images, to: :attachments
delegate :thumbnails, to: :attachments

Expand Down Expand Up @@ -131,6 +133,10 @@ def contract_price?(target)
end
end

def to_s
"#{tuoteno}: #{nimitys}"
end

private

def defaults
Expand Down
22 changes: 22 additions & 0 deletions app/views/administration/online_stores/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= render 'administration/form_errors', resource: @online_store %>

<%= simple_form_for @online_store,
builder: AdminFormBuilder,
defaults: { input_html: { class: :large } },
alias_set: params[:alias_set] do |f| %>

<table width='600' class='admin-view-30'>
<%= f.input :name %>
<%= f.association :theme %>
<%= f.input :type, collection: OnlineStore.child_class_names.keys,
label_method: :demodulize,
include_blank: false %>
<%= f.association :products, collection: Product.active,
input_html: { class: %w(large chosen-select) } %>
</table>

<br>

<%= f.button :submit %>

<% end %>
11 changes: 11 additions & 0 deletions app/views/administration/online_stores/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= return_link(t('administration.online_stores.index.header'), online_stores_path) %>

<%= render 'administration/header', text: t('administration.online_stores.index.header') %>
<%= render 'form' %>

<br>

<%= button_to(t('.button_remove'),
@online_store,
data: { confirm: t('administration.online_stores.edit.confirm_remove') },
method: 'delete') %>
27 changes: 27 additions & 0 deletions app/views/administration/online_stores/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= render 'administration/header', text: t('.header') %>

<hr>

<table>
<thead>
<tr>
<th><%= OnlineStore.human_attribute_name(:name) %></th>
<th><%= OnlineStore.human_attribute_name(:theme) %></th>
<th><%= OnlineStore.human_attribute_name(:type) %></th>
</tr>
</thead>

<tbody>
<% @online_stores.each do |online_store| %>
<tr class="aktiivi">
<td><%= link_to online_store, online_store %></td>
<td><%= online_store.theme %></td>
<td><%= online_store.type.demodulize %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= button_to_new 'online_store', new_online_store_path %>
4 changes: 4 additions & 0 deletions app/views/administration/online_stores/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= return_link(t('administration.online_stores.index.header'), online_stores_path) %>

<%= render 'administration/header', text: t('administration.online_stores.index.header') %>
<%= render 'form' %>
18 changes: 18 additions & 0 deletions config/locales/fi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ fi:
smtp_password: SMPT-palvelimen salasana
smtp_server: SMPT-palvelin
smtp_username: SMPT-palvelimen käyttäjätunnus
online_store:
name: Nimi
products: Tuotteet
theme: Teema
type: Tyyppi
package:
erikoispakkaus: Erikoispakkaus
jarjestys: Järjestys
Expand Down Expand Up @@ -395,6 +400,7 @@ fi:
keyword/customer_subcategory: Asiakasryhmä
keyword/revenue_expenditure: Vaihtoehtoinen meno
mail_server: Sähköpostipalvelin
online_store: Verkkokauppa
package: Pakkaus
package_code: Pakkauskoodi
packing_area: Pakkaamo
Expand Down Expand Up @@ -570,6 +576,18 @@ fi:
header: Sähköpostipalvelimet
new:
header: Uusi sähköpostipalvelin
online_stores:
create:
success: Verkkokauppa luotiin onnistuneesti
destroy:
success: Verkkokauppa poistettiin onnistuneesti
edit:
button_remove: Poista verkkokauppa
confirm_remove: Haluatko varmasti poistaa tämän verkkokakupan?
index:
header: Verkkokaupat
update:
success: Verkkokauppa päivitettiin onnistuneesti
packages:
create:
create_success: Pakkaus lisättiin onnistuneesti
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
resources :fiscal_years, except: :destroy
resources :incoming_mails, only: :index
resources :mail_servers
resources :online_stores
resources :packages
resources :packing_areas
resources :printers
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20151118134711_create_online_store_themes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateOnlineStoreThemes < ActiveRecord::Migration
def change
create_table :online_store_themes do |t|
t.string :name

t.timestamps null: false
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20151123071517_create_online_stores.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateOnlineStores < ActiveRecord::Migration
def change
create_table :online_stores do |t|
t.string :name
t.string :type
t.references :online_store_theme, index: true, foreign_key: true
t.references :company, index: true, foreign_key: true

t.timestamps null: false
end
end
end
8 changes: 8 additions & 0 deletions db/migrate/20151123074934_create_online_stores_products.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateOnlineStoresProducts < ActiveRecord::Migration
def change
create_table :online_stores_products do |t|
t.references :online_store, index: true, foreign_key: true
t.references :product, index: true, foreign_key: true
end
end
end
18 changes: 18 additions & 0 deletions db/migrate/20151123084500_add_online_stores_menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require File.expand_path('test/permission_helper')
include PermissionHelper

class AddOnlineStoresMenu < ActiveRecord::Migration
def up
PermissionHelper.add_item(
program: 'Tuotehallinta',
name: 'Verkkokaupat',
uri: 'pupenext/online_stores'
)
end

def down
PermissionHelper.remove_all(
uri: 'pupenext/online_stores'
)
end
end
26 changes: 26 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,32 @@
add_index "oikeu", ["yhtio", "kuka", "sovellus"], name: "sovellus_index", using: :btree
add_index "oikeu", ["yhtio", "sovellus", "nimi", "alanimi"], name: "menut_index", using: :btree

create_table "online_store_themes", force: :cascade do |t|
t.string "name", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "online_stores", force: :cascade do |t|
t.string "name", limit: 255
t.string "type", limit: 255
t.integer "online_store_theme_id", limit: 4
t.integer "company_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "online_stores", ["company_id"], name: "index_online_stores_on_company_id", using: :btree
add_index "online_stores", ["online_store_theme_id"], name: "index_online_stores_on_online_store_theme_id", using: :btree

create_table "online_stores_products", force: :cascade do |t|
t.integer "online_store_id", limit: 4
t.integer "product_id", limit: 4
end

add_index "online_stores_products", ["online_store_id"], name: "index_online_stores_products_on_online_store_id", using: :btree
add_index "online_stores_products", ["product_id"], name: "index_online_stores_products_on_product_id", using: :btree

create_table "pakkaamo", primary_key: "tunnus", force: :cascade do |t|
t.string "yhtio", limit: 5, default: "", null: false
t.string "nimi", limit: 150, default: "", null: false
Expand Down
Loading