Last active
August 16, 2019 08:38
-
-
Save mankind/0bf01e296ff1b5447e85227938c751a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AccountSettingsController < ApplicationController | |
before_action :set_company | |
def index | |
end | |
def update | |
@company.update(set_record_params) | |
redirect_to account_settings_path | |
end | |
def edit | |
end | |
private | |
def set_company | |
@company = Company.find(1) | |
end | |
def set_record_params | |
params.require(:company).permit(settings: [:contact_email, weekly_email: []]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>AccountSettings#edit</h1> | |
<p>Find me in app/views/account_settings/edit.html.erb</p> | |
<%# form_with(model: @company, :url => account_setting_path(@company), method: "patch") do |f| %> | |
<%= form_for @company, :url => account_setting_path(@company) do |f| %> | |
<%= f.class %> | |
<%= f.fields_for :settings do |ff| %> | |
<%= ff.class %> | |
<%= ff.text_field :contact_email, :value => @company.contact_email %><br/> | |
weekly_email: | |
<%= ff.text_field :weekly_email, :name => "#{f.object_name}[settings][weekly_email][]" %> | |
<%= ff.text_field :weekly_email, :name => "#{f.object_name}[settings][weekly_email][]" %> | |
<% end %> | |
<br> | |
<%= f.submit %> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Ubiquity | |
module AccountSelfJoinAssociation | |
extend ActiveSupport::Concern | |
included do | |
before_save :get_previous_index_to_shared_search_value | |
after_commit :trigger_shared_search_rake | |
end | |
def trigger_shared_search_rake | |
if shared_search_settings_changed? && index_record_to_shared_search == 'true' | |
#Ubiquity::SharedSearchMailer.notify_changes(self, 'enabled').deliver_now | |
puts "######### shared-search changes notification sent ########" | |
puts "######## shared-search turn on for #{cname}, rake task running ########" | |
# `rake ubiquity_reindex_shared_search:update["#{cname}"]` if cname.present? | |
puts "######## finished running rake task indexing #{cname} to shared-search ########" | |
elsif shared_search_settings_changed? && index_record_to_shared_search == 'false' | |
#Ubiquity::SharedSearchMailer.notify_changes(self, 'disabled').deliver_now | |
puts "shared-search turn off" | |
end | |
end | |
def get_previous_index_to_shared_search_value | |
@old_index_record_to_shared_search = self.settings['index_record_to_shared_search'] | |
end | |
def shared_search_settings_changed? | |
value_changed = (@old_index_record_to_shared_search != index_record_to_shared_search) | |
if value_changed == false | |
true | |
else | |
false | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ubiquity::AccountSettingsController < AdminController | |
layout 'dashboard' | |
before_action :set_account | |
def update | |
tenant = @account.cname | |
puts "dandy #{tenant}" | |
puts "david #{session[:ubiquity_super].inspect}" | |
puts "liro #{params['acct_id']}" | |
puts "sani #{@account.id}" | |
puts "lari #{@account.cname}" | |
puts "london #{account_params.to_h.inspect}" | |
##Apartment::Tenant.reset if params['switch_to'].present? | |
AccountElevator.switch!(params['cname']) | |
new_account = Account.find(params['acct_id'].to_i) | |
new_account.settings["index_record_to_shared_search"] = account_params.to_h['settings']["index_record_to_shared_search"] | |
new_account.save | |
puts "saro #{new_account.inspect}" | |
puts "lasu #{@account.id}" | |
puts "dani #{@account.cname}" | |
@account.update(account_params) | |
respond_to do |format| | |
format.html {redirect_to admin_account_settings_path} | |
puts "vani" | |
format.json {render json: {account: @account} } | |
end | |
Apartment::Tenant.reset if session[:ubiquity_super].present? | |
end | |
def set_account | |
@account = current_account | |
end | |
def account_params | |
params.require(:account).permit(:settings => [:contact_email, :index_record_to_shared_search, weekly_email_list: [], | |
monthly_email_list: [], yearly_email_list: []]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= render 'ubiquity/superadmin_sessions/shared_search_dropdown', account: @account %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>AccountSettings#index</h1> | |
<p>Find me in app/views/account_settings/index.html.erb</p> | |
<%= @company.name %> | |
- contact_email <%= @company.contact_email %> <br/> | |
- weekly email <% @company.weekly_email.each do |record| %> | |
<%= record %> | |
<% end %> | |
<%= link_to 'edit settings', edit_account_setting_path(@company) %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment