Dmitry Yu Okunev лет назад: 7
Родитель
Сommit
fc9f900729

+ 3 - 0
app/assets/javascripts/people.coffee

@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/

+ 3 - 0
app/assets/stylesheets/people.scss

@@ -0,0 +1,3 @@
+// Place all the styles related to the People controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/

+ 15 - 7
app/controllers/memo_controller.rb

@@ -1,4 +1,4 @@
-class MemoController < ApplicationController
+class PeopleController < ApplicationController
 	protect_from_forgery
 
 	before_filter :common
@@ -14,20 +14,28 @@ class MemoController < ApplicationController
 			session[:cas] = session[:cas].with_indifferent_access
 		end
 		if session[:cas].nil? || session[:cas][:user].nil? #|| (session[:cas][:last_validated_at].blank? || session[:cas][:last_validated_at] < 15.minutes.ago)
-			if not params[:anonymous].nil? and params[:anonymous] == "true"
-				return
-			end
-
-			redirect_to "https://login.mephi.ru/login?allow_anonymous=true&service=#{url_for(:only_path => false)}"
+			redirect_to "https://login.mephi.ru/login?service=#{url_for(:only_path => false)}"
 		end
 		@user = session[:cas]
 
 	end
 
 	def index
-		@requestTypes = RequestType.all
+		@people = Person.search(params[:search])
 	end
 
 	def show
 	end
+
+	def download
+		require 'net/http'
+
+		url = URI.parse("https://cps.mephi.ru/?cmd=fixok_people&apiKey=#{Rails.application.config.cps_api_key}")
+		http = Net::HTTP.new(url.host, url.port)
+		http.use_ssl = true
+		reply = http.get(url.request_uri)
+
+		json = ActiveSupport::JSON.decode(reply.body)
+		puts "#{json.to_yaml}"
+	end
 end

+ 2 - 0
app/helpers/people_helper.rb

@@ -0,0 +1,2 @@
+module PeopleHelper
+end

+ 9 - 0
app/models/person.rb

@@ -0,0 +1,9 @@
+class Person < ApplicationRecord
+	def self.search(search)
+		if search
+			where('lastname LIKE ?', "%#{search}%")
+		else
+			all
+		end
+	end
+end

+ 2 - 2
app/views/layouts/application.html.erb

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 	<html>
 	<head>
-		<title>Отправить запрос</title>
+		<title>Соответствие: ОК &lt;-&gt; ОФЗ</title>
 		<meta name="viewport" content="width=device-width">
 		<%= csrf_meta_tags %>
 
@@ -26,7 +26,7 @@
 		</div>
 
 		<div id='footer'>
-			<a href='tel:84957885699,9999'>Техническая поддержка: +7&nbsp;(495)&nbsp;788&#8209;56&#8209;99, доб.&nbsp;9999</a>
+			<a href='mailto:dyokunev@mephi.ru'>Техническая поддержка: dyokunev@mephi.ru</a>
 		</div>
 	</body>
 </html>

+ 0 - 1
app/views/memo/_request_type.html.erb

@@ -1 +0,0 @@
-<li><%= @requestType.title %></li>

+ 0 - 6
app/views/memo/index.html.erb

@@ -1,6 +0,0 @@
-<h1><%= t 'request_type' %></h1>
-<ul>
-	<% @requestTypes.each do |@requestType| %>
-		<%= render "request_type" %>
-	<% end %>
-</ul>

app/views/memo/show.html.erb → app/views/people/download.html.erb


+ 12 - 0
app/views/people/index.html.erb

@@ -0,0 +1,12 @@
+<%= form_tag people_index_path, :method => 'get' do %>
+	<p>
+		<%= text_field_tag :lastname, params[:lastname], :placeholder => t(:lastname) %>
+		<%= submit_tag t :search, :name => nil %>
+	</p>
+<% end %>
+
+<table>
+	<% @people.each do |person| -%>
+		<tr><td><%= person.Id %></td><td><%= person.Lastname %></td><td><%= person.Firstname %></td><td><%= person.Patronymic %></td></tr>
+	<% end -%>
+</table>

+ 4 - 2
config/application.rb-sample

@@ -21,7 +21,9 @@ module Request
 		config.rack_cas.protocol = 'p3'
 		require 'rack-cas/session_store/active_record'
 		config.rack_cas.session_store = RackCAS::ActiveRecordStore
-		require 'rack-cas/session-store/rack/active_record'
-		use Rack::Session::RackCASActiveRecordStore
+		#require 'rack-cas/session-store/rack/active_record'
+		#use Rack::Session::RackCASActiveRecordStore
+
+		config.cps_api_key = 'SoMe_SeCrEt_KeY'
 	end
 end

+ 2 - 0
config/locales/en.yml

@@ -2,3 +2,5 @@ en:
  request_type: "Request type"
  auth_required: "Authentication is required…"
  anonymous: "Anonymous"
+ lastname: "Lastname"
+ search: "Search"

+ 2 - 0
config/locales/ru.yml

@@ -2,3 +2,5 @@ ru:
  request_type: "Тип заявки"
  auth_required: "Требуется авторизация…"
  anonymous: "Аноним"
+ lastname: "Фамилия"
+ search: "Поиск"

+ 5 - 3
config/routes.rb

@@ -1,7 +1,9 @@
 Rails.application.routes.draw do
-	get 'memo/index'
-	get 'memo/:id', to: 'memo#show'
+	get 'people/index'
+	get 'people/download'
 
-	root 'memo#index'
+	get 'people/:id', to: 'people#show'
+
+	root 'people#index'
 	# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
 end

+ 14 - 0
db/migrate/20161102141008_create_people.rb

@@ -0,0 +1,14 @@
+class CreatePeople < ActiveRecord::Migration[5.0]
+  def change
+    create_table :people do |t|
+      t.string :Firstname
+      t.string :Lastname
+      t.string :Patronymic
+      t.integer :PassId
+      t.string :Description
+      t.date :DateOfBirth
+
+      t.timestamps
+    end
+  end
+end

+ 12 - 1
db/schema.rb

@@ -10,7 +10,18 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20161012183128) do
+ActiveRecord::Schema.define(version: 20161102141008) do
+
+  create_table "people", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1" do |t|
+    t.string   "Firstname"
+    t.string   "Lastname"
+    t.string   "Patronymic"
+    t.integer  "PassId"
+    t.string   "Description"
+    t.date     "DateOfBirth"
+    t.datetime "created_at",  null: false
+    t.datetime "updated_at",  null: false
+  end
 
   create_table "sessions", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
     t.string   "session_id",               null: false

+ 7 - 0
test/controllers/people_controller_test.rb

@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PeopleControllerTest < ActionDispatch::IntegrationTest
+  # test "the truth" do
+  #   assert true
+  # end
+end

+ 17 - 0
test/fixtures/people.yml

@@ -0,0 +1,17 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+  Firstname: MyString
+  Lastname: MyString
+  Patronymic: MyString
+  PassId: 1
+  Description: MyString
+  DateOfBirth: 2016-11-02
+
+two:
+  Firstname: MyString
+  Lastname: MyString
+  Patronymic: MyString
+  PassId: 1
+  Description: MyString
+  DateOfBirth: 2016-11-02

+ 7 - 0
test/models/person_test.rb

@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PersonTest < ActiveSupport::TestCase
+  # test "the truth" do
+  #   assert true
+  # end
+end