Skip to content

Commit

Permalink
Editing of app settings in Admin Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
reddragon committed Aug 7, 2010
1 parent 79637e3 commit 19a886b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 47 deletions.
33 changes: 29 additions & 4 deletions app/controllers/dashboard_controller.rb
Expand Up @@ -18,10 +18,6 @@
class DashboardController < ApplicationController

def index
output = File.new("#{RAILS_ROOT}/config/prefs.yml", 'w+')
output.puts YAML.dump(APP_CONFIG)
output.close
puts APP_CONFIG['timeframes']
end

def dashboard_links
Expand Down Expand Up @@ -179,4 +175,33 @@ def file_upload(upload, directory, name, operand)
# write the file
File.open(path, "wb") { |f| f.write(upload[operand].read) }
end

def edit_app_settings
@main = params[:main]
@sub = params[:sub]
@value = APP_CONFIG[@main][@sub]
render :partial => "edit_settings"
end

def update_app_settings
if params[:main] == "fsoc" and params[:sub] == "mode"
if params[:value] == "summer_coding"
date_params = [ "pct_from", "pct_to", "pst_from", "pst_to", "pat_from",\
"pat_to", "csd_on", "met_from", "met_to", "ced_on", "fet_from", "fet_to" ]

date_params.each do |dp|
APP_CONFIG['timeframes'][dp] = DateTime::now
end
else
APP_CONFIG['timeframes']['set'] = false
end
end
APP_CONFIG[params[:main]][params[:sub]] = params[:value]
output = File.new("#{RAILS_ROOT}/config/app_settings.yml", 'w+')
output.puts YAML.dump(APP_CONFIG)
output.close

flash[:notice] = 'Settings successfully updated'
redirect_to :controller => "dashboard"
end
end
11 changes: 11 additions & 0 deletions app/views/dashboard/_edit_settings.html.haml
@@ -0,0 +1,11 @@
%tr
%td
%b
Edit
= @sub.titleize
%tr
%td
- form_tag(:action => "update_app_settings", :main => @main, :sub => @sub) do
= text_field_tag "value", APP_CONFIG[@main][@sub]
&nbsp;
= submit_tag 'Update'
2 changes: 1 addition & 1 deletion app/views/dashboard/certificates.html.haml
Expand Up @@ -52,7 +52,7 @@
%p.links
- if admin?
- if can_configure?
= link_to 'Configure', :controller => "dashboard", :action => "configure"
= link_to 'Configure Timeframes', :controller => "dashboard", :action => "configure"
&nbsp;|&nbsp;
= link_to 'Certificates', :controller => "dashboard", :action => "certificates"

Expand Down
2 changes: 1 addition & 1 deletion app/views/dashboard/configure.html.haml
Expand Up @@ -132,6 +132,6 @@
%p.links
- if admin?
- if can_configure?
= link_to 'Configure', :controller => "dashboard", :action => "configure"
= link_to 'Configure Timeframes', :controller => "dashboard", :action => "configure"
&nbsp;|&nbsp;
= link_to 'Certificates', :controller => "dashboard", :action => "certificates"
39 changes: 29 additions & 10 deletions app/views/dashboard/index.html.haml
Expand Up @@ -15,6 +15,7 @@
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#++
= javascript_include_tag :defaults

.post
%h2.title
Expand All @@ -39,7 +40,7 @@
%div{:id => 'dashboard_content'}
- if admin?
%h3
FSoC Settings
FSoC Settings
%br
%h3
Program
Expand All @@ -56,21 +57,30 @@
%td
= APP_CONFIG['program']['name']
%td
- # Edit
= link_to_remote 'Edit', :update => "edit_program_name", :url => {:action => 'edit_app_settings', :main => "program", :sub => "name" }
%tr
%td
%div{:id => "edit_program_name"}
%tr
%td
Name Abbreviation
%td
= APP_CONFIG['program']['name_abbreviation']
%td
- # Edit
= link_to_remote 'Edit', :update => "edit_program_name_abbreviation", :url => {:action => 'edit_app_settings', :main => "program", :sub => "name_abbreviation" }
%tr
%td
%div{:id => "edit_program_name_abbreviation"}
%tr
%td
Year
Edition
%td
= APP_CONFIG['program']['edition']
%td
= APP_CONFIG['program']['year']
= link_to_remote 'Edit', :update => "edit_program_edition", :url => {:action => 'edit_app_settings', :main => "program", :sub => "edition" }
%tr
%td
- # Edit
%div{:id => "edit_program_edition"}

%br
%h3
Expand All @@ -88,14 +98,20 @@
%td
= APP_CONFIG['admin']['name']
%td
- # Edit
= link_to_remote 'Edit', :update => "edit_admin_name", :url => {:action => 'edit_app_settings', :main => "admin", :sub => "name" }
%tr
%td
%div{:id => "edit_admin_name"}
%tr
%td
Designation
%td
= APP_CONFIG['admin']['designation']
%td
- # Edit
= link_to_remote 'Edit', :update => "edit_admin_designation", :url => {:action => 'edit_app_settings', :main => "admin", :sub => "designation" }
%tr
%td
%div{:id => "edit_admin_designation"}

%br
%h3
Expand All @@ -113,7 +129,10 @@
%td
= APP_CONFIG['fsoc']['mode']
%td
- # Edit
= link_to_remote 'Edit', :update => "edit_fsoc_mode", :url => {:action => 'edit_app_settings', :main => "fsoc", :sub => "mode" }
%tr
%td
%div{:id => "edit_fsoc_mode"}


- if mentor?(current_user)
Expand Down Expand Up @@ -182,7 +201,7 @@
= link_to 'Project Task Status', :controller => "dashboard", :action => "task_status"
- if admin?
- if can_configure?
= link_to 'Configure', :controller => "dashboard", :action => "configure"
= link_to 'Configure Timeframes', :controller => "dashboard", :action => "configure"
&nbsp;|&nbsp;
= link_to 'Certificates', :controller => "dashboard", :action => "certificates"

2 changes: 1 addition & 1 deletion app/views/dashboard/task_status.html.haml
Expand Up @@ -137,6 +137,6 @@
&nbsp;|&nbsp;
= link_to 'Project Task Status', :controller => "dashboard", :action => "task_status"
- if admin?
= link_to 'Configure', :controller => "dashboard", :action => "configure"
= link_to 'Configure Timeframes', :controller => "dashboard", :action => "configure"
&nbsp;|&nbsp;
= link_to 'Certificates', :controller => "dashboard", :action => "certificates"
2 changes: 1 addition & 1 deletion app/views/proposals/certificate.pdf.prawn
Expand Up @@ -39,7 +39,7 @@ require "prawn/core"
pdf.text "For successfully completing the project\n\
#{@proposal.project.name}", \
:align => :center, :size => 20
pdf.text "in the #{APP_CONFIG['program']['name']} #{APP_CONFIG['program']['year']} program.", \
pdf.text "in the #{APP_CONFIG['program']['name']} #{APP_CONFIG['program']['edition']} program.", \
:align => :center, :size => 20

#pdf.move_down 80
Expand Down
4 changes: 2 additions & 2 deletions config/app_settings.yml
@@ -1,6 +1,6 @@
---
timeframes:
set:false
set: false
admin:
name: Abc Xyz
designation: Program Administrator
Expand All @@ -12,4 +12,4 @@ fsoc:
program:
name: Four Seasons of Code
name_abbreviation: FSoC
year: 2010
edition: "2010"
27 changes: 0 additions & 27 deletions config/prefs.yml

This file was deleted.

0 comments on commit 19a886b

Please sign in to comment.