added show page and other stuff

This commit is contained in:
Harry Bomrah 2017-05-26 00:35:05 +08:00
parent 4ca382009b
commit 56cfee7841
7 changed files with 95 additions and 30 deletions

View File

@ -3,6 +3,67 @@ class MemberCounselorsController < CUserController
before_filter :is_user_authorized?, :only => ["show"]
def index
idx = 0
cities = HpsCity.all.collect do |city|
total = 0
idx = idx + 1
schools = city.hps_schools.collect do |school|
count = HpsMember.where(:hps_school_id => school.id.to_s).count
total = count + total
{
"name" => school.name,
"url_to_show" => OrbitHelper.url_to_show(school.to_param) + "?method=proposals",
"count" => count
}
end
{
"name" => city.name,
"total" => total,
"id" => "tab#{idx}",
"schools" => schools
}
end
{
"cities" => cities,
"extras" => {}
}
end
def proposals
params = OrbitHelper.params
school = HpsSchool.where(:uid => params[:uid]).first
members = HpsMember.where(:hps_school_id => school.id.to_s)
page = Page.where(:page_id => params[:page_id]).first
files = []
members.each do |member|
member.hps_files.each do |file|
files << {
"title" => file.title,
"download_count" => file.download_count,
"url" => "/cuser/download?file_id=#{file.id.to_s}"
}
end
end
{
"files" => files,
"data" => {
"back-url" => "/" + I18n.locale.to_s + page.url
}
}
end
def download
file_id = params[:file_id]
file = HpsFile.find(file_id) rescue nil
if !file.nil?
file.download_count = file.download_count + 1
file.save
redirect_to file.file.url and return
end
render :nothing => true
end
def login
if !current_counselor_user.nil?
redirect_to member_dash_path(current_counselor_user.account)
end

View File

@ -1,9 +1,10 @@
class HpsSchool
include Mongoid::Document
include Mongoid::Timestamps
include Slug
field :old_id
field :name
field :name, as: :slug_title
field :address
field :telephone
field :land

View File

@ -31,9 +31,9 @@
<% if @hpsfile.new_record? %>
<% case current_counselor_user.user_type %>
<% when 0 %>
<div id="year-span">中正區 國立臺北商業技術學院 <span>105</span>推動計劃書</div>
<input type="hidden" id="hps_file_title" name="hps_file[title]" value="中正區 國立臺北商業技術學院 105推動計劃書">
<% title = HpsCity.find(current_counselor_user.hps_city_id).name + " " + HpsCounty.find(current_counselor_user.hps_county_id).name + " " + HpsSchool.find(current_counselor_user.hps_school_id).name %>
<div id="year-span"><%= title %> <span>105</span>推動計劃書</div>
<input type="hidden" id="hps_file_title" name="hps_file[title]" value="<%= title %> 105推動計劃書">
<% when 1 %>
<div id="year-span"><span>105</span>健康促進縣市推動計劃書</div>
<input type="hidden" id="hps_file_title" name="hps_file[title]" value="105健康促進縣市推動計劃書">

View File

@ -1,25 +1 @@
<%#= csrf_meta_tag %>
<% if params[:error] == "invld" %>
<div>Invalid username or password.</div>
<% end %>
<% if params[:error] == "dsbld" %>
<div>Your account is disabled.</div>
<% end %>
<form action="/cuser/member_counselor/login" method="post">
<div>
<label for="username">Account</label>
<input type="text" name="username" id="username" />
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" id="password" />
</div>
<div>
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<input type="submit" value="Submit" />
</div>
</form>
<%= render_view %>

View File

@ -0,0 +1,25 @@
<%#= csrf_meta_tag %>
<% if params[:error] == "invld" %>
<div>Invalid username or password.</div>
<% end %>
<% if params[:error] == "dsbld" %>
<div>Your account is disabled.</div>
<% end %>
<form action="/cuser/member_counselor/login" method="post">
<div>
<label for="username">Account</label>
<input type="text" name="username" id="username" />
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" id="password" />
</div>
<div>
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
<input type="submit" value="Submit" />
</div>
</form>

View File

@ -0,0 +1 @@
<%= render_view %>

View File

@ -14,7 +14,8 @@ Rails.application.routes.draw do
end
end
scope "cuser" do
get "/member_login", to: "member_counselors#index", as: "member_login"
get "download", to: "member_counselors#download"
get "/member_login", to: "member_counselors#login", as: "member_login"
get "/member/fileupload", to: "member_counselors#fileupload", as: "upload_cuser_file"
get "/member/:id/editfileupload", to: "member_counselors#editfileupload", as: "edit_upload_cuser_file"
delete "/member/:id/deletefileupload", to: "member_counselors#deletefileupload", as: "delete_upload_cuser_file"