Refactor supplier settings

This commit is contained in:
2014-07-16 17:41:43 +02:00
parent a302123c6b
commit 2fec0b3bb6
31 changed files with 311 additions and 49 deletions
+2
View File
@@ -1,2 +1,4 @@
--color --format Fuubar --color --format Fuubar
--format html
--out coverage/rspec_results.html
-r turnip/rspec -r turnip/rspec
+1 -1
View File
@@ -65,7 +65,7 @@ gem 'rqrcode'
gem 'mini_magick' gem 'mini_magick'
#gem 'geokit' #gem 'geokit'
#gem 'iso_country_codes' gem 'iso_country_codes'
#gem "less-rails-bootstrap-devise", :git => 'git://github.com/bigbento/less-rails-bootstrap-devise.git' #gem "less-rails-bootstrap-devise", :git => 'git://github.com/bigbento/less-rails-bootstrap-devise.git'
# To use ActiveModel has_secure_password # To use ActiveModel has_secure_password
+2
View File
@@ -221,6 +221,7 @@ GEM
hike (1.2.3) hike (1.2.3)
http_parser.rb (0.6.0) http_parser.rb (0.6.0)
i18n (0.6.11) i18n (0.6.11)
iso_country_codes (0.4.3)
jquery-rails (3.1.1) jquery-rails (3.1.1)
railties (>= 3.0, < 5.0) railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
@@ -435,6 +436,7 @@ DEPENDENCIES
font-awesome-rails font-awesome-rails
foundation-rails foundation-rails
fuubar fuubar
iso_country_codes
jquery-rails jquery-rails
jquery-ui-rails jquery-ui-rails
js-routes js-routes
@@ -1,4 +1,15 @@
Qsupplier.App.ApplicationController = Ember.Controller.extend Qsupplier.App.ApplicationController = Ember.Controller.extend
init: -> init: ->
#@set 'supplier', @store.createRecord('supplier', name: 'kkkl') #success = (supplier)=>
@set 'supplier', @store.find('supplier', 'current') ## A supplier record with id current and with the content of the returned supplier is created
## at the moment remove the dummy supplier, this should be resolved by Ember eventually
#if error_supplier = @store.all('supplier').findBy('id', 'current')
#error_supplier.eraseRecord()
#@set 'supplier', supplier
#error = (emberError)=>
#if error_supplier = @store.all('supplier').findBy('id', 'current')
#error_supplier.eraseRecord()
#@set 'supplier', null
#@store.find('supplier', 'current').then success, error
@set 'supplier', @store.find('supplier', supplier_id)
@@ -0,0 +1,9 @@
Qsupplier.App.SettingsController = Ember.ObjectController.extend
needs: ['application']
model: (-> @get('controllers.application.supplier')).property('controllers.application.supplier')
time_zones: (-> window.time_zones ).property()
countries: (-> window.countries ).property()
editIensProfile: (-> @get('model.country') is 'Netherlands' ).property('model.country')
actions:
saveSettings: ->
@get('model').save()
@@ -1,3 +1,15 @@
attr = DS.attr attr = DS.attr
Qsupplier.App.Supplier = DS.Model.extend Qsupplier.App.Supplier = DS.Model.extend
name: attr 'string' name: attr 'string'
email: attr 'string'
time_zone: attr 'string'
address: attr 'string'
house_number: attr 'number'
house_number_addition: attr 'string'
postal_code: attr 'string'
city: attr 'string'
country: attr 'string'
facebook_promotion_url: attr 'string'
iens_profile: attr 'string'
lat: attr 'number'
lng: attr 'number'
@@ -1,6 +1,9 @@
DS.Model.reopen DS.Model.reopen
created_at: DS.attr('date') created_at: DS.attr('date')
updated_at: DS.attr('date') updated_at: DS.attr('date')
eraseRecord: ->
@clearRelationships()
@transitionTo('deleted.saved')
DS.Model.reopenClass DS.Model.reopenClass
findCached: (id)-> findCached: (id)->
return null unless id return null unless id
@@ -10,4 +10,5 @@ Qsupplier.App.Router.map ->
@resource 'section', path: ':section_id' @resource 'section', path: ':section_id'
@resource 'lists', -> @resource 'lists', ->
@resource 'list', path: ':list_id' @resource 'list', path: ':list_id'
@route 'settings'
#@resource 'lists', queryParams: ['state'] #@resource 'lists', queryParams: ['state']
@@ -0,0 +1,7 @@
Qsupplier.App.SettingsRoute = Ember.Route.extend
model: ->
Em.RSVP.hash
supplier: @controllerFor('application').get('supplier')
setupController: (controller, model)->
#controller.set 'model', controller.get('controllers.application.supplier')
controller.set 'model', model.supplier
@@ -0,0 +1,40 @@
h2 These are Ember settings
.form-row
.form-label: label=t 'attributes.supplier.name'
.form-field: Ember.TextField valueBinding="controller.model.name"
.form-row
.form-label: label=t 'attributes.supplier.email'
.form-field: Qsupplier.App.EmailField valueBinding="controller.model.email"
/input.location_picker name="location" type="text" valueBinding="location"
/.form-row
.location_picker_map
= image_tag 'supplier/settings/location-balloon.png'
/.form-row
.form-label: label=t 'attributes.supplier.time_zone'
.form-field: Ember.Select content=time_zones optionValuePath="content.name" optionLabelPath="content.formatted" valueBinding="controller.model.time_zone"
.form-row
.form-label: label=t 'attributes.supplier.address'
.form-field.full
.row
.large-8.medium-8.columns: Ember.TextField valueBinding="controller.model.address"
.large-1.show-for-large-up.columns &nbsp;
.large-2.medium-2.small-3.columns: Qsupplier.App.NumberField valueBinding="controller.model.house_number"
.large-1.medium-2.small-2.columns: Ember.TextField valueBinding="controller.model.house_number_addition"
.form-row
.form-label: label=t 'attributes.supplier.postal_code'
.form-field: Ember.TextField valueBinding="controller.model.postal_code"
.form-row
.form-label: label=t 'attributes.supplier.city'
.form-field: Ember.TextField valueBinding="controller.model.city"
.form-row
.form-label: label=t 'attributes.supplier.country'
.form-field: Ember.Select content=countries optionValuePath="content.name" optionLabelPath="content.name" valueBinding="controller.model.country"
if editIensProfile
.form-row
.form-label: label=t 'attributes.supplier.iens_profile'
.form-field
Qsupplier.App.NumberField valueBinding="controller.model.iens_profile"
= image_tag 'supplier/settings/iens-example.png'
span=t "settings.reviews.explanation"
.form-row.form-actions
button.button{action 'saveSettings'} Save settings
@@ -0,0 +1,14 @@
Qsupplier.App.ApplicationView = Ember.View.extend
didInsertElement: ->
selector_mappings =
'.top-menu-root': '/'
'.top-menu-lists': 'lists'
'.top-menu-sections': 'sections'
'.top-menu-lists': 'lists'
'.supplier-settings-link': 'settings'
for selector, route of selector_mappings
do (selector, route)=>
$(selector).click (e)=>
e.preventDefault()
@get('controller').transitionToRoute route
@@ -0,0 +1,3 @@
Qsupplier.App.EmailField = Ember.TextField.extend
type: 'email'
#attributeBindings: ['min', 'max', 'step']
@@ -0,0 +1,90 @@
Qsupplier.App.SettingsView = Ember.View.extend
templateName: 'settings'
didInsertElement: ->
return
iconBase = 'https://maps.google.com/mapfiles/kml/'
#location_input = @$('.location_picker')
#map_div = $('<div>').addClass("location_picker_map")
map_div = @$('.location_picker_map')
#location_input.before(map_div)
#this.parentNode.insertBefore(map_div, this)
#location_input.hide()
#lat = 52.07436798080633
#lng = 4.316811561584473
#if @get('controller.location') and @get('controller.location').split(',').length == 2
#values = @get('controller.location').split(',')
#lat = values[0]
#lng = values[1]
lat = @get('controller.model.lat')
lng = @get('controller.model.lng')
center = new google.maps.LatLng(lat,lng)
mapOptions =
zoom: 15
center: center
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true
zoomControlOptions:
style: google.maps.ZoomControlStyle.SMALL
mapTypeControl: false
panControl: false
scaleControl: false
streetViewControl: false
map = new google.maps.Map(map_div.get(0), mapOptions)
marker = new google.maps.Marker(
position: center
map: map
title: 'Location'
icon: '/assets/icons/maps_location.png'
)
google.maps.event.addListener(map, 'click', (point)=>
marker.setPosition(point.latLng)
#location_input.val point.latLng.lat() + ','+ point.latLng.lng()
@set 'controller.model.lat', point.latLng.lat()
@set 'controller.model.lng', point.latLng.lng()
)
search_field = $('<input type="text">')
search_field.addClass('location_picker_search')
autocomplete = new google.maps.places.Autocomplete(search_field.get(0))
autocomplete.bindTo('bounds', map)
search_field.keypress( (e) ->
if e.which == 13
e.preventDefault()
)
window.autocomplete = autocomplete
map_div.before(search_field)
infowindow = new google.maps.InfoWindow()
search_marker = new google.maps.Marker({map: map, icon: iconBase + 'shapes/placemark_circle.png'})
google.maps.event.addListener autocomplete, 'place_changed', ->
infowindow.close()
search_marker.setVisible(false)
place = autocomplete.getPlace()
return unless place.geometry
#if place.geometry.viewport
# map.fitBounds(place.geometry.viewport)
#else
map.setCenter(place.geometry.location)
map.setZoom(17)
image =
url: place.icon
size: new google.maps.Size(71, 71)
origin: new google.maps.Point(0, 0)
anchor: new google.maps.Point(17, 34)
scaledSize: new google.maps.Size(35, 35)
#search_marker.setIcon(image)
search_marker.setPosition(place.geometry.location)
search_marker.setVisible(true)
address = ''
if place.address_components
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ')
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address + '</div>')
infowindow.open(map, search_marker)
@@ -23,6 +23,8 @@ $.extend($translations.nl, <%= I18n.t('supplier', locale: :nl).to_json %>);
String.prototype.capitalize = function() { String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1); return this.charAt(0).toUpperCase() + this.slice(1);
} }
window.time_zones = <%= ActiveSupport::TimeZone.all.map{|tz| {name: tz.name, formatted: "GMT#{tz.formatted_offset} #{tz.name}"}}.to_json.html_safe %>;
window.countries = <%= IsoCountryCodes.all.map{|cc| {name: cc.name}}.to_json.html_safe %>;
var path_mapping = { var path_mapping = {
user_root: '/user', user_root: '/user',
@@ -40,7 +40,26 @@ $ ->
setupTranslations() setupTranslations()
# GOOGLE LOCATION PICKER
$('.toggle-side-menu,.side-menu').click ->
menu = $('aside.side-menu')
toggle = $('.toggle-side-menu')
if menu.is(':visible')
menu.animate left: -255, -> $(@).hide()
toggle.animate left: 0, -> $(@).removeClass('open')
else
menu.show().animate left: 0
toggle.animate left: 222 - 30, -> $(@).addClass('open')
$('[data-boolean]').each ->
$(@).addClass(if $(@).data('boolean') then 'boolean-true' else 'boolean-false')
# Hide alert boxes on click
$(document).on 'click', '.general-alerts .alert-box', -> $(@).slideUp()
$(document).on 'click', '.supplier-is-closed', -> $(@).slideUp()
# GOOGLE LOCATION PICKER
###
$("input.location_picker").each (i)-> $("input.location_picker").each (i)->
#return if typeof(google) == 'undefined' #return if typeof(google) == 'undefined'
iconBase = 'https://maps.google.com/mapfiles/kml/' iconBase = 'https://maps.google.com/mapfiles/kml/'
@@ -124,21 +143,4 @@ $ ->
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address + '</div>') infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address + '</div>')
infowindow.open(map, search_marker) infowindow.open(map, search_marker)
# end google location map # end google location map
###
$('.toggle-side-menu,.side-menu').click ->
menu = $('aside.side-menu')
toggle = $('.toggle-side-menu')
if menu.is(':visible')
menu.animate left: -255, -> $(@).hide()
toggle.animate left: 0, -> $(@).removeClass('open')
else
menu.show().animate left: 0
toggle.animate left: 222 - 30, -> $(@).addClass('open')
$('[data-boolean]').each ->
$(@).addClass(if $(@).data('boolean') then 'boolean-true' else 'boolean-false')
# Hide alert boxes on click
$(document).on 'click', '.general-alerts .alert-box', -> $(@).slideUp()
$(document).on 'click', '.supplier-is-closed', -> $(@).slideUp()
@@ -2,5 +2,5 @@ DS.Model.reopen
created_at: DS.attr('date') created_at: DS.attr('date')
updated_at: DS.attr('date') updated_at: DS.attr('date')
eraseRecord: -> eraseRecord: ->
@clearRelationships(); @clearRelationships()
@transitionTo('deleted.saved'); @transitionTo('deleted.saved')
@@ -11,3 +11,6 @@ aside.side-menu
list-style: none list-style: none
a a
color: white color: white
.supplier-close-shop
+alert($bg: $alert-color, $radius: true)
padding: 3px
@@ -8,7 +8,7 @@
@import ./qdashboard @import ./qdashboard
@import ./qdisplays @import ./qdisplays
@import ./form_actions @import ./form_actions
@import ./qforms @import ./components/*
@import ./menu_main @import ./menu_main
@import ./menu_side @import ./menu_side
@import ./qsections @import ./qsections
@@ -15,8 +15,14 @@
@media #{$large-up} @media #{$large-up}
+grid-column($columns: 3, $last-column:true) +grid-column($columns: 3, $last-column:true)
&.full &.full
@media #{$small-only}
+grid-column($columns:10, $center:true, $last-column:true)
@media #{$medium-only}
+grid-column($columns:6, $last-column:true)
@media #{$large-up} @media #{$large-up}
+grid-column($columns: 9, $last-column:true) +grid-column($columns: 9, $last-column:true)
&.form-actions
padding-top: 12px
body body
label label
&.number &.number
+37 -8
View File
@@ -12,18 +12,24 @@ class SupplierController < ApplicationController
end end
def current def current
respond_to do |format| render json: SupplierSupplierSerializer.new(current_supplier).as_json
format.json { render json: {supplier: current_supplier.as_json} }
end
end end
# POST /supplier/settings # POST /supplier/settings
def update def update
@supplier = current_supplier @supplier = current_supplier
if current_supplier.update_attributes(supplier_params) respond_to do |format|
redirect_to supplier_root_path format.html do
else if current_supplier.update_attributes(supplier_params)
render action: :edit redirect_to supplier_root_path
else
render action: :edit
end
end
format.json do
current_supplier.update_attributes(supplier_params)
render nothing: true
end
end end
end end
@@ -119,6 +125,29 @@ class SupplierController < ApplicationController
private private
def supplier_params def supplier_params
params.require(:supplier).permit(:name, :email, :open, :time_zone, :night_offset, :location, :lat, :lng, :offer_wifi, :wifi_ssid, :wifi_type, :wifi_password, :iens_profile) params.require(:supplier).permit(
:name,
:email,
:open,
:time_zone,
:night_offset,
:location,
:lat,
:lng,
:offer_wifi,
:wifi_ssid,
:wifi_type,
:wifi_password,
:iens_profile,
:address,
:house_number,
:house_number_addition,
:postal_code,
:city,
:country,
:facebook_promotion_url,
:created_at,
:updated_at
)
end end
end end
+9 -2
View File
@@ -10,10 +10,17 @@ class Supplier
property :open, type: :boolean, default: false property :open, type: :boolean, default: false
property :time_zone, default: 'UTC' property :time_zone, default: 'UTC'
property :night_offset, type: Fixnum, default: 0 # Minutes property :night_offset, type: Fixnum, default: 0 # Minutes
property :address
property :house_number
property :house_number_addition
property :postal_code
property :city
property :country, default: 'Netherlands'
property :facebook_promotion_url
#LOCATION #LOCATION
property :lat, type: Float, default: 52.08062426379751 property :lat, type: Float #, default: 52.08062426379751
property :lng, type: Float, default: 4.312562942504883 property :lng, type: Float #, default: 4.312562942504883
#WIFI #WIFI
property :offer_wifi property :offer_wifi
@@ -1,6 +1,7 @@
class SupplierSupplierSerializer < Qwaiter::Serializer class SupplierSupplierSerializer < Qwaiter::Serializer
self.root = :supplier self.root = :supplier
attributes :extended_version, :open, :name attributes :extended_version, :open, :name, :lat, :lng, :email, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
:facebook_promotion_url, :iens_profile
def extended_version def extended_version
false false
+3
View File
@@ -15,6 +15,9 @@ html lang="en"
= render 'suppliers/application/head' = render 'suppliers/application/head'
= javascript_include_tag "supplier/foundation1/application" = javascript_include_tag "supplier/foundation1/application"
= yield :head = yield :head
= javascript_include_tag "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places&language=#{I18n.locale}"
javascript:
supplier_id="#{current_supplier.id}";
body body
= render 'suppliers/application/top_menu' = render 'suppliers/application/top_menu'
+2 -2
View File
@@ -1,7 +1,7 @@
- content_for :head do - content_for :head do
= javascript_include_tag "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places&language=#{I18n.locale}" = javascript_include_tag 'supplier/app/application'
= form_for @supplier, url: supplier_update_settings_path, html: {class: 'form-horizontal'} do |f| /= form_for @supplier, url: supplier_update_settings_path, html: {class: 'form-horizontal'} do |f|
= render 'suppliers/application/error_messages', target: current_supplier = render 'suppliers/application/error_messages', target: current_supplier
.control-group class=(@supplier.errors[:name].any? ? 'error' : nil) .control-group class=(@supplier.errors[:name].any? ? 'error' : nil)
= f.label :name, class: 'control-label' = f.label :name, class: 'control-label'
@@ -5,12 +5,12 @@ header.top-menu
section.main-buttons section.main-buttons
//li= link_to t('supplier.menu.active_orders', orders: Order.model_name.human_plural), supplier_active_orders_path //li= link_to t('supplier.menu.active_orders', orders: Order.model_name.human_plural), supplier_active_orders_path
//li= link_to t('supplier.menu.active_lists', lists: List.model_name.human_plural), supplier_active_lists_path //li= link_to t('supplier.menu.active_lists', lists: List.model_name.human_plural), supplier_active_lists_path
= link_to image_tag('icons/logo-small.png'), supplier_root_path = link_to image_tag('icons/logo-small.png'), supplier_root_path, class: 'top-menu-root'
= link_to ProductCategory.model_name.human_plural, suppliers_product_categories_path, data: {t: 'models.plural.product_category'} = link_to ProductCategory.model_name.human_plural, suppliers_product_categories_path, data: {t: 'models.plural.product_category'}, class: 'top-menu-product_categories'
= link_to Product.model_name.human_plural, suppliers_products_path, data: {t: 'models.plural.product'} = link_to Product.model_name.human_plural, suppliers_products_path, data: {t: 'models.plural.product'}, class: 'top-menu-products'
= link_to Section.model_name.human_plural, suppliers_sections_path, data: {t: 'models.plural.section'} = link_to Section.model_name.human_plural, suppliers_sections_path, data: {t: 'models.plural.section'}, class: 'top-menu-sections'
= link_to Table.model_name.human_plural, suppliers_tables_path, data: {t: 'models.plural.table'} = link_to Table.model_name.human_plural, suppliers_tables_path, data: {t: 'models.plural.table'}, class: 'top-menu-tables'
= link_to List.model_name.human_plural, suppliers_lists_path, data: {t: 'models.plural.list'} = link_to List.model_name.human_plural, suppliers_lists_path, data: {t: 'models.plural.list'}, class: 'top-menu-lists'
section.extra-info section.extra-info
.supplier-info-row .supplier-info-row
.supplier-name= current_supplier.name.presence || current_supplier.email .supplier-name= current_supplier.name.presence || current_supplier.email
@@ -29,9 +29,9 @@ aside.side-menu
- if current_supplier.open? - if current_supplier.open?
li li
= form_tag supplier_mark_as_closed_path do = form_tag supplier_mark_as_closed_path do
= submit_tag t('supplier.close'), class: [:btn, 'btn-danger'], onClick: %|$(this).parents('form').submit()| = submit_tag t('supplier.close'), class: 'supplier-close-shop', onClick: %|$(this).parents('form').submit()|
li= link_to 'Settings', supplier_settings_path li= link_to 'Settings', supplier_settings_path, class: 'supplier-settings-link'
li= link_to 'Logout', destroy_supplier_session_path, method: :delete li= link_to 'Logout', destroy_supplier_session_path, method: :delete, class: 'supplier-sign-out-link'
/.navbar.navbar-fixed-top.navbar-inverse /.navbar.navbar-fixed-top.navbar-inverse
.navbar-inner .navbar-inner
.container .container
@@ -4,6 +4,9 @@ h2= t('devise.sessions.title')
= f.row :email do = f.row :email do
.form-label= f.label :email .form-label= f.label :email
.form-field= f.email_field :email .form-field= f.email_field :email
= f.row :email do
.form-label= f.label :password, class: 'control-label'
.form-field= f.password_field :password
.form-row .form-row
= f.label :remember_me do = f.label :remember_me do
= f.check_box :remember_me = f.check_box :remember_me
+1 -1
View File
@@ -86,7 +86,7 @@ en:
settings: settings:
reviews: reviews:
title: Reviews title: Reviews
explanation: Fill in your Iens id. You can find this id in the web location of your profile explanation: Fill in your Iens id. You can find this id in the web location of your page
product_category: product_category:
week_days: week_days:
abbreviation: abbreviation:
+1 -1
View File
@@ -86,7 +86,7 @@ nl:
settings: settings:
reviews: reviews:
title: Reviews title: Reviews
explanation: Vul hier je iens id in. Deze kan je halen uit de url van je iens profiel explanation: Vul hier je iens id in. Deze kan je halen uit de url van je iens pagina
product_category: product_category:
week_days: week_days:
abbreviation: abbreviation:
+2
View File
@@ -83,6 +83,8 @@ Qwaiter::Application.routes.draw do
get '/supplier/suppliers/current' => 'supplier#current' #ember get '/supplier/suppliers/current' => 'supplier#current' #ember
get '/supplier/suppliers/:id' => 'supplier#current' #ember
put '/supplier/suppliers/:id' => 'supplier#update' #ember
#match '/show_products' => 'dashboard#show_products', as: :user_products #match '/show_products' => 'dashboard#show_products', as: :user_products
# GENERAL # GENERAL
+9
View File
@@ -125,6 +125,15 @@ RSpec.configure do |config|
Capybara.session_name = :default Capybara.session_name = :default
end end
config.after :suite do
rspec_outfile = Rails.root.join('coverage/rspec_results.html')
result = File.read rspec_outfile
replacement = %|<body><div><a href="index.html" style="padding:4px 8px;background-color:#393;color:white;font-weight:bold;border:2px #050 outset">Coverage</a></div>|
result.gsub! /<body>/, replacement
File.open(rspec_outfile, 'w'){|f| f.puts result}
`open #{rspec_outfile}`
end
# If true, the base class of anonymous controllers will be inferred # If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of # automatically. This will be the default behavior in future versions of
# rspec-rails. # rspec-rails.
+1
View File
@@ -60,3 +60,4 @@ Users can disable their own help request (maak ongedaan?)
Users can disable their own bill request (maak ongedaan?) Users can disable their own bill request (maak ongedaan?)
Think about extra confirmation box for these requests Think about extra confirmation box for these requests
Supplier section 100% on ember :) Supplier section 100% on ember :)
Supplier give help for settings